Skip to content

Commit 1204ac7

Browse files
kosztiraunaqmorarka
authored andcommitted
Add query json page to Preview Web UI
1 parent 998666f commit 1204ac7

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

core/trino-web-ui/src/main/resources/webapp-preview/src/components/QueryDetails.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import React, { ReactNode, useState } from 'react'
1515
import { useLocation, useParams } from 'react-router-dom'
1616
import { Alert, Box, Divider, Grid2 as Grid, Tabs, Tab, Typography } from '@mui/material'
17+
import { QueryJson } from './QueryJson'
1718
import { QueryOverview } from './QueryOverview'
1819
import { Texts } from '../constant.ts'
1920

@@ -24,7 +25,7 @@ const tabComponentMap: Record<TabValue, ReactNode> = {
2425
livePlan: <Alert severity="error">{Texts.Error.NotImplemented}</Alert>,
2526
stagePerformance: <Alert severity="error">{Texts.Error.NotImplemented}</Alert>,
2627
splits: <Alert severity="error">{Texts.Error.NotImplemented}</Alert>,
27-
json: <Alert severity="error">{Texts.Error.NotImplemented}</Alert>,
28+
json: <QueryJson />,
2829
references: <Alert severity="error">{Texts.Error.NotImplemented}</Alert>,
2930
}
3031
export const QueryDetails = () => {
@@ -58,7 +59,7 @@ export const QueryDetails = () => {
5859
<Tab value="livePlan" label="Live plan" disabled />
5960
<Tab value="stagePerformance" label="Stage performance" disabled />
6061
<Tab value="splits" label="Splits" disabled />
61-
<Tab value="json" label="JSON" disabled />
62+
<Tab value="json" label="JSON" />
6263
<Tab value="references" label="References" disabled />
6364
</Tabs>
6465
</Box>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
import { useParams } from 'react-router-dom'
15+
import { useEffect, useState } from 'react'
16+
import { Alert, Box, CircularProgress, Grid2 as Grid } from '@mui/material'
17+
import { Texts } from '../constant.ts'
18+
import { queryStatusApi, QueryStatusInfo } from '../api/webapp/api.ts'
19+
import { ApiResponse } from '../api/base.ts'
20+
import { CodeBlock } from './CodeBlock.tsx'
21+
22+
export const QueryJson = () => {
23+
const { queryId } = useParams()
24+
25+
const [queryJson, setQueryJson] = useState<string | null>(null)
26+
const [loading, setLoading] = useState<boolean>(true)
27+
const [error, setError] = useState<string | null>(null)
28+
29+
useEffect(() => {
30+
if (queryId) {
31+
getQueryJson()
32+
}
33+
// eslint-disable-next-line react-hooks/exhaustive-deps
34+
}, [queryId])
35+
36+
const getQueryJson = () => {
37+
if (queryId) {
38+
queryStatusApi(queryId).then((apiResponse: ApiResponse<QueryStatusInfo>) => {
39+
setLoading(false)
40+
if (apiResponse.status === 200 && apiResponse.data) {
41+
setQueryJson(JSON.stringify(apiResponse.data, null, 2))
42+
setError(null)
43+
} else {
44+
setError(`${Texts.Error.Communication} ${apiResponse.status}: ${apiResponse.message}`)
45+
}
46+
})
47+
}
48+
}
49+
50+
return (
51+
<>
52+
{loading && <CircularProgress />}
53+
{error && <Alert severity="error">{Texts.Error.QueryNotFound}</Alert>}
54+
55+
{!loading && !error && queryJson && (
56+
<Grid container spacing={0}>
57+
<Grid size={{ xs: 12 }}>
58+
<Box sx={{ pt: 2 }}>
59+
<CodeBlock language="json" code={queryJson} />
60+
</Box>
61+
</Grid>
62+
</Grid>
63+
)}
64+
</>
65+
)
66+
}

0 commit comments

Comments
 (0)