Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add session saving and restoring to the provenance store #468

Merged
merged 5 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"d3": "7.8.0",
"eslint-import-resolver-alias": "^1.1.2",
"lineupjs": "^4.2.0",
"multinet": "^0.21.11",
"multinet": "^0.21.13",
"multinet-components": "^0.0.6",
"pinia": "^2.0.28",
"react": "^18.2.0",
Expand Down
6 changes: 1 addition & 5 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import ProvVis from '@/components/ProvVis.vue';
import ControlPanel from '@/components/ControlPanel.vue';
import MultiMatrix from '@/components/MultiMatrix.vue';
import { getUrlVars } from '@/lib/utils';

Check warning on line 6 in src/App.vue

View workflow job for this annotation

GitHub Actions / lint / lint

'getUrlVars' is defined but never used
import { useStore } from '@/store';
import 'multinet-components/dist/style.css';
import { storeToRefs } from 'pinia';
Expand All @@ -22,11 +22,7 @@
userInfo,
} = storeToRefs(store);

const urlVars = getUrlVars();
store.fetchNetwork(
urlVars.workspace,
urlVars.network,
);
store.fetchNetwork();

// Set up provenance undo and redo, provenance is not a ref here
const { provenance } = store;
Expand Down
31 changes: 14 additions & 17 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ export const useStore = defineStore('store', () => {
slicingConfig,
sliceIndex,
sortBy,
workspaceName,
networkName,
} = storeToRefs(provStore);

const workspaceName = ref('');
const networkName = ref('');
const loadError = ref<LoadError>({
message: '',
href: '',
Expand Down Expand Up @@ -290,10 +290,14 @@ export const useStore = defineStore('store', () => {
});
}

async function fetchNetwork(workspaceNameLocal: string, networkNameLocal: string) {
workspaceName.value = workspaceNameLocal;
networkName.value = networkNameLocal;

async function fetchNetwork() {
if (workspaceName.value === '' || networkName.value === '') {
loadError.value = {
message: 'Workspace and/or network were not defined in the url',
href: 'https://multinet.app',
};
return;
}
let networkLocal: NetworkSpec | undefined;

// Get all table names
Expand All @@ -302,17 +306,10 @@ export const useStore = defineStore('store', () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
if (error.status === 404) {
if (workspaceName.value === undefined || networkName.value === undefined) {
loadError.value = {
message: 'Workspace and/or network were not defined in the url',
href: 'https://multinet.app',
};
} else {
loadError.value = {
message: error.statusText,
href: 'https://multinet.app',
};
}
loadError.value = {
message: error.statusText,
href: 'https://multinet.app',
};
} else if (error.status === 401) {
loadError.value = {
message: 'You are not authorized to view this workspace',
Expand Down
28 changes: 28 additions & 0 deletions src/store/provenance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import api from '@/api';
import { findDifferencesInPrimitiveStates, getTrrackLabel, isArray } from '@/lib/provenanceUtils';
import { getUrlVars } from '@/lib/utils';
import { Cell, ProvState, SlicingConfig } from '@/types';
import { initializeTrrack, Registry } from '@trrack/core';
import { defineStore } from 'pinia';
Expand Down Expand Up @@ -112,6 +114,30 @@ export const useProvenanceStore = defineStore('provenance', () => {
}
});

// Variables to help with session management (this is not tracked in trrack)
const { sessionId, workspace, network } = getUrlVars();
const workspaceName = ref(workspace || '');
const networkName = ref(network || '');

// Update the session when the provenance changes
provenance.currentChange(() => {
api.updateSession(workspaceName.value, sessionId || '', 'network', provenance.export());
});

// Attempt to restore session on first load
async function restoreSession() {
if (sessionId) {
const session = await api.getSession(workspaceName.value, sessionId, 'network');

// If the session is empty, the API will be an empty object
// Only attempt to import if we have a string
if (typeof session.state === 'string') {
provenance.import(session.state);
}
}
}
restoreSession();

return {
provenance,
selectNeighbors,
Expand All @@ -126,5 +152,7 @@ export const useProvenanceStore = defineStore('provenance', () => {
slicingConfig,
sliceIndex,
sortBy,
workspaceName,
networkName,
};
});
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3267,10 +3267,10 @@ multinet-components@^0.0.6:
resolved "https://registry.yarnpkg.com/multinet-components/-/multinet-components-0.0.6.tgz#7b5b62de7a3504c0fe8b5928aea048506b209802"
integrity sha512-PkAEWTtk7/7lwZhYlHfMeYFo8zutvVJ/DxMsuN4wZCddyseBAP70vTnKkLcSK3WsS96XsibWjCDl1AHz2pACIg==

multinet@^0.21.11:
version "0.21.11"
resolved "https://registry.yarnpkg.com/multinet/-/multinet-0.21.11.tgz#040209b42a7b5dc4122c30f346109094ba1e0199"
integrity sha512-7MYTnqv4Gbr+AcQB2fwkA03F5nNqBrr/mNu/sSeIUcFd6cC/nZRQyRwPa40jTjFV80HahYeHvqQZCpMvdY/PYA==
multinet@^0.21.13:
version "0.21.13"
resolved "https://registry.yarnpkg.com/multinet/-/multinet-0.21.13.tgz#a4c440b05369bcb2001a728c9ecf9cc2b86a298c"
integrity sha512-UI++fPe3nr1ueEO5VSqGtL1rb6iV8Qt7ACE2Srw2HqcHt+jdhXmaf439XZtrRHl/TqcBE6xlnsObDSnbyiHbgQ==
dependencies:
axios "^0.21.1"
django-s3-file-field "^0.1.2"
Expand Down
Loading