-
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
7db974b
b5d8fc4
b42a43c
116fdef
319bb4d
911cd2e
f9dc13a
1443e47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,12 @@ export class SelectionModel extends Observable { | |
| super(); | ||
| const { availableOptions = [], defaultSelection = [], multiple = true, allowEmpty = true } = configuration || {}; | ||
|
|
||
| /** | ||
| * @type {SelectionOption[]} | ||
| * @protected | ||
| */ | ||
| this._selectionBacklog = []; | ||
|
|
||
| /** | ||
| * @type {RemoteData<SelectionOption[]>|SelectionOption[]} | ||
| * @protected | ||
|
|
@@ -243,14 +249,20 @@ export class SelectionModel extends Observable { | |
| } | ||
|
|
||
| /** | ||
| * Defines the list of available options | ||
| * Defines the list of available options and if there is a selection backlog, these will be applied | ||
| * | ||
| * @param {RemoteData<SelectionOption[], *>|SelectionOption[]} availableOptions the new available options | ||
| * @return {void} | ||
| */ | ||
| setAvailableOptions(availableOptions) { | ||
| this._availableOptions = availableOptions; | ||
| this.visualChange$.notify(); | ||
|
|
||
| if (this._selectionBacklog.length) { | ||
| this.selectedOptions = this._selectionBacklog; | ||
| this._selectionBacklog = []; | ||
| this.notify(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -315,12 +327,19 @@ export class SelectionModel extends Observable { | |
| } | ||
|
|
||
| /** | ||
| * Define (overrides) the list of currently selected options | ||
| * Define (overrides) the list of currently selected options. | ||
| * Invalid selection options are excluded | ||
| * | ||
| * @param {SelectionOption[]} selected the list of selected options | ||
| */ | ||
| set selectedOptions(selected) { | ||
| this._selectedOptions = selected; | ||
| let { options } = this; | ||
|
|
||
| if (this.options instanceof RemoteData) { | ||
| options = options.isSuccess() ? options.payload : []; | ||
| } | ||
|
|
||
| this._selectedOptions = options.filter((option) => selected.some(({ value }) => String(value) === String(option.value)));; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -332,6 +351,23 @@ export class SelectionModel extends Observable { | |
| return this._defaultSelection; | ||
| } | ||
|
|
||
| /** | ||
| * Sets selected options based on a comma-seperated string. | ||
| * Accounts for the options being either RemoteData or an array. | ||
| * | ||
| * @return {string} | ||
|
isaachilly marked this conversation as resolved.
Outdated
|
||
| */ | ||
| set normalized(value) { | ||
|
Collaborator
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. What happens if value is null or undefined? Could value ever be null or undefined? Maybe not in UI but maybe if passed in URL? What do you think? Goes for all the setters.
Collaborator
Author
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. Since queryRouter omits any values that are undefined when computing its As a result, if a value is passed via URL (which is why the setters exist), neither value nor its equivalent can end up being undefined.
Collaborator
Author
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. To clarify, while undefined can't really reach the setters, empty strings can |
||
| const options = value.split(',').map((option) => ({ value: option })); | ||
|
isaachilly marked this conversation as resolved.
Outdated
|
||
| const postponeSelection = this.options instanceof RemoteData || ! this.options?.length; | ||
|
|
||
| if (postponeSelection) { | ||
| this._selectionBacklog = options; | ||
| } else { | ||
| this.selectedOptions = options; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns the normalized value of the selection | ||
| * | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.