Skip to content

Commit

Permalink
Merge branch 'main' into 17-query-interface
Browse files Browse the repository at this point in the history
  • Loading branch information
JackWilb authored Oct 22, 2024
2 parents f3d5eb4 + b45b358 commit 34f25cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
17 changes: 10 additions & 7 deletions packages/app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ 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 = ProvenanceGraph<UpsetConfig, string> | null | 'not found';

export const ProvenanceContext = createContext<{
provenance: UpsetProvenance;
actions: UpsetActions;
Expand All @@ -28,7 +31,7 @@ function App() {
const setState = useSetRecoilState(configAtom);
const data = (encodedData === null) ? multinetData : encodedData
const { workspace, sessionId } = useRecoilValue(queryParamAtom);
const [sessionState, setSessionState] = useState<any>(null); // null is not tried to load, undefined is tried and no state to load, and value is loaded value
const [sessionState, setSessionState] = useState<SessionState>(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 }
Expand Down Expand Up @@ -62,7 +65,7 @@ function App() {

// Initialize Provenance and pass it setter to connect
const { provenance, actions } = useMemo(() => {
if (sessionState !== null) {
if (sessionState) {
const provenance: UpsetProvenance = initializeProvenanceTracking(conf);
const actions: UpsetActions = getActions(provenance);

Expand All @@ -72,16 +75,16 @@ function App() {
(provenance as UpsetProvenance & {_getState: typeof provenance.getState})._getState()
);

if (sessionState !== undefined) {
if (sessionState && sessionState !== 'not found') {
provenance.importObject(structuredClone(sessionState));
}

// Make sure the config atom stays up-to-date with the provenance
provenance.currentChange(() => setState(provenance.getState()));

return { provenance: provenance || null, actions: actions || null };
return { provenance: provenance, actions: actions };
}
return {provenance: null, actions: null};
return { provenance: null, actions: null };
}, [conf, setState, sessionState]);

/*
Expand All @@ -96,10 +99,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();
Expand Down
6 changes: 5 additions & 1 deletion packages/app/src/api/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 34f25cc

Please sign in to comment.