Skip to content

Commit 68bdf91

Browse files
committed
Fix after rebase
1 parent bbd7a8e commit 68bdf91

File tree

5 files changed

+39
-29
lines changed

5 files changed

+39
-29
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class TagFilterModel extends FilterModel {
2222
/**
2323
* Constructor
2424
*
25+
* @param {ObservableData<RemoteData<Tag[], ApiError>>} tags$ observable remote data of tags list
2526
* @param {SelectionOption[]} [operators] optionally the list of available operators for the filter
2627
* @constructor
2728
*/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* or submit itself to any jurisdiction.
1212
*/
1313

14-
import { SelectionDropdownModel } from '../../../common/selection/dropdown/SelectionDropdownModel.js';
14+
import { SelectionModel } from '../../../common/selection/SelectionModel.js';
1515

1616
const numericalComparisonOptions = Object.freeze([
1717
{ value: '<' },
@@ -24,7 +24,7 @@ const numericalComparisonOptions = Object.freeze([
2424
/**
2525
* Model storing state of a selection of comparison operator
2626
*/
27-
export class ComparisonSelectionModel extends SelectionDropdownModel {
27+
export class ComparisonSelectionModel extends SelectionModel {
2828
/**
2929
* Constructor
3030
*/

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export class NumericalComparisonFilterModel extends FilterModel {
4343
this._addSubmodel(this._operandInputModel);
4444

4545
this._operatorSelectionModel = new ComparisonSelectionModel();
46-
this._operatorSelectionModel.visualChange$.bubbleTo(this._visualChange$);
4746
this._operatorSelectionModel.observe(() => this._operandInputModel.raw ? this.notify() : this._visualChange$.notify());
4847
}
4948

lib/public/components/common/selection/FilterableRemoteSelectionModel.js

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ import { Observable, RemoteData } from '/js/src/index.js';
1414
import { SelectionModel } from './SelectionModel.js';
1515

1616
/**
17-
* @typedef SelectionOption A picker option, with the actual value and its string representation
18-
* @property {number|string} value The id of the object this is used to see if it is checked.
19-
* @property {Component} [label] The representation of the option (if null, value is used as label)
20-
* @property {string} [rawLabel] The string only representation of the option, useful if the label is not a string
21-
* @property {string} [selector] If the value of the option is not a valid CSS, this is used to define option's id
17+
* @typedef {SelectionModelConfiguration} FilterableRemoteSelectionModelConfiguration
18+
* @property {RemoteData<SelectionOption[], *>} [availableOptions=[]] the list of available options
2219
*/
2320

2421
/**
@@ -27,7 +24,7 @@ import { SelectionModel } from './SelectionModel.js';
2724
export class FilterableRemoteSelectionModel extends Observable {
2825
/**
2926
* Constructor
30-
* @param {SelectionModelConfiguration} [configuration] the model's configuration
27+
* @param {FilterableRemoteSelectionModelConfiguration} [configuration] the model's configuration
3128
*/
3229
constructor(configuration) {
3330
super();
@@ -47,6 +44,7 @@ export class FilterableRemoteSelectionModel extends Observable {
4744

4845
this._visualChange$ = new Observable();
4946

47+
this._selectionModel = RemoteData.notAsked();
5048
this.setAvailableOptions(availableOptions);
5149
}
5250

@@ -65,7 +63,7 @@ export class FilterableRemoteSelectionModel extends Observable {
6563
* @return {void}
6664
*/
6765
reset() {
68-
this.selectionModel.match({
66+
this._selectionModel.match({
6967
Success: (selectionModel) => selectionModel.reset(),
7068
Other: () => {
7169
// Do nothing
@@ -80,7 +78,7 @@ export class FilterableRemoteSelectionModel extends Observable {
8078
* @return {boolean} true if the selection is empty
8179
*/
8280
get isEmpty() {
83-
return this.selectionModel.match({
81+
return this._selectionModel.match({
8482
Success: (selectionModel) => selectionModel.isEmpty,
8583
Other: () => true,
8684
});
@@ -124,17 +122,17 @@ export class FilterableRemoteSelectionModel extends Observable {
124122
multiple: this._multiple,
125123
allowEmpty: this._allowEmpty,
126124
});
127-
this.selectionModel = RemoteData.success(selectionModel);
125+
this._selectionModel = RemoteData.success(selectionModel);
128126
selectionModel.bubbleTo(this);
129127
},
130128
Loading: () => {
131-
this.selectionModel = RemoteData.loading();
129+
this._selectionModel = RemoteData.loading();
132130
},
133131
Failure: (error) => {
134-
this.selectionModel = RemoteData.failure(error);
132+
this._selectionModel = RemoteData.failure(error);
135133
},
136134
NotAsked: () => {
137-
this.selectionModel = RemoteData.notAsked();
135+
this._selectionModel = RemoteData.notAsked();
138136
},
139137
});
140138

@@ -144,28 +142,31 @@ export class FilterableRemoteSelectionModel extends Observable {
144142
/**
145143
* Return the **values** of the currently selected options
146144
*
147-
* Do not use this getter to modify the selected list but use the `selected` setter to define the new selected list and to notify observers
148-
*
149145
* @return {string[]|number[]} the values of the selected options
150146
*/
151147
get selected() {
152-
return this.selectionModel.match({
148+
return this._selectionModel.match({
153149
Success: (selectionModel) => selectionModel.selected,
154150
Other: () => [],
155151
});
156152
}
157153

158154
/**
159-
* If the selection allows one and only one selection, current will return the currently selected option. In any other case it will throw an
160-
* error
161-
*
162-
* @return {string|number} the current selection
155+
* Return the list of available options
163156
*/
164-
get current() {
165-
if (this._allowEmpty || this._multiple) {
166-
throw new Error('"current" is available only in non-multiple select that do not allow empty value');
167-
}
157+
get options() {
158+
return this._selectionModel.match({
159+
Success: (selectionModel) => selectionModel.options,
160+
Other: () => [],
161+
});
162+
}
168163

169-
return this.selected[0];
164+
/**
165+
* Return the underlying selection model
166+
*
167+
* @return {RemoteData<SelectionModel, ApiError>} the selection model
168+
*/
169+
get selectionModel() {
170+
return this._selectionModel;
170171
}
171172
}

lib/public/components/common/selection/SelectionModel.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1+
import { Observable } from '/js/src/index.js';
2+
13
/**
24
* @typedef SelectionModelConfiguration
35
* @property {SelectionOption[]} [availableOptions=[]] the list of available options
46
* @property {SelectionOption[]} [defaultSelection=[]] the default selection
57
* @property {boolean} [multiple=true] if true, the selection can contain more than one element. Else, any selection will
68
* discard the previous one
7-
* @property {allowEmpty} [allowEmpty=true] if true, the selection can be empty. Else, deselect will be cancelled if it leads to
9+
* @property {boolean} [allowEmpty=true] if true, the selection can be empty. Else, deselect will be cancelled if it leads to
810
* empty selection
911
*/
10-
import { Observable } from '/js/src/index.js';
12+
13+
/**
14+
* @typedef SelectionOption A picker option, with the actual value and its string representation
15+
* @property {number|string} value The id of the object this is used to see if it is checked.
16+
* @property {Component} [label] The representation of the option (if null, value is used as label)
17+
* @property {string} [rawLabel] The string only representation of the option, useful if the label is not a string
18+
* @property {string} [selector] If the value of the option is not a valid CSS, this is used to define option's id
19+
*/
1120

1221
/**
1322
* Model to store any custom user selection of pre-defined options

0 commit comments

Comments
 (0)