From 4726f06c55ebf9e3b33da787c01416f1473b433a Mon Sep 17 00:00:00 2001 From: colin-roy-ehri Date: Thu, 10 Oct 2024 17:58:53 -0600 Subject: [PATCH] Handle url queryPrompt parameter --- .../src/pages/AgentPage/PromptInput.tsx | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/explore-assistant-extension/src/pages/AgentPage/PromptInput.tsx b/explore-assistant-extension/src/pages/AgentPage/PromptInput.tsx index aa5b23c0..6d9f5ced 100644 --- a/explore-assistant-extension/src/pages/AgentPage/PromptInput.tsx +++ b/explore-assistant-extension/src/pages/AgentPage/PromptInput.tsx @@ -1,17 +1,39 @@ import { Send } from '@material-ui/icons' -import React, { useState, useRef, useCallback } from 'react' +import React, { useState, useRef, useCallback, useContext, useEffect } from 'react' import { useDispatch, useSelector } from 'react-redux' import { RootState } from '../../store' import { setIsChatMode, setQuery } from '../../slices/assistantSlice' import clsx from 'clsx' +import { ExtensionContext } from '@looker/extension-sdk-react' const PromptInput = () => { const dispatch = useDispatch() const [inputText, setInputText] = useState('') + const [letsGo, setLetsGo] = useState(false) const inputRef = useRef(null) + const { lookerHostData } = React.useContext(ExtensionContext) + const { isQuerying } = useSelector((state: RootState) => state.assistant) + useEffect(() => { + // check if lookerHostData is undefined + if (lookerHostData) { + const queryPrompt = new URLSearchParams(lookerHostData?.route?.split('?')[1]).get('queryPrompt') as string + console.log('Query Prompt:', queryPrompt, lookerHostData) + if (queryPrompt && queryPrompt.length > 5) { + setInputText(queryPrompt) + setLetsGo(true) + } + } + }, [lookerHostData]) + + useEffect(() => { + if (letsGo) { + handleSubmit() + } + }, [letsGo]) + const handleInputChange = (e: any) => { setInputText(e.target.value) }