From 9054693baf0b997b61bac01ac445bb5bfb7348e0 Mon Sep 17 00:00:00 2001 From: Jeremy <51220084+jeremy-rifkin@users.noreply.github.com> Date: Sat, 10 Jun 2023 19:24:19 -0400 Subject: [PATCH] Fix ordering in the compiler picker popup --- lib/compiler-finder.ts | 1 + static/widgets/compiler-picker-popup.ts | 79 ++++++++++++++----------- types/compiler.interfaces.ts | 1 + 3 files changed, 45 insertions(+), 36 deletions(-) diff --git a/lib/compiler-finder.ts b/lib/compiler-finder.ts index 4bd4ae705..d7deec7c8 100644 --- a/lib/compiler-finder.ts +++ b/lib/compiler-finder.ts @@ -334,6 +334,7 @@ export class CompilerFinder { preamble: props('licensePreamble'), }, possibleOverrides: [], + $order: undefined as unknown as number, // TODO(jeremy-rifkin): Very dirty }; if (props('demanglerClassFile') !== undefined) { diff --git a/static/widgets/compiler-picker-popup.ts b/static/widgets/compiler-picker-popup.ts index 99d01d8d9..220418023 100644 --- a/static/widgets/compiler-picker-popup.ts +++ b/static/widgets/compiler-picker-popup.ts @@ -160,47 +160,17 @@ export class CompilerPickerPopup { } return true; }); - // figure out if there are any empty groups, these will be ignored - const groupCounts: Partial> = {}; - for (const compiler of filteredCompilers) { - for (const group of compiler.$groups) { - groupCounts[group] = (groupCounts[group] ?? 0) + 1; - } - } - // add the compiler entries / group headers themselves - this.resultsContainer.empty(); - this.favoritesContainer.empty(); - const groupMap: Record = {}; - for (const group of this.groups) { - if ((groupCounts[group.value] ?? 0) > 0 || group.value === CompilerPicker.favoriteGroupName) { - const group_elem = $( - ` -
-
-
${_.escape(group.label)}
-
-
- `, - ); - if (group.value === CompilerPicker.favoriteGroupName) { - group_elem.appendTo(this.favoritesContainer); - } else { - group_elem.appendTo(this.resultsContainer); - } - groupMap[group.value] = group_elem.find('.group'); - } - } - // if there can only ever be one column, don't bother with room for 2 - this.resultsContainer.toggleClass( - 'one-col', - this.groups.filter(group => group.value !== CompilerPicker.favoriteGroupName).length <= 1, - ); const searchRegexes = this.searchResults ? remove( this.searchResults.tokens.map(token => token.regex), null, ) : undefined; + // place compilers into groups + const groupMap: Record = {}; + for (const group of this.groups) { + groupMap[group.value] = []; + } for (const compiler of filteredCompilers) { const isFavorited = compiler.$groups.includes(CompilerPicker.favoriteGroupName); const extraClasses = isFavorited ? 'fas fa-star fav' : 'far fa-star'; @@ -223,9 +193,46 @@ export class CompilerPickerPopup { if (compiler.id === this.compilerPicker.lastCompilerId) { compiler_elem.addClass('selected'); } - compiler_elem.appendTo(groupMap[group]); + groupMap[group].push({ + elem: compiler_elem, + order: compiler.$order, + }); } } + // sort compilers before placing them into groups + for (const [_, compilers] of Object.entries(groupMap)) { + compilers.sort((a, b) => a.order - b.order); + } + // add groups and compilers + this.resultsContainer.empty(); + this.favoritesContainer.empty(); + for (const group of this.groups) { + if (groupMap[group.value].length > 0 || group.value === CompilerPicker.favoriteGroupName) { + const groupWrapper = $( + ` +
+
+
${_.escape(group.label)}
+
+
+ `, + ); + if (group.value === CompilerPicker.favoriteGroupName) { + groupWrapper.appendTo(this.favoritesContainer); + } else { + groupWrapper.appendTo(this.resultsContainer); + } + const groupElem = groupWrapper.find('.group'); + for (const compiler of groupMap[group.value]) { + compiler.elem.appendTo(groupElem); + } + } + } + // if there can only ever be one column, don't bother with room for 2 + this.resultsContainer.toggleClass( + 'one-col', + this.groups.filter(group => group.value !== CompilerPicker.favoriteGroupName).length <= 1, + ); // group header click events this.compilersContainer.find('.group').append('
⋯
'); this.compilersContainer.find('.group > .label').on('click', e => { diff --git a/types/compiler.interfaces.ts b/types/compiler.interfaces.ts index f4818f22a..9036e0ce9 100644 --- a/types/compiler.interfaces.ts +++ b/types/compiler.interfaces.ts @@ -131,6 +131,7 @@ export type CompilerInfo = { cachedPossibleArguments?: any; nvdisasm?: string; mtime?: any; + $order: number; }; // Compiler information collected by the compiler-finder