@@ -321,8 +321,8 @@ export class ListingsTableComponent implements OnInit {
321
321
private getOrganizations ( ) : void {
322
322
this . requestAccessService . getOrganizations ( 'LG' ) . subscribe ( {
323
323
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' } ) ) ;
326
326
327
327
const groupedData : Array < any > = this . communities . reduce ( ( acc : any , curr : any ) => {
328
328
const existingGroup = acc . find ( ( group : any ) => group . value === curr . localGovernmentType ) ;
@@ -338,24 +338,33 @@ export class ListingsTableComponent implements OnInit {
338
338
339
339
return acc ;
340
340
} , [ ] ) ;
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 ;
345
366
}
346
367
} ) ;
347
368
}
348
369
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
- }
361
370
}
0 commit comments