From 13b7ca68d77ab76446bf88be8b27162a072be779 Mon Sep 17 00:00:00 2001 From: Danny Wahl Date: Fri, 16 Feb 2024 13:58:30 -0700 Subject: [PATCH] add sort $Product Instructure AWS --- isp-site/src/utils/explorer.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/isp-site/src/utils/explorer.js b/isp-site/src/utils/explorer.js index a58f5a20..e641e7a4 100644 --- a/isp-site/src/utils/explorer.js +++ b/isp-site/src/utils/explorer.js @@ -17,13 +17,33 @@ async function getGithubRepoContents(owner, repo, branch) { }); const data = await response.json(); - return data.tree || null; + return data.tree.sort(sortProduct).reverse() || null; } catch (error) { console.error(`Error: ${error.message}`); return null; } } +function sortProduct(a, b) { + const getPriorityIndex = (path) => { + const uPath = path.toLocaleUpperCase(); + const index = priorityStrings.findIndex((str) => + uPath.startsWith(str.toLocaleUpperCase()), + ); + return index !== -1 ? index : priorityStrings.length; + }; + + const priorityStrings = ["Amazon Web Services", "Instructure"]; + + const priorityA = getPriorityIndex(a.path); + const priorityB = getPriorityIndex(b.path); + + if (priorityA !== priorityB) { + return priorityA - priorityB; + } + return a.path.localeCompare(b.path); +} + function formatGithubContents(contents, owner, repo, name, language) { const l = language; const s = getStrings(strings, l);