Skip to content

Commit 04d25a8

Browse files
committed
Fix query plan default viewport in preview UI
1 parent d0e2314 commit 04d25a8

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

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

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
import { useParams } from 'react-router-dom'
1515
import { useEffect, useRef, useState } from 'react'
16-
import { Alert, Box, CircularProgress, Grid } from '@mui/material'
16+
import { Alert, Box, CircularProgress, Grid, Typography } from '@mui/material'
1717
import { ReactFlow, type Edge, type Node, useNodesState, useEdgesState } from '@xyflow/react'
1818
import '@xyflow/react/dist/style.css'
1919
import { queryStatusApi, QueryStatusInfo } from '../api/webapp/api.ts'
@@ -115,21 +115,31 @@ export const QueryLivePlan = () => {
115115
ref={containerRef}
116116
sx={{ width: '100%', height: '80vh', border: '1px solid #ccc' }}
117117
>
118-
<ReactFlow
119-
nodes={nodes}
120-
edges={edges}
121-
onNodesChange={onNodesChange}
122-
onEdgesChange={onEdgesChange}
123-
nodeTypes={nodeTypes}
124-
minZoom={0.1}
125-
proOptions={{ hideAttribution: true }}
126-
defaultViewport={{ x: 200, y: 20, zoom: 0.8 }}
127-
>
128-
<HelpMessage
129-
layoutDirection={layoutDirection}
130-
onLayoutDirectionChange={setLayoutDirection}
131-
/>
132-
</ReactFlow>
118+
{nodes.length > 0 ? (
119+
<ReactFlow
120+
nodes={nodes}
121+
edges={edges}
122+
onNodesChange={onNodesChange}
123+
onEdgesChange={onEdgesChange}
124+
nodeTypes={nodeTypes}
125+
minZoom={0.1}
126+
proOptions={{ hideAttribution: true }}
127+
defaultViewport={{
128+
x: (nodes[0].position.x / 2) * -1,
129+
y: 20,
130+
zoom: 0.8,
131+
}}
132+
>
133+
<HelpMessage
134+
layoutDirection={layoutDirection}
135+
onLayoutDirectionChange={setLayoutDirection}
136+
/>
137+
</ReactFlow>
138+
) : (
139+
<Typography sx={{ p: 1 }} fontSize="small">
140+
Rendering...
141+
</Typography>
142+
)}
133143
</Box>
134144
</Box>
135145
</Grid>

0 commit comments

Comments
 (0)