Skip to content

Commit

Permalink
Ensemble Group List: now properly sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
turner committed Dec 4, 2024
1 parent 74132d2 commit 7d308ff
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion js/spacewalkFileLoadWidgetServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,21 @@ function createAndConfigureEnsembleGroupSelectModal(parentElement, ensembleGroup

selectElement.appendChild(createPlaceholderOptionElement())

for (const key of data ) {
// sort
const sorted = data.sort((a, b) => {
// Extract the first number after the initial string
const firstNumberA = parseInt(a.match(/^\D+(\d+)/)?.[1] || 0, 10);
const firstNumberB = parseInt(b.match(/^\D+(\d+)/)?.[1] || 0, 10);

// Extract the second number, whether it's foo23, foo_23, or foo_03
const secondNumberA = parseInt(a.match(/\D(\d+)$/)?.[1] || 0, 10);
const secondNumberB = parseInt(b.match(/\D(\d+)$/)?.[1] || 0, 10);

// Sort by the first number, then by the second number
return firstNumberA - firstNumberB || secondNumberA - secondNumberB;
});

for (const key of sorted ) {
const html = `<option value=\"${ key }\">${ key }</option>`
const fragment = document.createRange().createContextualFragment(html)
selectElement.appendChild(fragment.firstChild)
Expand Down

0 comments on commit 7d308ff

Please sign in to comment.