diff --git a/packages/libs/eda/src/lib/core/hooks/promise.ts b/packages/libs/eda/src/lib/core/hooks/promise.ts index 129318988e..cd0c1d3488 100644 --- a/packages/libs/eda/src/lib/core/hooks/promise.ts +++ b/packages/libs/eda/src/lib/core/hooks/promise.ts @@ -1,4 +1,5 @@ import { useEffect, useState } from 'react'; +import { useValueBasedUpdater } from './state'; export type PromiseHookState = { value?: T; @@ -28,13 +29,18 @@ export function usePromise( const [state, setState] = useState>({ pending: true, }); - useEffect(() => { - let ignoreResolve = false; + + // Set pending state synchronously + useValueBasedUpdater(task, () => { setState((prev) => ({ pending: true, value: keepPreviousValue ? prev.value : undefined, error: undefined, })); + }); + + useEffect(() => { + let ignoreResolve = false; task().then( (value) => { if (ignoreResolve) return; @@ -54,7 +60,7 @@ export function usePromise( return function cleanup() { ignoreResolve = true; }; - }, [keepPreviousValue, task]); + }, [task]); if (state.error && throwError) throw state.error; return state; } diff --git a/packages/libs/eda/src/lib/core/hooks/state.ts b/packages/libs/eda/src/lib/core/hooks/state.ts new file mode 100644 index 0000000000..c9078f3a80 --- /dev/null +++ b/packages/libs/eda/src/lib/core/hooks/state.ts @@ -0,0 +1,12 @@ +import { useRef } from 'react'; + +/** + * Calls the `updater` function when `value` changes. + */ +export function useValueBasedUpdater(value: T, updater: () => void) { + const ref = useRef(); + if (ref.current !== value) { + updater(); + } + ref.current = value; +} diff --git a/packages/libs/eda/src/lib/workspace/AllAnalyses.tsx b/packages/libs/eda/src/lib/workspace/AllAnalyses.tsx index 3b77b913e4..4a4febe834 100644 --- a/packages/libs/eda/src/lib/workspace/AllAnalyses.tsx +++ b/packages/libs/eda/src/lib/workspace/AllAnalyses.tsx @@ -187,8 +187,9 @@ export function AllAnalyses(props: Props) { const [ownUserDatasets, communityDatasets] = useWdkService(async (wdkService) => { if (isVdiCompatibleWdkService(wdkService)) { + const user = await wdkService.getCurrentUser(); return Promise.all([ - wdkService.getCurrentUserDatasets(), + user.isGuest ? [] : wdkService.getCurrentUserDatasets(), wdkService.getCommunityDatasets(), ]); } diff --git a/packages/libs/eda/src/lib/workspace/Subsetting/index.tsx b/packages/libs/eda/src/lib/workspace/Subsetting/index.tsx index d99ed5db09..78d95c6f18 100644 --- a/packages/libs/eda/src/lib/workspace/Subsetting/index.tsx +++ b/packages/libs/eda/src/lib/workspace/Subsetting/index.tsx @@ -65,21 +65,15 @@ export default function Subsetting({ [entity, variable] ); - if ( - entity == null || - (!Variable.is(variable) && !MultiFilterVariable.is(variable)) - ) { - return
Could not find specified variable.
; - } - if (multiFilterParent) { return ; } - const totalEntityCount = totalCounts && totalCounts[entity.id]; + const totalEntityCount = totalCounts && entity && totalCounts[entity.id]; // This will give you the count of rows for the current entity. - const filteredEntityCount = filteredCounts && filteredCounts[entity.id]; + const filteredEntityCount = + filteredCounts && entity && filteredCounts[entity.id]; const starredVariables = analysisState.analysis?.descriptor.starredVariables; @@ -88,22 +82,27 @@ export default function Subsetting({
- + {entity == null || + (!Variable.is(variable) && !MultiFilterVariable.is(variable)) ? ( +
Could not find specified variable in this study.
+ ) : ( + + )}
); diff --git a/packages/libs/user-datasets/src/lib/Controllers/UserDatasetDetailController.tsx b/packages/libs/user-datasets/src/lib/Controllers/UserDatasetDetailController.tsx index 257b3d2012..da02091b16 100644 --- a/packages/libs/user-datasets/src/lib/Controllers/UserDatasetDetailController.tsx +++ b/packages/libs/user-datasets/src/lib/Controllers/UserDatasetDetailController.tsx @@ -211,6 +211,7 @@ class UserDatasetDetailController extends PageController { const entry = userDatasetsById[id]; const isOwner = !!( user && + entry && entry.resource && entry.resource.ownerUserId === user.id ); @@ -237,8 +238,8 @@ class UserDatasetDetailController extends PageController { sharingSuccess, shareSuccessful, updateSharingModalState, - userDataset: entry.resource, - fileListing: entry.fileListing, + userDataset: entry?.resource, + fileListing: entry?.fileListing, getQuestionUrl: this.getQuestionUrl, questionMap: keyBy(questions, 'fullName'), workspaceTitle, @@ -254,9 +255,11 @@ class UserDatasetDetailController extends PageController { }; const DetailView = this.getDetailView( - typeof entry.resource === 'object' ? entry.resource.type : null + typeof entry?.resource === 'object' ? entry.resource.type : null ); - return user && user.isGuest ? ( + return entry?.resource?.meta.visibility !== 'public' && + user && + user.isGuest ? ( this.renderGuestView() ) : (