Skip to content

Commit 1f963b2

Browse files
committed
use abastraction
1 parent f885282 commit 1f963b2

5 files changed

Lines changed: 54 additions & 29 deletions

File tree

lib/domain/dtos/filters/RunFilterDto.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const { RUN_QUALITIES } = require('../../enums/RunQualities.js');
1717
const { IntegerComparisonDto, FloatComparisonDto } = require('./NumericalComparisonDto.js');
1818
const { RUN_CALIBRATION_STATUS } = require('../../enums/RunCalibrationStatus.js');
1919
const { RUN_DEFINITIONS } = require('../../enums/RunDefinition.js');
20-
const { regex } = require('../FileDto.js');
2120

2221
const DetectorsFilterDto = Joi.object({
2322
operator: Joi.string().valid('or', 'and', 'none').required(),

lib/public/components/Filters/common/FilteringModel.js

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

14+
import { expandQueryLikeNestedKey } from '../../../utilities/expandNestedKey.js';
1415
import { Observable } from '/js/src/index.js';
1516

1617
/**
@@ -52,13 +53,13 @@ export class FilteringModel extends Observable {
5253
* @return {object} the normalized values
5354
*/
5455
get normalized() {
55-
const ret = {};
56+
const result = {};
5657
for (const [filterKey, filter] of Object.entries(this._filters)) {
5758
if (filter && !filter.isEmpty) {
58-
ret[filterKey] = filter.normalized;
59+
result[filterKey] = filter.normalized;
5960
}
6061
}
61-
return ret;
62+
return expandQueryLikeNestedKey(result);
6263
}
6364

6465
/**
@@ -110,5 +111,7 @@ export class FilteringModel extends Observable {
110111
}
111112

112113
this._filters[key] = filter;
114+
filter.bubbleTo(this);
115+
filter.visualChange$?.bubbleTo(this._visualChange$);
113116
}
114117
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @license
3+
* Copyright CERN and copyright holders of ALICE O2. 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-o2.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+
/**
15+
* Expand query-like formatted keys of a object { a[b][c]: x } to { a: { b: { c: x } } }
16+
*
17+
* @param {object} obj a object
18+
* @return {object} obj
19+
*/
20+
export function expandQueryLikeNestedKey(obj) {
21+
const result = {};
22+
23+
for (const nestedKey in obj) {
24+
const value = obj[nestedKey];
25+
const subKeys = nestedKey.split(/[[\]]/).filter(Boolean);
26+
27+
let currentNestedObj = result;
28+
for (let i = 0; i < subKeys.length; i++) {
29+
const key = subKeys[i];
30+
if (i === subKeys.length - 1) {
31+
currentNestedObj[key] = value;
32+
} else {
33+
if (!(key in currentNestedObj)) {
34+
currentNestedObj[key] = {};
35+
}
36+
currentNestedObj = currentNestedObj[key];
37+
}
38+
}
39+
}
40+
41+
return result;
42+
}

lib/public/views/Runs/RunPerDataPass/RunsPerDataPassOverviewModel.js

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,10 @@ export class RunsPerDataPassOverviewModel extends FixedPdpBeamTypeRunsOverviewMo
5050
this._skimmableRuns$ = new ObservableData(RemoteData.notAsked());
5151
this._skimmableRuns$.bubbleTo(this);
5252

53-
this._gaqNotBadFractionFilterModel = new NumericalComparisonFilterModel({
53+
this._filteringModel.put('gaq[notBadFraction]', new NumericalComparisonFilterModel({
5454
scale: 0.01,
5555
integer: false,
56-
});
57-
this._gaqNotBadFractionFilterModel.observe(() => this._applyFilters());
58-
this._gaqNotBadFractionFilterModel.visualChange$.bubbleTo(this);
56+
}));
5957

6058
this._runDetectorsSelectionModel = new RunDetectorsSelectionModel();
6159
this._runDetectorsSelectionModel.bubbleTo(this);
@@ -67,13 +65,6 @@ export class RunsPerDataPassOverviewModel extends FixedPdpBeamTypeRunsOverviewMo
6765
this._discardAllQcFlagsActionState$.bubbleTo(this);
6866
}
6967

70-
/**
71-
* @inheritDoc
72-
*/
73-
isAnyFilterActive() {
74-
return super.isAnyFilterActive() || !this._gaqNotBadFractionFilterModel.isEmpty;
75-
}
76-
7768
/**
7869
* Change ready for skimming flag for given run
7970
*
@@ -133,10 +124,10 @@ export class RunsPerDataPassOverviewModel extends FixedPdpBeamTypeRunsOverviewMo
133124
* @inheritdoc
134125
*/
135126
getRootEndpoint() {
127+
const gaqNotBadFilter = this._filteringModel.get('gaq[notBadFraction]');
136128
const filter = { dataPassIds: [this._dataPassId] };
137-
if (!this._gaqNotBadFractionFilterModel.isEmpty) {
129+
if (!gaqNotBadFilter.isEmpty) {
138130
filter.gaq = {
139-
notBadFraction: this._gaqNotBadFractionFilterModel.normalized,
140131
mcReproducibleAsNotBad: this._mcReproducibleAsNotBad,
141132
};
142133
}
@@ -149,7 +140,6 @@ export class RunsPerDataPassOverviewModel extends FixedPdpBeamTypeRunsOverviewMo
149140
*/
150141
resetFiltering(fetch = true) {
151142
super.resetFiltering(fetch);
152-
this._gaqNotBadFractionFilterModel?.reset(); // Reset is called in super class
153143
}
154144

155145
/**
@@ -227,15 +217,6 @@ export class RunsPerDataPassOverviewModel extends FixedPdpBeamTypeRunsOverviewMo
227217
return this._discardAllQcFlagsActionState$.getCurrent();
228218
}
229219

230-
/**
231-
* Get gaqNotBadFraction filter model
232-
*
233-
* @return {NumericalComparisonFilterModel} filter model
234-
*/
235-
get gaqNotBadFractionFilterModel() {
236-
return this._gaqNotBadFractionFilterModel;
237-
}
238-
239220
/**
240221
* Send request to mark current data pass as skimmable
241222
* @return {Promise<void>} resolved once request is handled

lib/public/views/Runs/RunPerDataPass/RunsPerDataPassOverviewPage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ export const RunsPerDataPassOverviewPage = ({
192192

193193
return frontLink(gaqDisplay, 'gaq-flags', { dataPassId, runNumber });
194194
},
195-
filter: ({ gaqNotBadFractionFilterModel }) => numericalComparisonFilter(
196-
gaqNotBadFractionFilterModel,
195+
filter: ({ filteringModel }) => numericalComparisonFilter(
196+
filteringModel.get('gaq[notBadFraction]'),
197197
{ step: 0.0001, selectorPrefix: 'gaqNotBadFraction' },
198198
),
199199
filterTooltip: 'expressed as a percentage',

0 commit comments

Comments
 (0)