From 6a2cd7dd2da7c08143d9b87c46e1a31ae8a432c9 Mon Sep 17 00:00:00 2001 From: BoykoAlex Date: Tue, 3 Sep 2019 10:35:04 -0400 Subject: [PATCH] Fix error coming from empty array reduce call --- .../streams/components/flo/text-to-graph.ts | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/ui/src/app/streams/components/flo/text-to-graph.ts b/ui/src/app/streams/components/flo/text-to-graph.ts index 0d4f9f523..00ae3156a 100644 --- a/ui/src/app/streams/components/flo/text-to-graph.ts +++ b/ui/src/app/streams/components/flo/text-to-graph.ts @@ -284,7 +284,7 @@ export class TextToGraphConverter { } private matchGroup(name: string, incoming: number, outgoing: number): string { - const match1 = Array.from(this.metamodel.keys()).filter(grp => this.metamodel.get(grp).has(name)).map( + const matches = Array.from(this.metamodel.keys()).filter(grp => this.metamodel.get(grp).has(name)).map( grp => this.metamodel.get(grp).get(name)).map(match => { let score = 0; switch (match.group) { @@ -336,15 +336,21 @@ export class TextToGraphConverter { match, score }; - }).reduce((bestMatch, currentMatch) => { - if (bestMatch) { - if (currentMatch.score > bestMatch.score) { - return currentMatch; + }); + if (matches && matches.length > 0) { + const match1 = matches.reduce((bestMatch, currentMatch) => { + if (bestMatch) { + if (currentMatch.score > bestMatch.score) { + return currentMatch; + } } + return bestMatch; + }); + if (match1) { + return match1.match.group; } - return bestMatch; - }); - return match1 ? match1.match.group : ApplicationType[ApplicationType.app]; + } + return ApplicationType[ApplicationType.app]; } /**