From 22d44b0eeb995391af7b793c6243b2161fd00647 Mon Sep 17 00:00:00 2001 From: Joana Maia Date: Tue, 7 Feb 2023 23:41:24 +0000 Subject: [PATCH 1/2] Fix filters for custom attributes --- .../member/member-array-attributes-field.js | 42 +++++++++++++++++++ frontend/src/modules/member/store/actions.js | 4 +- .../shared/fields/get-custom-attributes.js | 18 +++++--- 3 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 frontend/src/modules/member/member-array-attributes-field.js diff --git a/frontend/src/modules/member/member-array-attributes-field.js b/frontend/src/modules/member/member-array-attributes-field.js new file mode 100644 index 0000000000..7dbc7e6384 --- /dev/null +++ b/frontend/src/modules/member/member-array-attributes-field.js @@ -0,0 +1,42 @@ +import StringField from '@/shared/fields/string-field' + +export default class MemberArrayAttributesField extends StringField { + constructor(name, label, config = {}) { + super(name, label) + + this.placeholder = config.placeholder + this.hint = config.hint + this.required = config.required + this.matches = config.matches + this.filterable = config.filterable || false + this.custom = config.custom || false + this.options = config.options + } + + dropdownOptions() { + return this.options.sort((x, y) => { + return x.label < y.label + ? -1 + : x.label > y.label + ? 1 + : 0 + }) + } + + forFilter() { + return { + name: this.name, + label: this.label, + custom: this.custom, + props: { + options: this.dropdownOptions(), + multiple: true + }, + defaultValue: [], + value: [], + defaultOperator: 'contains', + operator: 'contains', + type: 'select-multi' + } + } +} diff --git a/frontend/src/modules/member/store/actions.js b/frontend/src/modules/member/store/actions.js index bc8b056c68..90084f707d 100644 --- a/frontend/src/modules/member/store/actions.js +++ b/frontend/src/modules/member/store/actions.js @@ -366,7 +366,7 @@ export default { } }, - async doBulkEnrich({ rootGetters }, ids) { + async doBulkEnrich({ rootGetters, dispatch }, ids) { try { const currentTenant = rootGetters['auth/currentTenant'] @@ -403,6 +403,8 @@ export default { showEnrichmentLoadingMessage({ isBulk: true }) await MemberService.enrichMemberBulk(ids) + + await dispatch('doFetchCustomAttributes') } catch (error) { Message.closeAll() Errors.handle(error) diff --git a/frontend/src/shared/fields/get-custom-attributes.js b/frontend/src/shared/fields/get-custom-attributes.js index 209e825271..cbabefa406 100644 --- a/frontend/src/shared/fields/get-custom-attributes.js +++ b/frontend/src/shared/fields/get-custom-attributes.js @@ -2,7 +2,7 @@ import StringField from '@/shared/fields/string-field' import BooleanField from '@/shared/fields/boolean-field' import IntegerField from '@/shared/fields/integer-field' import DateField from '@/shared/fields/date-field' -import ArrayField from '@/shared/fields/array-field' +import MemberArrayAttributesField from '@/modules/member/member-array-attributes-field' export default (customAttributes) => { return ( @@ -30,12 +30,20 @@ export default (customAttributes) => { ) case 'multiSelect': - case 'special': - return new ArrayField( + case 'special': { + const options = customAttributes[ + customAttribute.name + ].options.map((o) => ({ + value: o, + label: o + })) + + return new MemberArrayAttributesField( customAttribute.name, - customAttribute.label + customAttribute.label, + { options } ) - + } default: return new StringField( customAttribute.name, From 90f8076576be50cfb41ead71d5a98104804c22e1 Mon Sep 17 00:00:00 2001 From: Joana Maia Date: Wed, 8 Feb 2023 10:21:02 +0000 Subject: [PATCH 2/2] Fix filters without options --- .../shared/fields/get-custom-attributes.js | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/frontend/src/shared/fields/get-custom-attributes.js b/frontend/src/shared/fields/get-custom-attributes.js index cbabefa406..b0c7c632ed 100644 --- a/frontend/src/shared/fields/get-custom-attributes.js +++ b/frontend/src/shared/fields/get-custom-attributes.js @@ -7,7 +7,17 @@ import MemberArrayAttributesField from '@/modules/member/member-array-attributes export default (customAttributes) => { return ( Object.values(customAttributes) - .filter((a) => a.show) + .filter((a) => { + // Don't render special filters that do not have available options + if ( + a.type === 'multiSelect' || + a.type === 'special' + ) { + return a.options.length && a.show + } + + return a.show + }) .map((customAttribute) => { switch (customAttribute.type) { case 'boolean': @@ -31,12 +41,12 @@ export default (customAttributes) => { case 'multiSelect': case 'special': { - const options = customAttributes[ - customAttribute.name - ].options.map((o) => ({ - value: o, - label: o - })) + const options = customAttribute.options.map( + (o) => ({ + value: o, + label: o + }) + ) return new MemberArrayAttributesField( customAttribute.name,