diff --git a/frontend/src/app/features/components/listings-table/listings-table.component.ts b/frontend/src/app/features/components/listings-table/listings-table.component.ts index 4bc59d44..855a0566 100644 --- a/frontend/src/app/features/components/listings-table/listings-table.component.ts +++ b/frontend/src/app/features/components/listings-table/listings-table.component.ts @@ -321,8 +321,8 @@ export class ListingsTableComponent implements OnInit { private getOrganizations(): void { this.requestAccessService.getOrganizations('LG').subscribe({ next: (orgs) => { - console.log(orgs.filter((x: any) => (x.organizationCd as string).includes('LGXFN-Homalco'))) - this.communities = orgs.map((org: DropdownOptionOrganization) => ({ label: org.label, value: org.value, localGovernmentType: org.localGovernmentType || 'Other' })); + this.communities = orgs.map((org: DropdownOptionOrganization) => + ({ label: org.label, value: org.value, localGovernmentType: org.localGovernmentType || 'Other' })); const groupedData: Array = this.communities.reduce((acc: any, curr: any) => { const existingGroup = acc.find((group: any) => group.value === curr.localGovernmentType); @@ -338,24 +338,33 @@ export class ListingsTableComponent implements OnInit { return acc; }, []); - - groupedData.sort((a: any, b: any) => this.sortOrg(a.label, b.label)); - - this.groupedCommunities = groupedData; + const municipality = groupedData.filter(x => x.label === 'Municipality')[0]; + const regional = groupedData.filter(x => x.label === 'Regional District Electoral Area')[0]; + const other = groupedData.filter(x => x.label === 'Other')[0]; + const firstNations = groupedData.filter(x => x.label === 'First Nations Community')[0]; + const uncategorized = groupedData.filter(x => + x.label !== 'Municipality' && + x.label !== 'Regional District Electoral Area' && + x.label !== 'Other' && + x.label !== 'First Nations Community' + ); + + const sorted = []; + + if (municipality) + sorted.push(municipality); + if (regional) + sorted.push(regional); + if (other) + sorted.push(other); + if (firstNations) + sorted.push(firstNations); + if (uncategorized.length) + sorted.push(...uncategorized); + + this.groupedCommunities = sorted; } }); } - private sortOrg(a: string, b: string): number { - if (b === 'Other') { - return -1; - } - if (a > b) { - return 1; - } - if (a < b) { - return -1; - } - return 0; - } }