-
Notifications
You must be signed in to change notification settings - Fork 21
[O2B-1555] Add normalize setter functions to all classes that extend filter model and selection model #2143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
graduta
merged 14 commits into
main
from
impov/O2B-1555/Add-normalize-setter-functions-to-all-classes-that-extend-FilterModel-and-SelectionModel
May 26, 2026
Merged
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7db974b
feat: add normalize setter to SelectionModel and FilteringModel
b5d8fc4
chore: add mundain normalized setters
b42a43c
chore: remove all mentions of selectionFilterModel and replace it wit…
116fdef
make MagnetsfilteringModel extend RemoteDataSelectionDropdown
319bb4d
feat: change all filters that have only ObservableBasedSelectionDropd…
911cd2e
chore: remove the backlog clear from setAvailable options and trim op…
f9dc13a
chore: fix comment on magnetsFilteringModel
1443e47
feat: guard against parsing empty strings to NaN in DateTimeInputMode…
79397e1
chore: add missing documentation for magnetsFilteringModel
2d0c916
feat: guard against undefined selection in magnetsFilteringModel
1d9af1e
chore: can normalized getters in tagFilterModel
1ec7cb6
chore: remove extra space for negation in SelectionModel normalized s…
4b9b459
chore: fix eslint issues
7ec70c2
Merge branch 'main' into impov/O2B-1555/Add-normalize-setter-function…
NarrowsProjects File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,86 +11,57 @@ | |
| * or submit itself to any jurisdiction. | ||
| */ | ||
|
|
||
| import { FilterModel } from '../common/FilterModel.js'; | ||
| import { ObservableBasedSelectionDropdownModel } from '../../detector/ObservableBasedSelectionDropdownModel.js'; | ||
|
|
||
| /** | ||
| * Return the option value corresponding to a given magnets current level | ||
| * | ||
| * @param {MagnetsCurrentLevels} currentLevels the current levels | ||
| * @return {string} the option's value | ||
| * @return {object<value: string>} the option's value | ||
| */ | ||
| const magnetsCurrentLevelsToOptionValue = ({ l3, dipole }) => `${l3}kA/${dipole}kA`; | ||
| const magnetsCurrentLevelsToKey = ({ l3, dipole }) => ({ value: `${l3}kA/${dipole}kA` }); | ||
|
|
||
| /** | ||
| * Return the magnets current lever based on a key string | ||
| * | ||
| * @param {object} option string containing the current levels | ||
| * @param {string} option.value string containing the current levels | ||
| * @return {MagnetsCurrentLevels} | ||
| */ | ||
| const keyToMagnetsCurrentLevels = (value) => { | ||
| const [l3, dipole] = value.split('/').map((str) => parseFloat(str.slice(0, -2))); | ||
| return { l3, dipole }; | ||
| }; | ||
|
|
||
| /** | ||
| * AliceL3AndDipoleFilteringModel | ||
| */ | ||
| export class MagnetsFilteringModel extends FilterModel { | ||
| export class MagnetsFilteringModel extends ObservableBasedSelectionDropdownModel { | ||
| /** | ||
| * Constructor | ||
| * | ||
| * @param {ObservableData<RemoteData<MagnetsCurrentLevels[], ApiError>>} magnetsCurrentLevels$ observable remote data of magnets current | ||
| * levels | ||
| */ | ||
| constructor(magnetsCurrentLevels$) { | ||
| super(); | ||
| this._selectionDropdownModel = new ObservableBasedSelectionDropdownModel( | ||
| magnetsCurrentLevels$, | ||
| (magnetsCurrentLevels) => ({ value: magnetsCurrentLevelsToOptionValue(magnetsCurrentLevels) }), | ||
| { multiple: false }, | ||
| ); | ||
| this._addSubmodel(this._selectionDropdownModel); | ||
|
|
||
| this._valueToFilteringParamsMap = new Map(); | ||
| magnetsCurrentLevels$.observe(() => { | ||
| magnetsCurrentLevels$.getCurrent().match({ | ||
|
|
||
| /** | ||
| * Fill map indexing current level by their corresponding value | ||
| * | ||
| * @param {MagnetsCurrentLevels[]} currentLevels the current levels to map | ||
| * @return {void} | ||
| */ | ||
| Success: (currentLevels) => { | ||
| this._valueToFilteringParamsMap = new Map(currentLevels.map(({ l3, dipole }) => [ | ||
| magnetsCurrentLevelsToOptionValue({ l3, dipole }), | ||
| { l3, dipole }, | ||
| ])); | ||
| }, | ||
| Other: () => { | ||
| this._valueToFilteringParamsMap = new Map(); | ||
| }, | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| reset() { | ||
| this._selectionDropdownModel.reset(); | ||
| } | ||
|
|
||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| get isEmpty() { | ||
| return this._selectionDropdownModel.isEmpty; | ||
| super(magnetsCurrentLevels$, magnetsCurrentLevelsToKey, { multiple: false }); | ||
| } | ||
|
|
||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| get normalized() { | ||
| return this._valueToFilteringParamsMap.get(this._selectionDropdownModel.selected[0]) ?? null; | ||
| const [selectedOption] = this.selected; | ||
| return keyToMagnetsCurrentLevels(selectedOption); | ||
|
isaachilly marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /** | ||
| * Return the underlying selection dropdown model | ||
| * Sets selected options based on an object containing l3 and dipole fields. | ||
| * Accounts for the options being either RemoteData or an array. | ||
| * | ||
| * @return {SelectionDropdownModel} the dropdown model | ||
| * @param {object} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incomplete docs |
||
| */ | ||
| get selectionDropdownModel() { | ||
| return this._selectionDropdownModel; | ||
| set normalized(value) { | ||
| super.normalized = magnetsCurrentLevelsToKey(value).value; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.