Skip to content

Commit

Permalink
[O2B-532] Use time range filter for run start stop (#1482)
Browse files Browse the repository at this point in the history
* [O2B-532] Use time range filter for run start stop

First attempt at fixing tests

Fix more tests

Fix min/max

Implement review comments

Renaming ret

Fix broken imports

Fix tests

* Fix linter and tests

* Revert merge issues

* Fix more tests

* Remove spurious tests

* Fix tests

* Fix linter

* Fix behavior when filtering runs "after" or "before" a given date

* Fix typo
  • Loading branch information
martinboulais authored Dec 12, 2024
1 parent 6d2c9c9 commit a809bc7
Show file tree
Hide file tree
Showing 15 changed files with 243 additions and 495 deletions.
22 changes: 22 additions & 0 deletions lib/public/components/Filters/RunsFilter/o2StartFilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

import { timeRangeFilter } from '../common/filters/timeRangeFilter.js';

/**
* Returns a filter to be applied on run start
*
* @param {RunsOverviewModel} runsOverviewModel the run overview model object
* @return {Component} the filter component
*/
export const o2StartFilter = (runsOverviewModel) => timeRangeFilter(runsOverviewModel.o2StartFilterModel);
21 changes: 21 additions & 0 deletions lib/public/components/Filters/RunsFilter/o2StopFilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/
import { timeRangeFilter } from '../common/filters/timeRangeFilter.js';

/**
* Returns a filter to be applied on run stop
*
* @param {RunsOverviewModel} runsOverviewModel the run overview model object
* @return {Component} the filter component
*/
export const o2StopFilter = (runsOverviewModel) => timeRangeFilter(runsOverviewModel.o2stopFilterModel);
92 changes: 0 additions & 92 deletions lib/public/components/Filters/RunsFilter/o2start.js

This file was deleted.

89 changes: 0 additions & 89 deletions lib/public/components/Filters/RunsFilter/o2stop.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class TimeRangeInputModel extends FilterModel {
this._toTimeInputModel.observe(() => this._periodLabel = null);
this._toTimeInputModel.bubbleTo(this);

this.setValue(value, periodLabel, false);
this.setValue(value, periodLabel, true);
}

/**
Expand Down Expand Up @@ -132,7 +132,7 @@ export class TimeRangeInputModel extends FilterModel {
* @override
*/
get isEmpty() {
return this._fromTimeInputModel.value === null && this._toTimeInputModel.value === null;
return this._fromTimeInputModel.isEmpty && this._toTimeInputModel.isEmpty;
}

// eslint-disable-next-line valid-jsdoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class ChartRenderer {
* - and if index axis is 'y', 'x' must contain an array in the same manner
*/
constructor(configuration, data) {
if (!data.length) {
if (!data?.length) {
throw new Error('The data list can not be empty');
}
this._data = data;
Expand Down
68 changes: 36 additions & 32 deletions lib/public/components/common/form/inputs/DateTimeInputComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export class DateTimeInputComponent extends StatefulComponent {
* @return {Component} the component
*/
view() {
const inputsMin = this._getInputsMin(this._min, this._value);
const inputsMax = this._getInputsMax(this._max, this._value);
const inputsMin = this._getInputsMin(this._minTimestamp, this._value);
const inputsMax = this._getInputsMax(this._maxTimestamp, this._value);

return h('.flex-row.items-center.g2', [
h(
Expand All @@ -81,8 +81,9 @@ export class DateTimeInputComponent extends StatefulComponent {
required: this._required,
value: this._value.date,
onchange: (e) => this._patchValue({ date: e.target.value }),
min: inputsMin ? inputsMin.date : undefined,
max: inputsMax ? inputsMax.date : undefined,
// Mithril do not remove min/max if previously set...
min: inputsMin?.date ?? '',
max: inputsMax?.date ?? '',
},
),
h(
Expand All @@ -93,8 +94,9 @@ export class DateTimeInputComponent extends StatefulComponent {
value: this._value.time,
step: this._seconds ? 1 : undefined,
onchange: (e) => this._patchValue({ time: e.target.value }),
min: inputsMin ? inputsMin.time : undefined,
max: inputsMax ? inputsMax.time : undefined,
// Mithril do not remove min/max if previously set...
min: inputsMin?.time ?? '',
max: inputsMax?.time ?? '',
},
),
h(
Expand Down Expand Up @@ -132,8 +134,8 @@ export class DateTimeInputComponent extends StatefulComponent {
time: defaultTime,
};

this._min = min;
this._max = max;
this._minTimestamp = min;
this._maxTimestamp = max;
}

/**
Expand Down Expand Up @@ -163,59 +165,61 @@ export class DateTimeInputComponent extends StatefulComponent {
/**
* Returns the min values to apply to the inputs
*
* @param {number|null} min the minimal timestamp to represent in the inputs
* @param {number|null} minTimestamp the minimal timestamp to represent in the inputs
* @param {DateTimeInputRawData} raw the current raw values
* @return {(Partial<{date: string, time: string}>|null)} the min values to apply to date and time inputs
*/
_getInputsMin(min, raw) {
if (min === null) {
_getInputsMin(minTimestamp, raw) {
if (minTimestamp === null) {
return null;
}

const minDateDayAfter = new Date(min + MILLISECONDS_IN_ONE_DAY);
const rawDate = raw.date || null;
const rawTime = raw.time || null;

const minDateAndTime = formatTimestampForDateTimeInput(min, this._seconds);
const ret = {};
const minDateAndTime = formatTimestampForDateTimeInput(minTimestamp, this._seconds);
const inputsMin = {};

if (raw.date !== null && raw.date === minDateAndTime.date) {
ret.time = minDateAndTime.time;
if (rawDate !== null && rawDate === minDateAndTime.date) {
inputsMin.time = minDateAndTime.time;
}

if (raw.time !== null && raw.time < minDateAndTime.time) {
ret.date = formatTimestampForDateTimeInput(minDateDayAfter.getTime(), this._seconds).date;
if (rawTime !== null && rawTime < minDateAndTime.time) {
inputsMin.date = formatTimestampForDateTimeInput(minTimestamp + MILLISECONDS_IN_ONE_DAY, this._seconds).date;
} else {
ret.date = minDateAndTime.date;
inputsMin.date = minDateAndTime.date;
}

return ret;
return inputsMin;
}

/**
* Returns the max values to apply to the inputs
*
* @param {number|null} max the maximal timestamp to represent in the inputs
* @param {number|null} maxTimestamp the maximal timestamp to represent in the inputs
* @param {DateTimeInputRawData} raw the current raw values
* @return {(Partial<{date: string, time: string}>|null)} the max values
*/
_getInputsMax(max, raw) {
if (max === null) {
_getInputsMax(maxTimestamp, raw) {
if (maxTimestamp === null) {
return null;
}

const maxDateDayBefore = new Date(max - MILLISECONDS_IN_ONE_DAY);
const rawDate = raw.date || null;
const rawTime = raw.time || null;

const maxDateAndTime = formatTimestampForDateTimeInput(max, this._seconds);
const ret = {};
const maxDateAndTime = formatTimestampForDateTimeInput(maxTimestamp, this._seconds);
const inputsMax = {};

if (raw.date !== null && raw.date === maxDateAndTime.date) {
ret.time = maxDateAndTime.time;
if (rawDate !== null && rawDate === maxDateAndTime.date) {
inputsMax.time = maxDateAndTime.time;
}
if (raw.time !== null && raw.time > maxDateAndTime.time) {
ret.date = formatTimestampForDateTimeInput(maxDateDayBefore.getTime(), this._seconds).date;
if (rawTime !== null && rawTime > maxDateAndTime.time) {
inputsMax.date = formatTimestampForDateTimeInput(maxTimestamp - MILLISECONDS_IN_ONE_DAY, this._seconds).date;
} else {
ret.date = maxDateAndTime.date;
inputsMax.date = maxDateAndTime.date;
}

return ret;
return inputsMax;
}
}
Loading

0 comments on commit a809bc7

Please sign in to comment.