From 54a685d4002d0199762369760a50476447bf48a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Barbeau?= Date: Wed, 7 Mar 2018 15:27:57 -0500 Subject: [PATCH] fix(featuresList): sort in feature.service --- src/lib/feature/shared/feature-group.pipe.ts | 4 +--- src/lib/feature/shared/feature.service.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lib/feature/shared/feature-group.pipe.ts b/src/lib/feature/shared/feature-group.pipe.ts index 96671ea6a4..78acf90303 100644 --- a/src/lib/feature/shared/feature-group.pipe.ts +++ b/src/lib/feature/shared/feature-group.pipe.ts @@ -19,9 +19,7 @@ export class FeatureGroupPipe implements PipeTransform { groupedFeatures[source].push(feature); }); - const sourceFeatures = Object.keys(groupedFeatures).sort((a, b) => { - return groupedFeatures[a][0].order - groupedFeatures[b][0].order; - }).map( + const sourceFeatures = Object.keys(groupedFeatures).map( (source: string) => [source, groupedFeatures[source]] ); diff --git a/src/lib/feature/shared/feature.service.ts b/src/lib/feature/shared/feature.service.ts index fa72a17d3a..160d4e1e41 100644 --- a/src/lib/feature/shared/feature.service.ts +++ b/src/lib/feature/shared/feature.service.ts @@ -14,7 +14,7 @@ export class FeatureService { constructor() { } setFeatures(features: Feature[]) { - this.features$.next(features); + this.features$.next(features.sort(this.sortFeatures)); } updateFeatures(features: Feature[], source: string, sourcesToKeep?: string[]) { @@ -23,7 +23,8 @@ export class FeatureService { return feature.source !== source && (!sourcesToKeep || sourcesToKeep.includes(feature.source)); }) - .concat(features); + .concat(features) + .sort(this.sortFeatures); this.features$.next(features_); } @@ -61,4 +62,7 @@ export class FeatureService { return feature1.id === feature2.id && feature1.source === feature2.source; } + private sortFeatures(feature1, feature2) { + return feature1.order - feature2.order; + } }