Skip to content

Commit 116fdef

Browse files
author
NarrowsProjects
committed
make MagnetsfilteringModel extend RemoteDataSelectionDropdown
1 parent b42a43c commit 116fdef

2 files changed

Lines changed: 25 additions & 56 deletions

File tree

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

Lines changed: 23 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -11,86 +11,57 @@
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} option string containing the current levels
28+
* @param {string} option.value string containing the current levels
29+
* @return {MagnetsCurrentLevels}
30+
*/
31+
const keyToMagnetsCurrentLevels = (value) => {
32+
const [l3, dipole] = value.split('/').map((str) => parseFloat(str.slice(0, -2)));
33+
return { l3, dipole };
34+
};
2435

2536
/**
2637
* AliceL3AndDipoleFilteringModel
2738
*/
28-
export class MagnetsFilteringModel extends FilterModel {
39+
export class MagnetsFilteringModel extends ObservableBasedSelectionDropdownModel {
2940
/**
3041
* Constructor
3142
*
3243
* @param {ObservableData<RemoteData<MagnetsCurrentLevels[], ApiError>>} magnetsCurrentLevels$ observable remote data of magnets current
3344
* levels
3445
*/
3546
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-
});
65-
}
66-
67-
/**
68-
* @inheritDoc
69-
*/
70-
reset() {
71-
this._selectionDropdownModel.reset();
72-
}
73-
74-
/**
75-
* @inheritDoc
76-
*/
77-
get isEmpty() {
78-
return this._selectionDropdownModel.isEmpty;
47+
super(magnetsCurrentLevels$, magnetsCurrentLevelsToKey, { multiple: false });
7948
}
8049

8150
/**
8251
* @inheritDoc
8352
*/
8453
get normalized() {
85-
return this._valueToFilteringParamsMap.get(this._selectionDropdownModel.selected[0]) ?? null;
54+
const [selectedOption] = this.selected;
55+
return keyToMagnetsCurrentLevels(selectedOption);
8656
}
8757

8858
/**
89-
* Return the underlying selection dropdown model
59+
* Sets selected options based on a comma-seperated string.
60+
* Accounts for the options being either RemoteData or an array.
9061
*
91-
* @return {SelectionDropdownModel} the dropdown model
62+
* @return {string}
9263
*/
93-
get selectionDropdownModel() {
94-
return this._selectionDropdownModel;
64+
set normalized(value) {
65+
super.normalized = magnetsCurrentLevelsToKey(value).value;
9566
}
9667
}

lib/public/views/Runs/ActiveColumns/runsActiveColumns.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,10 +667,8 @@ export const runsActiveColumns = {
667667
* @param {RunsOverviewModel} runsOverviewModel the runs overview model
668668
* @return {Component} the run types filter component
669669
*/
670-
filter: (runsOverviewModel) => selectionDropdown(
671-
runsOverviewModel.filteringModel.get('magnets').selectionDropdownModel,
672-
{ selectorPrefix: 'l3-dipole-current' },
673-
),
670+
filter: (runsOverviewModel) =>
671+
selectionDropdown(runsOverviewModel.filteringModel.get('magnets'), { selectorPrefix: 'l3-dipole-current' }),
674672
profiles: ['runsPerLhcPeriod', 'runsPerDataPass', 'runsPerSimulationPass', profiles.none],
675673
},
676674

0 commit comments

Comments
 (0)