mirror of
https://github.com/directus/directus.git
synced 2026-01-23 02:18:00 -05:00
Allow for nested fields in sidebar filter (#4723)
* allow for nested fields in sidebar filter * remove duplicate code and fix deep search
This commit is contained in:
@@ -233,6 +233,9 @@ export const useFieldsStore = createStore({
|
||||
else return 1;
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Retrieve field info for a field or a related field
|
||||
*/
|
||||
getField(collection: string, fieldKey: string) {
|
||||
if (fieldKey.includes('.')) {
|
||||
return this.getRelationalField(collection, fieldKey);
|
||||
@@ -249,13 +252,13 @@ export const useFieldsStore = createStore({
|
||||
const relationshipStore = useRelationsStore();
|
||||
const parts = fields.split('.');
|
||||
|
||||
const relationshipForField = relationshipStore
|
||||
const relation = relationshipStore
|
||||
.getRelationsForField(collection, parts[0])
|
||||
?.find((relation: Relation) => relation.many_field === parts[0] || relation.one_field === parts[0]);
|
||||
?.find((relation: Relation) => relation.many_field === parts[0] || relation.one_field === parts[0]) as Relation;
|
||||
|
||||
if (relationshipForField === undefined) return false;
|
||||
if (relation === undefined) return false;
|
||||
|
||||
const relatedCollection = relationshipForField.one_collection;
|
||||
const relatedCollection = relation.many_field === parts[0] ? relation.one_collection : relation.many_collection;
|
||||
parts.shift();
|
||||
const relatedField = parts.join('.');
|
||||
return this.getField(relatedCollection, relatedField);
|
||||
|
||||
Reference in New Issue
Block a user