Skip to content

Commit 0d89a8c

Browse files
author
GuustMetz
committed
feat: replace the multi checkboxes from the bad filter with radio buttons.
1 parent 89b1634 commit 0d89a8c

5 files changed

Lines changed: 66 additions & 17 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @license
3+
* Copyright CERN and copyright holders of ALICE Trg. This software is
4+
* distributed under the terms of the GNU General Public License v3 (GPL
5+
* Version 3), copied verbatim in the file "COPYING".
6+
*
7+
* See http://alice-Trg.web.cern.ch/license for full licensing information.
8+
*
9+
* In applying this license CERN does not waive the privileges and immunities
10+
* granted to it by virtue of its status as an Intergovernmental Organization
11+
* or submit itself to any jurisdiction.
12+
*/
13+
14+
import { radioButton } from '../../common/form/inputs/radioButton.js';
15+
import { h } from '/js/src/index.js';
16+
17+
/**
18+
* Radiobutton filter for the qcFlag 'bad' filter
19+
* @param {SelectionModel} selectionModel the a selectionmodel
20+
* @return {vnode} A number of radiobuttons corresponding with the selection options
21+
*/
22+
const badFilterRadioButtons = (selectionModel) => {
23+
const name = 'badFilterRadio';
24+
return h('.form-group-header.flex-row.w-100',
25+
selectionModel.options.map((option) => {
26+
const { label } = option;
27+
const action = () => selectionModel.select(option);
28+
const isChecked = selectionModel.isSelected(option);
29+
30+
return radioButton({ label, isChecked, action, name});
31+
}
32+
))
33+
};
34+
35+
export default badFilterRadioButtons;

lib/public/components/common/selection/SelectionModel.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,17 @@ export class SelectionModel extends Observable {
162162
selectOption = option;
163163
}
164164

165+
console.log('option', option);
166+
console.log('selectOption', selectOption);
167+
console.log('!this.isSelected(selectOption)', !this.isSelected(selectOption));
168+
165169
if (selectOption && !this.isSelected(selectOption)) {
166170
if (this._multiple || this._selectedOptions.length === 0) {
171+
console.log('pushed');
172+
167173
this._selectedOptions.push(selectOption);
168174
} else {
175+
console.log('replaced');
169176
this._selectedOptions = [selectOption];
170177
}
171178

@@ -331,4 +338,16 @@ export class SelectionModel extends Observable {
331338
get optionsSelectedByDefault() {
332339
return this._defaultSelection;
333340
}
341+
342+
/**
343+
* Returns the normalized value of the selection
344+
*
345+
* @return {string|boolean|number} the normalized value
346+
* @abstract
347+
*/
348+
get normalized() {
349+
return (this._allowEmpty || this._multiple)
350+
? this._selectedOptions.join()
351+
: this.current;
352+
}
334353
}

lib/public/views/QcFlagTypes/ActiveColumns/qcFlagTypesActiveColumns.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
import { h } from '/js/src/index.js';
1515
import { formatTimestamp } from '../../../utilities/formatting/formatTimestamp.js';
1616
import { textFilter } from '../../../components/Filters/common/filters/textFilter.js';
17-
import { checkboxes } from '../../../components/Filters/common/filters/checkboxFilter.js';
1817
import { qcFlagTypeColoredBadge } from '../../../components/qcFlags/qcFlagTypeColoredBadge.js';
18+
import badFilterRadioButtons from '../../../components/Filters/QcFlagTypesFilter/bad.js';
1919

2020
/**
2121
* List of active columns for a QC Flag Types table
@@ -54,10 +54,7 @@ export const qcFlagTypesActiveColumns = {
5454
name: 'Bad',
5555
visible: true,
5656
sortable: true,
57-
filter: ({ filteringModel }) => checkboxes(
58-
filteringModel.get('bad'),
59-
{ class: 'w-75 mt1', selector: 'qc-flag-type-bad-filter' },
60-
),
57+
filter: ({ filteringModel }) => badFilterRadioButtons(filteringModel.get('bad')),
6158
classes: 'f6 w-5',
6259
format: (bad) => bad ? h('.danger', 'Yes') : h('.success', 'No'),
6360
},

lib/public/views/QcFlagTypes/Overview/QcFlagTypesOverviewModel.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@ export class QcFlagTypesOverviewModel extends OverviewPageModel {
3030
this._filteringModel = new FilteringModel({
3131
names: new TextTokensFilterModel(),
3232
methods: new TextTokensFilterModel(),
33-
bad: new SelectionModel({ availableOptions: [{ label: 'Bad', value: true }, { label: 'Not Bad', value: false }] })
33+
bad: new SelectionModel(
34+
{
35+
availableOptions: [{ label: 'Any' }, { label: 'Bad', value: true }, { label: 'Not Bad', value: false }],
36+
defaultSelection: [{ label: 'Any' }],
37+
allowEmpty: false,
38+
multiple: false,
39+
}
40+
)
3441
});
3542

3643
this._filteringModel.observe(() => {
@@ -45,16 +52,7 @@ export class QcFlagTypesOverviewModel extends OverviewPageModel {
4552
* @inheritdoc
4653
*/
4754
getRootEndpoint() {
48-
const params = {};
49-
if (this.isAnyFilterActive()) {
50-
params.filter = {
51-
names: this._filteringModel.get("names").normalized,
52-
methods: this._filteringModel.get("methods").normalized,
53-
bad: this._filteringModel.get('bad').selected.length === 2 ? undefined : this._filteringModel.get('bad').selected[0],
54-
};
55-
}
56-
57-
return buildUrl('/api/qcFlagTypes', params);
55+
return buildUrl('/api/qcFlagTypes', { filter: this._filteringModel.normalized });
5856
}
5957

6058
/**

test/public/qcFlagTypes/overview.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ module.exports = () => {
112112
it('should successfully apply QC flag type bad filter', async () => {
113113
await waitForTableLength(page, 7);
114114

115-
await pressElement(page, '.bad-filter input[type=checkbox]', true);
115+
await pressElement(page, '#badFilterRadioBad', true);
116116
await checkColumnValuesWithRegex(page, 'bad', '^Yes$');
117117

118118
await pressElement(page, '#reset-filters', true);

0 commit comments

Comments
 (0)