From e1df0ed28691c1d0790e0eecf56dab6574077e57 Mon Sep 17 00:00:00 2001 From: Yulong Ruan Date: Mon, 20 May 2024 13:30:02 +0800 Subject: [PATCH] tweak prompt and save input to localstorage Signed-off-by: Yulong Ruan --- src/plugins/vis_type_vega/public/text_to_vega.ts | 1 - .../application/components/visualize_top_nav.tsx | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) 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 d6d11810c7a1..bb91d679f28c 100644 --- a/src/plugins/vis_type_vega/public/text_to_vega.ts +++ b/src/plugins/vis_type_vega/public/text_to_vega.ts @@ -19,7 +19,6 @@ ${ppl} The user's instruction is: ${input} -You seem not quite understand how to set y-scales of the different layers, the correct syntax is {"resolve": {"scale": {"y": "independent"}}} please use it when appropriate. Just return the chart specification json based on Vega-Lite format. Just reply with the json based Vega-Lite object, do not include any other content in the reply. `; diff --git a/src/plugins/visualize/public/application/components/visualize_top_nav.tsx b/src/plugins/visualize/public/application/components/visualize_top_nav.tsx index 0c0884431863..d01cff288f65 100644 --- a/src/plugins/visualize/public/application/components/visualize_top_nav.tsx +++ b/src/plugins/visualize/public/application/components/visualize_top_nav.tsx @@ -222,6 +222,18 @@ const TopNav = ({ const [isPopoverOpen, setIsPopoverOpen] = useState(false); const inputRef = useRef(null); + const onValueChange = useCallback((value: string) => { + setValue(value); + localStorage.setItem('text_to_vega_input', value); + }, []); + + useEffect(() => { + const input = localStorage.getItem('text_to_vega_input'); + if (input) { + setValue(input); + } + }, []); + useEffect(() => { window['llmRunning$'].subscribe((running) => { setGenerating(!!running); @@ -265,7 +277,7 @@ const TopNav = ({ value={value} prepend={} fullWidth - onChange={(event) => setValue(event.target.value)} + onChange={(event) => onValueChange(event.target.value)} onKeyDown={(e) => { if (e.key === 'Enter') onGenerate(); }} @@ -282,7 +294,7 @@ const TopNav = ({ {HARDCODED_SUGGESTIONS?.map((question) => ( { - setValue(question); + onValueChange(question); inputRef.current?.focus(); setIsPopoverOpen(false); }}