-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add visualization card in customized parser #16
Changes from 1 commit
a74ff7f
b240c47
85b5146
2be2bb4
13b799b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||||||||
}; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you add the TODO comment
theoretically id can contain any character, i haven't tested whether also should dashboards-assistant/server/olly/utils/output_builders/__tests__/saved_objects.test.ts Line 11 in a74ff7f
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am using And sure, I migrate the test cases in save_objects.test.ts and add some edge cases. |
||||||||
|
||||||||
export const VisualizationCardParser = { | ||||||||
id: 'core_visualization', | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should there be an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If order is not specified, default order value will be 999. |
||||||||
async parserProvider(interaction: Interaction) { | ||||||||
const additionalInfo = interaction.additional_info as { | ||||||||
'VisualizationTool.output': string[]; | ||||||||
}; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This type doesn't seem right, on line 21, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think assertion should happen after field check |
||||||||
const visualizationOutputs = additionalInfo?.['VisualizationTool.output']; | ||||||||
SuZhou-Joe marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
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; | ||||||||
}, | ||||||||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a good place to add some unit tests for the parser :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, added cases accordingly.