Skip to content

Commit d26466c

Browse files
authored
Merge pull request #514 from bcgov/oleks
DSS-658: FE: Filter Listings by Location - Group communities
2 parents 7ac9a79 + d6a71fb commit d26466c

File tree

4 files changed

+57
-8
lines changed

4 files changed

+57
-8
lines changed
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
export interface DropdownOption {
2-
label: string,
3-
value: any,
2+
label: string;
3+
value: any;
44
}
5+
6+
export interface DropdownOptionOrganization {
7+
label: string;
8+
value: any;
9+
localGovernmentType?: string;
10+
}
11+
512
export interface DropdownOptionSelectable extends DropdownOption {
613
selected: boolean;
714
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,13 @@ <h2 class="title">Listings</h2>
301301
</div>
302302
</p-accordionTab>
303303
<p-accordionTab *ngIf="isCEU" iconPos="end" header="By Community ">
304-
<p-dropdown placeholder="Select a Community" [appendTo]="'body'" [inputId]="'community-filter-dropdown'"
305-
[filter]="true" class="auto-width" [options]="communities"
306-
[(ngModel)]="cancelableFilter.community"></p-dropdown>
304+
<p-dropdown placeholder="Select a Community" appendTo="body" panelStyleClass="select-community"
305+
[inputId]="'community-filter-dropdown'" [filter]="true" [filterBy]="'label'" class="auto-width"
306+
[options]="groupedCommunities" [group]="true" [(ngModel)]="cancelableFilter.community">
307+
<ng-template let-group pTemplate="group">
308+
<strong>{{group.label}}</strong>
309+
</ng-template>
310+
</p-dropdown>
307311

308312
</p-accordionTab>
309313
<p-accordionTab iconPos="end" header="By Status">

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

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { PaginatorModule } from 'primeng/paginator';
1111
import { DialogModule } from 'primeng/dialog';
1212
import { InputTextModule } from 'primeng/inputtext';
1313
import { PanelModule } from 'primeng/panel';
14-
import { DropdownOption } from '../../../common/models/dropdown-option';
14+
import { DropdownOption, DropdownOptionOrganization } from '../../../common/models/dropdown-option';
1515
import { UserDataService } from '../../../common/services/user-data.service';
1616
import { User } from '../../../common/models/user';
1717
import { ListingDetailsComponent } from './listing-details/listing-details.component';
@@ -63,7 +63,8 @@ export class ListingsTableComponent implements OnInit {
6363
searchTerm!: string;
6464
searchColumn: 'all' | 'address' | 'url' | 'listingId' | 'hostName' | 'businessLicense' = 'all';
6565
searchColumns = new Array<DropdownOption>();
66-
communities = new Array<DropdownOption>();
66+
communities = new Array<DropdownOptionOrganization>();
67+
groupedCommunities = new Array();
6768

6869
isCEU = false;
6970
isLegendShown = false;
@@ -320,8 +321,37 @@ export class ListingsTableComponent implements OnInit {
320321
private getOrganizations(): void {
321322
this.requestAccessService.getOrganizations('LG').subscribe({
322323
next: (orgs) => {
323-
this.communities = orgs;
324+
this.communities = orgs.map((org: DropdownOptionOrganization) => ({ label: org.label, value: org.value, localGovernmentType: org.localGovernmentType || 'Uncategorized' }));
325+
326+
const groupedData: Array<any> = this.communities.reduce((acc: any, curr: any) => {
327+
const existingGroup = acc.find((group: any) => group.value === curr.localGovernmentType);
328+
if (existingGroup) {
329+
existingGroup.items.push({ label: curr.label, value: curr.value });
330+
} else {
331+
acc.push({
332+
label: curr.localGovernmentType,
333+
value: curr.localGovernmentType,
334+
items: [{ label: curr.label, value: curr.value }]
335+
});
336+
}
337+
338+
return acc;
339+
}, []);
340+
341+
groupedData.sort((a: any, b: any) => this.sortOrg(a.label, b.label));
342+
343+
this.groupedCommunities = groupedData;
324344
}
325345
});
326346
}
347+
348+
private sortOrg(a: string, b: string): number {
349+
if (a > b) {
350+
return 1;
351+
}
352+
if (a < b) {
353+
return -1;
354+
}
355+
return 0;
356+
}
327357
}

frontend/src/styles.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ body {
126126
}
127127
}
128128

129+
.select-community {
130+
p-dropdownitem {
131+
.p-dropdown-item {
132+
padding-left: 42px;
133+
}
134+
}
135+
}
136+
129137
p-dropdown {
130138
&.search-by-select {
131139
.p-dropdown {

0 commit comments

Comments
 (0)