From 13b799be48115573ab7a66d6b90bd8edf53e0cf2 Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Wed, 29 Nov 2023 10:52:57 +0800 Subject: [PATCH] feat: optimize Signed-off-by: SuZhou-Joe --- server/parsers/visualization_card_parser.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/server/parsers/visualization_card_parser.ts b/server/parsers/visualization_card_parser.ts index 574bc251..b6afb731 100644 --- a/server/parsers/visualization_card_parser.ts +++ b/server/parsers/visualization_card_parser.ts @@ -6,7 +6,7 @@ import { IMessage, Interaction } from '../../common/types/chat_saved_object_attributes'; import { getJsonFromString } from '../utils/csv-parser-helper'; -const extractNthColumn = async (csv: string, column: number) => { +const extractIdsFromCsvString = async (csv: string) => { const lines = (await getJsonFromString(csv)) as Array<{ Id: string }>; return lines .map((line) => line.Id) @@ -16,16 +16,15 @@ const extractNthColumn = async (csv: string, column: number) => { export const VisualizationCardParser = { id: 'core_visualization', async parserProvider(interaction: Interaction) { - const additionalInfo = interaction.additional_info as { - 'VisualizationTool.output': string[]; - } | null; - const visualizationOutputs = additionalInfo?.['VisualizationTool.output']; + const visualizationOutputs = interaction.additional_info?.['VisualizationTool.output'] as + | string[] + | undefined; if (!visualizationOutputs) { return []; } const visualizationIds = ( - await Promise.all(visualizationOutputs.map((output) => extractNthColumn(output, 1))) - ).flatMap((id) => id); // second column is id field + await Promise.all(visualizationOutputs.map((output) => extractIdsFromCsvString(output))) + ).flatMap((id) => id); const visOutputs: IMessage[] = visualizationIds /**