Skip to content

Commit

Permalink
fix: fixed the timer not clearing issue (#1303)
Browse files Browse the repository at this point in the history
Co-authored-by: Darshan Simha <darshan_simha@intuit.com>
  • Loading branch information
darshansimha and Darshan Simha committed Oct 31, 2023
1 parent c7bdbda commit 93eec96
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions ui/src/components/pages/Pipeline/partials/Graph/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,22 @@ const Flow = (props: FlowProps) => {
undefined
);
const [statusPayload, setStatusPayload] = useState<any>(undefined);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [timerDateStamp, setTimerDateStamp] = useState<any>(undefined);
const [timer, setTimer] = useState<any>(undefined);
const [timer, setTimer] = useState<number | undefined>(undefined);

const handleTimer = useCallback(() => {
if (timer) {
clearInterval(timer);
}
const dateString = new Date().toISOString();
const time = timeAgo(dateString);
setTimerDateStamp(time);
const pauseTimer = setInterval(() => {
const time = timeAgo(dateString);
setTimerDateStamp(time);
}, 1000);
setTimer(pauseTimer);
}, [timer]);
const handlePlayClick = useCallback(() => {
handleTimer();
setStatusPayload({
Expand All @@ -187,7 +199,7 @@ const Flow = (props: FlowProps) => {
},
},
});
}, []);
}, [handleTimer]);

const handlePauseClick = useCallback(() => {
handleTimer();
Expand All @@ -198,18 +210,7 @@ const Flow = (props: FlowProps) => {
},
},
});
}, []);

const handleTimer = useCallback(() => {
const dateString = new Date().toISOString();
const time = timeAgo(dateString);
setTimerDateStamp(time);
const pauseTimer = setInterval(() => {
const time = timeAgo(dateString);
setTimerDateStamp(time);
}, 1000);
setTimer(pauseTimer);
}, []);
}, [handleTimer]);

useEffect(() => {
const patchStatus = async () => {
Expand Down Expand Up @@ -245,14 +246,12 @@ const Flow = (props: FlowProps) => {
statusPayload?.spec?.lifecycle?.desiredPhase === PAUSED &&
data?.pipeline?.status?.phase === PAUSED
) {
clearInterval(timer);
setStatusPayload(undefined);
}
if (
statusPayload?.spec?.lifecycle?.desiredPhase === RUNNING &&
data?.pipeline?.status?.phase === RUNNING
) {
clearInterval(timer);
setStatusPayload(undefined);
}
}, [data]);
Expand Down

0 comments on commit 93eec96

Please sign in to comment.