From 7a829b8c6665b21cffb7f64355fa643ed9e608b7 Mon Sep 17 00:00:00 2001 From: Yulong Ruan Date: Tue, 4 Jun 2024 17:57:28 +0800 Subject: [PATCH] show error toast when getting error from text to vega execution Signed-off-by: Yulong Ruan --- .../public/components/vega_vis_editor.tsx | 10 +++++++++- src/plugins/vis_type_vega/public/text_to_vega.ts | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/plugins/vis_type_vega/public/components/vega_vis_editor.tsx b/src/plugins/vis_type_vega/public/components/vega_vis_editor.tsx index 23c6d2975f3c..73abdd4788bc 100644 --- a/src/plugins/vis_type_vega/public/components/vega_vis_editor.tsx +++ b/src/plugins/vis_type_vega/public/components/vega_vis_editor.tsx @@ -97,7 +97,15 @@ function VegaVisEditor({ stateParams, setValue }: VisOptionsProps) { const text2vega = getText2Vega(); const subscription = text2vega.getResult$().subscribe((result) => { if (result) { - setValue('spec', JSON.stringify(result, null, 4)); + if (result.error) { + getNotifications().toasts.addError(result.error, { + title: i18n.translate('visTypeVega.editor.llmError', { + defaultMessage: 'Error while executing text to vega', + }), + }); + } else { + setValue('spec', JSON.stringify(result, null, 4)); + } } }); diff --git a/src/plugins/vis_type_vega/public/text_to_vega.ts b/src/plugins/vis_type_vega/public/text_to_vega.ts index f217b1bd6c38..6718a283f521 100644 --- a/src/plugins/vis_type_vega/public/text_to_vega.ts +++ b/src/plugins/vis_type_vega/public/text_to_vega.ts @@ -30,7 +30,7 @@ Just reply with the json based Vega-Lite object, do not include any other conten export class Text2Vega { input$ = new BehaviorSubject({ input: '' }); - result$: Observable; + result$: Observable | { error: any }>; status$ = new BehaviorSubject<'RUNNING' | 'STOPPED'>('STOPPED'); http: HttpSetup;