Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/public/components/Filters/common/FilterModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

/**
* Model storing the state of a given filter
*
* @abstract
*/
export class FilterModel extends Observable {
Expand Down Expand Up @@ -49,7 +50,7 @@
/**
* Returns the normalized value of the filter, that can be used as URL parameter
*
* @return {string|number|object|array|null} the normalized value
* @return {string|number|object|string[]|number[]|null} the normalized value
* @abstract
*/
get normalized() {
Expand All @@ -64,4 +65,19 @@
get visualChange$() {
return this._visualChange$;
}

/**
* Utility function to register a filter model as sub-filter model
*
* TODO for now this function simply propagate observable notifications, in the future this should register submodels with a key and allow
* automated normalization (recursive filter model)
*
* @param {object} subModel the submodel to register
* @return {void}
* @protected
*/
_addSubmodel(subModel) {
subModel.bubbleTo(this);
subModel?.visualChange$.bubbleTo(this._visualChange$);

Check warning on line 81 in lib/public/components/Filters/common/FilterModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/common/FilterModel.js#L79-L81

Added lines #L79 - L81 were not covered by tests
}
}
100 changes: 100 additions & 0 deletions lib/public/components/Filters/common/FilteringModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
* @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 { Observable } from '/js/src/index.js';

/**
* Model representing a filtering system, including filter inputs visibility, filters values and so on
*/
export class FilteringModel extends Observable {
/**
* Constructor
*
* @param {Object<string, FilterModel>} filters the filters with their label and model
*/
constructor(filters) {
super();

Check warning on line 26 in lib/public/components/Filters/common/FilteringModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/common/FilteringModel.js#L25-L26

Added lines #L25 - L26 were not covered by tests

this._visualChange$ = new Observable();

Check warning on line 28 in lib/public/components/Filters/common/FilteringModel.js

View check run for this annotation

Codecov / codecov/patch

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

Added line #L28 was not covered by tests

this._filters = filters;
this._filterModels = Object.values(filters);
for (const model of this._filterModels) {
model.bubbleTo(this);
model.visualChange$?.bubbleTo(this._visualChange$);

Check warning on line 34 in lib/public/components/Filters/common/FilteringModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/common/FilteringModel.js#L30-L34

Added lines #L30 - L34 were not covered by tests
}
}

/**
* Reset the filters
*
* @return {void}
*/
reset() {
for (const model of this._filterModels) {
model.reset();

Check warning on line 45 in lib/public/components/Filters/common/FilteringModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/common/FilteringModel.js#L43-L45

Added lines #L43 - L45 were not covered by tests
}
}

/**
* Returns the normalized value of all the filters, without null values
*
* @return {object} the normalized values
*/
get normalized() {
const ret = {};
for (const [filterKey, filter] of Object.entries(this._filters)) {
if (filter && !filter.isEmpty) {
ret[filterKey] = filter.normalized;

Check warning on line 58 in lib/public/components/Filters/common/FilteringModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/common/FilteringModel.js#L54-L58

Added lines #L54 - L58 were not covered by tests
}
}
return ret;

Check warning on line 61 in lib/public/components/Filters/common/FilteringModel.js

View check run for this annotation

Codecov / codecov/patch

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

Added line #L61 was not covered by tests
}

/**
* States if there is currently at least one filter active
*
* @return {boolean} true if at least one filter is active
*/
isAnyFilterActive() {
for (const model of this._filterModels) {
if (!model.isEmpty) {
return true;

Check warning on line 72 in lib/public/components/Filters/common/FilteringModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/common/FilteringModel.js#L69-L72

Added lines #L69 - L72 were not covered by tests
}
}
return false;

Check warning on line 75 in lib/public/components/Filters/common/FilteringModel.js

View check run for this annotation

Codecov / codecov/patch

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

Added line #L75 was not covered by tests
}

/**
* Returns the observable notified any time there is a visual change which has no impact on the actual filtering
*
* @return {Observable} the filters visibility observable
*/
get visualChange$() {
return this._visualChange$;

Check warning on line 84 in lib/public/components/Filters/common/FilteringModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/common/FilteringModel.js#L83-L84

Added lines #L83 - L84 were not covered by tests
}

/**
* Return the filter model for a given key
*
* @param {string} key the key of the filtering model
* @return {FilterModel} the filtering model
*/
get(key) {
if (!(key in this._filters)) {
throw new Error(`No filter found with key ${key}`);

Check warning on line 95 in lib/public/components/Filters/common/FilteringModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/common/FilteringModel.js#L93-L95

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

return this._filters[key];

Check warning on line 98 in lib/public/components/Filters/common/FilteringModel.js

View check run for this annotation

Codecov / codecov/patch

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

Added line #L98 was not covered by tests
}
}
48 changes: 24 additions & 24 deletions lib/public/components/Filters/common/TagFilterModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/
import { Observable } from '/js/src/index.js';
import { CombinationOperatorChoiceModel } from './CombinationOperatorChoiceModel.js';
import { TagSelectionDropdownModel } from '../../tag/TagSelectionDropdownModel.js';
import { FilterModel } from './FilterModel.js';

/**
* Model to handle the state of a tags filter
*/
export class TagFilterModel extends Observable {
export class TagFilterModel extends FilterModel {
/**
* Constructor
*
Expand All @@ -27,29 +27,38 @@
constructor(operators) {
super();
this._selectionModel = new TagSelectionDropdownModel({ includeArchived: true });
this._selectionModel.bubbleTo(this);
this._addSubmodel(this._selectionModel);

Check warning on line 30 in lib/public/components/Filters/common/TagFilterModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/common/TagFilterModel.js#L30

Added line #L30 was not covered by tests

this._combinationOperatorModel = new CombinationOperatorChoiceModel(operators);
this._combinationOperatorModel.bubbleTo(this);
this._addSubmodel(this._combinationOperatorModel);

Check warning on line 33 in lib/public/components/Filters/common/TagFilterModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/common/TagFilterModel.js#L33

Added line #L33 was not covered by tests
}

// eslint-disable-next-line valid-jsdoc
/**
* States if the filter has no tags selected
*
* @return {boolean} true if no tags are selected
* @inheritDoc
*/
isEmpty() {
return this.selected.length === 0;
reset() {
this._selectionModel.reset();
this._combinationOperatorModel.reset();

Check warning on line 42 in lib/public/components/Filters/common/TagFilterModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/common/TagFilterModel.js#L40-L42

Added lines #L40 - L42 were not covered by tests
}

// eslint-disable-next-line valid-jsdoc
/**
* Reset the model to its default state
*
* @return {void}
* @inheritDoc
*/
reset() {
this._selectionModel.reset();
this._combinationOperatorModel.reset();
get isEmpty() {
return this._selectionModel.isEmpty;

Check warning on line 50 in lib/public/components/Filters/common/TagFilterModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/common/TagFilterModel.js#L49-L50

Added lines #L49 - L50 were not covered by tests
}

// eslint-disable-next-line valid-jsdoc
/**
* @inheritDoc
*/
get normalized() {
return {

Check warning on line 58 in lib/public/components/Filters/common/TagFilterModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/Filters/common/TagFilterModel.js#L57-L58

Added lines #L57 - L58 were not covered by tests
values: this.selected.join(),
operation: this.combinationOperator,
};
}

/**
Expand Down Expand Up @@ -87,13 +96,4 @@
get combinationOperator() {
return this._combinationOperatorModel.current;
}

/**
* Returns an observable notified any time a visual change occurs that has no impact on the actual selection
*
* @return {Observable} the visual change observable
*/
get visualChange$() {
return this._selectionModel.visualChange$;
}
}

This file was deleted.

9 changes: 9 additions & 0 deletions lib/public/components/common/selection/SelectionModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,15 @@
return [...new Set(this._selectedOptions.map(({ value }) => value))];
}

/**
* States if the current selection is empty
*
* @return {boolean} true if the selection is empty
*/
get isEmpty() {
return this.selected.length === 0;

Check warning on line 272 in lib/public/components/common/selection/SelectionModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/components/common/selection/SelectionModel.js#L271-L272

Added lines #L271 - L272 were not covered by tests
}

/**
* If the selection allows one and only one selection, current will return the currently selected option. In any other case it will throw an
* error
Expand Down
3 changes: 2 additions & 1 deletion lib/public/views/Home/Overview/HomePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const MIN_ROWS = 5;

/**
* Home Page component
* @param {Object} model global model
*
* @param {Model} model global model
* @return {Component} Return the component of the home page
*/
export const HomePage = ({ home: { logsOverviewModel, runsOverviewModel, lhcFillsOverviewModel } }) => {
Expand Down
6 changes: 6 additions & 0 deletions lib/public/views/Logs/ActiveColumns/logsActiveColumns.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ export const logsActiveColumns = {
sortable: true,
size: 'w-15',
format: (tags) => formatTagsList(tags),

/**
* Tag filter component
* @param {LogsOverviewModel} logsModel the log model
* @return {Component} the filter component
*/
filter: (logsModel) => tagFilter(logsModel.listingTagsFilterModel),
balloon: true,
profiles: [profiles.none, 'embeded'],
Expand Down
4 changes: 2 additions & 2 deletions lib/public/views/Logs/Overview/LogsOverviewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
|| !this._authorFilter.isEmpty
|| this.createdFilterFrom !== ''
|| this.createdFilterTo !== ''
|| !this.listingTagsFilterModel.isEmpty()
|| !this.listingTagsFilterModel.isEmpty

Check warning on line 162 in lib/public/views/Logs/Overview/LogsOverviewModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Logs/Overview/LogsOverviewModel.js#L162

Added line #L162 was not covered by tests
|| this.runFilterValues.length !== 0
|| this.environmentFilterValues.length !== 0
|| this.lhcFillFilterValues.length !== 0
Expand Down Expand Up @@ -396,7 +396,7 @@
'filter[created][to]':
new Date(`${this.createdFilterTo.replace(/\//g, '-')}T23:59:59.999`).getTime(),
},
...!this.listingTagsFilterModel.isEmpty() && {
...!this.listingTagsFilterModel.isEmpty && {

Check warning on line 399 in lib/public/views/Logs/Overview/LogsOverviewModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Logs/Overview/LogsOverviewModel.js#L399

Added line #L399 was not covered by tests
'filter[tags][values]': this.listingTagsFilterModel.selected.join(),
'filter[tags][operation]': this.listingTagsFilterModel.combinationOperator,
},
Expand Down
9 changes: 8 additions & 1 deletion lib/public/views/Runs/ActiveColumns/runsActiveColumns.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,14 @@
classes: 'w-5 f6',
format: (tags) => formatTagsList(tags),
exportFormat: (tags) => tags?.length ? tags.map(({ text }) => text).join('-') : '-',
filter: (runModel) => tagFilter(runModel.listingTagsFilterModel),

/**
* Tags filter component
*
* @param {RunsOverviewModel} runModel the runs overview model
* @return {Component} the filter component
*/
filter: (runModel) => tagFilter(runModel.filteringModel.get('tags')),

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L144 was not covered by tests
balloon: (tags) => tags && tags.length > 0,
},
fillNumber: {
Expand Down
Loading
Loading