Skip to content

Commit 27a8bbc

Browse files
author
GuustMetz
committed
feat: move methodsFilterModelFilter to filteringModel
1 parent cdaaf0e commit 27a8bbc

5 files changed

Lines changed: 59 additions & 48 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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(
25+
'.form-group-header.flex-row.w-100',
26+
selectionModel.options.map((option) => {
27+
const { label } = option;
28+
const action = () => selectionModel.select(option);
29+
const isChecked = selectionModel.isSelected(option);
30+
31+
return radioButton({ label, isChecked, action, name });
32+
}),
33+
);
34+
};
35+
36+
export default badFilterRadioButtons;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,4 +331,16 @@ export class SelectionModel extends Observable {
331331
get optionsSelectedByDefault() {
332332
return this._defaultSelection;
333333
}
334+
335+
/**
336+
* Returns the normalized value of the selection
337+
*
338+
* @return {string|boolean|number} the normalized value
339+
* @abstract
340+
*/
341+
get normalized() {
342+
return (this._allowEmpty || this._multiple)
343+
? this._selectedOptions.join()
344+
: this.current;
345+
}
334346
}

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: ({ isBadFilterModel }) => checkboxes(
58-
isBadFilterModel,
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: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ export class QcFlagTypesOverviewModel extends OverviewPageModel {
3030
this._filteringModel = new FilteringModel({
3131
names: new TextTokensFilterModel(),
3232
methods: new TextTokensFilterModel(),
33+
bad: new SelectionModel({
34+
availableOptions: [{ label: 'Any' }, { label: 'Bad', value: true }, { label: 'Not Bad', value: false }],
35+
defaultSelection: [{ label: 'Any' }],
36+
allowEmpty: false,
37+
multiple: false,
38+
}),
3339
});
3440

35-
this._isBadFilterModel =
36-
new SelectionModel({ availableOptions: [{ label: 'Bad', value: true }, { label: 'Not Bad', value: false }] });
37-
this._registerFilter(this._isBadFilterModel);
38-
3941
this._filteringModel.observe(() => {
4042
this._pagination.silentlySetCurrentPage(1);
4143
this.load();
@@ -48,18 +50,7 @@ export class QcFlagTypesOverviewModel extends OverviewPageModel {
4850
* @inheritdoc
4951
*/
5052
getRootEndpoint() {
51-
const params = {};
52-
if (this.isAnyFilterActive()) {
53-
params.filter = {
54-
names: this._filteringModel.get("names").normalized,
55-
methods: this._filteringModel.get("methods").normalized,
56-
bad: this._isBadFilterModel.selected.length === 2
57-
? undefined
58-
: this._isBadFilterModel.selected[0],
59-
};
60-
}
61-
62-
return buildUrl('/api/qcFlagTypes', params);
53+
return buildUrl('/api/qcFlagTypes', { filter: this._filteringModel.normalized });
6354
}
6455

6556
/**
@@ -71,37 +62,13 @@ export class QcFlagTypesOverviewModel extends OverviewPageModel {
7162
return this._filteringModel;
7263
}
7364

74-
/**
75-
* Returns filter model for filtering bad and not bad flags
76-
*
77-
* @return {TextTokensFilterModel} filter model for filtering bad and not bad flags
78-
*/
79-
get isBadFilterModel() {
80-
return this._isBadFilterModel;
81-
}
82-
83-
/**
84-
* Register a new filter model
85-
*
86-
* @param {FilterModel} filterModel the filter model to register
87-
* @return {void}
88-
* @private
89-
*/
90-
_registerFilter(filterModel) {
91-
filterModel.visualChange$.bubbleTo(this);
92-
filterModel.observe(() => {
93-
this._pagination.silentlySetCurrentPage(1);
94-
this.load();
95-
});
96-
}
97-
9865
/**
9966
* States whether any filter is active
10067
*
10168
* @return {boolean} true if any filter is active
10269
*/
10370
isAnyFilterActive() {
104-
return this._filteringModel.isAnyFilterActive() || this._isBadFilterModel.selected.length;
71+
return this._filteringModel.isAnyFilterActive();
10572
}
10673

10774
/**
@@ -111,7 +78,6 @@ export class QcFlagTypesOverviewModel extends OverviewPageModel {
11178
*/
11279
reset() {
11380
this._filteringModel.reset();
114-
this._isBadFilterModel.reset();
11581
super.reset();
11682
}
11783
}

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)