Skip to content

Commit 094e6c5

Browse files
committed
[O2B-1502] Filtering with Stable Beams Only works, radioButton element extracted and reused.
1 parent 2648f1c commit 094e6c5

8 files changed

Lines changed: 172 additions & 96 deletions

File tree

lib/public/components/Filters/LhcFillsFilter/stableBeamFilter.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,40 @@
1111
* or submit itself to any jurisdiction.
1212
*/
1313

14+
import { h } from '/js/src/index.js';
1415
import { switchInput } from '../../common/form/switchInput.js';
16+
import radiobutton from '../../common/form/inputs/RadioButton.js';
1517

1618
/**
1719
* Display a toggle switch to display stable beams only
1820
*
1921
* @param {LhcFillsOverviewModel} lhcFillsOverviewModel the overview model
22+
* @param radioButtonMode
2023
* @returns {Component} the toggle switch
2124
*/
22-
export const toggleStableBeamOnlyFilter = (lhcFillsOverviewModel) => {
25+
export const toggleStableBeamOnlyFilter = (lhcFillsOverviewModel, radioButtonMode = false) => {
2326
const isStableBeamsOnly = lhcFillsOverviewModel.getStableBeamsOnly();
24-
return switchInput(isStableBeamsOnly, (newState) => {
25-
lhcFillsOverviewModel.setStableBeamsFilter(newState);
26-
}, { labelAfter: 'STABLE BEAM ONLY' });
27+
const name = 'stableBeamsOnlyRadio';
28+
const label1 = 'OFF';
29+
const label2 = 'ON';
30+
if (radioButtonMode) {
31+
return h('.form-group-header.flex-row.w-100', [
32+
radiobutton({
33+
label: label1,
34+
isChecked: isStableBeamsOnly === false,
35+
action: () => lhcFillsOverviewModel.setStableBeamsFilter(false),
36+
name: name,
37+
}),
38+
radiobutton({
39+
label: label2,
40+
isChecked: isStableBeamsOnly === true,
41+
action: () => lhcFillsOverviewModel.setStableBeamsFilter(true),
42+
name: name,
43+
}),
44+
]);
45+
} else {
46+
return switchInput(isStableBeamsOnly, (newState) => {
47+
lhcFillsOverviewModel.setStableBeamsFilter(newState);
48+
}, { labelAfter: 'STABLE BEAM ONLY' });
49+
}
2750
};

lib/public/components/Filters/RunsFilter/dcs.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* or submit itself to any jurisdiction.
1212
*/
1313

14+
import radiobutton from '../../common/form/inputs/RadioButton.js';
1415
import { h } from '/js/src/index.js';
1516

1617
/**
@@ -20,33 +21,30 @@ import { h } from '/js/src/index.js';
2021
*/
2122
const dcsOperationRadioButtons = (runModel) => {
2223
const state = runModel.getDcsFilterOperation();
24+
const name = 'dcsFilterRadio';
25+
const label1 = 'ANY';
26+
const label2 = 'OFF';
27+
const label3 = 'ON';
2328
return h('.form-group-header.flex-row.w-100', [
24-
radioButton('ANY', state === '', () => runModel.removeDcs()),
25-
radioButton('OFF', state === false, () => runModel.setDcsFilterOperation(false)),
26-
radioButton('ON', state === true, () => runModel.setDcsFilterOperation(true)),
29+
radiobutton({
30+
label: label1,
31+
isChecked: state === '',
32+
action: () => runModel.removeDcs(),
33+
name: name,
34+
}),
35+
radiobutton({
36+
label: label2,
37+
isChecked: state === false,
38+
action: () => runModel.setDcsFilterOperation(false),
39+
name: name,
40+
}),
41+
radiobutton({
42+
label: label3,
43+
isChecked: state === true,
44+
action: () => runModel.setDcsFilterOperation(true),
45+
name: name,
46+
}),
2747
]);
2848
};
2949

30-
/**
31-
* Build a radio button with its configuration and actions
32-
* @param {string} label - label to be displayed to the user for radio button
33-
* @param {boolean} isChecked - is radio button selected or not
34-
* @param {Function} action - action to be followed on user click
35-
* @return {vnode} - radio button with label associated
36-
*/
37-
const radioButton = (label, isChecked, action) => h('.w-33.form-check', [
38-
h('input.form-check-input', {
39-
onchange: action,
40-
type: 'radio',
41-
id: `dcsFilterRadio${label}`,
42-
name: 'dcsFilterRadio',
43-
value: label,
44-
checked: isChecked,
45-
}, ''),
46-
h('label.form-check-label', {
47-
style: 'cursor: pointer;',
48-
for: `dcsFilterRadio${label}`,
49-
}, label),
50-
]);
51-
5250
export default dcsOperationRadioButtons;

lib/public/components/Filters/RunsFilter/ddflp.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* or submit itself to any jurisdiction.
1212
*/
1313

14+
import radioButton from '../../common/form/inputs/RadioButton.js';
1415
import { h } from '/js/src/index.js';
1516

1617
/**
@@ -20,33 +21,30 @@ import { h } from '/js/src/index.js';
2021
*/
2122
const ddflpOperationRadioButtons = (runModel) => {
2223
const state = runModel.getDdflpFilterOperation();
24+
const name = 'ddFlpFilterRadio';
25+
const label1 = 'ANY';
26+
const label2 = 'OFF';
27+
const label3 = 'ON';
2328
return h('.form-group-header.flex-row.w-100', [
24-
radioButton('ANY', state === '', () => runModel.removeDdflp()),
25-
radioButton('OFF', state === false, () => runModel.setDdflpFilterOperation(false)),
26-
radioButton('ON', state === true, () => runModel.setDdflpFilterOperation(true)),
29+
radioButton({
30+
label: label1,
31+
isChecked: state === '',
32+
action: () => runModel.removeDdflp(),
33+
name: name,
34+
}),
35+
radioButton({
36+
label: label2,
37+
isChecked: state === false,
38+
action: () => runModel.setDdflpFilterOperation(false),
39+
name: name,
40+
}),
41+
radioButton({
42+
label: label3,
43+
isChecked: state === true,
44+
action: () => runModel.setDdflpFilterOperation(true),
45+
name: name,
46+
}),
2747
]);
2848
};
2949

30-
/**
31-
* Build a radio button with its configuration and actions
32-
* @param {string} label - label to be displayed to the user for radio button
33-
* @param {boolean} isChecked - is radio button selected or not
34-
* @param {Function} action - action to be followed on user click
35-
* @return {vnode} - radio button with label associated
36-
*/
37-
const radioButton = (label, isChecked, action) => h('.w-33.form-check', [
38-
h('input.form-check-input', {
39-
onchange: action,
40-
type: 'radio',
41-
id: `ddFlpFilterRadio${label}`,
42-
name: 'ddFlpFilterRadio',
43-
value: label,
44-
checked: isChecked,
45-
}, ''),
46-
h('label.form-check-label', {
47-
style: 'cursor: pointer;',
48-
for: `ddFlpFilterRadio${label}`,
49-
}, label),
50-
]);
51-
5250
export default ddflpOperationRadioButtons;

lib/public/components/Filters/RunsFilter/epn.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* or submit itself to any jurisdiction.
1212
*/
1313

14+
import radiobutton from '../../common/form/inputs/RadioButton.js';
1415
import { h } from '/js/src/index.js';
1516

1617
/**
@@ -20,33 +21,30 @@ import { h } from '/js/src/index.js';
2021
*/
2122
const epnOperationRadioButtons = (runModel) => {
2223
const state = runModel.getEpnFilterOperation();
24+
const name = 'epnFilterRadio';
25+
const label1 = 'ANY';
26+
const label2 = 'OFF';
27+
const label3 = 'ON';
2328
return h('.form-group-header.flex-row.w-100', [
24-
radioButton('ANY', state === '', () => runModel.removeEpn()),
25-
radioButton('OFF', state === false, () => runModel.setEpnFilterOperation(false)),
26-
radioButton('ON', state === true, () => runModel.setEpnFilterOperation(true)),
29+
radiobutton({
30+
label: label1,
31+
isChecked: state === '',
32+
action: () => runModel.removeEpn(),
33+
name: name,
34+
}),
35+
radiobutton({
36+
label: label2,
37+
isChecked: state === false,
38+
action: () => runModel.setEpnFilterOperation(false),
39+
name: name,
40+
}),
41+
radiobutton({
42+
label: label3,
43+
isChecked: state === true,
44+
action: () => runModel.setEpnFilterOperation(true),
45+
name: name,
46+
}),
2747
]);
2848
};
2949

30-
/**
31-
* Build a radio button with its configuration and actions
32-
* @param {string} label - label to be displayed to the user for radio button
33-
* @param {boolean} isChecked - is radio button selected or not
34-
* @param {Function} action - action to be followed on user click
35-
* @return {vnode} - radio button with label associated
36-
*/
37-
const radioButton = (label, isChecked, action) => h('.w-33.form-check', [
38-
h('input.form-check-input', {
39-
onchange: action,
40-
type: 'radio',
41-
id: `epnFilterRadio${label}`,
42-
name: 'epnFilterRadio',
43-
value: label,
44-
checked: isChecked,
45-
}, ''),
46-
h('label.form-check-label', {
47-
style: 'cursor: pointer;',
48-
for: `epnFilterRadio${label}`,
49-
}, label),
50-
]);
51-
5250
export default epnOperationRadioButtons;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 { h } from '/js/src/index.js';
15+
16+
/**
17+
* @typedef radioButtonConfig - configration object for radioButton.
18+
*
19+
* @property {string} label - label to be displayed to the user for radio button
20+
* @property {boolean} isChecked - is radio button selected or not
21+
* @property {function} action - action to be followed on user click
22+
* @property {string} id - id of the radiobutton element
23+
* @property {string} name - name of the radiobutton element
24+
* @property {string} style - label style property
25+
*/
26+
27+
/**
28+
* Build a radio button with its configuration and actions
29+
* @param {radioButtonConfig} configuration - configration object for radioButton.
30+
* @return {vnode} - radio button with associated label.
31+
*/
32+
const radiobutton = (configuration = {}) => {
33+
const {
34+
label = 'radio',
35+
isChecked = false,
36+
action = () => { },
37+
name = 'value',
38+
id = `${name}${label}`,
39+
style = 'cursor: pointer;',
40+
} = configuration;
41+
return h('.w-33.form-check', [
42+
h('input.form-check-input', {
43+
onchange: action,
44+
type: 'radio',
45+
id: id,
46+
name: name,
47+
value: label,
48+
checked: isChecked,
49+
}, ''),
50+
h('label.form-check-label', {
51+
style: style,
52+
for: `${name}${label}`,
53+
}, label),
54+
]);
55+
};
56+
57+
export default radiobutton;

lib/public/views/LhcFills/ActiveColumns/lhcFillsActiveColumns.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ export const lhcFillsActiveColumns = {
8686
},
8787
},
8888
stableBeams: {
89-
name: 'Stable beams',
89+
name: 'Stable Beams Only',
9090
visible: false,
9191
format: (boolean) => boolean ? 'On' : 'Off',
92-
filter: toggleStableBeamOnlyFilter,
92+
filter: (lhcFillModel) => toggleStableBeamOnlyFilter(lhcFillModel, true),
9393
},
9494
stableBeamsDuration: {
9595
name: 'SB Duration',

lib/public/views/LhcFills/Overview/LhcFillsOverviewModel.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,6 @@ export class LhcFillsOverviewModel extends OverviewPageModel {
129129
return this._filteringModel;
130130
}
131131

132-
/**
133-
* Returns the list of URL params corresponding to the currently applied filter
134-
*
135-
* @return {Object} the URL params
136-
*
137-
* @private
138-
*/
139-
_getFilterQueryParams() {
140-
return {};
141-
}
142-
143132
/**
144133
* Apply the current filtering and update the remote data list
145134
*

test/public/lhcFills/overview.test.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const { expect } = chai;
3131
const percentageRegex = new RegExp(/\d{1,2}.\d{2}%/);
3232
const durationRegex = new RegExp(/\d{2}:\d{2}:\d{2}/);
3333

34+
const filterButtonSellector= '#openFilterToggle';
35+
3436
const defaultViewPort = {
3537
width: 700,
3638
height: 763,
@@ -265,14 +267,25 @@ module.exports = () => {
265267
});
266268

267269
it('should successfully display filter elements', async () => {
268-
const efficiencyExpect = { selector: 'tbody tr:nth-child(1) td:nth-child(8)', value: '41.67%' };
269-
270+
const filterSBExpect = { selector: '.w-30', value: 'Stable Beams Only' };
270271
await goToPage(page, 'lhc-fill-overview');
272+
await pressElement(page, filterButtonSellector);
273+
await expectInnerText(page, filterSBExpect.selector, filterSBExpect.value);
274+
});
271275

272-
await expectInnerText(page, beamTypeExpect.selector, beamTypeExpect.value);
276+
277+
it('should successfully un-apply Stable Beam filter menu', async () => {
278+
const filterButtonSBOnlySellector= '#stableBeamsOnlyRadioOFF';
279+
const filterSBExpect = { selector: '.w-30', value: 'Stable Beams Only' };
280+
await goToPage(page, 'lhc-fill-overview');
281+
await waitForTableLength(page, 5);
282+
await pressElement(page, filterButtonSellector);
283+
await pressElement(page, filterButtonSBOnlySellector);
284+
await waitForTableLength(page, 6);
273285
});
274286

275-
it('should successfully toggle to stable beam only', async () => {
287+
it('should successfully turn off stable beam only from header', async () => {
288+
await goToPage(page, 'lhc-fill-overview');
276289
await waitForTableLength(page, 5);
277290
await pressElement(page, '.slider.round');
278291
await waitForTableLength(page, 6);

0 commit comments

Comments
 (0)