From 279d1b570bb5c70febafb9ab33d56d53a5cb2486 Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Mon, 6 Feb 2023 19:06:45 -0500 Subject: [PATCH] cleanup, fix bug with no-recording target selection --- src/app/Dashboard/Charts/ChartCard.tsx | 84 +++++---------- src/app/Dashboard/Charts/ChartContext.tsx | 8 +- src/app/Dashboard/Charts/ChartController.tsx | 104 ++++++++++--------- 3 files changed, 85 insertions(+), 111 deletions(-) diff --git a/src/app/Dashboard/Charts/ChartCard.tsx b/src/app/Dashboard/Charts/ChartCard.tsx index 004a3b3899..5cf56bd6af 100644 --- a/src/app/Dashboard/Charts/ChartCard.tsx +++ b/src/app/Dashboard/Charts/ChartCard.tsx @@ -52,14 +52,14 @@ import { EmptyStateVariant, Title, } from '@patternfly/react-core'; -import { ExternalLinkAltIcon, PlusCircleIcon, RedoIcon } from '@patternfly/react-icons'; +import { ExternalLinkAltIcon, PlusCircleIcon } from '@patternfly/react-icons'; import * as React from 'react'; import { useHistory } from 'react-router-dom'; -import { first, interval, timer } from 'rxjs'; +import { interval } from 'rxjs'; import { DashboardCardDescriptor, DashboardCardProps, DashboardCardSizes } from '../Dashboard'; import { DashboardCard } from '../DashboardCard'; import { ChartContext } from './ChartContext'; -import { MIN_REFRESH, RECORDING_NAME } from './ChartController'; +import { RECORDING_NAME } from './ChartController'; export interface ChartCardProps extends DashboardCardProps { theme: string; @@ -114,10 +114,10 @@ export const ChartCard: React.FC = (props) => { const controllerContext = React.useContext(ChartContext); const history = useHistory(); const addSubscription = useSubscriptions(); + const [idx, setIdx] = React.useState(0); const [hasRecording, setHasRecording] = React.useState(false); const [chartSrc, setChartSrc] = React.useState(''); const [dashboardUrl, setDashboardUrl] = React.useState(''); - const [refreshDisabled, setRefreshDisabled] = React.useState(true); React.useEffect(() => { addSubscription(controllerContext.controller.hasActiveRecording().subscribe(setHasRecording)); @@ -131,31 +131,17 @@ export const ChartCard: React.FC = (props) => { if (!dashboardUrl) { return; } - setRefreshDisabled(true); const u = new URL('/d-solo/main', dashboardUrl); u.searchParams.append('theme', props.theme); u.searchParams.append('panelId', String(kindToId(props.chartKind))); u.searchParams.append('to', 'now'); u.searchParams.append('from', `now-${props.duration}s`); - // TODO make this configurable - u.searchParams.append('refresh', '5s'); + u.searchParams.append('refresh', `${props.period}s`); setChartSrc(u.toString()); - }, [dashboardUrl, setRefreshDisabled, props.theme, props.chartKind, props.duration, setChartSrc]); - - const handleOnLoad = React.useCallback(() => { - addSubscription( - timer(MIN_REFRESH) - .pipe(first()) - .subscribe((_) => setRefreshDisabled(false)) - ); - }, [addSubscription, setRefreshDisabled]); + }, [dashboardUrl, props.theme, props.chartKind, props.duration, props.period, setChartSrc]); React.useEffect(() => { - addSubscription( - controllerContext.controller.refresh().subscribe((_) => { - /* do nothing */ - }) - ); + addSubscription(controllerContext.controller.attach().subscribe(setIdx)); }, [addSubscription, controllerContext]); const refresh = React.useCallback(() => { @@ -183,6 +169,7 @@ export const ChartCard: React.FC = (props) => { return ( <>