Skip to content

Commit

Permalink
delayed loader
Browse files Browse the repository at this point in the history
  • Loading branch information
insmac committed Jan 10, 2025
1 parent 851c995 commit ba41c1d
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/web-console/src/scenes/Editor/Metrics/graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export const Graph = ({
const [endTime, setEndTime] = useState<number>(
new Date(durationTokenToDate(dateTo)).getTime(),
)
const [delayedLoading, setDelayedLoading] = useState(loading)

const { isTableMetric, mapYValue, label } = widgetConfig

Expand Down Expand Up @@ -148,6 +149,16 @@ export const Graph = ({
}
}, [graphRootRef.current])

useEffect(() => {
if (loading) {
const timeout = setTimeout(() => {
setDelayedLoading(true)
}, 1000)
return () => clearTimeout(timeout)
}
setDelayedLoading(false)
}, [loading])

return (
<Root ref={graphRootRef}>
<Header>
Expand All @@ -159,12 +170,12 @@ export const Graph = ({
tooltip={widgetConfig.description}
placement="bottom"
/>
{loading && <Loader size="18px" spin />}
{delayedLoading && <Loader size="18px" spin />}
</Box>
<Actions>{actions}</Actions>
</Header>
<GraphWrapper>
{!hasData(data) && !loading && (
{!hasData(data) && (
<GraphOverlay>
{isTableMetric && !tableName ? (
<Text color="gray2">
Expand Down

0 comments on commit ba41c1d

Please sign in to comment.