Skip to content

Commit ac1a913

Browse files
authored
Merge pull request #522 from bcgov/oleks
DSS-658 FE: Filter Listings by Location - Group communities - Fixes and order corrections
2 parents 120c2fb + 80591ff commit ac1a913

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

frontend/src/app/features/components/listings-table/listings-table.component.ts

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,8 @@ export class ListingsTableComponent implements OnInit {
321321
private getOrganizations(): void {
322322
this.requestAccessService.getOrganizations('LG').subscribe({
323323
next: (orgs) => {
324-
console.log(orgs.filter((x: any) => (x.organizationCd as string).includes('LGXFN-Homalco')))
325-
this.communities = orgs.map((org: DropdownOptionOrganization) => ({ label: org.label, value: org.value, localGovernmentType: org.localGovernmentType || 'Other' }));
324+
this.communities = orgs.map((org: DropdownOptionOrganization) =>
325+
({ label: org.label, value: org.value, localGovernmentType: org.localGovernmentType || 'Other' }));
326326

327327
const groupedData: Array<any> = this.communities.reduce((acc: any, curr: any) => {
328328
const existingGroup = acc.find((group: any) => group.value === curr.localGovernmentType);
@@ -338,24 +338,33 @@ export class ListingsTableComponent implements OnInit {
338338

339339
return acc;
340340
}, []);
341-
342-
groupedData.sort((a: any, b: any) => this.sortOrg(a.label, b.label));
343-
344-
this.groupedCommunities = groupedData;
341+
const municipality = groupedData.filter(x => x.label === 'Municipality')[0];
342+
const regional = groupedData.filter(x => x.label === 'Regional District Electoral Area')[0];
343+
const other = groupedData.filter(x => x.label === 'Other')[0];
344+
const firstNations = groupedData.filter(x => x.label === 'First Nations Community')[0];
345+
const uncategorized = groupedData.filter(x =>
346+
x.label !== 'Municipality' &&
347+
x.label !== 'Regional District Electoral Area' &&
348+
x.label !== 'Other' &&
349+
x.label !== 'First Nations Community'
350+
);
351+
352+
const sorted = [];
353+
354+
if (municipality)
355+
sorted.push(municipality);
356+
if (regional)
357+
sorted.push(regional);
358+
if (other)
359+
sorted.push(other);
360+
if (firstNations)
361+
sorted.push(firstNations);
362+
if (uncategorized.length)
363+
sorted.push(...uncategorized);
364+
365+
this.groupedCommunities = sorted;
345366
}
346367
});
347368
}
348369

349-
private sortOrg(a: string, b: string): number {
350-
if (b === 'Other') {
351-
return -1;
352-
}
353-
if (a > b) {
354-
return 1;
355-
}
356-
if (a < b) {
357-
return -1;
358-
}
359-
return 0;
360-
}
361370
}

0 commit comments

Comments
 (0)