From 8239cc8a05865c5f0b4f5b33dfb224e87d25a319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gutemberg=20S=C3=A1?= <41520256+gutembergsa@users.noreply.github.com> Date: Tue, 24 Sep 2024 22:07:39 -0300 Subject: [PATCH] fix: Internal classes `_User`, `_Role`, `_Installation` referenced with pointer don't appear in data browser filter dialog (#2599) --- src/lib/Filters.js | 31 +++++++++++++++++++++---------- src/lib/queryFromFilters.js | 23 +++++++++++++---------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/lib/Filters.js b/src/lib/Filters.js index 9b394e467d..fe0013938c 100644 --- a/src/lib/Filters.js +++ b/src/lib/Filters.js @@ -233,7 +233,7 @@ export function availableFilters(schema, currentFilters, blacklist) { return available; } -export function findRelatedClasses(referClass , allClasses, blacklist, currentFilters) { +export function findRelatedClasses(referClass, allClasses, blacklist, currentFilters) { const relatedClasses = {}; if (allClasses[referClass]) { const availableForRefer = availableFilters(allClasses[referClass], currentFilters, blacklist); @@ -243,31 +243,42 @@ export function findRelatedClasses(referClass , allClasses, blacklist, currentFi } for (const className in allClasses) { - if (className === referClass){ + if (className === referClass) { continue; } - if (!checkRelation(referClass, allClasses[className])) { + if (!checkRelation(referClass, allClasses, className)) { continue; } + const schema = allClasses[className]; const available = availableFilters(schema, currentFilters, blacklist); if (Object.keys(available).length > 0) { relatedClasses[className] = available; } } - return relatedClasses; } -function checkRelation(classname,schema){ - for (const col in schema) { - if (schema[col].type === 'Pointer' && schema[col].targetClass === classname) { - return true; +const checkRelationHelper = (schema, col, className) => + schema[col].type === 'Pointer' && schema[col].targetClass === className; + +function checkRelation(currentClassname, schemas, classToReferName) { + const currentClassSchema = schemas[currentClassname]; + const classSchemaBeingCheckedToRefer = schemas[classToReferName]; + let flag = false; + + for (const col in currentClassSchema) { + if (checkRelationHelper(currentClassSchema, col, classToReferName)) { + flag = true; } } - return false; - + for (const col in classSchemaBeingCheckedToRefer) { + if (checkRelationHelper(classSchemaBeingCheckedToRefer, col, currentClassname)) { + flag = true; + } + } + return flag; } export const BLACKLISTED_FILTERS = ['containsAny', 'doesNotContainAny']; diff --git a/src/lib/queryFromFilters.js b/src/lib/queryFromFilters.js index 17772cd831..047d69cad2 100644 --- a/src/lib/queryFromFilters.js +++ b/src/lib/queryFromFilters.js @@ -42,17 +42,20 @@ export default async function queryFromFilters(className, filters) { } const reversePointerField = getPointerField(allClassesSchema, filterClassName, className); const pointerField = getPointerField(allClassesSchema, className, filterClassName); - if (pointerField) { - tempquery.matchesQuery(pointerField, queries[filterClassName]); - } else if (reversePointerField) { - await tempquery.matchesKeyInQuery( - 'objectId', - `${reversePointerField}.objectId`, - queries[filterClassName] - ) - querieslist.push(tempquery); - } else { + if (!pointerField && !reversePointerField) { console.warn(`No relationship found between ${className} and ${filterClassName}`); + } else { + if (pointerField) { + tempquery.matchesQuery(pointerField, queries[filterClassName]); + } + if (!pointerField && reversePointerField) { + await tempquery.matchesKeyInQuery( + 'objectId', + `${reversePointerField}.objectId`, + queries[filterClassName] + ); + } + querieslist.push(tempquery); } }) );