2727 :item_id =" item_id"
2828 :block_id =" block_id"
2929 :extensions =" blockInfo.attributes.accepted_file_extensions"
30- :update-block-on-change =" mode !== 'multi'"
30+ :update-block-on-change =" false"
31+ @update:modelValue =" onFileSelectionChange"
3132 />
3233 </div >
33- <div v-if = " mode === 'multi' " class =" form-row mt-2" >
34- <button class =" btn btn-primary btn-sm" @click =" applyMultiSelect " >Apply Selection</button >
34+ <div class =" form-row mt-2" >
35+ <button class =" btn btn-primary btn-sm" @click =" applyFileSelection " >Apply Selection</button >
3536 </div >
3637 <CollapsibleComparisonFileSelect
3738 v-model =" comparisonFileModel"
@@ -216,7 +217,10 @@ export default {
216217 bokehPlotLimitedWidth: true ,
217218 isReplotButtonDisplayed: false ,
218219 pending_file_ids: [],
220+ pending_single_file_id: null ,
219221 pending_comparison_file_ids: [],
222+ single_mode_file: null ,
223+ multi_mode_files: [],
220224 };
221225 },
222226 computed: {
@@ -239,19 +243,17 @@ export default {
239243 },
240244 fileModel: {
241245 get () {
242- const ids = this .file_ids || [];
243246 if (this .mode === " multi" ) {
244247 return this .pending_file_ids ;
245248 } else {
246- return ids[ 0 ] || null ;
249+ return this . pending_single_file_id ;
247250 }
248251 },
249252 set (val ) {
250253 if (this .mode === " multi" ) {
251254 this .pending_file_ids = Array .isArray (val) ? val : [val];
252255 } else {
253- this .file_ids = val ? [val] : [];
254- this .updateBlock ();
256+ this .pending_single_file_id = val;
255257 }
256258 },
257259 },
@@ -278,16 +280,44 @@ export default {
278280 mode: createComputedSetterForBlockField (" mode" ),
279281 comparison_file_ids: createComputedSetterForBlockField (" comparison_file_ids" ),
280282 },
283+ watch: {
284+ mode (newMode , oldMode ) {
285+ if (oldMode === " single" && newMode === " multi" ) {
286+ // Save current single mode selection
287+ this .single_mode_file = this .pending_single_file_id ;
288+ // Restore multi mode selection
289+ this .pending_file_ids = this .multi_mode_files .slice ();
290+ } else if (oldMode === " multi" && newMode === " single" ) {
291+ // Save current multi mode selection
292+ this .multi_mode_files = this .pending_file_ids .slice ();
293+ // Restore single mode selection
294+ this .pending_single_file_id = this .single_mode_file ;
295+ }
296+ },
297+ },
281298 mounted () {
299+ // Set default mode to 'single' if not already set
300+ if (! this .mode ) {
301+ this .mode = " single" ;
302+ }
303+
282304 // Ensure file_ids is always an array
283305 if (! Array .isArray (this .file_ids )) {
284306 this .file_ids = [];
285307 console .log (" file_ids was not an array, so it has been reset to an empty array." );
286308 }
309+
310+ // Initialize mode-specific selections from persisted file_ids
287311 if (this .mode === " multi" ) {
288- // Ensure pending_file_ids matches persisted file_ids on reload
312+ // Multi mode: restore the file list from persisted file_ids
289313 this .pending_file_ids = this .file_ids .slice ();
314+ this .multi_mode_files = this .file_ids .slice ();
315+ } else {
316+ // Single mode: restore the single file from persisted file_ids
317+ this .pending_single_file_id = this .file_ids .length > 0 ? this .file_ids [0 ] : null ;
318+ this .single_mode_file = this .pending_single_file_id ;
290319 }
320+
291321 // Initialize pending comparison files from persisted state
292322 if (this .comparison_file_ids && Array .isArray (this .comparison_file_ids )) {
293323 this .pending_comparison_file_ids = this .comparison_file_ids .slice ();
@@ -335,9 +365,23 @@ export default {
335365
336366 this .all_cycles = all_cycles;
337367 },
338- applyMultiSelect () {
339- if (this .mode !== " multi" ) return ;
340- this .file_ids = this .pending_file_ids .slice ();
368+ onFileSelectionChange () {
369+ // Auto-update in single mode when file selection changes
370+ if (this .mode === " single" ) {
371+ this .file_ids = this .pending_single_file_id ? [this .pending_single_file_id ] : [];
372+ this .single_mode_file = this .pending_single_file_id ;
373+ this .updateBlock ();
374+ }
375+ // In multi mode, just stage the selection (don't auto-update)
376+ },
377+ applyFileSelection () {
378+ if (this .mode === " multi" ) {
379+ this .file_ids = this .pending_file_ids .slice ();
380+ this .multi_mode_files = this .pending_file_ids .slice ();
381+ } else {
382+ this .file_ids = this .pending_single_file_id ? [this .pending_single_file_id ] : [];
383+ this .single_mode_file = this .pending_single_file_id ;
384+ }
341385 this .updateBlock ();
342386 },
343387 applyComparisonFiles () {
0 commit comments