Skip to content

Commit 9365718

Browse files
committed
move multiselect field to filterOption
1 parent 9a5d34c commit 9365718

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

adminforth/modules/configValidator.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,9 @@ export default class ConfigValidator implements IConfigValidator {
454454
debounceTimeMs: 10,
455455
substringSearch: true,
456456
};
457+
if (col.enum || col.foreignResource) {
458+
col.filterOptions.multiselect = true;
459+
}
457460
} else {
458461
if (col.filterOptions.debounceTimeMs !== undefined) {
459462
if (typeof col.filterOptions.debounceTimeMs !== 'number') {
@@ -470,6 +473,18 @@ export default class ConfigValidator implements IConfigValidator {
470473
} else {
471474
col.filterOptions.substringSearch = true;
472475
}
476+
477+
if (col.filterOptions.multiselect !== undefined) {
478+
if (typeof col.filterOptions.multiselect !== 'boolean') {
479+
errors.push(`Resource "${res.resourceId}" column "${col.name}" has multiselectFilter in filterOptions that is not boolean`);
480+
}
481+
482+
if (!col.enum && !col.foreignResource) {
483+
errors.push(`Resource "${res.resourceId}" column "${col.name}" multiselectFilter in filterOptions should be set only for enum or foreign resource columns`);
484+
}
485+
} else if (col.enum || col.foreignResource) {
486+
col.filterOptions.multiselect = true;
487+
}
473488
}
474489

475490
col.showIn = this.validateAndNormalizeShowIn(resInput, inCol, errors, warnings);
@@ -664,18 +679,6 @@ export default class ConfigValidator implements IConfigValidator {
664679
}
665680
}
666681

667-
if (col.multiselectFilter !== undefined) {
668-
if (typeof col.multiselectFilter !== 'boolean') {
669-
errors.push(`Resource "${res.resourceId}" column "${col.name}" has multiselectFilter that is not boolean`);
670-
}
671-
672-
if (!col.enum && !col.foreignResource) {
673-
errors.push(`Resource "${res.resourceId}" column "${col.name}" multiselectFilter should be set only for enum or foreign resource columns`);
674-
}
675-
} else if (col.enum || col.foreignResource) {
676-
col.multiselectFilter = true;
677-
}
678-
679682
if (inCol.inputPrefix || inCol.inputSuffix) {
680683
if (![AdminForthDataTypes.DECIMAL, AdminForthDataTypes.FLOAT, AdminForthDataTypes.INTEGER, AdminForthDataTypes.STRING, undefined].includes(col.type)) {
681684
if (inCol.type === AdminForthDataTypes.JSON) {

adminforth/spa/src/components/Filters.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424

2525
<Select
2626
v-if="c.foreignResource"
27-
:multiple="c.multiselectFilter"
27+
:multiple="c.filterOptions.multiselect"
2828
class="w-full"
2929
:options="columnOptions[c.name] || []"
30-
@update:modelValue="onFilterInput[c.name]({ column: c, operator: c.multiselectFilter ? 'in' : 'eq', value: c.multiselectFilter ? ($event.length ? $event : undefined) : $event || undefined })"
31-
:modelValue="filtersStore.filters.find(f => f.field === c.name && f.operator === (c.multiselectFilter ? 'in' : 'eq'))?.value || []"
30+
@update:modelValue="onFilterInput[c.name]({ column: c, operator: c.filterOptions.multiselect ? 'in' : 'eq', value: c.filterOptions.multiselect ? ($event.length ? $event : undefined) : $event || undefined })"
31+
:modelValue="filtersStore.filters.find(f => f.field === c.name && f.operator === (c.filterOptions.multiselect ? 'in' : 'eq'))?.value || []"
3232
/>
3333
<Select
3434
multiple
@@ -45,12 +45,12 @@
4545
/>
4646

4747
<Select
48-
:multiple="c.multiselectFilter"
48+
:multiple="c.filterOptions.multiselect"
4949
class="w-full"
5050
v-else-if="c.enum"
5151
:options="c.enum"
52-
@update:modelValue="onFilterInput[c.name]({ column: c, operator: c.multiselectFilter ? 'in' : 'eq', value: c.multiselectFilter ? ($event.length ? $event : undefined) : $event || undefined })"
53-
:modelValue="filtersStore.filters.find(f => f.field === c.name && f.operator === (c.multiselectFilter ? 'in' : 'eq'))?.value || []"
52+
@update:modelValue="onFilterInput[c.name]({ column: c, operator: c.filterOptions.multiselect ? 'in' : 'eq', value: c.filterOptions.multiselect ? ($event.length ? $event : undefined) : $event || undefined })"
53+
:modelValue="filtersStore.filters.find(f => f.field === c.name && f.operator === (c.filterOptions.multiselect ? 'in' : 'eq'))?.value || []"
5454
/>
5555

5656
<Input
@@ -165,7 +165,7 @@ const columnOptions = computedAsync(async () => {
165165
},
166166
});
167167
ret[column.name] = list.items;
168-
if (!column.multiselectFilter) {
168+
if (!column.filterOptions.multiselect) {
169169
ret[column.name].push({
170170
label: t('Unset'),
171171
value: '',

adminforth/types/Common.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -803,11 +803,6 @@ export interface AdminForthResourceColumnInputCommon {
803803
*/
804804
foreignResource?: AdminForthForeignResourceCommon,
805805

806-
/**
807-
* Boolean value that determines what select input type to display on filter page.
808-
*/
809-
multiselectFilter?: boolean,
810-
811806
sortable?: boolean,
812807

813808

@@ -820,6 +815,10 @@ export interface AdminForthResourceColumnInputCommon {
820815
* If false - will force EQ operator for filter instead of ILIKE.
821816
*/
822817
substringSearch?: boolean,
818+
/**
819+
* Boolean value that determines what select input type to display on filter page.
820+
*/
821+
multiselect?: boolean,
823822
},
824823

825824
/**

0 commit comments

Comments
 (0)