-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add implement visualization in customized parser
Signed-off-by: SuZhou-Joe <[email protected]>
- Loading branch information
1 parent
15ea29b
commit a74ff7f
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { IMessage, Interaction } from '../../common/types/chat_saved_object_attributes'; | ||
|
||
const extractNthColumn = (csv: string, column: number) => { | ||
const lines = csv.split(/\r?\n/).slice(1); | ||
return lines | ||
.map((line) => line.split(',').at(column)) | ||
.filter(<T>(v: T | null | undefined): v is T => v !== null && v !== undefined); | ||
}; | ||
|
||
export const VisualizationCardParser = { | ||
id: 'core_visualization', | ||
async parserProvider(interaction: Interaction) { | ||
const additionalInfo = interaction.additional_info as { | ||
'VisualizationTool.output': string[]; | ||
}; | ||
const visualizationOutputs = additionalInfo?.['VisualizationTool.output']; | ||
if (!visualizationOutputs) { | ||
return []; | ||
} | ||
const visualizationIds = visualizationOutputs.flatMap((output) => extractNthColumn(output, 1)); // second column is id field | ||
|
||
const visOutputs: IMessage[] = visualizationIds.map((id) => ({ | ||
type: 'output', | ||
content: id, | ||
contentType: 'visualization', | ||
suggestedActions: [ | ||
{ | ||
message: 'View in Visualize', | ||
actionType: 'view_in_dashboards', | ||
}, | ||
], | ||
})); | ||
|
||
return visOutputs; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters