(props: QueryProps)
| 28 | } |
| 29 | |
| 30 | export function Query(props: QueryProps): JSX.Element { |
| 31 | const { query: propsQuery, setQuery: propsSetQuery, readOnly, context } = props |
| 32 | const [localQuery, localSetQuery] = useState(propsQuery) |
| 33 | useEffect(() => { |
| 34 | if (propsQuery !== localQuery) { |
| 35 | localSetQuery(propsQuery) |
| 36 | } |
| 37 | }, [propsQuery]) |
| 38 | |
| 39 | const query = readOnly ? propsQuery : localQuery |
| 40 | const setQuery = readOnly ? undefined : propsSetQuery ?? localSetQuery |
| 41 | |
| 42 | if (typeof query === 'string') { |
| 43 | try { |
| 44 | return <Query {...props} query={JSON.parse(query)} /> |
| 45 | } catch (e: any) { |
| 46 | return <div className="border border-danger p-4 text-danger">Error parsing JSON: {e.message}</div> |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | let component |
| 51 | if (isLegacyQuery(query)) { |
| 52 | component = <LegacyInsightQuery query={query} /> |
| 53 | } else if (isDataTableNode(query)) { |
| 54 | component = <DataTable query={query} setQuery={setQuery} context={context} /> |
| 55 | } else if (isDataNode(query)) { |
| 56 | component = <DataNode query={query} /> |
| 57 | } else if (isInsightVizNode(query)) { |
| 58 | component = <InsightViz query={query} setQuery={setQuery} /> |
| 59 | } else if (isInsightQueryNode(query)) { |
| 60 | component = <InsightQuery query={query} /> |
| 61 | } else if (isTimeToSeeDataQuery(query)) { |
| 62 | component = <TimeToSeeData query={query} /> |
| 63 | } |
| 64 | |
| 65 | if (component) { |
| 66 | return <ErrorBoundary>{component}</ErrorBoundary> |
| 67 | } |
| 68 | |
| 69 | return ( |
| 70 | <div className="text-danger border border-danger p-2"> |
| 71 | <strong>PostHoqQuery error:</strong> {query?.kind ? `Invalid node type "${query.kind}"` : 'Invalid query'} |
| 72 | </div> |
| 73 | ) |
| 74 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…