-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created an endpoint selection modal popup for users to save, add impr…
…ovements on endpoint selection (#630) * A minor and temporary fix for auth issue with the globus endpoint search popup. This will be addressed more elegantly in the future. * Created some persistence related functions which will store variables in a local scope object and keep them loaded/synchronized with session storage when redirects occur. Did a rewrite of the transfer function which uses goals to keep track of what the user wanted to do between redirects. Uses local storage to save goals, as it is faster and more reliable than session storage. Consolidated and simplifed the globus transfer related data types and atoms. Globus transfers seem to be failing when testing locally, and that issue will still need to be addressed. Removed the default endpoint in favor of allowing users to save their endpoints and prefered paths, and that is then saved in session storage for when they would log in later. * Moved the persistent storage functions to a separate file so that they can be used by other components. Re-organized the globus download steps function so that sign in tokens aren't required when setting the path of a saved endpoint. Also simplified the flow of the function to follow based on user goals rather than page state.
- Loading branch information
Showing
13 changed files
with
665 additions
and
575 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { SetterOrUpdater } from 'recoil'; | ||
import { loadSessionValue, saveSessionValue } from '../api'; | ||
|
||
export type PersistentVar<T> = { | ||
loader: () => Promise<T>; | ||
saver: () => Promise<void>; | ||
getter: () => T; | ||
setter: (value: T) => void; | ||
value: T; | ||
}; | ||
|
||
const PERSISTENT_VARS: { | ||
[key: string]: PersistentVar<unknown>; | ||
} = {}; | ||
|
||
export function addPersistVar<T>( | ||
varKey: string, | ||
defaultVal: T, | ||
setterFunc: SetterOrUpdater<T>, | ||
loaderFunc?: () => Promise<T> | ||
): void { | ||
if (Object.hasOwn(PERSISTENT_VARS, varKey)) { | ||
return; | ||
} | ||
|
||
const loader = async (): Promise<T> => { | ||
let val: T | null = null; | ||
if (loaderFunc) { | ||
val = await loaderFunc(); | ||
} else { | ||
val = await loadSessionValue<T>(varKey); | ||
} | ||
|
||
if (PERSISTENT_VARS[varKey]) { | ||
PERSISTENT_VARS[varKey].value = val || defaultVal; | ||
setterFunc(val || defaultVal); | ||
} | ||
return val || defaultVal; | ||
}; | ||
|
||
const saver = async (): Promise<void> => { | ||
if (PERSISTENT_VARS[varKey]) { | ||
await saveSessionValue<T>(varKey, PERSISTENT_VARS[varKey].value as T); | ||
} else { | ||
await saveSessionValue<T>(varKey, defaultVal); | ||
} | ||
}; | ||
|
||
const setter = (val: T): void => { | ||
if (PERSISTENT_VARS[varKey]) { | ||
PERSISTENT_VARS[varKey].value = val; | ||
setterFunc(val); | ||
} | ||
}; | ||
|
||
const getter = (): T => { | ||
if (PERSISTENT_VARS[varKey]) { | ||
return PERSISTENT_VARS[varKey].value as T; | ||
} | ||
return defaultVal; | ||
}; | ||
|
||
const newVar = { loader, saver, getter, setter, value: defaultVal }; | ||
PERSISTENT_VARS[varKey] = newVar as PersistentVar<unknown>; | ||
} | ||
|
||
export function getPersistVal<T>(varKey: string): T | null { | ||
if (PERSISTENT_VARS[varKey]) { | ||
return PERSISTENT_VARS[varKey].value as T; | ||
} | ||
return null; | ||
} | ||
|
||
export async function loadPersistVal<T>(varKey: string): Promise<T | null> { | ||
if (PERSISTENT_VARS[varKey]) { | ||
return PERSISTENT_VARS[varKey].loader() as Promise<T>; | ||
} | ||
return null; | ||
} | ||
|
||
export async function setPersistVal<T>( | ||
varKey: string, | ||
value: T, | ||
save: boolean | ||
): Promise<void> { | ||
if (PERSISTENT_VARS[varKey]) { | ||
PERSISTENT_VARS[varKey].setter(value); | ||
|
||
if (save) { | ||
await PERSISTENT_VARS[varKey].saver(); | ||
} | ||
} | ||
} | ||
|
||
export async function loadAllPersistVals(): Promise<void> { | ||
const loadFuncs: Promise<unknown>[] = []; | ||
Object.values(PERSISTENT_VARS).forEach((persistVar) => { | ||
if (persistVar && persistVar.loader) { | ||
loadFuncs.push(persistVar.loader()); | ||
} | ||
}); | ||
|
||
await Promise.all(loadFuncs); | ||
} | ||
|
||
export async function saveAllPersistVals(): Promise<void> { | ||
const saveFuncs: Promise<void>[] = []; | ||
Object.values(PERSISTENT_VARS).forEach((persistVar) => { | ||
if (persistVar && persistVar.saver) { | ||
saveFuncs.push(persistVar.saver()); | ||
} | ||
}); | ||
|
||
await Promise.all(saveFuncs); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.