feat: invalidate runs data

This commit is contained in:
Rohit Rajan
2025-09-19 11:25:31 +05:30
parent 883922606c
commit 6d25f26594

View File

@@ -6,7 +6,7 @@ import { Recordings } from "../components/robot/Recordings";
import { Runs } from "../components/run/Runs"; import { Runs } from "../components/run/Runs";
import ProxyForm from '../components/proxy/ProxyForm'; import ProxyForm from '../components/proxy/ProxyForm';
import ApiKey from '../components/api/ApiKey'; import ApiKey from '../components/api/ApiKey';
import { useGlobalInfoStore } from "../context/globalInfo"; import { useGlobalInfoStore, useCacheInvalidation } from "../context/globalInfo";
import { createAndRunRecording, createRunForStoredRecording, CreateRunResponseWithQueue, interpretStoredRecording, notifyAboutAbort, scheduleStoredRecording } from "../api/storage"; import { createAndRunRecording, createRunForStoredRecording, CreateRunResponseWithQueue, interpretStoredRecording, notifyAboutAbort, scheduleStoredRecording } from "../api/storage";
import { io, Socket } from "socket.io-client"; import { io, Socket } from "socket.io-client";
import { stopRecording } from "../api/recording"; import { stopRecording } from "../api/recording";
@@ -50,6 +50,7 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
let aborted = false; let aborted = false;
const { notify, setRerenderRuns, setRecordingId } = useGlobalInfoStore(); const { notify, setRerenderRuns, setRecordingId } = useGlobalInfoStore();
const { invalidateRuns } = useCacheInvalidation();
const navigate = useNavigate(); const navigate = useNavigate();
const { state } = useContext(AuthContext); const { state } = useContext(AuthContext);
@@ -66,12 +67,14 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
if (!response.success) { if (!response.success) {
notify('error', t('main_page.notifications.abort_failed', { name: robotName })); notify('error', t('main_page.notifications.abort_failed', { name: robotName }));
setRerenderRuns(true); setRerenderRuns(true);
invalidateRuns();
return; return;
} }
if (response.isQueued) { if (response.isQueued) {
setRerenderRuns(true); setRerenderRuns(true);
invalidateRuns();
notify('success', t('main_page.notifications.abort_success', { name: robotName })); notify('success', t('main_page.notifications.abort_success', { name: robotName }));
setQueuedRuns(prev => { setQueuedRuns(prev => {
@@ -92,6 +95,7 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
if (abortData.runId === runId) { if (abortData.runId === runId) {
notify('success', t('main_page.notifications.abort_success', { name: abortData.robotName || robotName })); notify('success', t('main_page.notifications.abort_success', { name: abortData.robotName || robotName }));
setRerenderRuns(true); setRerenderRuns(true);
invalidateRuns();
abortSocket.disconnect(); abortSocket.disconnect();
} }
}); });
@@ -100,6 +104,7 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
console.log('Abort socket connection error:', error); console.log('Abort socket connection error:', error);
notify('error', t('main_page.notifications.abort_failed', { name: robotName })); notify('error', t('main_page.notifications.abort_failed', { name: robotName }));
setRerenderRuns(true); setRerenderRuns(true);
invalidateRuns();
abortSocket.disconnect(); abortSocket.disconnect();
}); });
}); });
@@ -125,8 +130,9 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
setRunningRecordingName(''); setRunningRecordingName('');
setCurrentInterpretationLog(''); setCurrentInterpretationLog('');
setRerenderRuns(true); setRerenderRuns(true);
invalidateRuns();
}) })
}, [runningRecordingName, aborted, currentInterpretationLog, notify, setRerenderRuns]); }, [runningRecordingName, aborted, currentInterpretationLog, notify, setRerenderRuns, invalidateRuns]);
const debugMessageHandler = useCallback((msg: string) => { const debugMessageHandler = useCallback((msg: string) => {
setCurrentInterpretationLog((prevState) => setCurrentInterpretationLog((prevState) =>
@@ -156,6 +162,7 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
setRunningRecordingName(''); setRunningRecordingName('');
setCurrentInterpretationLog(''); setCurrentInterpretationLog('');
setRerenderRuns(true); setRerenderRuns(true);
invalidateRuns();
const robotName = data.robotName; const robotName = data.robotName;
@@ -193,7 +200,7 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
socket.off('connect_error'); socket.off('connect_error');
socket.off('disconnect'); socket.off('disconnect');
} }
}, [runningRecordingName, sockets, ids, debugMessageHandler, user?.id, t, notify, setRerenderRuns, setQueuedRuns, navigate, setContent, setIds]); }, [runningRecordingName, sockets, ids, debugMessageHandler, user?.id, t, notify, setRerenderRuns, setQueuedRuns, navigate, setContent, setIds, invalidateRuns]);
const handleScheduleRecording = async (settings: ScheduleSettings) => { const handleScheduleRecording = async (settings: ScheduleSettings) => {
const { message, runId }: ScheduleRunResponse = await scheduleStoredRecording(runningRecordingId, settings); const { message, runId }: ScheduleRunResponse = await scheduleStoredRecording(runningRecordingId, settings);
@@ -209,6 +216,7 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
if (user?.id) { if (user?.id) {
const handleRunCompleted = (completionData: any) => { const handleRunCompleted = (completionData: any) => {
setRerenderRuns(true); setRerenderRuns(true);
invalidateRuns();
if (queuedRuns.has(completionData.runId)) { if (queuedRuns.has(completionData.runId)) {
setQueuedRuns(prev => { setQueuedRuns(prev => {
@@ -233,7 +241,7 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
disconnectQueueSocket(); disconnectQueueSocket();
}; };
} }
}, [user?.id, connectToQueueSocket, disconnectQueueSocket, t, setRerenderRuns, queuedRuns, setQueuedRuns]); }, [user?.id, connectToQueueSocket, disconnectQueueSocket, t, setRerenderRuns, queuedRuns, setQueuedRuns, invalidateRuns]);
const DisplayContent = () => { const DisplayContent = () => {
switch (content) { switch (content) {