Skip to content

Commit

Permalink
fix: initial workspace is removed in 3-pane layout
Browse files Browse the repository at this point in the history
  • Loading branch information
dominictb committed Oct 22, 2024
1 parent d0d5b4c commit 0386167
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ function adaptStateIfNecessary(state: StackState) {
workspaceCentralPane?.params && 'policyID' in workspaceCentralPane.params && typeof workspaceCentralPane.params.policyID === 'string'
? workspaceCentralPane.params.policyID
: undefined;
const policy = PolicyUtils.getPolicy(policyID ?? '');
const isLoadingReportData = PolicyUtils.getIsLoadingReportData();
const isPolicyAccessible = PolicyUtils.isPolicyAccessible(policy);

// There should always be WORKSPACE.INITIAL screen in the state to make sure go back works properly if we deeplinkg to a subpage of settings.
// The only exception is when the workspace is invalid or inaccessible.
if (!isAtLeastOneInState(state, SCREENS.WORKSPACE.INITIAL)) {
const policy = PolicyUtils.getPolicy(policyID ?? '');
const isPolicyAccessible = PolicyUtils.isPolicyAccessible(policy);
if (!isPolicyAccessible) {
if (isNarrowLayout && !isLoadingReportData && !isPolicyAccessible) {
return;
}

// @ts-expect-error Updating read only property
// noinspection JSConstantReassignment
state.stale = true; // eslint-disable-line
Expand Down
9 changes: 7 additions & 2 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1071,8 +1071,12 @@ function getActivePolicy(): OnyxEntry<Policy> {
return getPolicy(activePolicyId);
}

function isPolicyAccessible(policy: OnyxEntry<Policy>) {
return !isLoadingReportData && !isEmptyObject(policy) && (Object.keys(policy).length !== 1 || isEmptyObject(policy.errors)) && policy?.id;
function isPolicyAccessible(policy: OnyxEntry<Policy>): boolean {
return !isEmptyObject(policy) && (Object.keys(policy).length !== 1 || isEmptyObject(policy.errors)) && !!policy?.id;
}

function getIsLoadingReportData() {
return isLoadingReportData;
}

export {
Expand Down Expand Up @@ -1193,6 +1197,7 @@ export {
getAllPoliciesLength,
getActivePolicy,
isPolicyAccessible,
getIsLoadingReportData,
};

export type {MemberEmailsToAccountIDs};
4 changes: 2 additions & 2 deletions src/pages/workspace/AccessOrNotFoundWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ function AccessOrNotFoundWrapper({
const childrenProps = useMemo(() => ({report, policy, isLoadingReportData}), [report, policy, isLoadingReportData]);

useEffect(() => {
if (!isPolicyNotAccessible) {
if (isLoadingReportData || !isPolicyNotAccessible) {
return;
}
Navigation.removeScreenFromNavigationState(SCREENS.WORKSPACE.INITIAL);
}, [isPolicyNotAccessible]);
}, [isLoadingReportData, isPolicyNotAccessible]);

if (shouldShowFullScreenLoadingIndicator) {
return <FullscreenLoadingIndicator />;
Expand Down

0 comments on commit 0386167

Please sign in to comment.