4eaf56ff3eb90ea8ebcf1697ac3830b8a7b5465f
jrobinso
  Tue Sep 16 09:32:52 2025 -0700
Handle file picker edge case - picker is open but doesn't have handles for requested files.   Also more comments and reformatting.

diff --git src/hg/htdocs/admin/filePicker.html src/hg/htdocs/admin/filePicker.html
index 7ea150cb67e..dade2d2adf4 100644
--- src/hg/htdocs/admin/filePicker.html
+++ src/hg/htdocs/admin/filePicker.html
@@ -83,30 +83,32 @@
         <label for="urlInput">URL</label>
         <input type="url" id="urlInput">
     </div>
     <div class="input-row">
         <label for="indexURLInput">Index URL</label>
         <input type="url" id="indexURLInput">
     </div>
     <p>
         <button id="urlButton">Load</button>
     </p>
 </section>
 
 
 <script>
     document.addEventListener('DOMContentLoaded', () => {
+
+        window.focus()
         const channel = new BroadcastChannel('igv_file_channel')
         channel.postMessage({type: 'filePickerReady'})
         const fileCache = new Map()
         const restoreCache = new Map()
 
         document.getElementById('fileInput').addEventListener('change', function (event) {
             const files = []
             for (let file of event.target.files) {
                 const id = `${file.name}_${file.size}`
                 files.push({id, file}) //value)
                 fileCache.set(id, file)
                 restoreCache.delete(id)
                 refreshFileList()
             }
             event.target.value = ""
@@ -135,34 +137,38 @@
         channel.onmessage = function (event) {
             const {id, type} = event.data
             if (type === 'getFile') {
                 const selectedFile = fileCache.get(id)
 
                 if(selectedFile) {
                 channel.postMessage({type: 'file', data: selectedFile})   // TODO -- what if selectedFile is undefined?  Handle here or in browser?
                 } else {
                     // Don't respond if we don't have the file.  Its possible multiple file pickers are open.
                     console.info(`No file found for id: ${id}`)
                 }
             } else if (type === 'removeFile') {
                 fileCache.delete(id)
                 refreshFileList()
             } else if (type === 'restoreFiles') {
+
+                // Process a request to restore a list of files, which means prompt the user to select them
+
                 const failed = event.data.files
                 for (const f of failed) {
                     restoreCache.set(f.id, f.name)
                 }
+                window.focus()
                 refreshFileList()
             } else if (type === 'removedTrack') {
                 // TODO -- might want to remove from restoreCache too
                 const config = event.data.config
                 if (config.url && config.url.id) {
                     fileCache.delete(config.url.id)
                     restoreCache.delete(config.url.id)
                 }
                 if (config.indexURL && config.indexURL.id) {
                     fileCache.delete(config.indexURL.id)
                     restoreCache.delete(config.indexURL.id)
                 }
                 refreshFileList()
             } else if (type === 'ping') {
                 window.focus()