Skip to content

Commit

Permalink
[O2B-532] Minor improvements to selection dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
martinboulais committed Jan 8, 2025
1 parent d467d32 commit c03c84b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,23 @@ export const combinationOperatorChoiceComponent = (combinationOperatorModel, con
'.form-group-header.flex-row',
// Available options are always an array
combinationOperatorModel.options.map((option) => h('.form-check.mr2', [
h('input.form-check-input', {
onclick: () => combinationOperatorModel.select(option),
id: `${selectorPrefix}combination-operator-radio-button-${option.value}`,
checked: combinationOperatorModel.isSelected(option),
type: 'radio',
name: selectorPrefix,
}),
h('label.form-check-label', {
for: `${selectorPrefix}combination-operator-radio-button-${option.value}`,
}, option.label),
h(
'input.form-check-input',
{
onclick: () => combinationOperatorModel.select(option),

Check warning on line 36 in lib/public/components/Filters/common/combinationOperatorChoiceComponent.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/common/combinationOperatorChoiceComponent.js#L36

Added line #L36 was not covered by tests
id: `${selectorPrefix}combination-operator-radio-button-${option.value}`,
checked: combinationOperatorModel.isSelected(option),
type: 'radio',
name: selectorPrefix,
},
),
h(
'label.form-check-label',
{
for: `${selectorPrefix}combination-operator-radio-button-${option.value}`,
},
option.label || option.value,

Check warning on line 48 in lib/public/components/Filters/common/combinationOperatorChoiceComponent.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/common/combinationOperatorChoiceComponent.js#L48

Added line #L48 was not covered by tests
),
])),
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import { SelectionDropdownModel } from '../../../common/selection/dropdown/SelectionDropdownModel.js';

const numericalComparisonOptions = Object.freeze([
{ label: '<', value: 'lt' },
{ label: '<=', value: 'le' },
{ label: '=', value: 'eq' },
{ label: '>=', value: 'ge' },
{ label: '>', value: 'gt' },
{ value: '<', selector: 'lt' },
{ value: '<=', selector: 'le' },
{ value: '=', selector: 'eq' },
{ value: '>=', selector: 'ge' },
{ value: '>', selector: 'gt' },
]);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class FloatComparisonFilterModel extends FilterInputModel {
*/
get value() {
return {
operator: this._operatorSelectionModel.selectedOptions[0].label,
operator: this._operatorSelectionModel.current,
operand: this._operandInputModel.value,
};
}
Expand Down
10 changes: 10 additions & 0 deletions lib/public/components/common/selection/SelectionModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Observable, RemoteData } from '/js/src/index.js';
* @property {number|string} value The id of the object this is used to see if it is checked.
* @property {Component} [label] The representation of the option (if null, value is used as label)
* @property {string} [rawLabel] The string only representation of the option, useful if the label is not a string
* @property {string} [selector] If the value of the option is not a valid CSS, this is used to define option's id
*/

/**
Expand Down Expand Up @@ -277,6 +278,15 @@ export class SelectionModel extends Observable {
return this.selected[0];
}

/**
* States if the selection allows for multiple options to be chosen at the same time
*
* @return {boolean} true if multiple options are allowed
*/
get multiple() {
return this._multiple;

Check warning on line 287 in lib/public/components/common/selection/SelectionModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/common/selection/SelectionModel.js#L286-L287

Added lines #L286 - L287 were not covered by tests
}

/**
* Return the list of currently selected options
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,26 @@ export const selectionDropdown = (selectionDropdownModel, configuration) => {
const selectorPrefix = cleanPrefix(configuration.selectorPrefix);

if (displayOption === null) {
displayOption = (option, checked, onChange, selectorPrefix) => h(
'label.dropdown-option.form-check-label.flex-row.g2.ph2.pv1',
{ key: option.value },
[
h(
`input#${selectorPrefix}dropdown-option-${option.value}`,
{
type: 'checkbox',
checked,
onchange: (e) => onChange(option, e.target.checked),
},
),
option.label || option.value,
],
);
displayOption = (option, checked, onChange, selectorPrefix) => {
const selector = option.selector ?? option.value;

Check warning on line 136 in lib/public/components/common/selection/dropdown/selectionDropdown.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/common/selection/dropdown/selectionDropdown.js#L135-L136

Added lines #L135 - L136 were not covered by tests

return h(

Check warning on line 138 in lib/public/components/common/selection/dropdown/selectionDropdown.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/common/selection/dropdown/selectionDropdown.js#L138

Added line #L138 was not covered by tests
'label.dropdown-option.form-check-label.flex-row.g2.ph2.pv1',
{ key: selector },
[
h(
`input#${selectorPrefix}dropdown-option-${selector}`,
{
type: selectionDropdownModel.multiple ? 'checkbox' : 'radio',
name: `${selectorPrefix}dropdown-option-${selectionDropdownModel.multiple ? selector : 'group'}`,

Check warning on line 146 in lib/public/components/common/selection/dropdown/selectionDropdown.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/common/selection/dropdown/selectionDropdown.js#L145-L146

Added lines #L145 - L146 were not covered by tests
checked,
onchange: (e) => onChange(option, e.target.checked),

Check warning on line 148 in lib/public/components/common/selection/dropdown/selectionDropdown.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/common/selection/dropdown/selectionDropdown.js#L148

Added line #L148 was not covered by tests
},
),
option.label || option.value,

Check warning on line 151 in lib/public/components/common/selection/dropdown/selectionDropdown.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/common/selection/dropdown/selectionDropdown.js#L151

Added line #L151 was not covered by tests
],
);
};
}

if (displaySelectionItem === null) {
Expand Down

0 comments on commit c03c84b

Please sign in to comment.