-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[O2B-536] Improve runs overview detectors filter (#1840)
* [O2B-532] Improve runs overview detectors filter * Uniformize remote-based selection dropdown * Fix lint * Try to fix qc flag types test randomly failing * Fix typo
- Loading branch information
1 parent
d333be2
commit f63cacb
Showing
13 changed files
with
228 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/** | ||
* @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 { RemoteData } from '/js/src/index.js'; | ||
import { ObservableData } from '../utilities/ObservableData.js'; | ||
|
||
/** | ||
* Data provider based on remote data | ||
* | ||
* @template T | ||
*/ | ||
export class RemoteDataProvider { | ||
/** | ||
* Constructor | ||
*/ | ||
constructor() { | ||
this._items = null; | ||
|
||
this._items$ = ObservableData.builder() | ||
.initialValue(RemoteData.notAsked()) | ||
.build(); | ||
} | ||
|
||
/** | ||
* Return the list of items | ||
* | ||
* @return {Promise<T[]>} the items | ||
*/ | ||
async getItems() { | ||
if (!this._items) { | ||
this._items = await this.getRemoteData(); | ||
} | ||
|
||
return this._items; | ||
} | ||
|
||
/** | ||
* Return the observable list of items (lazy-load it if needed) | ||
* | ||
* @return {ObservableData<RemoteData<T[], ApiError>>} the observable list of items | ||
*/ | ||
get items$() { | ||
if (this._isStale()) { | ||
this._load(); | ||
} | ||
|
||
return this._items$; | ||
} | ||
|
||
/** | ||
* Fetch the data | ||
* | ||
* @return {Promise<T[]>} the fetched items | ||
* @abstract | ||
*/ | ||
getRemoteData() { | ||
throw new Error('Method not implemented'); | ||
} | ||
|
||
/** | ||
* Mark the state of the provider as being stale, data will be fetched again next time it will be asked | ||
* | ||
* @return {void} | ||
*/ | ||
markAsStale() { | ||
this._items = null; | ||
this._items$.setCurrent(RemoteData.notAsked()); | ||
} | ||
|
||
/** | ||
* States if the items observable has never been asked | ||
* | ||
* @return {boolean} true if the items observable has never been asked | ||
* @protected | ||
*/ | ||
_isStale() { | ||
return this._items$.getCurrent().match({ | ||
NotAsked: () => true, | ||
Other: () => false, | ||
}); | ||
} | ||
|
||
/** | ||
* Fill the items$ observable data | ||
* | ||
* @return {void} | ||
* @protected | ||
*/ | ||
_load() { | ||
this._items$.setCurrent(RemoteData.loading()); | ||
this.getItems().then( | ||
(items) => this._items$.setCurrent(RemoteData.success(items)), | ||
(error) => this._items$.setCurrent(RemoteData.failure(error)), | ||
); | ||
} | ||
} |
Oops, something went wrong.