Skip to content

Commit

Permalink
Merge pull request #522 from bcgov/oleks
Browse files Browse the repository at this point in the history
DSS-658 FE: Filter Listings by Location - Group communities - Fixes and order corrections
  • Loading branch information
larsenle authored Aug 9, 2024
2 parents 120c2fb + 80591ff commit ac1a913
Showing 1 changed file with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> = this.communities.reduce((acc: any, curr: any) => {
const existingGroup = acc.find((group: any) => group.value === curr.localGovernmentType);
Expand All @@ -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;
}
}

0 comments on commit ac1a913

Please sign in to comment.