Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
martinboulais committed Dec 29, 2024
1 parent b4166fe commit 5fe9f8a
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 79 deletions.
109 changes: 109 additions & 0 deletions lib/public/components/Filters/RunsFilter/RunDefinitionFilterModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { RunDefinition } from '../../../domain/enums/RunDefinition.js';
import { FilterModel } from '../common/FilterModel.js';

/**
* Run definition filter model
*/
export class RunDefinitionFilterModel extends FilterModel {
/**
* Constructor
*/
constructor() {
super();
this._definitions = [];

Check warning on line 13 in lib/public/components/Filters/RunsFilter/RunDefinitionFilterModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/RunsFilter/RunDefinitionFilterModel.js#L11-L13

Added lines #L11 - L13 were not covered by tests
}

// eslint-disable-next-line valid-jsdoc
/**
* @inheritDoc
*/
reset() {
this._definitions = [];

Check warning on line 21 in lib/public/components/Filters/RunsFilter/RunDefinitionFilterModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/RunsFilter/RunDefinitionFilterModel.js#L20-L21

Added lines #L20 - L21 were not covered by tests
}

// eslint-disable-next-line valid-jsdoc
/**
* @inheritDoc
*/
get isEmpty() {
return this._definitions.length === 0;

Check warning on line 29 in lib/public/components/Filters/RunsFilter/RunDefinitionFilterModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/RunsFilter/RunDefinitionFilterModel.js#L28-L29

Added lines #L28 - L29 were not covered by tests
}

// eslint-disable-next-line valid-jsdoc
/**
* @inheritDoc
*/
get normalized() {
return this._definitions.join(',');

Check warning on line 37 in lib/public/components/Filters/RunsFilter/RunDefinitionFilterModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/RunsFilter/RunDefinitionFilterModel.js#L36-L37

Added lines #L36 - L37 were not covered by tests
}

/**
* States if the given definition is currently in the run definition filter
*
* @param {string} definition the run definition to look for
* @return {boolean} true if the definition is included in the filter
*/
isDefinitionInFilter(definition) {
return this._definitions.includes(definition);

Check warning on line 47 in lib/public/components/Filters/RunsFilter/RunDefinitionFilterModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/RunsFilter/RunDefinitionFilterModel.js#L46-L47

Added lines #L46 - L47 were not covered by tests
}

/**
* Add a given definition in the current run definition filter if it is not already present
*
* @param {string} definition the run definition to add
* @return {void}
*/
addDefinition(definition) {
if (!this.isDefinitionInFilter(definition)) {
this._definitions.push(definition);
this.notify();

Check warning on line 59 in lib/public/components/Filters/RunsFilter/RunDefinitionFilterModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/RunsFilter/RunDefinitionFilterModel.js#L56-L59

Added lines #L56 - L59 were not covered by tests
}
}

/**
* Remove a given definition from the current run definition filter if it is in it (else do nothing)
*
* @param {string} definition the definition to add
* @return {void}
*/
removeDefinition(definition) {
const originalLength = this._definitions._definitions;
this._definitions = this._definitions.filter((existingDefinition) => definition !== existingDefinition);
if (this._definitions.length !== originalLength) {
this.notify();

Check warning on line 73 in lib/public/components/Filters/RunsFilter/RunDefinitionFilterModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/RunsFilter/RunDefinitionFilterModel.js#L69-L73

Added lines #L69 - L73 were not covered by tests
}
}

/**
* Sets the current filter to physics only
*
* @return {void}
*/
setPhysicsOnly() {
if (!this.isPhysicsOnly()) {
this._definitions = [RunDefinition.Physics];
this.notify();

Check warning on line 85 in lib/public/components/Filters/RunsFilter/RunDefinitionFilterModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/RunsFilter/RunDefinitionFilterModel.js#L82-L85

Added lines #L82 - L85 were not covered by tests
}
}

/**
* Returns true if the current filter is physics only
*
* @return {boolean} true if filter is physics only
*/
isPhysicsOnly() {
return this._definitions.length === 1 && this._definitions[0] === RunDefinition.Physics;

Check warning on line 95 in lib/public/components/Filters/RunsFilter/RunDefinitionFilterModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/RunsFilter/RunDefinitionFilterModel.js#L94-L95

Added lines #L94 - L95 were not covered by tests
}

/**
* Empty the current filter
*
* @return {void}
*/
setEmpty() {
if (!this.isEmpty) {
this.reset();
this.notify();

Check warning on line 106 in lib/public/components/Filters/RunsFilter/RunDefinitionFilterModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/RunsFilter/RunDefinitionFilterModel.js#L103-L106

Added lines #L103 - L106 were not covered by tests
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@ import { checkboxFilter } from '../common/filters/checkboxFilter.js';
import { RUN_DEFINITIONS } from '../../../domain/enums/RunDefinition.js';

/**
* Returns the definition filter component
* @param {RunsOverviewModel} runModel The run model
* @return {vnode} A list of checkboxes that lets the user look for runs with specific definition
* Renders a list of checkboxes that lets the user look for runs with specific definition
*
* @param {RunDefinitionFilterModel} runDefinitionFilterModel run definition filter model
* @return {Component} the filter
*/
const definitionFilter = (runModel) => checkboxFilter(
export const runDefinitionFilter = (runDefinitionFilterModel) => checkboxFilter(

Check warning on line 23 in lib/public/components/Filters/RunsFilter/runDefinitionFilter.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/RunsFilter/runDefinitionFilter.js#L23

Added line #L23 was not covered by tests
'runDefinition',
RUN_DEFINITIONS,
(runQuality) => runModel.isDefinitionInFilter(runQuality),
(runDefinition) => runDefinitionFilterModel.isDefinitionInFilter(runDefinition),

Check warning on line 26 in lib/public/components/Filters/RunsFilter/runDefinitionFilter.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/RunsFilter/runDefinitionFilter.js#L26

Added line #L26 was not covered by tests
(e, definition) => e.target.checked
? runModel.addDefinitionFilter(definition)
: runModel.removeDefinitionFilter(definition),
? runDefinitionFilterModel.addDefinition(definition)
: runDefinitionFilterModel.removeDefinition(definition),

Check warning on line 29 in lib/public/components/Filters/RunsFilter/runDefinitionFilter.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/RunsFilter/runDefinitionFilter.js#L28-L29

Added lines #L28 - L29 were not covered by tests
);

export default definitionFilter;
11 changes: 9 additions & 2 deletions lib/public/views/Runs/ActiveColumns/runsActiveColumns.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import nEpnsFilter from '../../../components/Filters/RunsFilter/nEpns.js';
import { triggerValueFilter } from '../../../components/Filters/RunsFilter/triggerValueFilter.js';
import lhcPeriodsFilter from '../../../components/Filters/RunsFilter/lhcPeriod.js';
import { formatRunType } from '../../../utilities/formatting/formatRunType.js';
import definitionFilter from '../../../components/Filters/RunsFilter/definitionFilter.js';
import { runDefinitionFilter } from '../../../components/Filters/RunsFilter/runDefinitionFilter.js';
import { profiles } from '../../../components/common/table/profiles.js';
import { formatDuration } from '../../../utilities/formatting/formatDuration.mjs';
import { formatRunStart } from '../format/formatRunStart.js';
Expand Down Expand Up @@ -326,7 +326,14 @@ export const runsActiveColumns = {
}
return h('.flex-column.items-start', lines);
},
filter: definitionFilter,

/**
* Run definition filter component
*
* @param {RunsOverviewModel} runsOverviewModel the runs overview model
* @return {Component} the filter component
*/
filter: (runsOverviewModel) => runDefinitionFilter(runsOverviewModel.filteringModel.get('definitions')),

Check warning on line 336 in lib/public/views/Runs/ActiveColumns/runsActiveColumns.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Runs/ActiveColumns/runsActiveColumns.js#L336

Added line #L336 was not covered by tests
},
runDuration: {
name: 'Duration',
Expand Down
63 changes: 2 additions & 61 deletions lib/public/views/Runs/Overview/RunsOverviewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { FilteringModel } from '../../../components/Filters/common/FilteringMode
import { buildUrl } from '../../../utilities/fetch/buildUrl.js';
import { TimeRangeFilterModel } from '../../../components/Filters/RunsFilter/TimeRangeFilter.js';
import { RawTextFilterModel } from '../../../components/Filters/common/filters/RawTextFilterModel.js';
import { RunDefinitionFilterModel } from '../../../components/Filters/RunsFilter/RunDefinitionFilterModel.js';

/**
* Model representing handlers for runs page
Expand All @@ -53,6 +54,7 @@ export class RunsOverviewModel extends OverviewPageModel {
]),
o2start: new TimeRangeFilterModel(),
o2end: new TimeRangeFilterModel(),
definitions: new RunDefinitionFilterModel(),
runTypes: new RunTypesFilterModel(),
eorReason: new EorReasonFilterModel(),
magnets: new MagnetsFilteringModel(),
Expand Down Expand Up @@ -160,8 +162,6 @@ export class RunsOverviewModel extends OverviewPageModel {
resetFiltering(fetch = true) {
this._filteringModel.reset();

Check warning on line 163 in lib/public/views/Runs/Overview/RunsOverviewModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Runs/Overview/RunsOverviewModel.js#L163

Added line #L163 was not covered by tests

this._runDefinitionFilter = [];

this._fillNumbersFilter = '';

this._runDurationFilter = null;
Expand Down Expand Up @@ -199,7 +199,6 @@ export class RunsOverviewModel extends OverviewPageModel {
*/
isAnyFilterActive() {
return this._filteringModel.isAnyFilterActive()
|| this._runDefinitionFilter.length > 0
|| this._fillNumbersFilter !== ''
|| this._runDurationFilter !== null
|| this._lhcPeriodsFilter !== null
Expand Down Expand Up @@ -247,61 +246,6 @@ export class RunsOverviewModel extends OverviewPageModel {
this.notify();
}

/**
* States if the given definition is currently in the run definition filter, and it's the only one
*
* @param {string} definition the run definition to look for
* @return {boolean} true if the definition is the only one currently applied
*/
isDefinitionOnlyOneInFilter(definition) {
return this._runDefinitionFilter.length === 1 && this._runDefinitionFilter[0] === definition;
}

/**
* States if the given definition is currently in the run definition filter
*
* @param {string} definition the run definition to look for
* @return {boolean} true if the definition is included in the filter
*/
isDefinitionInFilter(definition) {
return this._runDefinitionFilter.includes(definition);
}

/**
* Add a given definition in the current run definition filter if it is not already present, then refresh runs list
*
* @param {string} definition the run definition to add
* @return {void}
*/
addDefinitionFilter(definition) {
if (!this.isDefinitionInFilter(definition)) {
this._runDefinitionFilter.push(definition);
this._applyFilters();
}
}

/**
* Remove a given definition from the current run definition filter if it is in it (else do nothing) then refresh runs list
*
* @param {string} definition the definition to add
* @return {void}
*/
removeDefinitionFilter(definition) {
this._runDefinitionFilter = this._runDefinitionFilter.filter((existingDefinition) => definition !== existingDefinition);
this._applyFilters();
}

/**
* Set the list of definition to be used as the current run definition filter
*
* @param {string[]} definitions the new definition filter
* @return {void}
*/
setDefinitionFilter(definitions) {
this._runDefinitionFilter = [...definitions];
this._applyFilters();
}

/**
* Return the currently applied fill number filter
*
Expand Down Expand Up @@ -631,9 +575,6 @@ export class RunsOverviewModel extends OverviewPageModel {
...this.runFilterValues && {
'filter[runNumbers]': this.runFilterValues,
},
...this._runDefinitionFilter.length > 0 && {
'filter[definitions]': this._runDefinitionFilter.join(','),
},
...this._fillNumbersFilter && {
'filter[fillNumbers]': this._fillNumbersFilter,
},
Expand Down
14 changes: 7 additions & 7 deletions lib/public/views/Runs/Overview/RunsOverviewPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { runsActiveColumns } from '../ActiveColumns/runsActiveColumns.js';
import { table } from '../../../components/common/table/table.js';
import { runNumberFilter } from '../../../components/Filters/RunsFilter/runNumberFilter.js';
import { switchInput } from '../../../components/common/form/switchInput.js';
import { RunDefinition } from '../../../domain/enums/RunDefinition.js';

const TABLEROW_HEIGHT = 59;
// Estimate of the navbar and pagination elements height total; Needs to be updated in case of changes;
Expand All @@ -29,14 +28,15 @@ const PAGE_USED_HEIGHT = 215;
/**
* Display a toggle switch to display physics runs only
*
* @param {RunsOverviewModel} runsOverviewModel the model of the runs overview
* @param {RunDefinitionFilterModel} runDefinitionFilterModel the run definition filter model
* @returns {Component} the toggle switch
*/
export const togglePhysicsOnlyFilter = (runsOverviewModel) => {
const isPhysicsOnly = runsOverviewModel.isDefinitionOnlyOneInFilter(RunDefinition.Physics);
export const togglePhysicsOnlyFilter = (runDefinitionFilterModel) => {
const isPhysicsOnly = runDefinitionFilterModel.isPhysicsOnly();

Check warning on line 35 in lib/public/views/Runs/Overview/RunsOverviewPage.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Runs/Overview/RunsOverviewPage.js#L34-L35

Added lines #L34 - L35 were not covered by tests
const onChange = isPhysicsOnly
? () => runsOverviewModel.setDefinitionFilter([])
: () => runsOverviewModel.setDefinitionFilter([RunDefinition.Physics]);
? () => runDefinitionFilterModel.setEmpty()
: () => runDefinitionFilterModel.setPhysicsOnly();

Check warning on line 38 in lib/public/views/Runs/Overview/RunsOverviewPage.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Runs/Overview/RunsOverviewPage.js#L37-L38

Added lines #L37 - L38 were not covered by tests

return switchInput(isPhysicsOnly, onChange, { labelAfter: 'PHYSICS ONLY' });
};

Expand All @@ -55,7 +55,7 @@ export const RunsOverviewPage = ({ runs: { overviewModel: runsOverviewModel }, m
h('.flex-row.header-container.g2.pv2', [
filtersPanelPopover(runsOverviewModel, runsActiveColumns),
h('.pl2#runOverviewFilter', runNumberFilter(runsOverviewModel.filteringModel.get('runNumber'))),
togglePhysicsOnlyFilter(runsOverviewModel),
togglePhysicsOnlyFilter(runsOverviewModel.filteringModel.get('definitions')),
exportRunsTriggerAndModal(runsOverviewModel, modalModel),
]),
h('.flex-column.w-100', [
Expand Down

0 comments on commit 5fe9f8a

Please sign in to comment.