Skip to content

Commit af40f73

Browse files
committed
simplify errors, and loading
1 parent 12f3419 commit af40f73

2 files changed

Lines changed: 8 additions & 15 deletions

File tree

lib/public/components/common/dataExport/exportTriggerAndModal.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313

1414
import { DATA_EXPORT_TYPES } from '../../../domain/enums/ExportTypes.js';
15+
import errorAlert from '../errorAlert.js';
1516
import spinner from '../spinner.js';
1617
import { h } from '/js/src/index.js';
1718

@@ -73,15 +74,13 @@ const exportForm = (exportModel, modalHandler) => {
7374
]);
7475
}));
7576

76-
const dataAvailable = exportModel.items.match({ Success: () => true, Other: () => false });
77-
7877
const exportBtn = h('button.shadow-level1.btn.btn-success.mt2#send', {
79-
disabled: !(fieldsSelected && dataAvailable),
78+
disabled: !fieldsSelected,
8079
onclick: async () => {
8180
await exportModel.createExport();
8281
modalHandler.dismiss();
8382
},
84-
}, dataAvailable ? 'Export' : 'Loading data...');
83+
}, 'Export');
8584

8685
const dataLength = exportModel.items.match({ Success: ({ length } = {}) => length, Other: () => null });
8786
const { totalExistingItemsCount } = exportModel;
@@ -103,8 +102,6 @@ const exportForm = (exportModel, modalHandler) => {
103102
];
104103
};
105104

106-
const errorDisplay = () => h('.danger', 'Data fetching failed');
107-
108105
/**
109106
* A function to construct the exports data screen
110107
*
@@ -114,16 +111,13 @@ const errorDisplay = () => h('.danger', 'Data fetching failed');
114111
*/
115112
const exportModal = (exportModel, modalHandler) => {
116113
exportModel.callForData();
117-
const dataLoading = exportModel.items.match({ Loading: () => true, Other: () => false });
118114

119115
return h('div#export-data-modal', [
120-
h('.flex-row', [
121-
h('h2.w-50', 'Export data'),
122-
dataLoading ? h('.w-50', spinner({ size: 2, absolute: false })) : null,
123-
]),
116+
h('h2.w-50', 'Export data'),
124117
exportModel.items.match({
125-
NotAsked: () => errorDisplay(),
126-
Failure: () => errorDisplay(),
118+
NotAsked: () => errorAlert(),
119+
Failure: (errors) => errorAlert(errors),
120+
Loading: () => spinner({ size: 2, absolute: false }),
127121
Other: () => exportForm(exportModel, modalHandler),
128122
}),
129123
]);

lib/public/models/DataExportModel.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ export class DataExportModel extends Observable {
173173
* @return {void}
174174
*/
175175
setSelectedFields(selectedOptions) {
176-
this._selectedFields = [];
177-
[...selectedOptions].forEach(({ value }) => this._selectedFields.push(value));
176+
this._selectedFields = Array.from(selectedOptions).map(({ value }) => value);
178177
this.notify();
179178
this._visualChange$.notify();
180179
}

0 commit comments

Comments
 (0)