From 63ac451dbbf42aa14c9ee58616612ece9f9db28d Mon Sep 17 00:00:00 2001 From: garethgeorge Date: Sat, 17 Feb 2024 01:41:00 -0800 Subject: [PATCH] fix: improved sidebar status refresh interval during live operations --- webui/src/views/App.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/webui/src/views/App.tsx b/webui/src/views/App.tsx index 8b8dc877..55f8c0e5 100644 --- a/webui/src/views/App.tsx +++ b/webui/src/views/App.tsx @@ -15,7 +15,7 @@ import { useAlertApi } from "../components/Alerts"; import { useShowModal } from "../components/ModalManager"; import { uiBuildVersion } from "../state/buildcfg"; import { ActivityBar } from "../components/ActivityBar"; -import { OperationStatus } from "../../gen/ts/v1/operations_pb"; +import { OperationEvent, OperationStatus } from "../../gen/ts/v1/operations_pb"; import { colorForStatus, getStatusForPlan, getStatusForRepo, subscribeToOperations, unsubscribeFromOperations } from "../state/oplog"; import LogoSvg from "url:../../assets/logo.svg"; import _ from "lodash"; @@ -278,10 +278,17 @@ const IconForResource = ({ planId, repoId }: { planId?: string, repoId?: string } }; load(); - const refresh = _.debounce(load, 5000); - subscribeToOperations(refresh); + const refresh = _.debounce(load, 1000, { maxWait: 5000, trailing: true }); + const callback = ({ operation }: OperationEvent) => { + if (!operation) return; + if (operation.planId === planId || operation.repoId === repoId) { + refresh(); + } + } + + subscribeToOperations(callback); return () => { - unsubscribeFromOperations(refresh); + unsubscribeFromOperations(callback); } }, [planId, repoId]); return iconForStatus(status);