-
Notifications
You must be signed in to change notification settings - Fork 49
restore track selection from a list #345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| export default function createTrackSelectionListModal({id, label = '', sections, description = '', okHandler}) { | ||
|
|
||
| // Flatten sections to get all tracks. | ||
| const tracks = [] | ||
| const trackMap = new Map() | ||
| const flattenSections = (sections) => { | ||
| sections.forEach(section => { | ||
| if (section.tracks) { | ||
| section.tracks.forEach(track => { | ||
| tracks.push(track) | ||
| trackMap.set(track._id, track) | ||
| }) | ||
| } | ||
| if (section.children) { | ||
| flattenSections(section.children) | ||
| } | ||
| }) | ||
| } | ||
| flattenSections(sections) | ||
|
|
||
| // Generate the HTML for the modal | ||
| const renderTracks = (tracks) => { | ||
| // Generate options for the select element | ||
| // Disable options for tracks that are already loaded | ||
| const options = tracks.map(track => { | ||
| const disabled = track._loaded ? 'disabled' : '' | ||
| return `<option value="${track._id}" ${disabled}>${track.name}</option>` | ||
| }).join('') | ||
|
|
||
| // Return the Bootstrap-styled select widget | ||
| return ` | ||
| <div class="mb-3 h-100 d-flex flex-column"> | ||
| <select id="track-select" class="form-select flex-grow-1" multiple> | ||
| ${options} | ||
| </select> | ||
| </div> | ||
| ` | ||
| } | ||
|
|
||
| const html = ` | ||
| <div id="${id}" class="modal fade igv-app-track-select-modal" tabindex="-1"> | ||
| <div class="modal-dialog modal-lg"> | ||
| <div class="modal-content"> | ||
| <div class="modal-header flex-column position-sticky top-0 bg-white z-index-1"> | ||
| <h5 class="modal-title text-center w-100">${label}</h5> | ||
| <div class="additional-html w-100">${description}</div> | ||
| <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> | ||
| </div> | ||
| <div class="modal-body overflow-auto" style="max-height: 70vh;"> | ||
| ${renderTracks(tracks)} | ||
| </div> | ||
| <div class="modal-footer"> | ||
| <button type="button" class="btn btn-sm btn-outline-secondary" data-bs-dismiss="modal">Cancel</button> | ||
| <button type="button" class="btn btn-sm btn-secondary" data-bs-dismiss="modal">OK</button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ` | ||
|
|
||
| const tempDiv = document.createElement('div') | ||
| tempDiv.innerHTML = html.trim() | ||
| const modalElement = tempDiv.firstChild | ||
| document.body.appendChild(modalElement) | ||
|
|
||
| const modal = new bootstrap.Modal(modalElement, { | ||
| backdrop: 'static', | ||
| keyboard: false | ||
| }) | ||
|
|
||
| let modalAction = null // Variable to track the action | ||
|
|
||
| // Add event listeners to buttons | ||
| document.querySelector(`#${id} .btn-secondary`).addEventListener('click', () => { | ||
| modalAction = 'ok' | ||
| }) | ||
| document.querySelector(`#${id} .btn-outline-secondary`).addEventListener('click', () => { | ||
| modalAction = 'cancel' | ||
| }) | ||
|
|
||
|
|
||
| // Listen for the modal close event | ||
| modalElement.addEventListener('hidden.bs.modal', () => { | ||
| if (modalAction === 'ok') { | ||
| console.log('Modal closed with OK button') | ||
| const selectedOptions = Array.from(modalElement.querySelectorAll('#track-select option:checked')) | ||
| const checkedTracks = selectedOptions.map(option => trackMap.get(option.value)) | ||
| const uncheckedTracks = [] // There is no way to unselect a track with this widget | ||
|
|
||
| if (okHandler) { | ||
| okHandler(checkedTracks, uncheckedTracks) | ||
| } else { | ||
| console.log('URLs of checked tracks:', checkedTracks) | ||
| } | ||
| } | ||
|
|
||
| // Clean up resources | ||
| modal.dispose() // Dispose of the Bootstrap modal instance | ||
| modalElement.remove() // Remove the modal element from the DOM | ||
| modalAction = null // Reset the action | ||
| }) | ||
|
|
||
| return modal | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
uncheckedTracksarray is always empty, but theokHandlerin trackWidgets.js (lines 247-252) expects to process unchecked tracks to remove them from the browser. This means users cannot unload tracks using this modal, which differs fromtrackSelectionModalwhere checkboxes can be unchecked. This is a functional limitation that should be addressed. Consider collecting all non-selected tracks (tracks not in the selected options) asuncheckedTracksif track removal is intended to be supported.