@@ -210,10 +210,11 @@ export default {
210
210
},
211
211
fileModel: {
212
212
get () {
213
+ const ids = this .file_ids || [];
213
214
if (this .isMultiSelect ) {
214
215
return this .pending_file_ids ;
215
216
} else {
216
- return ( this . file_ids && this . file_ids [0 ]) || null ;
217
+ return ids [0 ] || null ;
217
218
}
218
219
},
219
220
set (val ) {
@@ -240,6 +241,11 @@ export default {
240
241
characteristic_mass: createComputedSetterForBlockField (" characteristic_mass" ),
241
242
},
242
243
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
+ }
243
249
if (this .isMultiSelect ) {
244
250
// Ensure pending_file_ids matches persisted file_ids on reload
245
251
this .pending_file_ids = this .file_ids .slice ();
@@ -288,24 +294,21 @@ export default {
288
294
this .all_cycles = all_cycles;
289
295
},
290
296
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
-
295
297
if (this .isMultiSelect ) {
296
298
// 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 ();
298
300
if (this .prev_single_file_id ) {
299
301
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 ]];
302
304
} else {
303
305
this .file_ids = [];
304
306
}
305
307
} else {
306
308
// 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 () : [];
309
312
this .pending_file_ids = this .file_ids .slice ();
310
313
}
311
314
this .isMultiSelect = ! this .isMultiSelect ;
0 commit comments