From 668ea4091ca4a4ae0e8421be01e2d386c676f14f Mon Sep 17 00:00:00 2001 From: Nate Lanza Date: Tue, 22 Oct 2024 11:49:50 -0600 Subject: [PATCH 1/3] Bugfix: App once again loads when session is empty --- packages/app/src/App.tsx | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/packages/app/src/App.tsx b/packages/app/src/App.tsx index 0616358a..61828c7c 100644 --- a/packages/app/src/App.tsx +++ b/packages/app/src/App.tsx @@ -17,6 +17,8 @@ import { CircularProgress } from '@mui/material'; const defaultVisibleSets = 6; +type SessionState = any | null | 'not found'; + export const ProvenanceContext = createContext<{ provenance: UpsetProvenance; actions: UpsetActions; @@ -28,7 +30,7 @@ function App() { const setState = useSetRecoilState(configAtom); const data = (encodedData === null) ? multinetData : encodedData const { workspace, sessionId } = useRecoilValue(queryParamAtom); - const [sessionState, setSessionState] = useState(null); // null is not tried to load, undefined is tried and no state to load, and value is loaded value + const [sessionState, setSessionState] = useState(null); // null is not tried to load, undefined is tried and no state to load, and value is loaded value const conf = useMemo(() => { const config: UpsetConfig = { ...DefaultConfig } @@ -62,26 +64,23 @@ function App() { // Initialize Provenance and pass it setter to connect const { provenance, actions } = useMemo(() => { - if (sessionState !== null) { - const provenance: UpsetProvenance = initializeProvenanceTracking(conf); - const actions: UpsetActions = getActions(provenance); - - // Make sure the provenance state gets converted every time this is called - (provenance as UpsetProvenance & {_getState: typeof provenance.getState})._getState = provenance.getState; - provenance.getState = () => convertConfig( - (provenance as UpsetProvenance & {_getState: typeof provenance.getState})._getState() - ); - - if (sessionState !== undefined) { - provenance.importObject(structuredClone(sessionState)); - } + const provenance: UpsetProvenance = initializeProvenanceTracking(conf); + const actions: UpsetActions = getActions(provenance); - // Make sure the config atom stays up-to-date with the provenance - provenance.currentChange(() => setState(provenance.getState())); + // Make sure the provenance state gets converted every time this is called + (provenance as UpsetProvenance & {_getState: typeof provenance.getState})._getState = provenance.getState; + provenance.getState = () => convertConfig( + (provenance as UpsetProvenance & {_getState: typeof provenance.getState})._getState() + ); - return { provenance: provenance || null, actions: actions || null }; + if (sessionState && sessionState !== 'not found') { + provenance.importObject(structuredClone(sessionState)); } - return {provenance: null, actions: null}; + + // Make sure the config atom stays up-to-date with the provenance + provenance.currentChange(() => setState(provenance.getState())); + + return { provenance: provenance, actions: actions }; }, [conf, setState, sessionState]); /* @@ -96,10 +95,10 @@ function App() { if (session?.state && typeof session.state === 'object' && Object.keys(session.state).length !== 0) { setSessionState(session.state); } else { - setSessionState(undefined); + setSessionState('not found'); } } else { - setSessionState(undefined); + setSessionState('not found'); } } update(); From ae0b0bfccdafd9c1fcba77e571b48246d75a3b1e Mon Sep 17 00:00:00 2001 From: Nate Lanza Date: Tue, 22 Oct 2024 13:17:25 -0600 Subject: [PATCH 2/3] Re-prevent double render with diff provenance objects; catch error when sessionId not found --- packages/app/src/App.tsx | 31 +++++++++++++++++-------------- packages/app/src/api/session.ts | 6 +++++- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/packages/app/src/App.tsx b/packages/app/src/App.tsx index 61828c7c..abcaa33f 100644 --- a/packages/app/src/App.tsx +++ b/packages/app/src/App.tsx @@ -64,23 +64,26 @@ function App() { // Initialize Provenance and pass it setter to connect const { provenance, actions } = useMemo(() => { - const provenance: UpsetProvenance = initializeProvenanceTracking(conf); - const actions: UpsetActions = getActions(provenance); + if (sessionState) { + const provenance: UpsetProvenance = initializeProvenanceTracking(conf); + const actions: UpsetActions = getActions(provenance); + + // Make sure the provenance state gets converted every time this is called + (provenance as UpsetProvenance & {_getState: typeof provenance.getState})._getState = provenance.getState; + provenance.getState = () => convertConfig( + (provenance as UpsetProvenance & {_getState: typeof provenance.getState})._getState() + ); + + if (sessionState && sessionState !== 'not found') { + provenance.importObject(structuredClone(sessionState)); + } - // Make sure the provenance state gets converted every time this is called - (provenance as UpsetProvenance & {_getState: typeof provenance.getState})._getState = provenance.getState; - provenance.getState = () => convertConfig( - (provenance as UpsetProvenance & {_getState: typeof provenance.getState})._getState() - ); + // Make sure the config atom stays up-to-date with the provenance + provenance.currentChange(() => setState(provenance.getState())); - if (sessionState && sessionState !== 'not found') { - provenance.importObject(structuredClone(sessionState)); + return { provenance: provenance, actions: actions }; } - - // Make sure the config atom stays up-to-date with the provenance - provenance.currentChange(() => setState(provenance.getState())); - - return { provenance: provenance, actions: actions }; + return { provenance: null, actions: null }; }, [conf, setState, sessionState]); /* diff --git a/packages/app/src/api/session.ts b/packages/app/src/api/session.ts index 43b00981..d0552ac2 100644 --- a/packages/app/src/api/session.ts +++ b/packages/app/src/api/session.ts @@ -21,5 +21,9 @@ export function updateMultinetSession(workspace: string, sessionId: string, prov * @returns A promise that resolves to the retrieved session. */ export async function getMultinetSession(workspace: string, sessionId: string) { - return api.getSession(workspace, parseInt(sessionId), 'table'); + try { + return await api.getSession(workspace, parseInt(sessionId), 'table'); + } catch { + return null; + } } From c48f09029495c1d4b25ed76e1d4b921340a4d6b8 Mon Sep 17 00:00:00 2001 From: Nate Lanza Date: Tue, 22 Oct 2024 13:19:00 -0600 Subject: [PATCH 3/3] Improve SessionState type --- packages/app/src/App.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/app/src/App.tsx b/packages/app/src/App.tsx index abcaa33f..6a2e8922 100644 --- a/packages/app/src/App.tsx +++ b/packages/app/src/App.tsx @@ -11,13 +11,14 @@ import { configAtom } from './atoms/configAtoms'; import { queryParamAtom } from './atoms/queryParamAtom'; import { getMultinetSession } from './api/session'; import { CircularProgress } from '@mui/material'; +import { ProvenanceGraph } from '@trrack/core/graph/graph-slice'; /** @jsxImportSource @emotion/react */ // eslint-disable-next-line @typescript-eslint/no-unused-vars const defaultVisibleSets = 6; -type SessionState = any | null | 'not found'; +type SessionState = ProvenanceGraph | null | 'not found'; export const ProvenanceContext = createContext<{ provenance: UpsetProvenance;