Skip to content

Commit 7a03dd1

Browse files
[O2B-1577] Rename include.byName filter to permittedNonPhysicsNames (#2128)
* rename include[byname] to permittedNonPhysicsNames * the lines of code in datapassService.getAll with regards to filtering have been refactored for readability
1 parent 469ef0f commit 7a03dd1

9 files changed

Lines changed: 45 additions & 44 deletions

File tree

lib/domain/enums/NonPhysicsProductionsNamesWords.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ const NonPhysicsProductionsNamesWords = Object.freeze({
2323
module.exports.NonPhysicsProductionsNamesWords = NonPhysicsProductionsNamesWords;
2424

2525
module.exports.NON_PHYSICS_PRODUCTIONS_NAMES_WORDS = Object.values(NonPhysicsProductionsNamesWords);
26+
27+
module.exports.NON_PHYSICS_PRODUCTIONS_NAMES_TOTAL_LENGTH = Object.values(NonPhysicsProductionsNamesWords).join(',').length;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class DetectorsFilterModel extends FilterModel {
6262
operator: this._combinationOperatorModel.current,
6363
};
6464
if (!this.isNone()) {
65-
normalized.values = this._dropdownModel.selected.join();
65+
normalized.values = this._dropdownModel.normalized;
6666
}
6767
return normalized;
6868
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,6 @@ export class SelectionModel extends Observable {
373373
* @return {string|string[]|boolean|boolean[]|number|number[]|SelectionOption|SelectionOption[]} the normalized value
374374
*/
375375
get normalized() {
376-
return (this._allowEmpty || this._multiple) ? this.selected.join() : this.current;
376+
return (this._allowEmpty || this._multiple) ? this.selected.join(',') : this.current;
377377
}
378378
}

lib/public/views/DataPasses/ActiveColumns/dataPassesActiveColumns.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const dataPassesActiveColumns = {
102102

103103
nonPhysicsProductions: {
104104
name: 'Include nonphysics productions',
105-
filter: (filteringModel) => checkboxes(filteringModel.get('include[byName]')),
105+
filter: (filteringModel) => checkboxes(filteringModel.get('permittedNonPhysicsNames')),
106106
visible: false,
107107
},
108108
};

lib/public/views/DataPasses/DataPassesOverviewModel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class DataPassesOverviewModel extends OverviewPageModel {
3131
router,
3232
{
3333
names: new TextTokensFilterModel(),
34-
'include[byName]': new SelectionModel({
34+
permittedNonPhysicsNames: new SelectionModel({
3535
availableOptions: NON_PHYSICS_PRODUCTIONS_NAMES_WORDS.map((word) => ({ label: word.toUpperCase(), value: word })),
3636
}),
3737
},

lib/server/controllers/dataPasses.controller.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ const { dtoValidator } = require('../utilities/dtoValidator.js');
2121
const { countedItemsToHttpView } = require('../utilities/countedItemsToHttpView.js');
2222
const { updateExpressResponseFromNativeError } = require('../express/updateExpressResponseFromNativeError');
2323
const PaginationDto = require('../../domain/dtos/PaginationDto.js');
24-
const { NON_PHYSICS_PRODUCTIONS_NAMES_WORDS } = require('../../domain/enums/NonPhysicsProductionsNamesWords.js');
24+
const {
25+
NON_PHYSICS_PRODUCTIONS_NAMES_WORDS,
26+
NON_PHYSICS_PRODUCTIONS_NAMES_TOTAL_LENGTH,
27+
} = require('../../domain/enums/NonPhysicsProductionsNamesWords.js');
2528

2629
/**
2730
* List All DataPasses with statistics
@@ -34,17 +37,14 @@ const listDataPassesHandler = async (req, res) => {
3437
lhcPeriodIds: Joi.array().items(Joi.number()),
3538
ids: Joi.array().items(Joi.number()),
3639
names: Joi.array().items(Joi.string()),
37-
include: Joi.object({ byName: Joi.string().custom((value, helper) => {
38-
if (value.length > 10) {
39-
return helper.error('byName cannot have more than 10 characters');
40-
}
41-
const nameTokens = value?.split(',');
40+
permittedNonPhysicsNames: Joi.string().max(NON_PHYSICS_PRODUCTIONS_NAMES_TOTAL_LENGTH).custom((value, helper) => {
41+
const nameTokens = value.split(',');
4242
const allTokensCorrect = nameTokens.every((token) => NON_PHYSICS_PRODUCTIONS_NAMES_WORDS.includes(token));
4343
if (!allTokensCorrect) {
44-
return helper.error(`All byName must comma delimited list of ${NON_PHYSICS_PRODUCTIONS_NAMES_WORDS}`);
44+
return helper.error(`All permittedNonPhysicsNames must comma delimited list of ${NON_PHYSICS_PRODUCTIONS_NAMES_WORDS}`);
4545
}
4646
return nameTokens;
47-
}) }),
47+
}),
4848
},
4949
page: PaginationDto,
5050
sort: DtoFactory.order(['id', 'name']),

lib/server/services/dataPasses/DataPassService.js

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,25 @@ class DataPassService {
8888
* @returns {Promise<CountedItems<DataPass>>} result
8989
*/
9090
async getAll({
91-
filter,
91+
filter = {},
9292
limit,
9393
offset,
9494
sort,
9595
} = {}) {
9696
const queryBuilder = this.prepareQueryBuilder();
9797

98+
/**
99+
* @typedef
100+
* @property {object} filter
101+
* @property {number[]} [filter.lhcPeriodIds] lhcPeriod identifier to filter with
102+
* @property {number[]} [filter.simulationPassIds] simulationPass identifier to filter with
103+
* @property {number[]} [filter.ids] data passes identifier to filter with
104+
* @property {string[]} [filter.names] data passes names to filter with
105+
* @property {string[]} [filter.permittedNonPhysicsNames] list of tokens in data passes names which indicate
106+
* a given data pass should not be excluded, possible tokens are 'test', 'debug'.
107+
*/
108+
const { ids, names, permittedNonPhysicsNames = [], lhcPeriodIds, simulationPassIds } = filter;
109+
98110
if (sort) {
99111
for (const property in sort) {
100112
queryBuilder.orderBy(property, sort[property]);
@@ -108,37 +120,24 @@ class DataPassService {
108120
queryBuilder.offset(offset);
109121
}
110122

111-
if (filter) {
112-
/**
113-
* @typedef
114-
* @property {object} filter
115-
* @property {number[]} [filter.lhcPeriodIds] lhcPeriod identifier to filter with
116-
* @property {number[]} [filter.simulationPassIds] simulationPass identifier to filter with
117-
* @property {number[]} [filter.ids] data passes identifier to filter with
118-
* @property {string[]} [filter.names] data passes names to filter with
119-
* @property {boolean} [filter.include.byName] list of tokens in data passes names which indicate
120-
* a given data pass should not be excluded, possible tokens are 'test', 'debug'.
121-
*/
122-
const { ids, names, lhcPeriodIds, simulationPassIds } = filter;
123-
if (lhcPeriodIds) {
124-
queryBuilder.where('lhcPeriodId').oneOf(...lhcPeriodIds);
125-
}
126-
if (simulationPassIds) {
127-
queryBuilder.whereAssociation('anchoredSimulationPasses', 'id').oneOf(...simulationPassIds);
128-
}
129-
if (ids) {
130-
queryBuilder.where('id').oneOf(...ids);
131-
}
132-
if (names) {
133-
queryBuilder.where('name').oneOf(...names);
134-
}
123+
if (lhcPeriodIds) {
124+
queryBuilder.where('lhcPeriodId').oneOf(...lhcPeriodIds);
125+
}
126+
if (simulationPassIds) {
127+
queryBuilder.whereAssociation('anchoredSimulationPasses', 'id').oneOf(...simulationPassIds);
128+
}
129+
if (ids) {
130+
queryBuilder.where('id').oneOf(...ids);
131+
}
132+
if (names) {
133+
queryBuilder.where('name').oneOf(...names);
135134
}
136135

137-
const byName = filter?.include?.byName ?? [];
138-
if (!byName.includes(NonPhysicsProductionsNamesWords.TEST)) {
136+
if (!permittedNonPhysicsNames.includes(NonPhysicsProductionsNamesWords.TEST)) {
139137
queryBuilder.where('name').not().substring(`\\_${NonPhysicsProductionsNamesWords.TEST}`);
140138
}
141-
if (!byName.includes(NonPhysicsProductionsNamesWords.DEBUG)) {
139+
140+
if (!permittedNonPhysicsNames.includes(NonPhysicsProductionsNamesWords.DEBUG)) {
142141
queryBuilder.where('name').not().substring(`\\_${NonPhysicsProductionsNamesWords.DEBUG}`);
143142
}
144143

test/api/dataPasses.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,13 @@ module.exports = () => {
296296
});
297297
});
298298
it('should successfully include TEST productions', async () => {
299-
const response = await request(server).get('/api/dataPasses?filter[lhcPeriodIds][]=2&filter[include][byName]=test');
299+
const response = await request(server).get('/api/dataPasses?filter[lhcPeriodIds][]=2&filter[permittedNonPhysicsNames]=test');
300300
expect(response.status).to.be.equal(200);
301301
const { data } = await response.body;
302302
expect(data.map(({ name }) => name)).to.have.all.members(['LHC22b_apass1', 'LHC22b_skimming','LHC22b_apass2_skimmed', 'LHC22b_test']);
303303
});
304304
it('should successfully include DEBUG productions', async () => {
305-
const response = await request(server).get('/api/dataPasses?filter[lhcPeriodIds][]=2&filter[include][byName]=debug');
305+
const response = await request(server).get('/api/dataPasses?filter[lhcPeriodIds][]=2&filter[permittedNonPhysicsNames]=debug');
306306
expect(response.status).to.be.equal(200);
307307
const { data } = await response.body;
308308
expect(data.map(({ name }) => name)).to.have.all.members(['LHC22b_apass1', 'LHC22b_skimming','LHC22b_apass2_skimmed', 'LHC22b_debug']);

test/public/Filters/filtersToUrl.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ module.exports = () => {
352352
"page": "data-passes-per-lhc-period-overview",
353353
"lhcPeriodId": "2",
354354
"filter[names][]": "LHC22b_apass1",
355-
"filter[include][byName]": "test"
355+
"filter[permittedNonPhysicsNames]": "test"
356356
});
357357
});
358358

@@ -367,7 +367,7 @@ module.exports = () => {
367367
"page": "data-passes-per-simulation-pass-overview",
368368
"simulationPassId": "1",
369369
"filter[names][]": "LHC22b_apass1",
370-
"filter[include][byName]": "test"
370+
"filter[permittedNonPhysicsNames]": "test"
371371
});
372372
});
373373

0 commit comments

Comments
 (0)