Skip to content

Commit 8f11704

Browse files
author
NarrowsProjects
committed
feat: update radioFilterModel with defaultIsEmpty argument
1 parent 86eb3b7 commit 8f11704

2 files changed

Lines changed: 19 additions & 11 deletions

File tree

lib/public/components/Filters/common/RadioButtonFilterModel.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,24 @@ export class RadioButtonFilterModel extends SelectionModel {
2222
*
2323
* @param {SelectionOption[]} [availableOptions] the list of possible operators
2424
* @param {function} [setDefault] function that selects the default from the list of available options. Selects first entry by default
25+
* @param {boolean} [defaultIsEmpty] if true, the default selection will be treated as empty
2526
*/
26-
constructor(availableOptions, setDefault = (options) => [options[0]]) {
27+
constructor(availableOptions, setDefault = (options) => [options[0]], defaultIsEmpty = true) {
2728
super({
2829
availableOptions,
2930
defaultSelection: setDefault(availableOptions),
3031
multiple: false,
3132
allowEmpty: false,
3233
});
34+
35+
this._defaultIsEmpty = defaultIsEmpty;
36+
}
37+
38+
get isEmpty() {
39+
if (this._defaultIsEmpty) {
40+
return this.hasOnlyDefaultSelection();
41+
}
42+
43+
return false;
3344
}
3445
}

lib/public/components/Filters/common/filters/ToggleFilterModel.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ export class ToggleFilterModel extends SelectionModel {
1919
/**
2020
* Constructor
2121
* @param {boolean} toggledByDefault If the filter should be toggled by default
22-
* @param {boolean} falseIsEmpty if true, will treat false as empty.
22+
* @param {boolean} untoggledIsEmpty if true, will treat the untoggled state (false) as empty.
2323
*/
24-
constructor(toggledByDefault = false, falseIsEmpty = false) {
24+
constructor(toggledByDefault = false, untoggledIsEmpty = false) {
2525
super({
2626
availableOptions: [{ value: true }, { value: false }],
2727
defaultSelection: [{ value: toggledByDefault }],
2828
multiple: false,
2929
allowEmpty: false,
3030
});
3131

32-
this._falseIsEmpty = falseIsEmpty;
32+
this._untoggledIsEmpty = untoggledIsEmpty;
3333
}
3434

3535
/**
@@ -52,18 +52,15 @@ export class ToggleFilterModel extends SelectionModel {
5252

5353
/**
5454
* Determines whether the current value should be considered empty.
55-
*
56-
* By default (`falseIsEmpty = false`), this model never treats its value
57-
* as empty—both `true` and `false` are considered valid selections.
58-
*
59-
* If `falseIsEmpty = true`, then a value of `false` is treated as empty.
55+
* When this._falseIsEmpty is set to 'true', then a 'false' selection (untoggled)
56+
* will be treated as an empty filter
6057
*
6158
* @return {boolean} `true` if the current value is considered empty,
6259
* otherwise `false`.
6360
*/
6461
get isEmpty() {
65-
if (this._falseIsEmpty) {
66-
return this.current === false;
62+
if (this._untoggledIsEmpty) {
63+
return this.isToggled === false;
6764
}
6865

6966
return false;

0 commit comments

Comments
 (0)