Skip to content

Commit

Permalink
fix: Internal classes _User, _Role, _Installation referenced wi…
Browse files Browse the repository at this point in the history
…th pointer don't appear in data browser filter dialog (#2599)
  • Loading branch information
gutembergsa authored Sep 25, 2024
1 parent b7565c2 commit 8239cc8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
31 changes: 21 additions & 10 deletions src/lib/Filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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'];
Expand Down
23 changes: 13 additions & 10 deletions src/lib/queryFromFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
})
);
Expand Down

0 comments on commit 8239cc8

Please sign in to comment.