From 805ea8ba2cbc16140de2c58d93045767695d9484 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Thu, 8 Apr 2021 22:51:37 +0200 Subject: [PATCH] Allow for nested fields in sidebar filter (#4723) * allow for nested fields in sidebar filter * remove duplicate code and fix deep search --- app/src/stores/fields.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/stores/fields.ts b/app/src/stores/fields.ts index 074cae5b98..2a71e91841 100644 --- a/app/src/stores/fields.ts +++ b/app/src/stores/fields.ts @@ -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);