Skip to content

Commit 469ef0f

Browse files
[O2B-1555] Add normalize setter functions to all classes that extend filter model and selection model (#2143)
Notable changes for users: - Setting filters will now display them in the url Notable changes for developers: - All filters now have a normalized setter that will set the values of the filters based on the output of the normalize getter in query parameter form.
1 parent 2497966 commit 469ef0f

30 files changed

Lines changed: 230 additions & 231 deletions

lib/public/components/Filters/LhcFillsFilter/BeamTypeFilterModel.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
*/
1313

1414
import { beamTypesProvider } from '../../../services/beamTypes/beamTypesProvider.js';
15-
import { SelectionFilterModel } from '../common/filters/SelectionFilterModel.js';
15+
import { SelectionModel } from '../../common/selection/SelectionModel.js';
1616

1717
/**
1818
* Beam type filter model
1919
*/
20-
export class BeamTypeFilterModel extends SelectionFilterModel {
20+
export class BeamTypeFilterModel extends SelectionModel {
2121
/**
2222
* Constructor
2323
*/
@@ -28,7 +28,7 @@ export class BeamTypeFilterModel extends SelectionFilterModel {
2828
beamTypesProvider.items$.getCurrent().apply({
2929
Success: (types) => {
3030
const beamTypes = types.map((type) => ({ value: type.beam_type }));
31-
this._selectionModel.setAvailableOptions(beamTypes);
31+
this.setAvailableOptions(beamTypes);
3232
},
3333
});
3434
});

lib/public/components/Filters/LhcFillsFilter/beamTypeFilter.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,4 @@ import { checkboxes } from '../common/filters/checkboxFilter.js';
1919
* @param {BeamTypeFilterModel} beamTypeFilterModel beamTypeFilterModel
2020
* @return {Component} the filter
2121
*/
22-
export const beamTypeFilter = (beamTypeFilterModel) =>
23-
checkboxes(
24-
beamTypeFilterModel.selectionModel,
25-
{ selector: 'beam-types' },
26-
);
22+
export const beamTypeFilter = (beamTypeFilterModel) => checkboxes(beamTypeFilterModel, { selector: 'beam-types' });

lib/public/components/Filters/RunsFilter/BeamModeFilterModel.js

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,50 +12,17 @@
1212
*/
1313

1414
import { ObservableBasedSelectionDropdownModel } from '../../detector/ObservableBasedSelectionDropdownModel.js';
15-
import { FilterModel } from '../common/FilterModel.js';
1615

1716
/**
1817
* Beam mode filter model
1918
*/
20-
export class BeamModeFilterModel extends FilterModel {
19+
export class BeamModeFilterModel extends ObservableBasedSelectionDropdownModel {
2120
/**
2221
* Constructor
2322
*
2423
* @param {ObservableData<RemoteData<{name: string}, ApiError>>} beamModes$ observable remote data of objects representing beam modes
2524
*/
2625
constructor(beamModes$) {
27-
super();
28-
this._selectionDropdownModel = new ObservableBasedSelectionDropdownModel(beamModes$, ({ name }) => ({ value: name }));
29-
this._addSubmodel(this._selectionDropdownModel);
30-
}
31-
32-
/**
33-
* @inheritDoc
34-
*/
35-
reset() {
36-
this._selectionDropdownModel.reset();
37-
}
38-
39-
/**
40-
* @inheritDoc
41-
*/
42-
get isEmpty() {
43-
return this._selectionDropdownModel.isEmpty;
44-
}
45-
46-
/**
47-
* Return the underlying dropdown model
48-
*
49-
* @return {ObservableDropDownModel} the underlying dropdown model
50-
*/
51-
get selectionDropdownModel() {
52-
return this._selectionDropdownModel;
53-
}
54-
55-
/**
56-
* @inheritDoc
57-
*/
58-
get normalized() {
59-
return this._selectionDropdownModel.selected;
26+
super(beamModes$, ({ name }) => ({ value: name }));
6027
}
6128
}

lib/public/components/Filters/RunsFilter/DetectorsFilterModel.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ export class DetectorsFilterModel extends FilterModel {
6767
return normalized;
6868
}
6969

70+
/**
71+
* @inheritDoc
72+
*/
73+
set normalized({ operator, values }) {
74+
this._combinationOperatorModel.normalized = operator;
75+
this._dropdownModel.normalized = values;
76+
}
77+
7078
/**
7179
* Return true if the current combination operator is none
7280
*

lib/public/components/Filters/RunsFilter/EorReasonFilterModel.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ export class EorReasonFilterModel extends FilterModel {
6666
return ret;
6767
}
6868

69+
/**
70+
* @inheritDoc
71+
*/
72+
set normalized({ category, title, description }) {
73+
this._category = category;
74+
this._title = title;
75+
this._description = description;
76+
}
77+
6978
/**
7079
* Returns the EOR reason filter category
7180
*

lib/public/components/Filters/RunsFilter/GaqFilterModel.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ export class GaqFilterModel extends FilterModel {
6969
return normalized;
7070
}
7171

72+
/**
73+
* @inheritDoc
74+
*/
75+
set normalized({ notBadFraction, mcReproducibleAsNotBad }) {
76+
this._notBadFraction.normalized = notBadFraction;
77+
this._mcReproducibleAsNotBad.normalized = mcReproducibleAsNotBad;
78+
}
79+
7280
/**
7381
* Return the underlying notBadFraction model
7482
*

lib/public/components/Filters/RunsFilter/MagnetsFilteringModel.js

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

14-
import { FilterModel } from '../common/FilterModel.js';
1514
import { ObservableBasedSelectionDropdownModel } from '../../detector/ObservableBasedSelectionDropdownModel.js';
1615

1716
/**
1817
* Return the option value corresponding to a given magnets current level
1918
*
2019
* @param {MagnetsCurrentLevels} currentLevels the current levels
21-
* @return {string} the option's value
20+
* @return {object<value: string>} the option's value
2221
*/
23-
const magnetsCurrentLevelsToOptionValue = ({ l3, dipole }) => `${l3}kA/${dipole}kA`;
22+
const magnetsCurrentLevelsToKey = ({ l3, dipole }) => ({ value: `${l3}kA/${dipole}kA` });
23+
24+
/**
25+
* Return the magnets current lever based on a key string
26+
*
27+
* @param {object} value string containing the current levels
28+
* @return {MagnetsCurrentLevels}
29+
*/
30+
const keyToMagnetsCurrentLevels = (value) => {
31+
const [l3, dipole] = value.split('/').map((str) => parseFloat(str.slice(0, -2)));
32+
return { l3, dipole };
33+
};
2434

2535
/**
2636
* AliceL3AndDipoleFilteringModel
2737
*/
28-
export class MagnetsFilteringModel extends FilterModel {
38+
export class MagnetsFilteringModel extends ObservableBasedSelectionDropdownModel {
2939
/**
3040
* Constructor
3141
*
3242
* @param {ObservableData<RemoteData<MagnetsCurrentLevels[], ApiError>>} magnetsCurrentLevels$ observable remote data of magnets current
3343
* levels
3444
*/
3545
constructor(magnetsCurrentLevels$) {
36-
super();
37-
this._selectionDropdownModel = new ObservableBasedSelectionDropdownModel(
38-
magnetsCurrentLevels$,
39-
(magnetsCurrentLevels) => ({ value: magnetsCurrentLevelsToOptionValue(magnetsCurrentLevels) }),
40-
{ multiple: false },
41-
);
42-
this._addSubmodel(this._selectionDropdownModel);
43-
44-
this._valueToFilteringParamsMap = new Map();
45-
magnetsCurrentLevels$.observe(() => {
46-
magnetsCurrentLevels$.getCurrent().match({
47-
48-
/**
49-
* Fill map indexing current level by their corresponding value
50-
*
51-
* @param {MagnetsCurrentLevels[]} currentLevels the current levels to map
52-
* @return {void}
53-
*/
54-
Success: (currentLevels) => {
55-
this._valueToFilteringParamsMap = new Map(currentLevels.map(({ l3, dipole }) => [
56-
magnetsCurrentLevelsToOptionValue({ l3, dipole }),
57-
{ l3, dipole },
58-
]));
59-
},
60-
Other: () => {
61-
this._valueToFilteringParamsMap = new Map();
62-
},
63-
});
64-
});
46+
super(magnetsCurrentLevels$, magnetsCurrentLevelsToKey, { multiple: false });
6547
}
6648

6749
/**
6850
* @inheritDoc
6951
*/
70-
reset() {
71-
this._selectionDropdownModel.reset();
72-
}
52+
get normalized() {
53+
const [selectedOption] = this.selected;
7354

74-
/**
75-
* @inheritDoc
76-
*/
77-
get isEmpty() {
78-
return this._selectionDropdownModel.isEmpty;
79-
}
55+
if (selectedOption === undefined) {
56+
return null;
57+
}
8058

81-
/**
82-
* @inheritDoc
83-
*/
84-
get normalized() {
85-
return this._valueToFilteringParamsMap.get(this._selectionDropdownModel.selected[0]) ?? null;
59+
return keyToMagnetsCurrentLevels(selectedOption);
8660
}
8761

8862
/**
89-
* Return the underlying selection dropdown model
63+
* Sets selected options based on an object containing l3 and dipole fields.
64+
* Accounts for the options being either RemoteData or an array.
9065
*
91-
* @return {SelectionDropdownModel} the dropdown model
66+
* @param {MagnetsCurrentLevels} value the magnets current levels
67+
* @param {number} value.l3 the L3 current level in kA
68+
* @param {number} value.dipole the dipole current level in kA
9269
*/
93-
get selectionDropdownModel() {
94-
return this._selectionDropdownModel;
70+
set normalized(value) {
71+
super.normalized = magnetsCurrentLevelsToKey(value).value;
9572
}
9673
}

lib/public/components/Filters/RunsFilter/MultiCompositionFilterModel.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,15 @@ export class MultiCompositionFilterModel extends FilterModel {
8989

9090
return normalized;
9191
}
92+
93+
/**
94+
* @inheritDoc
95+
*/
96+
set normalized(filters) {
97+
for (const [key, value] of Object.entries(filters)) {
98+
if (key in this._filters) {
99+
this._filters[key].normalized = value;
100+
}
101+
}
102+
}
92103
}

lib/public/components/Filters/RunsFilter/RunDefinitionFilterModel.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { RUN_DEFINITIONS, RunDefinition } from '../../../domain/enums/RunDefinition.js';
2-
import { SelectionFilterModel } from '../common/filters/SelectionFilterModel.js';
2+
import { SelectionModel } from '../../common/selection/SelectionModel.js';
33

44
/**
55
* Run definition filter model
66
*/
7-
export class RunDefinitionFilterModel extends SelectionFilterModel {
7+
export class RunDefinitionFilterModel extends SelectionModel {
88
/**
99
* Constructor
1010
*/
@@ -18,7 +18,7 @@ export class RunDefinitionFilterModel extends SelectionFilterModel {
1818
* @return {boolean} true if filter is physics only
1919
*/
2020
isPhysicsOnly() {
21-
const selectedOptions = this._selectionModel.selected;
21+
const selectedOptions = this.selected;
2222
return selectedOptions.length === 1 && selectedOptions[0] === RunDefinition.Physics;
2323
}
2424

@@ -29,8 +29,8 @@ export class RunDefinitionFilterModel extends SelectionFilterModel {
2929
*/
3030
setPhysicsOnly() {
3131
if (!this.isPhysicsOnly()) {
32-
this._selectionModel.selectedOptions = [];
33-
this._selectionModel.select(RunDefinition.Physics);
32+
this.selectedOptions = [];
33+
this.select(RunDefinition.Physics);
3434
this.notify();
3535
}
3636
}

lib/public/components/Filters/RunsFilter/TimeRangeFilter.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ export class TimeRangeFilterModel extends FilterModel {
4545
return normalized;
4646
}
4747

48+
/**
49+
* @inheritDoc
50+
*/
51+
set normalized({ from, to }) {
52+
this._timeRangeInputModel.normalized = { from, to };
53+
}
54+
4855
/**
4956
* Return the underlying time range input model
5057
*

0 commit comments

Comments
 (0)