Skip to content

Commit 8ed26e5

Browse files
committed
Changed vue component to initialise with an empty array for file ids if not in store.
1 parent 1eee18e commit 8ed26e5

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

webapp/src/components/datablocks/CycleBlock.vue

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,11 @@ export default {
210210
},
211211
fileModel: {
212212
get() {
213+
const ids = this.file_ids || [];
213214
if (this.isMultiSelect) {
214215
return this.pending_file_ids;
215216
} else {
216-
return (this.file_ids && this.file_ids[0]) || null;
217+
return ids[0] || null;
217218
}
218219
},
219220
set(val) {
@@ -240,6 +241,11 @@ export default {
240241
characteristic_mass: createComputedSetterForBlockField("characteristic_mass"),
241242
},
242243
mounted() {
244+
// Ensure file_ids is always an array
245+
if (!Array.isArray(this.file_ids)) {
246+
this.file_ids = [];
247+
console.log("file_ids was not an array, so it has been reset to an empty array.");
248+
}
243249
if (this.isMultiSelect) {
244250
// Ensure pending_file_ids matches persisted file_ids on reload
245251
this.pending_file_ids = this.file_ids.slice();
@@ -288,24 +294,21 @@ export default {
288294
this.all_cycles = all_cycles;
289295
},
290296
toggleMultiSelect() {
291-
// Ensure file_ids and prev_file_ids are always arrays
292-
const currentFileIds = this.file_ids || [];
293-
const prevFileIds = this.prev_file_ids || [];
294-
295297
if (this.isMultiSelect) {
296298
// Switching from multi to single: save multi selection, restore last single selection
297-
this.prev_file_ids = currentFileIds.slice();
299+
this.prev_file_ids = this.file_ids.slice();
298300
if (this.prev_single_file_id) {
299301
this.file_ids = [this.prev_single_file_id];
300-
} else if (prevFileIds.length > 0) {
301-
this.file_ids = [prevFileIds[0]];
302+
} else if (this.prev_file_ids.length > 0) {
303+
this.file_ids = [this.prev_file_ids[0]];
302304
} else {
303305
this.file_ids = [];
304306
}
305307
} else {
306308
// Switching from single to multi: save single selection, restore previous multi selection or start empty
307-
this.prev_single_file_id = currentFileIds[0] || null;
308-
this.file_ids = prevFileIds.length > 0 ? prevFileIds.slice() : [];
309+
this.prev_single_file_id = this.file_ids[0] || null;
310+
this.file_ids =
311+
this.prev_file_ids && this.prev_file_ids.length > 0 ? this.prev_file_ids.slice() : [];
309312
this.pending_file_ids = this.file_ids.slice();
310313
}
311314
this.isMultiSelect = !this.isMultiSelect;

0 commit comments

Comments
 (0)