Skip to content

Commit ae3f377

Browse files
committed
cleanup
1 parent 175b6f1 commit ae3f377

4 files changed

Lines changed: 44 additions & 23 deletions

File tree

lib/public/models/DataExportModel.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,30 @@ import { Observable } from '/js/src/index.js';
1515
import { createCSVExport, createJSONExport } from '../utilities/export.js';
1616
import pick from '../utilities/pick.js';
1717

18+
/**
19+
* @typedef FieldExportConfiguration
20+
*
21+
* @property {function|null} exportFormat
22+
*/
23+
24+
/**
25+
* @typdef DataExportConfiguration
26+
*
27+
* @type {object<string, FieldExportConfiguration>} mapping: field name -> field export configuration
28+
*/
29+
1830
/**
1931
* Model handling export configuration and creation
2032
*/
2133
export class DataExportModel extends Observable {
2234
/**
2335
* Constructor
36+
*
2437
* @param {ObservableData<RemoteData<T[]>>} items$ observable data used as source for export
25-
* @param {object<string, {exportFormat: function|null|undefined}>} fieldsFormatting defines selectable fields and their formatting
38+
* @param {DataExportConfiguration} dataExportConfiguration defines selectable fields and their formatting
2639
* @param {function} onDataNotAskedAction function to be called in case of missing data
2740
*/
28-
constructor(items$, fieldsFormatting, onDataNotAskedAction) {
41+
constructor(items$, dataExportConfiguration, onDataNotAskedAction) {
2942
super();
3043

3144
this._items$ = items$;
@@ -39,7 +52,7 @@ export class DataExportModel extends Observable {
3952

4053
this._exportName = 'data';
4154

42-
this._fieldsFormatting = fieldsFormatting;
55+
this._dataExportConfiguration = dataExportConfiguration;
4356
this._onDataNotAskedAction = onDataNotAskedAction;
4457

4558
this._disabled = null;
@@ -48,15 +61,17 @@ export class DataExportModel extends Observable {
4861
}
4962

5063
/**
51-
* Get mapping of selecteble fields to their format functions
52-
* @return {object<string, {exportFormat: function|null|undefined}>} mapping
64+
* Get data export configuration
65+
*
66+
* @return {DataExportConfiguration>} configuration
5367
*/
54-
get fieldsFormatting() {
55-
return this._fieldsFormatting;
68+
get dataExportConfiguration() {
69+
return this._dataExportConfiguration;
5670
}
5771

5872
/**
5973
* Get total number of items that model knows they exist
74+
*
6075
* @return {number} totalExistingItemsCount
6176
*/
6277
get totalExistingItemsCount() {
@@ -113,6 +128,7 @@ export class DataExportModel extends Observable {
113128

114129
/**
115130
* Observable notified when the export configuration visually changes
131+
*
116132
* @return {Observable} the visual change observable
117133
*/
118134
get visualChange$() {
@@ -121,6 +137,7 @@ export class DataExportModel extends Observable {
121137

122138
/**
123139
* Get export type selected by the user
140+
*
124141
* @return {string} export type
125142
*/
126143
get selectedExportType() {
@@ -129,6 +146,7 @@ export class DataExportModel extends Observable {
129146

130147
/**
131148
* Set export type
149+
*
132150
* @param {string} exportType export type
133151
* @return {void}
134152
*/
@@ -140,6 +158,7 @@ export class DataExportModel extends Observable {
140158

141159
/**
142160
* Get selected fields
161+
*
143162
* @return {string[]} selected fields
144163
*/
145164
get selectedFields() {
@@ -148,6 +167,7 @@ export class DataExportModel extends Observable {
148167

149168
/**
150169
* Update selected fields from HTML options list
170+
*
151171
* @param {HTMLCollection|Array} selectedOptions options collection
152172
* @return {void}
153173
*/
@@ -160,6 +180,7 @@ export class DataExportModel extends Observable {
160180

161181
/**
162182
* Create export using current items observable
183+
*
163184
* @return {Promise<void>} void
164185
*/
165186
async createExport() {
@@ -170,7 +191,7 @@ export class DataExportModel extends Observable {
170191
const formatted = items.map((item) => {
171192
const selectedEntries = Object.entries(pick(item, selectedFields));
172193
const mappedEntries = selectedEntries.map(([key, value]) => {
173-
const formatter = this.fieldsFormatting[key]?.exportFormat || ((v) => v);
194+
const formatter = this.dataExportConfiguration[key]?.exportFormat || ((v) => v);
174195
return [key, formatter(value, item)];
175196
});
176197

lib/public/models/OverviewModel.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,29 @@ export class OverviewPageModel extends Observable {
4646
});
4747
this._sortModel.visualChange$.bubbleTo(this);
4848

49+
// Single page data handling
4950
this._pagination = new PaginationModel();
5051
this._pagination.observe(() => this.load());
5152
this._pagination.itemsPerPageSelector$.observe(() => this.notify());
5253

5354
const dataSourceObservable = ObservableData.builder().initialValue(RemoteData.loading()).build();
54-
dataSourceObservable.observe(() => this.parseApiRemoteData(dataSourceObservable.getCurrent()));
55+
dataSourceObservable.observe(() => this.parseApiPaginatedRemoteData(dataSourceObservable.getCurrent()));
5556

5657
this._dataSource = new PaginatedRemoteDataSource();
5758
this._dataSource.pipe(dataSourceObservable);
5859

5960
this._item$ = ObservableData.builder().initialValue(RemoteData.loading()).build();
6061
this._item$.bubbleTo(this);
6162

62-
{
63-
const allDataSourceObservable = ObservableData.builder().initialValue(RemoteData.loading()).build();
64-
allDataSourceObservable.observe(() => this.parseAllApiRemoteData(allDataSourceObservable.getCurrent()));
63+
// All data handling
64+
const allDataSourceObservable = ObservableData.builder().initialValue(RemoteData.loading()).build();
65+
allDataSourceObservable.observe(() => this.parseApiNotPaginatedRemoteData(allDataSourceObservable.getCurrent()));
6566

66-
this._allDataSource = new PaginatedRemoteDataSource();
67-
this._allDataSource.pipe(allDataSourceObservable);
67+
this._allDataSource = new PaginatedRemoteDataSource();
68+
this._allDataSource.pipe(allDataSourceObservable);
6869

69-
this._allItems$ = ObservableData.builder().initialValue(RemoteData.loading()).build();
70-
this._allItems$.bubbleTo(this);
71-
}
70+
this._allItems$ = ObservableData.builder().initialValue(RemoteData.loading()).build();
71+
this._allItems$.bubbleTo(this);
7272

7373
/**
7474
* @type {ObservableData<TableConfiguration>}
@@ -105,7 +105,7 @@ export class OverviewPageModel extends Observable {
105105
* @param {RemoteData<{items: T[], totalCount: number}, *>} remoteData the API remote data
106106
* @return {void}
107107
*/
108-
parseApiRemoteData(remoteData) {
108+
parseApiPaginatedRemoteData(remoteData) {
109109
/*
110110
* When fetching data, to avoid concurrency issues, save a flag stating if the fetched data should be concatenated with the current one
111111
* (infinite scroll) or if they should replace them
@@ -135,7 +135,7 @@ export class OverviewPageModel extends Observable {
135135
* @param {RemoteData<{items: T[], totalCount: number}, *>} remoteData the API remote data
136136
* @return {void}
137137
*/
138-
parseAllApiRemoteData(remoteData) {
138+
parseApiNotPaginatedRemoteData(remoteData) {
139139
remoteData.match({
140140
NotAsked: () => this._allItems$.setCurrent(RemoteData.notAsked()),
141141
Loading: () => this._allItems$.setCurrent(RemoteData.loading()),
@@ -158,7 +158,7 @@ export class OverviewPageModel extends Observable {
158158

159159
/**
160160
* Fetch all the relevant items from the API
161-
* it takes into account pagination parameters
161+
* it takes into account pagination parameters, but also reset not-paginated observable data
162162
*
163163
* @return {Promise<void>} void
164164
*/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { RunDefinitionFilterModel } from '../../../components/Filters/RunsFilter
3434
import { RUN_QUALITIES } from '../../../domain/enums/RunQualities.js';
3535
import { SelectionFilterModel } from '../../../components/Filters/common/filters/SelectionFilterModel.js';
3636
import { DataExportModel } from '../../../models/DataExportModel.js';
37-
import { runsActiveColumns as fieldsFormattingConf } from '../ActiveColumns/runsActiveColumns.js';
37+
import { runsActiveColumns as dataExportConfiguration } from '../ActiveColumns/runsActiveColumns.js';
3838

3939
/**
4040
* Model representing handlers for runs page
@@ -101,7 +101,7 @@ export class RunsOverviewModel extends OverviewPageModel {
101101
this._debouncedLoad = debounce(this.load.bind(this), model.inputDebounceTime);
102102
};
103103

104-
this._exportModel = new DataExportModel(this._allItems$, fieldsFormattingConf, () => this.loadAll());
104+
this._exportModel = new DataExportModel(this._allItems$, dataExportConfiguration, () => this.loadAll());
105105
this._item$.observe(() => {
106106
this._exportModel.setDisabled(!this.hasAnyData());
107107
this._exportModel.setTotalExistingItemsCount(this._pagination.itemsCount);

lib/public/views/Runs/Overview/exportTriggerAndModal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const exportForm = (exportModel, modalHandler) => {
2727

2828
const { selectedFields } = exportModel;
2929
const { selectedExportType } = exportModel;
30-
const fields = Object.keys(exportModel.fieldsFormatting);
30+
const fields = Object.keys(exportModel.dataExportConfiguration);
3131

3232
const fieldsSelected = selectedFields.length > 0;
3333

0 commit comments

Comments
 (0)