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

[Search v1] Add ReportScreen to RHP #40570

Merged
merged 21 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
5 changes: 5 additions & 0 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ const ROUTES = {
getRoute: (query: string) => `search/${query}` as const,
},

SEARCH_REPORT: {
route: '/search/:query/view/:reportID',
getRoute: (query: string, reportID: string) => `search/${query}/view/${reportID}` as const,
},

// This is a utility route used to go to the user's concierge chat, or the sign-in page if the user's not authenticated
CONCIERGE: 'concierge',
FLAG_COMMENT: {
Expand Down
2 changes: 2 additions & 0 deletions src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const SCREENS = {
WORKSPACES_CENTRAL_PANE: 'WorkspacesCentralPane',
SEARCH: {
CENTRAL_PANE: 'Search_Central_Pane',
REPORT: 'Search_Report',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Search_Report' value is used two times here

BOTTOM_TAB: 'Search_Bottom_Tab',
},
SETTINGS: {
Expand Down Expand Up @@ -131,6 +132,7 @@ const SCREENS = {
ROOM_INVITE: 'RoomInvite',
REFERRAL: 'Referral',
PROCESS_MONEY_REQUEST_HOLD: 'ProcessMoneyRequestHold',
SEARCH_REPORT: 'Search_Report',
},
ONBOARDING_MODAL: {
ONBOARDING: 'Onboarding',
Expand Down
23 changes: 13 additions & 10 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,16 @@ type MoneyReportHeaderProps = MoneyReportHeaderOnyxProps & {
/** The reportID of the transaction thread report associated with this current report, if any */
// eslint-disable-next-line react/no-unused-prop-types
transactionThreadReportID?: string | null;

/** Whether we should display the header as in narrow layout */
isNarrowLayout?: boolean;
};

function MoneyReportHeader({session, policy, chatReport, nextStep, report: moneyRequestReport, transactionThreadReport, reportActions}: MoneyReportHeaderProps) {
function MoneyReportHeader({session, policy, chatReport, nextStep, report: moneyRequestReport, transactionThreadReport, reportActions, isNarrowLayout = false}: MoneyReportHeaderProps) {
const styles = useThemeStyles();
const [isDeleteRequestModalVisible, setIsDeleteRequestModalVisible] = useState(false);
const {translate} = useLocalize();
const {windowWidth, isSmallScreenWidth} = useWindowDimensions();
const {windowWidth} = useWindowDimensions();
const {reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(moneyRequestReport);
const isSettled = ReportUtils.isSettled(moneyRequestReport.reportID);
const requestParentReportAction = useMemo(() => {
Expand Down Expand Up @@ -108,7 +111,7 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money
const formattedAmount = CurrencyUtils.convertToDisplayString(reimbursableSpend, moneyRequestReport.currency);
const [nonHeldAmount, fullAmount] = ReportUtils.getNonHeldAndFullAmount(moneyRequestReport, policy);
const displayedAmount = ReportUtils.hasHeldExpenses(moneyRequestReport.reportID) && canAllowSettlement ? nonHeldAmount : formattedAmount;
const isMoreContentShown = shouldShowNextStep || (shouldShowAnyButton && isSmallScreenWidth);
const isMoreContentShown = shouldShowNextStep || (shouldShowAnyButton && isNarrowLayout);

const confirmPayment = (type?: PaymentMethodType | undefined) => {
if (!type) {
Expand Down Expand Up @@ -185,15 +188,15 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money
shouldShowPinButton={false}
report={moneyRequestReport}
policy={policy}
shouldShowBackButton={isSmallScreenWidth}
shouldShowBackButton={isNarrowLayout}
onBackButtonPress={() => Navigation.goBack(undefined, false, true)}
// Shows border if no buttons or next steps are showing below the header
shouldShowBorderBottom={!(shouldShowAnyButton && isSmallScreenWidth) && !(shouldShowNextStep && !isSmallScreenWidth)}
shouldShowBorderBottom={!(shouldShowAnyButton && isNarrowLayout) && !(shouldShowNextStep && !isNarrowLayout)}
shouldShowThreeDotsButton
threeDotsMenuItems={threeDotsMenuItems}
threeDotsAnchorPosition={styles.threeDotsPopoverOffsetNoCloseButton(windowWidth)}
>
{shouldShowSettlementButton && !isSmallScreenWidth && (
{shouldShowSettlementButton && !isNarrowLayout && (
<View style={styles.pv2}>
<SettlementButton
currency={moneyRequestReport.currency}
Expand All @@ -213,7 +216,7 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money
/>
</View>
)}
{shouldShowSubmitButton && !isSmallScreenWidth && (
{shouldShowSubmitButton && !isNarrowLayout && (
<View style={styles.pv2}>
<Button
medium
Expand All @@ -227,7 +230,7 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money
)}
</HeaderWithBackButton>
<View style={isMoreContentShown ? [styles.dFlex, styles.flexColumn, styles.borderBottom] : []}>
{shouldShowSettlementButton && isSmallScreenWidth && (
{shouldShowSettlementButton && isNarrowLayout && (
<View style={[styles.ph5, styles.pb2]}>
<SettlementButton
currency={moneyRequestReport.currency}
Expand All @@ -246,7 +249,7 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money
/>
</View>
)}
{shouldShowSubmitButton && isSmallScreenWidth && (
{shouldShowSubmitButton && isNarrowLayout && (
<View style={[styles.ph5, styles.pb2]}>
<Button
medium
Expand All @@ -269,7 +272,7 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money
nonHeldAmount={!ReportUtils.hasOnlyHeldExpenses(moneyRequestReport.reportID) ? nonHeldAmount : undefined}
requestType={requestType}
fullAmount={fullAmount}
isSmallScreenWidth={isSmallScreenWidth}
isSmallScreenWidth={isNarrowLayout}
onClose={() => setIsHoldMenuVisible(false)}
isVisible={isHoldMenuVisible}
paymentType={paymentType}
Expand Down
15 changes: 9 additions & 6 deletions src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ type MoneyRequestHeaderProps = MoneyRequestHeaderOnyxProps & {

/** The report action the transaction is tied to from the parent report */
parentReportAction: OnyxEntry<ReportAction>;

/** Whether we should display the header as in narrow layout */
isNarrowLayout?: boolean;
};

function MoneyRequestHeader({session, parentReport, report, parentReportAction, transaction, shownHoldUseExplanation = false, policy}: MoneyRequestHeaderProps) {
function MoneyRequestHeader({session, parentReport, report, parentReportAction, transaction, shownHoldUseExplanation = false, policy, isNarrowLayout = false}: MoneyRequestHeaderProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const [isDeleteModalVisible, setIsDeleteModalVisible] = useState(false);
Expand All @@ -61,7 +64,7 @@ function MoneyRequestHeader({session, parentReport, report, parentReportAction,
const isSettled = ReportUtils.isSettled(moneyRequestReport?.reportID);
const isApproved = ReportUtils.isReportApproved(moneyRequestReport);
const isOnHold = TransactionUtils.isOnHold(transaction);
const {isSmallScreenWidth, windowWidth} = useWindowDimensions();
const {windowWidth} = useWindowDimensions();

// Only the requestor can take delete the expense, admins can only edit it.
const isActionOwner = typeof parentReportAction?.actorAccountID === 'number' && typeof session?.accountID === 'number' && parentReportAction.actorAccountID === session?.accountID;
Expand Down Expand Up @@ -144,14 +147,14 @@ function MoneyRequestHeader({session, parentReport, report, parentReportAction,
return;
}

if (isSmallScreenWidth) {
if (isNarrowLayout) {
if (Navigation.getActiveRoute().slice(1) === ROUTES.PROCESS_MONEY_REQUEST_HOLD) {
Navigation.goBack();
}
} else {
Navigation.navigate(ROUTES.PROCESS_MONEY_REQUEST_HOLD);
}
}, [isSmallScreenWidth, shouldShowHoldMenu]);
}, [isNarrowLayout, shouldShowHoldMenu]);

const handleHoldRequestClose = () => {
IOU.setShownHoldUseExplanation();
Expand Down Expand Up @@ -180,7 +183,7 @@ function MoneyRequestHeader({session, parentReport, report, parentReportAction,
ownerAccountID: parentReport?.ownerAccountID,
}}
policy={policy}
shouldShowBackButton={isSmallScreenWidth}
shouldShowBackButton={isNarrowLayout}
onBackButtonPress={() => Navigation.goBack(undefined, false, true)}
/>
{isPending && (
Expand Down Expand Up @@ -209,7 +212,7 @@ function MoneyRequestHeader({session, parentReport, report, parentReportAction,
cancelText={translate('common.cancel')}
danger
/>
{isSmallScreenWidth && shouldShowHoldMenu && (
{isNarrowLayout && shouldShowHoldMenu && (
<ProcessMoneyRequestHoldMenu
onClose={handleHoldRequestClose}
onConfirm={handleHoldRequestClose}
Expand Down
12 changes: 12 additions & 0 deletions src/hooks/useIsNarrowLayout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {useNavigationState} from '@react-navigation/native';
import getTopmostRouteName from '@libs/Navigation/getTopmostRouteName';
import SCREENS from '@src/SCREENS';
import useWindowDimensions from './useWindowDimensions';

// This hook checks whether narrow layout styles should be applied to the screen.
// SCREENS.SEARCH.REPORT is the screen displaying the chat in RHP, this page should be styled like a page displayed on a small screen.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nitpicky but this style of comment is nicer for long comments 😅

/** .........
*/

export default function useIsNarrowLayout() {
const {isSmallScreenWidth} = useWindowDimensions();
const activeRoute = useNavigationState(getTopmostRouteName);
return activeRoute === SCREENS.SEARCH.REPORT || isSmallScreenWidth;
}
6 changes: 3 additions & 3 deletions src/hooks/useThumbnailDimensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {useMemo} from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import type {DimensionValue} from 'react-native/Libraries/StyleSheet/StyleSheetTypes';
import CONST from '@src/CONST';
import useWindowDimensions from './useWindowDimensions';
import useIsNarrowLayout from './useIsNarrowLayout';

type ThumbnailDimensions = {
thumbnailDimensionsStyles: {
Expand All @@ -13,8 +13,8 @@ type ThumbnailDimensions = {
};

export default function useThumbnailDimensions(width: number, height: number): ThumbnailDimensions {
const {isSmallScreenWidth} = useWindowDimensions();
const fixedDimension = isSmallScreenWidth ? CONST.THUMBNAIL_IMAGE.SMALL_SCREEN.SIZE : CONST.THUMBNAIL_IMAGE.WIDE_SCREEN.SIZE;
const isNarrowLayout = useIsNarrowLayout();
const fixedDimension = isNarrowLayout ? CONST.THUMBNAIL_IMAGE.SMALL_SCREEN.SIZE : CONST.THUMBNAIL_IMAGE.WIDE_SCREEN.SIZE;
const thumbnailDimensionsStyles = useMemo(() => {
if (!width || !height) {
return {width: fixedDimension, aspectRatio: CONST.THUMBNAIL_IMAGE.NAN_ASPECT_RATIO};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
ReportSettingsNavigatorParamList,
RoomInviteNavigatorParamList,
RoomMembersNavigatorParamList,
SearchReportParamList,
SettingsNavigatorParamList,
SignInNavigatorParamList,
SplitDetailsNavigatorParamList,
Expand Down Expand Up @@ -333,7 +334,6 @@ const PrivateNotesModalStackNavigator = createModalStackNavigator<PrivateNotesNa
const SignInModalStackNavigator = createModalStackNavigator<SignInNavigatorParamList>({
[SCREENS.SIGN_IN_ROOT]: () => require('../../../../pages/signin/SignInModal').default as React.ComponentType,
});

const ReferralModalStackNavigator = createModalStackNavigator<ReferralDetailsNavigatorParamList>({
[SCREENS.REFERRAL_DETAILS]: () => require('../../../../pages/ReferralDetailsPage').default as React.ComponentType,
});
Expand All @@ -342,6 +342,10 @@ const ProcessMoneyRequestHoldStackNavigator = createModalStackNavigator({
[SCREENS.PROCESS_MONEY_REQUEST_HOLD_ROOT]: () => require('../../../../pages/ProcessMoneyRequestHoldPage').default as React.ComponentType,
});

const SearchReportModalStackNavigator = createModalStackNavigator<SearchReportParamList>({
[SCREENS.SEARCH.REPORT]: () => require('../../../../pages/home/ReportScreen').default as React.ComponentType,
});

export {
AddPersonalBankAccountModalStackNavigator,
DetailsModalStackNavigator,
Expand Down Expand Up @@ -372,4 +376,5 @@ export {
WalletStatementStackNavigator,
ProcessMoneyRequestHoldStackNavigator,
WorkspaceSettingsModalStackNavigator,
SearchReportModalStackNavigator,
};
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ function RightModalNavigator({navigation}: RightModalNavigatorProps) {
name="ProcessMoneyRequestHold"
component={ModalStackNavigators.ProcessMoneyRequestHoldStackNavigator}
/>
<Stack.Screen
name={SCREENS.RIGHT_MODAL.SEARCH_REPORT}
component={ModalStackNavigators.SearchReportModalStackNavigator}
/>
</Stack.Navigator>
</View>
</NoDropZone>
Expand Down
12 changes: 12 additions & 0 deletions src/libs/Navigation/getTopmostRouteName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type {NavigationState, PartialState} from '@react-navigation/native';

// Get the name of topmost route in the navigation stack.
function getTopmostRouteName(state: NavigationState | PartialState<NavigationState>): string | undefined {
if (!state) {
return;
}

return state.routes.at(-1)?.name;
}

export default getTopmostRouteName;
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const CENTRAL_PANE_TO_RHP_MAPPING: Partial<Record<CentralPaneName, string[]>> =
[SCREENS.SETTINGS.ABOUT]: [SCREENS.SETTINGS.APP_DOWNLOAD_LINKS],
[SCREENS.SETTINGS.SAVE_THE_WORLD]: [SCREENS.I_KNOW_A_TEACHER, SCREENS.INTRO_SCHOOL_PRINCIPAL, SCREENS.I_AM_A_TEACHER],
[SCREENS.SETTINGS.TROUBLESHOOT]: [SCREENS.SETTINGS.CONSOLE],
[SCREENS.SEARCH.CENTRAL_PANE]: [SCREENS.SEARCH.REPORT],
};

export default CENTRAL_PANE_TO_RHP_MAPPING;
5 changes: 5 additions & 0 deletions src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,11 @@ const config: LinkingOptions<RootStackParamList>['config'] = {
[SCREENS.PROCESS_MONEY_REQUEST_HOLD_ROOT]: ROUTES.PROCESS_MONEY_REQUEST_HOLD,
},
},
[SCREENS.RIGHT_MODAL.SEARCH_REPORT]: {
screens: {
[SCREENS.SEARCH.REPORT]: ROUTES.SEARCH_REPORT.route,
},
},
},
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ function getAdaptedState(state: PartialState<NavigationState<RootStackParamList>
if (matchingRootRoute?.name === NAVIGATORS.FULL_SCREEN_NAVIGATOR) {
routes.push(createCentralPaneNavigator({name: SCREENS.SETTINGS.WORKSPACES}));
}
if (matchingRootRoute?.state?.routes[0]?.name === SCREENS.SEARCH.CENTRAL_PANE) {
const centralPaneRoute = matchingRootRoute?.state?.routes[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the logic responsible for excluding params for this screen should be in the getMatchingCentralPaneRouteForState? Instead of removing params we would simply not include them in the first place

delete (centralPaneRoute?.params as Record<string, string | undefined>)?.reportID;
}
if (matchingRootRoute && (!isNarrowLayout || !isRHPScreenOpenedFromLHN)) {
routes.push(matchingRootRoute);
}
Expand Down
9 changes: 9 additions & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ type RightModalNavigatorParamList = {
[SCREENS.RIGHT_MODAL.PROCESS_MONEY_REQUEST_HOLD]: NavigatorScreenParams<ProcessMoneyRequestHoldNavigatorParamList>;
[SCREENS.RIGHT_MODAL.REFERRAL]: NavigatorScreenParams<ReferralDetailsNavigatorParamList>;
[SCREENS.RIGHT_MODAL.PRIVATE_NOTES]: NavigatorScreenParams<PrivateNotesNavigatorParamList>;
[SCREENS.RIGHT_MODAL.SEARCH_REPORT]: NavigatorScreenParams<SearchReportParamList>;
};

type WorkspacesCentralPaneNavigatorParamList = {
Expand Down Expand Up @@ -826,6 +827,13 @@ type AuthScreensParamList = SharedScreensParamList & {
};
};

type SearchReportParamList = {
[SCREENS.SEARCH.REPORT]: {
query: string;
reportID: string;
};
};

type RootStackParamList = PublicScreensParamList & AuthScreensParamList & ChatFinderNavigatorParamList;

type BottomTabName = keyof BottomTabNavigatorParamList;
Expand Down Expand Up @@ -891,4 +899,5 @@ export type {
WelcomeVideoModalNavigatorParamList,
WorkspaceSwitcherNavigatorParamList,
WorkspacesCentralPaneNavigatorParamList,
SearchReportParamList,
};
2 changes: 1 addition & 1 deletion src/libs/actions/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ function deleteTask(report: OnyxEntry<OnyxTypes.Report>) {
* Closes the current open task modal and clears out the task info from the store.
*/
function dismissModalAndClearOutTaskInfo() {
Navigation.dismissModal();
Navigation.goBack();
Copy link
Contributor

@hoangzinh hoangzinh Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's the same. Could you elaborate on why did you make a change here to ensure it won't cause any regression bugs?

clearOutTaskInfo();
}

Expand Down
Loading
Loading