From 8ee68ed19cb25dc5af6e70f4fa06deff33e0f708 Mon Sep 17 00:00:00 2001 From: Adam Grzybowski Date: Thu, 1 Feb 2024 15:37:07 +0100 Subject: [PATCH 01/15] remove old todo comment --- src/pages/workspace/WorkspaceNamePage.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/pages/workspace/WorkspaceNamePage.tsx b/src/pages/workspace/WorkspaceNamePage.tsx index 581f7fee35a8..e9d1ddd021d0 100644 --- a/src/pages/workspace/WorkspaceNamePage.tsx +++ b/src/pages/workspace/WorkspaceNamePage.tsx @@ -22,7 +22,6 @@ function WorkspaceNamePage({policy}: Props) { const styles = useThemeStyles(); const {translate} = useLocalize(); - // TODO: Change this once Form (https://github.com/Expensify/App/issues/31972) is migrated to TypeScript. const submit = useCallback( (values: OnyxFormValuesFields) => { if (!policy || policy.isPolicyUpdating) { @@ -36,7 +35,6 @@ function WorkspaceNamePage({policy}: Props) { [policy], ); - // TODO: Change this once Form (https://github.com/Expensify/App/issues/31972) is migrated to TypeScript. const validate = useCallback((values: OnyxFormValuesFields) => { const errors: Record = {}; const name = values.name.trim(); From c4466cccc7415c20b41f6c22aabd1971243b6aaa Mon Sep 17 00:00:00 2001 From: Adam Grzybowski Date: Thu, 1 Feb 2024 15:43:32 +0100 Subject: [PATCH 02/15] remove commented out code WorkspaceAvatar --- src/pages/workspace/WorkspaceAvatar.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/pages/workspace/WorkspaceAvatar.tsx b/src/pages/workspace/WorkspaceAvatar.tsx index cbfdd22c66b7..a08400617fbc 100644 --- a/src/pages/workspace/WorkspaceAvatar.tsx +++ b/src/pages/workspace/WorkspaceAvatar.tsx @@ -26,11 +26,7 @@ function WorkspaceAvatar({policy, isLoadingApp = true}: WorkspaceAvatarProps) { headerTitle={policy?.name ?? ''} defaultOpen source={UserUtils.getFullSizeAvatar(avatarURL, 0)} - onModalClose={() => { - // TODO - Check the correct path for ideal-nav - Navigation.goBack(); - // Navigation.goBack(ROUTES.WORKSPACE_SETTINGS.getRoute(route.params.policyID ?? '')); - }} + onModalClose={Navigation.goBack} isWorkspaceAvatar originalFileName={policy?.originalFileName ?? policy?.name ?? ''} shouldShowNotFoundPage={!Object.keys(policy ?? {}).length && !isLoadingApp} From a0a33843e4165f6a5bd22163410533aa8435c5fd Mon Sep 17 00:00:00 2001 From: Adam Grzybowski Date: Thu, 1 Feb 2024 15:52:58 +0100 Subject: [PATCH 03/15] change policyId to policyID --- src/libs/Navigation/NavigationRoot.tsx | 4 ++-- src/libs/Navigation/dismissModalWithReport.ts | 4 ++-- src/libs/Navigation/getPolicyIdFromState.ts | 8 ++++---- src/libs/Navigation/linkTo.ts | 6 +++--- .../linkingConfig/customGetPathFromState.ts | 4 ++-- .../linkingConfig/getAdaptedStateFromPath.ts | 4 ++-- src/libs/ReportUtils.ts | 4 ++-- src/libs/actions/ReimbursementAccount/navigation.js | 6 +++--- .../ReimbursementAccount/ReimbursementAccountPage.js | 5 +++-- src/pages/WorkspaceSwitcherPage.js | 12 ++++++------ 10 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/libs/Navigation/NavigationRoot.tsx b/src/libs/Navigation/NavigationRoot.tsx index f022f5c6a657..20c426a74c71 100644 --- a/src/libs/Navigation/NavigationRoot.tsx +++ b/src/libs/Navigation/NavigationRoot.tsx @@ -12,7 +12,7 @@ import {updateLastVisitedPath} from '@userActions/App'; import type {Route} from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; import AppNavigator from './AppNavigator'; -import getPolicyIdFromState from './getPolicyIdFromState'; +import getPolicyIDFromState from './getPolicyIDFromState'; import linkingConfig from './linkingConfig'; import customGetPathFromState from './linkingConfig/customGetPathFromState'; import getAdaptedStateFromPath from './linkingConfig/getAdaptedStateFromPath'; @@ -118,7 +118,7 @@ function NavigationRoot({authenticated, lastVisitedPath, initialUrl, onReady}: N if (!state) { return; } - const activeWorkspaceID = getPolicyIdFromState(state as NavigationState); + const activeWorkspaceID = getPolicyIDFromState(state as NavigationState); // Performance optimization to avoid context consumers to delay first render setTimeout(() => { currentReportIDValue?.updateCurrentReportID(state); diff --git a/src/libs/Navigation/dismissModalWithReport.ts b/src/libs/Navigation/dismissModalWithReport.ts index 00217452c5f9..28fd9d90b4a1 100644 --- a/src/libs/Navigation/dismissModalWithReport.ts +++ b/src/libs/Navigation/dismissModalWithReport.ts @@ -11,7 +11,7 @@ import SCREENS from '@src/SCREENS'; import type {Report} from '@src/types/onyx'; import type {EmptyObject} from '@src/types/utils/EmptyObject'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; -import getPolicyIdFromState from './getPolicyIdFromState'; +import getPolicyIDFromState from './getPolicyIDFromState'; import getStateFromPath from './getStateFromPath'; import getTopmostReportId from './getTopmostReportId'; import linkingConfig from './linkingConfig'; @@ -41,7 +41,7 @@ function dismissModalWithReport(targetReport: Report | EmptyObject, navigationRe // if we are not in the target report, we need to navigate to it after dismissing the modal if (targetReport.reportID !== getTopmostReportId(state)) { const reportState = getStateFromPath(ROUTES.REPORT_WITH_ID.getRoute(targetReport.reportID)); - const policyID = getPolicyIdFromState(state as State); + const policyID = getPolicyIDFromState(state as State); const policyMemberAccountIDs = getPolicyMemberAccountIDs(policyID); const shouldOpenAllWorkspace = isEmptyObject(targetReport) ? true : !doesReportBelongToWorkspace(targetReport, policyMemberAccountIDs, policyID); diff --git a/src/libs/Navigation/getPolicyIdFromState.ts b/src/libs/Navigation/getPolicyIdFromState.ts index 29a26deae642..00236fb0fce0 100644 --- a/src/libs/Navigation/getPolicyIdFromState.ts +++ b/src/libs/Navigation/getPolicyIdFromState.ts @@ -1,16 +1,16 @@ import getTopmostBottomTabRoute from './getTopmostBottomTabRoute'; import type {RootStackParamList, State} from './types'; -const getPolicyIdFromState = (state: State): string | undefined => { +const getPolicyIDFromState = (state: State): string | undefined => { const topmostBottomTabRoute = getTopmostBottomTabRoute(state); - const shouldAddPolicyIdToUrl = !!topmostBottomTabRoute && !!topmostBottomTabRoute.params && 'policyID' in topmostBottomTabRoute.params && !!topmostBottomTabRoute.params?.policyID; + const shouldAddPolicyIDToUrl = !!topmostBottomTabRoute && !!topmostBottomTabRoute.params && 'policyID' in topmostBottomTabRoute.params && !!topmostBottomTabRoute.params?.policyID; - if (!shouldAddPolicyIdToUrl) { + if (!shouldAddPolicyIDToUrl) { return undefined; } return topmostBottomTabRoute.params?.policyID as string; }; -export default getPolicyIdFromState; +export default getPolicyIDFromState; diff --git a/src/libs/Navigation/linkTo.ts b/src/libs/Navigation/linkTo.ts index 2c7c9357af26..39e85892da46 100644 --- a/src/libs/Navigation/linkTo.ts +++ b/src/libs/Navigation/linkTo.ts @@ -10,7 +10,7 @@ import SCREENS from '@src/SCREENS'; import getActionsFromPartialDiff from './AppNavigator/getActionsFromPartialDiff'; import getPartialStateDiff from './AppNavigator/getPartialStateDiff'; import dismissModal from './dismissModal'; -import getPolicyIdFromState from './getPolicyIdFromState'; +import getPolicyIDFromState from './getPolicyIDFromState'; import getStateFromPath from './getStateFromPath'; import getTopmostBottomTabRoute from './getTopmostBottomTabRoute'; import getTopmostCentralPaneRoute from './getTopmostCentralPaneRoute'; @@ -134,8 +134,8 @@ export default function linkTo(navigation: NavigationContainerRef)?.name === SCREENS.WORKSPACE.INITIAL && path.includes('workspace'); diff --git a/src/libs/Navigation/linkingConfig/customGetPathFromState.ts b/src/libs/Navigation/linkingConfig/customGetPathFromState.ts index dbef90bb0bd7..32d81f272d4a 100644 --- a/src/libs/Navigation/linkingConfig/customGetPathFromState.ts +++ b/src/libs/Navigation/linkingConfig/customGetPathFromState.ts @@ -1,6 +1,6 @@ import {getPathFromState} from '@react-navigation/native'; import _ from 'lodash'; -import getPolicyIdFromState from '@libs/Navigation/getPolicyIdFromState'; +import getPolicyIDFromState from '@libs/Navigation/getPolicyIDFromState'; import getTopmostBottomTabRoute from '@libs/Navigation/getTopmostBottomTabRoute'; import type {RootStackParamList, State} from '@libs/Navigation/types'; import SCREENS from '@src/SCREENS'; @@ -18,7 +18,7 @@ const customGetPathFromState: typeof getPathFromState = (state, options) => { const stateWithoutPolicyID = removePolicyIDParamFromState(state as State); // For the Home page we should remove policyID from the params, const path = getPathFromState(stateWithoutPolicyID, options); - const policyIDFromState = getPolicyIdFromState(state as State); + const policyIDFromState = getPolicyIDFromState(state as State); const isWorkspaceSettingsOpened = getTopmostBottomTabRoute(state as State)?.name === SCREENS.WORKSPACE.INITIAL && path.includes('workspace'); return `${policyIDFromState && !isWorkspaceSettingsOpened ? `/w/${policyIDFromState}` : ''}${path}`; }; diff --git a/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts b/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts index 1d5568a4d4c7..90f8873da4c8 100644 --- a/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts +++ b/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts @@ -33,7 +33,7 @@ type GetAdaptedStateFromPath = (...args: Parameters) => // The function getPathFromState that we are using in some places isn't working correctly without defined index. const getRoutesWithIndex = (routes: NavigationPartialRoute[]): PartialState => ({routes, index: routes.length - 1}); -const addPolicyIdToRoute = (route: NavigationPartialRoute, policyID?: string) => { +const addPolicyIDToRoute = (route: NavigationPartialRoute, policyID?: string) => { const routeWithPolicyID = {...route}; if (!routeWithPolicyID.params) { routeWithPolicyID.params = {policyID}; @@ -54,7 +54,7 @@ function createBottomTabNavigator(route: NavigationPartialRoute, if (route.name !== SCREENS.HOME) { // If the generated state requires tab other than HOME, we need to insert it. - routesForBottomTabNavigator.push(addPolicyIdToRoute(route, policyID) as NavigationPartialRoute); + routesForBottomTabNavigator.push(addPolicyIDToRoute(route, policyID) as NavigationPartialRoute); } return { diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index dd979e52bebf..5f3efcbcdbb0 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -904,7 +904,7 @@ function doesReportBelongToWorkspace(report: Report, policyMemberAccountIDs: num /** * Given an array of reports, return them filtered by a policyID and policyMemberAccountIDs. */ -function filterReportsByPolicyIdAndMemberAccountIDs(reports: Report[], policyMemberAccountIDs: number[] = [], policyID?: string) { +function filterReportsByPolicyIDAndMemberAccountIDs(reports: Report[], policyMemberAccountIDs: number[] = [], policyID?: string) { return reports.filter((report) => !!report && doesReportBelongToWorkspace(report, policyMemberAccountIDs, policyID)); } @@ -1004,7 +1004,7 @@ function findLastAccessedReport( let reportsValues = Object.values(reports ?? {}) as Report[]; if (!!policyID || policyMemberAccountIDs.length > 0) { - reportsValues = filterReportsByPolicyIdAndMemberAccountIDs(reportsValues, policyMemberAccountIDs, policyID); + reportsValues = filterReportsByPolicyIDAndMemberAccountIDs(reportsValues, policyMemberAccountIDs, policyID); } let sortedReports = sortReportsByLastRead(reportsValues, reportMetadata); diff --git a/src/libs/actions/ReimbursementAccount/navigation.js b/src/libs/actions/ReimbursementAccount/navigation.js index ebc1862e9c74..0ea09465d795 100644 --- a/src/libs/actions/ReimbursementAccount/navigation.js +++ b/src/libs/actions/ReimbursementAccount/navigation.js @@ -16,11 +16,11 @@ function goToWithdrawalAccountSetupStep(stepID, newAchData) { /** * Navigate to the correct bank account route based on the bank account state and type * - * @param {string} policyId - The policy ID associated with the bank account. + * @param {string} policyID - The policy ID associated with the bank account. * @param {string} [backTo=''] - An optional return path. If provided, it will be URL-encoded and appended to the resulting URL. */ -function navigateToBankAccountRoute(policyId, backTo) { - Navigation.navigate(ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute('', policyId, backTo)); +function navigateToBankAccountRoute(policyID, backTo) { + Navigation.navigate(ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute('', policyID, backTo)); } export {goToWithdrawalAccountSetupStep, navigateToBankAccountRoute}; diff --git a/src/pages/ReimbursementAccount/ReimbursementAccountPage.js b/src/pages/ReimbursementAccount/ReimbursementAccountPage.js index 09ad8fd323cc..2882e1436b9d 100644 --- a/src/pages/ReimbursementAccount/ReimbursementAccountPage.js +++ b/src/pages/ReimbursementAccount/ReimbursementAccountPage.js @@ -331,9 +331,10 @@ function ReimbursementAccountPage({reimbursementAccount, route, onfidoToken, pol } const backTo = lodashGet(route.params, 'backTo'); - const policyId = lodashGet(route.params, 'policyID'); + // eslint-disable-next-line no-shadow + const policyID = lodashGet(route.params, 'policyID'); - Navigation.navigate(ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute(getRouteForCurrentStep(currentStep), policyId, backTo)); + Navigation.navigate(ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute(getRouteForCurrentStep(currentStep), policyID, backTo)); }, // eslint-disable-next-line react-hooks/exhaustive-deps [isOffline, reimbursementAccount, route, hasACHDataBeenLoaded, shouldShowContinueSetupButton], diff --git a/src/pages/WorkspaceSwitcherPage.js b/src/pages/WorkspaceSwitcherPage.js index 6c63617200c8..1aaaa91b504f 100644 --- a/src/pages/WorkspaceSwitcherPage.js +++ b/src/pages/WorkspaceSwitcherPage.js @@ -79,9 +79,9 @@ function WorkspaceSwitcherPage({policies}) { const unreadStatusesForPolicies = useMemo(() => getWorkspacesUnreadStatuses(), []); const getIndicatorTypeForPolicy = useCallback( - (policyId) => { - if (policyId && policyId !== activeWorkspaceID) { - return brickRoadsForPolicies[policyId]; + (policyID) => { + if (policyID && policyID !== activeWorkspaceID) { + return brickRoadsForPolicies[policyID]; } if (_.values(brickRoadsForPolicies).includes(CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR)) { @@ -100,9 +100,9 @@ function WorkspaceSwitcherPage({policies}) { const hasUnreadData = useCallback( // TO DO: Implement checking if policy has some unread data // eslint-disable-next-line no-unused-vars - (policyId) => { - if (policyId) { - return unreadStatusesForPolicies[policyId]; + (policyID) => { + if (policyID) { + return unreadStatusesForPolicies[policyID]; } return _.some(_.values(unreadStatusesForPolicies), (status) => status); From 583ff1879c044532c0a4667265b5db6612ada4ae Mon Sep 17 00:00:00 2001 From: Adam Grzybowski Date: Thu, 1 Feb 2024 15:58:57 +0100 Subject: [PATCH 04/15] start comment with capital letter --- src/libs/Navigation/dismissModalWithReport.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Navigation/dismissModalWithReport.ts b/src/libs/Navigation/dismissModalWithReport.ts index 28fd9d90b4a1..4db9e30d61e9 100644 --- a/src/libs/Navigation/dismissModalWithReport.ts +++ b/src/libs/Navigation/dismissModalWithReport.ts @@ -38,7 +38,7 @@ function dismissModalWithReport(targetReport: Report | EmptyObject, navigationRe case NAVIGATORS.RIGHT_MODAL_NAVIGATOR: case SCREENS.NOT_FOUND: case SCREENS.REPORT_ATTACHMENTS: - // if we are not in the target report, we need to navigate to it after dismissing the modal + // If we are not in the target report, we need to navigate to it after dismissing the modal if (targetReport.reportID !== getTopmostReportId(state)) { const reportState = getStateFromPath(ROUTES.REPORT_WITH_ID.getRoute(targetReport.reportID)); const policyID = getPolicyIDFromState(state as State); From 26ccc06b7e8d512b02583753ad6aaca5b9e807f8 Mon Sep 17 00:00:00 2001 From: Adam Grzybowski Date: Thu, 1 Feb 2024 16:38:38 +0100 Subject: [PATCH 05/15] rename WorkspacesUtils --- .../createCustomBottomTabNavigator/BottomTabBar.tsx | 2 +- src/libs/{WorkspacesUtils.ts => WorkspacesSettingsUtils.ts} | 0 src/pages/WorkspaceSwitcherPage.js | 2 +- src/pages/home/sidebar/AllSettingsScreen.tsx | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename src/libs/{WorkspacesUtils.ts => WorkspacesSettingsUtils.ts} (100%) diff --git a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/BottomTabBar.tsx b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/BottomTabBar.tsx index 0fe0e7557610..436ac998b698 100644 --- a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/BottomTabBar.tsx +++ b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/BottomTabBar.tsx @@ -14,7 +14,7 @@ import interceptAnonymousUser from '@libs/interceptAnonymousUser'; import getTopmostBottomTabRoute from '@libs/Navigation/getTopmostBottomTabRoute'; import Navigation from '@libs/Navigation/Navigation'; import type {RootStackParamList} from '@libs/Navigation/types'; -import {checkIfWorkspaceSettingsTabHasRBR, getChatTabBrickRoad} from '@libs/WorkspacesUtils'; +import {checkIfWorkspaceSettingsTabHasRBR, getChatTabBrickRoad} from '@libs/WorkspacesSettingsUtils'; import BottomTabBarFloatingActionButton from '@pages/home/sidebar/BottomTabBarFloatingActionButton'; import variables from '@styles/variables'; import CONST from '@src/CONST'; diff --git a/src/libs/WorkspacesUtils.ts b/src/libs/WorkspacesSettingsUtils.ts similarity index 100% rename from src/libs/WorkspacesUtils.ts rename to src/libs/WorkspacesSettingsUtils.ts diff --git a/src/pages/WorkspaceSwitcherPage.js b/src/pages/WorkspaceSwitcherPage.js index 1aaaa91b504f..4bdf1d6aa302 100644 --- a/src/pages/WorkspaceSwitcherPage.js +++ b/src/pages/WorkspaceSwitcherPage.js @@ -22,7 +22,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; import * as PolicyUtils from '@libs/PolicyUtils'; import * as ReportUtils from '@libs/ReportUtils'; -import {getWorkspacesBrickRoads, getWorkspacesUnreadStatuses} from '@libs/WorkspacesUtils'; +import {getWorkspacesBrickRoads, getWorkspacesUnreadStatuses} from '@libs/WorkspacesSettingsUtils'; import * as App from '@userActions/App'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; diff --git a/src/pages/home/sidebar/AllSettingsScreen.tsx b/src/pages/home/sidebar/AllSettingsScreen.tsx index 6e7447244a4d..aa308d523db4 100644 --- a/src/pages/home/sidebar/AllSettingsScreen.tsx +++ b/src/pages/home/sidebar/AllSettingsScreen.tsx @@ -11,7 +11,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import useWaitForNavigation from '@hooks/useWaitForNavigation'; import useWindowDimensions from '@hooks/useWindowDimensions'; import Navigation from '@libs/Navigation/Navigation'; -import {hasGlobalWorkspaceSettingsRBR} from '@libs/WorkspacesUtils'; +import {hasGlobalWorkspaceSettingsRBR} from '@libs/WorkspacesSettingsUtils'; import * as Link from '@userActions/Link'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; From af81459859993f3cea00392403a63b54200969ef Mon Sep 17 00:00:00 2001 From: Adam Grzybowski Date: Thu, 1 Feb 2024 16:40:01 +0100 Subject: [PATCH 06/15] add new line --- src/libs/Navigation/switchPolicyID.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libs/Navigation/switchPolicyID.ts b/src/libs/Navigation/switchPolicyID.ts index 0cbd4874e7ae..4b9259c76ad7 100644 --- a/src/libs/Navigation/switchPolicyID.ts +++ b/src/libs/Navigation/switchPolicyID.ts @@ -40,10 +40,12 @@ function getActionForBottomTabNavigator(action: StackNavigationAction, state: Na if (screen === SCREENS.ALL_SETTINGS && policyID) { screen = SCREENS.WORKSPACE.INITIAL; } + // Alternative case when the user is on the specific workspace settings screen and selects "All" workspace. else if (!policyID && screen === SCREENS.WORKSPACE.INITIAL) { screen = SCREENS.ALL_SETTINGS; } + if (!payloadParams) { payloadParams = {policyID}; } else { From 773f323e62ebb13ae702d38be41d540ad7b057ef Mon Sep 17 00:00:00 2001 From: Adam Grzybowski Date: Thu, 1 Feb 2024 16:40:58 +0100 Subject: [PATCH 07/15] add new line v2 --- src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts b/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts index 90f8873da4c8..16cdee23bd17 100644 --- a/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts +++ b/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts @@ -282,6 +282,7 @@ const getAdaptedStateFromPath: GetAdaptedStateFromPath = (path, options) => { const normalizedPath = !path.startsWith('/') ? `/${path}` : path; const pathWithoutPolicyID = getPathWithoutPolicyID(normalizedPath); const isAnonymous = isAnonymousUser(); + // Anonymous users don't have access to workspaces const policyID = isAnonymous ? undefined : extractPolicyIDFromPath(path); From 45ec5823bab01626ca406fa27e3a236720d66e44 Mon Sep 17 00:00:00 2001 From: Adam Grzybowski Date: Thu, 1 Feb 2024 16:42:28 +0100 Subject: [PATCH 08/15] add new line v3 --- src/libs/Navigation/linkingConfig/customGetPathFromState.ts | 1 + src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/libs/Navigation/linkingConfig/customGetPathFromState.ts b/src/libs/Navigation/linkingConfig/customGetPathFromState.ts index 32d81f272d4a..76ad0bb06bd0 100644 --- a/src/libs/Navigation/linkingConfig/customGetPathFromState.ts +++ b/src/libs/Navigation/linkingConfig/customGetPathFromState.ts @@ -16,6 +16,7 @@ const removePolicyIDParamFromState = (state: State) => { const customGetPathFromState: typeof getPathFromState = (state, options) => { const stateWithoutPolicyID = removePolicyIDParamFromState(state as State); + // For the Home page we should remove policyID from the params, const path = getPathFromState(stateWithoutPolicyID, options); const policyIDFromState = getPolicyIDFromState(state as State); diff --git a/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts b/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts index 16cdee23bd17..a15da286bd94 100644 --- a/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts +++ b/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts @@ -163,6 +163,7 @@ function getAdaptedState(state: PartialState metainfo.isFullScreenNavigatorMandatory = false; matchingRootRoute = createCentralPaneNavigator({name: SCREENS.REPORT}); } + // If the root route is type of FullScreenNavigator, the default bottom tab will be added. const matchingBottomTabRoute = getMatchingBottomTabRouteForState({routes: [matchingRootRoute]}); routes.push(createBottomTabNavigator(matchingBottomTabRoute, policyID)); From c88334e326c709ad54faace90d7e05cddc004ec7 Mon Sep 17 00:00:00 2001 From: Adam Grzybowski Date: Thu, 1 Feb 2024 17:17:05 +0100 Subject: [PATCH 09/15] improve comments --- .../createCustomBottomTabNavigator/index.tsx | 3 ++- .../createCustomFullScreenNavigator/index.tsx | 2 +- .../createCustomStackNavigator/CustomRouter.ts | 2 +- .../Navigation/AppNavigator/getPartialStateDiff.ts | 10 ++++++++++ src/libs/Navigation/dismissModal.ts | 2 +- src/libs/Navigation/dismissModalWithReport.ts | 2 +- src/libs/Navigation/getTopmostReportActionID.ts | 2 +- src/libs/Navigation/getTopmostReportId.ts | 2 +- src/libs/Navigation/linkTo.ts | 1 + 9 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/index.tsx b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/index.tsx index e6ecfccb47ee..bd32c6cab73c 100644 --- a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/index.tsx +++ b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/index.tsx @@ -18,7 +18,8 @@ type CustomNavigatorProps = DefaultNavigatorOptions): StackNavigationState { const routesToRender = [state.routes.at(-1)] as NavigationStateRoute[]; - // We need to render at least one HOME screen to make sure everything load properly. + // We need to render at least one HOME screen to make sure everything load properly. This may be not necessary after changing how IS_SIDEBAR_LOADED is handled. + // Currently this value will be switched only after the first HOME screen is rendered. if (routesToRender[0].name !== SCREENS.HOME) { const routeToRender = state.routes.find((route) => route.name === SCREENS.HOME); if (routeToRender) { diff --git a/src/libs/Navigation/AppNavigator/createCustomFullScreenNavigator/index.tsx b/src/libs/Navigation/AppNavigator/createCustomFullScreenNavigator/index.tsx index cfadd8bb3118..469a4ebfff68 100644 --- a/src/libs/Navigation/AppNavigator/createCustomFullScreenNavigator/index.tsx +++ b/src/libs/Navigation/AppNavigator/createCustomFullScreenNavigator/index.tsx @@ -60,7 +60,7 @@ function CustomFullScreenNavigator(props: FullScreenNavigatorProps) { if (!navigationRef.isReady()) { return; } - // We need to separetly reset state of this navigator to trigger getRehydratedState. + // We need to separately reset state of this navigator to trigger getRehydratedState. navigation.reset(navigation.getState()); // eslint-disable-next-line react-hooks/exhaustive-deps }, [isSmallScreenWidth]); diff --git a/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts b/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts index e69045822253..0efa34758beb 100644 --- a/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts +++ b/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts @@ -48,7 +48,7 @@ function compareAndAdaptState(state: StackNavigationState) { } // We will generate a template state and compare the current state with it. - // If there is a differences in the screens that should be visible under the overlay, we will add the screen from templateState to the current state. + // If there is a difference in the screens that should be visible under the overlay, we will add the screen from templateState to the current state. const pathFromCurrentState = getPathFromState(state, linkingConfig.config); const {adaptedState: templateState} = getAdaptedStateFromPath(pathFromCurrentState, linkingConfig.config); diff --git a/src/libs/Navigation/AppNavigator/getPartialStateDiff.ts b/src/libs/Navigation/AppNavigator/getPartialStateDiff.ts index a5cecf276e9e..a22185422a11 100644 --- a/src/libs/Navigation/AppNavigator/getPartialStateDiff.ts +++ b/src/libs/Navigation/AppNavigator/getPartialStateDiff.ts @@ -24,6 +24,16 @@ type GetPartialStateDiffReturnType = { /** * This function returns partial additive diff between the two states. + * + * Example: Let's start with state A on route /r/123. If the screen is wide we will have a HOME opened on bottom tab and REPORT on central pane. + * Now let's say we want to navigate to /workspace/345/overview. We will generate state B from this path. + * State B will have WORKSPACE_INITIAL on the bottom tab and WORKSPACE_OVERVIEW on the central pane. + * Now we will generate partial diff between state A and state B. The diff will tell us that we need to push WORKSPACE_INITIAL on the bottom tab and WORKSPACE_OVERVIEW on the central pane. + * + * Then we can generate actions from this diff and dispatch them to the linkTo function. + * + * It's named partial diff because we don't cover RHP and LHP navigators yet. In the future we can improve this function to handle all navigators to help us clean and simplify the linkTo function. + * * The partial diff has information which bottom tab, central pane and full screen screens we need to push to go from state to templateState. * @param state - Current state. * @param templateState - Desired state generated with getAdaptedStateFromPath. diff --git a/src/libs/Navigation/dismissModal.ts b/src/libs/Navigation/dismissModal.ts index c80b2545e865..484008d2e070 100644 --- a/src/libs/Navigation/dismissModal.ts +++ b/src/libs/Navigation/dismissModal.ts @@ -5,7 +5,7 @@ import NAVIGATORS from '@src/NAVIGATORS'; import SCREENS from '@src/SCREENS'; import type {RootStackParamList} from './types'; -// This function is in a separate file than Navigation.js to avoid cyclic dependency. +// This function is in a separate file than Navigation.ts to avoid cyclic dependency. /** * Dismisses the last modal stack if there is any diff --git a/src/libs/Navigation/dismissModalWithReport.ts b/src/libs/Navigation/dismissModalWithReport.ts index 4db9e30d61e9..b708819cdf9c 100644 --- a/src/libs/Navigation/dismissModalWithReport.ts +++ b/src/libs/Navigation/dismissModalWithReport.ts @@ -18,7 +18,7 @@ import linkingConfig from './linkingConfig'; import switchPolicyID from './switchPolicyID'; import type {RootStackParamList, StackNavigationAction, State} from './types'; -// This function is in a separate file than Navigation.js to avoid cyclic dependency. +// This function is in a separate file than Navigation.ts to avoid cyclic dependency. /** * Dismisses the last modal stack if there is any diff --git a/src/libs/Navigation/getTopmostReportActionID.ts b/src/libs/Navigation/getTopmostReportActionID.ts index f9931343b2eb..a1527a5f36b8 100644 --- a/src/libs/Navigation/getTopmostReportActionID.ts +++ b/src/libs/Navigation/getTopmostReportActionID.ts @@ -3,7 +3,7 @@ import NAVIGATORS from '@src/NAVIGATORS'; import SCREENS from '@src/SCREENS'; import type {RootStackParamList} from './types'; -// This function is in a separate file than Navigation.js to avoid cyclic dependency. +// This function is in a separate file than Navigation.ts to avoid cyclic dependency. /** * Find the last visited report screen in the navigation state and get the linked reportActionID of it. diff --git a/src/libs/Navigation/getTopmostReportId.ts b/src/libs/Navigation/getTopmostReportId.ts index 2c3b74e9f52f..4438cb273b84 100644 --- a/src/libs/Navigation/getTopmostReportId.ts +++ b/src/libs/Navigation/getTopmostReportId.ts @@ -3,7 +3,7 @@ import NAVIGATORS from '@src/NAVIGATORS'; import SCREENS from '@src/SCREENS'; import type {RootStackParamList} from './types'; -// This function is in a separate file than Navigation.js to avoid cyclic dependency. +// This function is in a separate file than Navigation.ts to avoid cyclic dependency. /** * Find the last visited report screen in the navigation state and get the id of it. diff --git a/src/libs/Navigation/linkTo.ts b/src/libs/Navigation/linkTo.ts index 39e85892da46..3767e1ea010c 100644 --- a/src/libs/Navigation/linkTo.ts +++ b/src/libs/Navigation/linkTo.ts @@ -210,6 +210,7 @@ export default function linkTo(navigation: NavigationContainerRef Date: Thu, 1 Feb 2024 17:29:58 +0100 Subject: [PATCH 10/15] fix type --- src/libs/Navigation/types.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 68d374763ae3..3c4cf17853f1 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -123,7 +123,6 @@ type SettingsNavigatorParamList = { [SCREENS.SETTINGS.PROFILE.STATUS_CLEAR_AFTER]: undefined; [SCREENS.SETTINGS.PROFILE.STATUS_CLEAR_AFTER_DATE]: undefined; [SCREENS.SETTINGS.PROFILE.STATUS_CLEAR_AFTER_TIME]: undefined; - [SCREENS.WORKSPACE.INITIAL]: undefined; [SCREENS.WORKSPACE.CURRENCY]: undefined; [SCREENS.WORKSPACE.NAME]: undefined; [SCREENS.WORKSPACE.RATE_AND_UNIT]: undefined; From 351c4992ea40bfcff224ea9e11b3bfc29ee79fe1 Mon Sep 17 00:00:00 2001 From: Adam Grzybowski Date: Thu, 1 Feb 2024 17:30:15 +0100 Subject: [PATCH 11/15] add small fixes --- src/libs/Navigation/AppNavigator/ModalStackNavigators.tsx | 1 + src/libs/Navigation/AppNavigator/PublicScreens.tsx | 2 +- src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts | 2 ++ .../createCustomBottomTabNavigator/BottomTabBar.tsx | 4 ++-- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/ModalStackNavigators.tsx b/src/libs/Navigation/AppNavigator/ModalStackNavigators.tsx index 030d6956dd28..4606f867c3fc 100644 --- a/src/libs/Navigation/AppNavigator/ModalStackNavigators.tsx +++ b/src/libs/Navigation/AppNavigator/ModalStackNavigators.tsx @@ -194,6 +194,7 @@ const AccountSettingsModalStackNavigator = createModalStackNavigator( }, (styles) => ({cardStyle: styles.navigationScreenCardStyle, headerShown: false}), ); + const WorkspaceSwitcherModalStackNavigator = createModalStackNavigator({ [SCREENS.WORKSPACE_SWITCHER.ROOT]: () => require('../../../pages/WorkspaceSwitcherPage').default as React.ComponentType, }); diff --git a/src/libs/Navigation/AppNavigator/PublicScreens.tsx b/src/libs/Navigation/AppNavigator/PublicScreens.tsx index 0324cc85dcfa..e8021c4d4998 100644 --- a/src/libs/Navigation/AppNavigator/PublicScreens.tsx +++ b/src/libs/Navigation/AppNavigator/PublicScreens.tsx @@ -17,7 +17,7 @@ const RootStack = createStackNavigator(); function PublicScreens() { return ( - {/* The structure for the HOME route have to be the same in public and auth screens. That's why we need to wrap the HOME screen with "fake" bottomTabNavigator. */} + {/* The structure for the HOME route have to be the same in public and auth screens. That's why the name for SignInPage is BOTTOM_TAB_NAVIGATOR. */} ; + /** Members of all the workspaces the user is member of */ policyMembers: OnyxCollection; /** Whether user is a new user */ @@ -25,6 +26,7 @@ type ReportScreenIDSetterComponentProps = { /** The report metadata */ reportMetadata: OnyxCollection; + /** The accountID of the current user */ accountID?: number; }; diff --git a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/BottomTabBar.tsx b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/BottomTabBar.tsx index 436ac998b698..2c7074028a34 100644 --- a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/BottomTabBar.tsx +++ b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/BottomTabBar.tsx @@ -34,7 +34,7 @@ function BottomTabBar() { return topmostBottomTabRoute?.name ?? SCREENS.HOME; }); - const showWorkspaceRedBrickRoad = checkIfWorkspaceSettingsTabHasRBR(activeWorkspaceID) && currentTabName === SCREENS.HOME; + const shouldShowWorkspaceRedBrickRoad = checkIfWorkspaceSettingsTabHasRBR(activeWorkspaceID) && currentTabName === SCREENS.HOME; const chatTabBrickRoad = currentTabName !== SCREENS.HOME ? getChatTabBrickRoad(activeWorkspaceID) : undefined; @@ -83,7 +83,7 @@ function BottomTabBar() { width={variables.iconBottomBar} height={variables.iconBottomBar} /> - {showWorkspaceRedBrickRoad && } + {shouldShowWorkspaceRedBrickRoad && } From b724a86decf5d00b65c18f60dcb930c1a374b72a Mon Sep 17 00:00:00 2001 From: Adam Grzybowski Date: Thu, 1 Feb 2024 18:09:35 +0100 Subject: [PATCH 12/15] add small fixes v2 --- src/ROUTES.ts | 2 ++ src/components/ContextMenuItem.tsx | 2 +- src/components/FeatureList.js | 8 ++++---- src/libs/Navigation/AppNavigator/PublicScreens.tsx | 2 +- .../createCustomBottomTabNavigator/BottomTabBar.tsx | 1 - .../createCustomFullScreenNavigator/index.tsx | 1 - .../createCustomStackNavigator/CustomRouter.ts | 2 ++ src/libs/Navigation/linkingConfig/config.ts | 4 ++-- 8 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 4f6d3a92765e..a84dc9c8f9ae 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -12,8 +12,10 @@ function getUrlWithBackToParam(url: TUrl, backTo?: string): } const ROUTES = { + // If the user opens this route, we'll redirect them to the path saved in the last visited path or to the home page if the last visited path is empty. ROOT: '', + // This route renders the list of reports. HOME: 'home', ALL_SETTINGS: 'all-settings', diff --git a/src/components/ContextMenuItem.tsx b/src/components/ContextMenuItem.tsx index b11e2a4aa943..d292f80d135e 100644 --- a/src/components/ContextMenuItem.tsx +++ b/src/components/ContextMenuItem.tsx @@ -39,7 +39,7 @@ type ContextMenuItemProps = { /** Whether the menu item is focused or not */ isFocused?: boolean; - /** Should limit width. */ + /** Whether the width should be limited */ shouldLimitWidth?: boolean; }; diff --git a/src/components/FeatureList.js b/src/components/FeatureList.js index 14b807aed85e..53d0d8f7c381 100644 --- a/src/components/FeatureList.js +++ b/src/components/FeatureList.js @@ -25,7 +25,7 @@ const propTypes = { ctaAccessibilityLabel: PropTypes.string, /** Action to call on cta button press */ - onCtaPress: PropTypes.func, + onCTAPress: PropTypes.func, /** A list of menuItems representing the feature list. */ menuItems: PropTypes.arrayOf(PropTypes.shape({...menuItemPropTypes, translationKey: PropTypes.string})).isRequired, @@ -48,13 +48,13 @@ const defaultProps = { ctaText: '', ctaAccessibilityLabel: '', subtitle: '', - onCtaPress: () => {}, + onCTAPress: () => {}, illustration: null, illustrationBackgroundColor: '', illustrationStyle: [], }; -function FeatureList({title, subtitle, ctaText, ctaAccessibilityLabel, onCtaPress, menuItems, illustration, illustrationStyle, illustrationBackgroundColor}) { +function FeatureList({title, subtitle, ctaText, ctaAccessibilityLabel, onCTAPress, menuItems, illustration, illustrationStyle, illustrationBackgroundColor}) { const styles = useThemeStyles(); const {translate} = useLocalize(); @@ -91,7 +91,7 @@ function FeatureList({title, subtitle, ctaText, ctaAccessibilityLabel, onCtaPres