Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Internal classes _User, _Role, _Installation referenced with pointer don't appear in data browser filter dialog #2599

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading