From 75ef962bb824f651c4b1bfff05167179437d05ae Mon Sep 17 00:00:00 2001 From: Emmy Leke Date: Wed, 5 Jul 2023 16:53:03 +0100 Subject: [PATCH] Add new select types to Select field --- .../ModuleFields/Configurator/Record.vue | 56 ++++++++++-------- .../ModuleFields/Configurator/Select.vue | 48 +++++++++++---- .../ModuleFields/Configurator/User.vue | 58 +++++++++++-------- .../components/ModuleFields/Editor/Select.vue | 23 +++++++- locale/en/corteza-webapp-compose/field.yaml | 4 +- 5 files changed, 130 insertions(+), 59 deletions(-) diff --git a/client/web/compose/src/components/ModuleFields/Configurator/Record.vue b/client/web/compose/src/components/ModuleFields/Configurator/Record.vue index 81c062817..bc0c52a2e 100644 --- a/client/web/compose/src/components/ModuleFields/Configurator/Record.vue +++ b/client/web/compose/src/components/ModuleFields/Configurator/Record.vue @@ -69,26 +69,28 @@ - - - + - {{ $t('kind.select.allow-duplicates') }} - - + + + + + + {{ $t('kind.select.allow-duplicates') }} + + + @@ -108,9 +110,9 @@ export default { return { selected: null, selectOptions: [ - { text: this.$t('kind.select.optionType.default'), value: 'default' }, + { text: this.$t('kind.select.optionType.default'), value: 'default', allowDuplicates: true }, { text: this.$t('kind.select.optionType.multiple'), value: 'multiple' }, - { text: this.$t('kind.select.optionType.each'), value: 'each' }, + { text: this.$t('kind.select.optionType.each'), value: 'each', allowDuplicates: true }, ], } }, @@ -204,6 +206,13 @@ export default { labelFieldQueryOptions () { return this.labelFieldOptions.filter(({ name }) => name !== this.field.options.recordLabelField) }, + + shouldAllowDuplicates () { + if (!this.f.isMulti) return false + + const { allowDuplicates } = this.selectOptions.find(({ value }) => value === this.f.options.selectType) || {} + return !!allowDuplicates + }, }, watch: { @@ -215,8 +224,9 @@ export default { }, methods: { - onUpdateIsUniqueMultiValue () { - if (this.f.options.selectType === 'multiple') { + updateIsUniqueMultiValue (value) { + const { allowDuplicates = false } = this.selectOptions.find(({ value: v }) => v === value) || {} + if (!allowDuplicates) { this.f.options.isUniqueMultiValue = true } }, diff --git a/client/web/compose/src/components/ModuleFields/Configurator/Select.vue b/client/web/compose/src/components/ModuleFields/Configurator/Select.vue index 74f20461a..964eb6263 100644 --- a/client/web/compose/src/components/ModuleFields/Configurator/Select.vue +++ b/client/web/compose/src/components/ModuleFields/Configurator/Select.vue @@ -108,21 +108,21 @@ - + + + {{ $t('kind.select.allow-duplicates') }} @@ -152,10 +152,12 @@ export default { data () { return { newOption: { value: undefined, text: undefined, new: true }, - selectOptions: [ - { text: this.$t('kind.select.optionType.default'), value: 'default' }, - { text: this.$t('kind.select.optionType.multiple'), value: 'multiple' }, - { text: this.$t('kind.select.optionType.each'), value: 'each' }, + + options: [ + { text: this.$t('kind.select.optionType.default'), value: 'default', allowDuplicates: true }, + { text: this.$t('kind.select.optionType.multiple'), value: 'multiple', onlyMulti: true }, + { text: this.$t('kind.select.optionType.each'), value: 'each', allowDuplicates: true, onlyMulti: true }, + { value: 'list' }, ], } }, @@ -184,6 +186,29 @@ export default { isNew () { return this.module.moduleID === NoID || this.field.fieldID === NoID }, + + selectOptions () { + const selectOptions = this.options.map((o) => { + if (o.value === 'list') { + o.text = this.$t(`kind.select.optionType.${this.f.isMulti ? 'checkbox' : 'radio'}`) + } + + return o + }) + + if (this.f.isMulti) { + return selectOptions + } + + return selectOptions.filter(({ onlyMulti }) => !onlyMulti) + }, + + shouldAllowDuplicates () { + if (!this.f.isMulti) return false + + const { allowDuplicates } = this.options.find(({ value }) => value === this.f.options.selectType) || {} + return !!allowDuplicates + }, }, created () { @@ -203,8 +228,9 @@ export default { }) }, - onUpdateIsUniqueMultiValue () { - if (this.f.options.selectType === 'multiple') { + updateIsUniqueMultiValue (value) { + const { allowDuplicates = false } = this.options.find(({ value: v }) => v === value) || {} + if (!allowDuplicates) { this.f.options.isUniqueMultiValue = true } }, diff --git a/client/web/compose/src/components/ModuleFields/Configurator/User.vue b/client/web/compose/src/components/ModuleFields/Configurator/User.vue index cf0649a96..e49f5e6f7 100644 --- a/client/web/compose/src/components/ModuleFields/Configurator/User.vue +++ b/client/web/compose/src/components/ModuleFields/Configurator/User.vue @@ -27,26 +27,28 @@ /> - - - - + - {{ $t('kind.select.allow-duplicates') }} - - + + + + + + {{ $t('kind.select.allow-duplicates') }} + + + @@ -68,14 +70,23 @@ export default { data () { return { selectOptions: [ - { text: this.$t('kind.select.optionType.default'), value: 'default' }, + { text: this.$t('kind.select.optionType.default'), value: 'default', allowDuplicates: true }, { text: this.$t('kind.select.optionType.multiple'), value: 'multiple' }, - { text: this.$t('kind.select.optionType.each'), value: 'each' }, + { text: this.$t('kind.select.optionType.each'), value: 'each', allowDuplicates: true }, ], roleOptions: [], } }, + computed: { + shouldAllowDuplicates () { + if (!this.f.isMulti) return false + + const { allowDuplicates } = this.selectOptions.find(({ value }) => value === this.f.options.selectType) || {} + return !!allowDuplicates + }, + }, + mounted () { this.$SystemAPI.roleList().then(({ set: roles = [] }) => { this.roleOptions = roles @@ -87,8 +98,9 @@ export default { return roleID }, - onUpdateIsUniqueMultiValue () { - if (this.f.options.selectType === 'multiple') { + updateIsUniqueMultiValue (value) { + const { allowDuplicates = false } = this.selectOptions.find(({ value: v }) => v === value) || {} + if (!allowDuplicates) { this.f.options.isUniqueMultiValue = true } }, diff --git a/client/web/compose/src/components/ModuleFields/Editor/Select.vue b/client/web/compose/src/components/ModuleFields/Editor/Select.vue index df5030f53..f64dca4c4 100644 --- a/client/web/compose/src/components/ModuleFields/Editor/Select.vue +++ b/client/web/compose/src/components/ModuleFields/Editor/Select.vue @@ -25,7 +25,16 @@ + + + {{ findLabel(value[ctx.index]) }} @@ -78,6 +90,7 @@ v-else > @@ -87,6 +100,14 @@ + + + @@ -107,7 +128,7 @@ export default { const disabled = o.value && this.field.isMulti && !this.field.options.isUniqueMultiValue ? this.value === o.value : (this.value || []).includes(o.value) - return { ...o, disabled } + return { ...o, disabled: this.field.options.selectType !== 'list' && disabled } }).filter(({ value = '', text = '' }) => value && text) }, }, diff --git a/locale/en/corteza-webapp-compose/field.yaml b/locale/en/corteza-webapp-compose/field.yaml index 341d8d292..2819511e8 100644 --- a/locale/en/corteza-webapp-compose/field.yaml +++ b/locale/en/corteza-webapp-compose/field.yaml @@ -119,8 +119,10 @@ kind: optionType: default: Single input each: Input for each value - label: Multiple value input type + label: Select type multiple: Multiple select + checkbox: Checkbox Group + radio: Radio Group optionValuePlaceholder: Value optionsLabel: Options to select from placeholder: Select an option by clicking here