Skip to content

Commit b5ccf42

Browse files
authored
Merge pull request #186 from devforth/fix-boolean-filter-singleselect
fix: add support for singleselect filter for boolean fields
2 parents 27483f2 + e37745d commit b5ccf42

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

adminforth/modules/configValidator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ export default class ConfigValidator implements IConfigValidator {
458458
debounceTimeMs: 10,
459459
substringSearch: true,
460460
};
461-
if (col.enum || col.foreignResource) {
461+
if (col.enum || col.foreignResource || col.type === AdminForthDataTypes.BOOLEAN) {
462462
col.filterOptions.multiselect = true;
463463
}
464464
} else {
@@ -483,8 +483,8 @@ export default class ConfigValidator implements IConfigValidator {
483483
errors.push(`Resource "${res.resourceId}" column "${col.name}" has multiselectFilter in filterOptions that is not boolean`);
484484
}
485485

486-
if (!col.enum && !col.foreignResource) {
487-
errors.push(`Resource "${res.resourceId}" column "${col.name}" multiselectFilter in filterOptions should be set only for enum or foreign resource columns`);
486+
if (!col.enum && !col.foreignResource && col.type !== AdminForthDataTypes.BOOLEAN) {
487+
errors.push(`Resource "${res.resourceId}" column "${col.name}" multiselectFilter in filterOptions should be set only for enum, foreign resource or boolean columns`);
488488
}
489489
} else if (col.enum || col.foreignResource) {
490490
col.filterOptions.multiselect = true;

adminforth/spa/src/components/Filters.vue

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
class="w-full"
2929
:options="columnOptions[c.name] || []"
3030
@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 || []"
31+
:modelValue="filtersStore.filters.find(f => f.field === c.name && f.operator === (c.filterOptions.multiselect ? 'in' : 'eq'))?.value || (c.filterOptions.multiselect ? [] : '')"
3232
/>
3333
<Select
34-
multiple
34+
:multiple="c.filterOptions.multiselect"
3535
class="w-full"
3636
v-else-if="c.type === 'boolean'"
3737
:options="[
@@ -40,8 +40,10 @@
4040
// if field is not required, undefined might be there, and user might want to filter by it
4141
...(c.required ? [] : [ { label: $t('Unset'), value: undefined } ])
4242
]"
43-
@update:modelValue="onFilterInput[c.name]({ column: c, operator: 'in', value: $event.length ? $event : undefined })"
44-
:modelValue="filtersStore.filters.find(f => f.field === c.name && f.operator === 'in')?.value || []"
43+
@update:modelValue="onFilterInput[c.name]({ column: c, operator: c.filterOptions.multiselect ? 'in' : 'eq', value: c.filterOptions.multiselect ? ($event.length ? $event : undefined) : $event })"
44+
:modelValue="filtersStore.filters.find(f => f.field === c.name && f.operator === (c.filterOptions.multiselect ? 'in' : 'eq'))?.value !== undefined
45+
? filtersStore.filters.find(f => f.field === c.name && f.operator === (c.filterOptions.multiselect ? 'in' : 'eq'))?.value
46+
: (c.filterOptions.multiselect ? [] : '')"
4547
/>
4648

4749
<Select
@@ -50,7 +52,7 @@
5052
v-else-if="c.enum"
5153
:options="c.enum"
5254
@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 || []"
55+
:modelValue="filtersStore.filters.find(f => f.field === c.name && f.operator === (c.filterOptions.multiselect ? 'in' : 'eq'))?.value || (c.filterOptions.multiselect ? [] : '')"
5456
/>
5557

5658
<Input
@@ -165,12 +167,6 @@ const columnOptions = computedAsync(async () => {
165167
},
166168
});
167169
ret[column.name] = list.items;
168-
if (!column.filterOptions.multiselect) {
169-
ret[column.name].push({
170-
label: t('Unset'),
171-
value: '',
172-
});
173-
}
174170
}
175171
})
176172
);

0 commit comments

Comments
 (0)