@@ -11,7 +11,7 @@ import { PaginatorModule } from 'primeng/paginator';
11
11
import { DialogModule } from 'primeng/dialog' ;
12
12
import { InputTextModule } from 'primeng/inputtext' ;
13
13
import { PanelModule } from 'primeng/panel' ;
14
- import { DropdownOption } from '../../../common/models/dropdown-option' ;
14
+ import { DropdownOption , DropdownOptionOrganization } from '../../../common/models/dropdown-option' ;
15
15
import { UserDataService } from '../../../common/services/user-data.service' ;
16
16
import { User } from '../../../common/models/user' ;
17
17
import { ListingDetailsComponent } from './listing-details/listing-details.component' ;
@@ -63,7 +63,8 @@ export class ListingsTableComponent implements OnInit {
63
63
searchTerm ! : string ;
64
64
searchColumn : 'all' | 'address' | 'url' | 'listingId' | 'hostName' | 'businessLicense' = 'all' ;
65
65
searchColumns = new Array < DropdownOption > ( ) ;
66
- communities = new Array < DropdownOption > ( ) ;
66
+ communities = new Array < DropdownOptionOrganization > ( ) ;
67
+ groupedCommunities = new Array ( ) ;
67
68
68
69
isCEU = false ;
69
70
isLegendShown = false ;
@@ -320,8 +321,37 @@ export class ListingsTableComponent implements OnInit {
320
321
private getOrganizations ( ) : void {
321
322
this . requestAccessService . getOrganizations ( 'LG' ) . subscribe ( {
322
323
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 ;
324
344
}
325
345
} ) ;
326
346
}
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
+ }
327
357
}
0 commit comments