From 3f53490f7a40a2fcb65838d24f654b41a7959b65 Mon Sep 17 00:00:00 2001 From: Shaun Lum Date: Wed, 15 Jan 2025 12:50:05 -0800 Subject: [PATCH] updated the district list to sort by active and district number --- frontend/src/sharedMethods.js | 19 +++++++++++++++++++ frontend/src/store/modules/app.js | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/frontend/src/sharedMethods.js b/frontend/src/sharedMethods.js index dc5eda91..de9d92d8 100644 --- a/frontend/src/sharedMethods.js +++ b/frontend/src/sharedMethods.js @@ -132,6 +132,25 @@ export default { jobLabel(jobId) { return this.jobId.replace("job-", ""); }, + sortDistrictListByActiveAndDistrictNumber(districtsList) { + if (!districtsList) return []; + + return districtsList.sort((a, b) => { + // First, prioritize districts with districtStatusCode "ACTIVE" + if (a.districtStatusCode === "ACTIVE" && b.districtStatusCode !== "ACTIVE") { + return -1; // "ACTIVE" comes first + } + if (a.districtStatusCode !== "ACTIVE" && b.districtStatusCode === "ACTIVE") { + return 1; // "ACTIVE" comes first + } + + // Second, sort by districtNumber (as numeric, handling strings like "103", "005", etc.) + const aNumber = parseInt(a.districtNumber, 10); + const bNumber = parseInt(b.districtNumber, 10); + + return aNumber - bNumber; // Numeric sorting + }); + }, sortSchoolListByTranscriptsAndMincode(schoolsList) { if (!schoolsList) return []; //remove special characters from displayname by overwriting with displayNameNoSpecialChars diff --git a/frontend/src/store/modules/app.js b/frontend/src/store/modules/app.js index 9318b626..0fb91d26 100644 --- a/frontend/src/store/modules/app.js +++ b/frontend/src/store/modules/app.js @@ -100,6 +100,10 @@ export const useAppStore = defineStore("app", { InstituteService.getDistrictsList().then((response) => { try { this.districtsList = response.data; + this.districtList = + sharedMethods.sortDistrictListByActiveAndDistrictNumber( + this.districtsList + ); } catch (error) { console.error(error); }