Skip to content

Commit

Permalink
Cleanup display SearchButton component on all Pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Kicu committed Sep 20, 2024
1 parent c2cb908 commit d11bfe1
Show file tree
Hide file tree
Showing 24 changed files with 126 additions and 150 deletions.
3 changes: 3 additions & 0 deletions src/components/HeaderWithBackButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import PinButton from '@components/PinButton';
import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback';
import SearchButton from '@components/Search/SearchRouter/SearchButton';
import ThreeDotsMenu from '@components/ThreeDotsMenu';
import Tooltip from '@components/Tooltip';
import useKeyboardState from '@hooks/useKeyboardState';
Expand Down Expand Up @@ -60,6 +61,7 @@ function HeaderWithBackButton({
shouldOverlayDots = false,
shouldOverlay = false,
shouldNavigateToTopMostReport = false,
shouldDisplaySearchRouter = false,
progressBarPercentage,
style,
}: HeaderWithBackButtonProps) {
Expand Down Expand Up @@ -261,6 +263,7 @@ function HeaderWithBackButton({
</PressableWithoutFeedback>
</Tooltip>
)}
{shouldDisplaySearchRouter && <SearchButton />}
</View>
</View>
</View>
Expand Down
3 changes: 3 additions & 0 deletions src/components/HeaderWithBackButton/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ type HeaderWithBackButtonProps = Partial<ChildrenProps> & {
/** Whether we should overlay the 3 dots menu */
shouldOverlayDots?: boolean;

/** Whether we should display button that opens new SearchRouter */
shouldDisplaySearchRouter?: boolean;

/** 0 - 100 number indicating current progress of the progress bar */
progressBarPercentage?: number;

Expand Down
1 change: 1 addition & 0 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
report={moneyRequestReport}
policy={policy}
shouldShowBackButton={shouldUseNarrowLayout}
shouldDisplaySearchRouter
onBackButtonPress={onBackButtonPress}
// Shows border if no buttons or banners are showing below the header
shouldShowBorderBottom={!isMoreContentShown}
Expand Down
1 change: 1 addition & 0 deletions src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, shouldUseNarrow
policy={policy}
shouldShowBackButton={shouldUseNarrowLayout}
onBackButtonPress={onBackButtonPress}
shouldDisplaySearchRouter
>
{hasAllPendingRTERViolations && !shouldUseNarrowLayout && (
<Button
Expand Down
44 changes: 25 additions & 19 deletions src/components/Search/SearchPageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import type {SearchDataTypes, SearchReport} from '@src/types/onyx/SearchResults'
import type DeepValueOf from '@src/types/utils/DeepValueOf';
import type IconAsset from '@src/types/utils/IconAsset';
import {useSearchContext} from './SearchContext';
import SearchButton from './SearchRouter/SearchButton';
import type {SearchQueryJSON} from './types';

type HeaderWrapperProps = Pick<HeaderWithBackButtonProps, 'title' | 'subtitle' | 'icon' | 'children'> & {
Expand Down Expand Up @@ -295,36 +296,41 @@ function SearchPageHeader({queryJSON, hash, onSelectDeleteOption, setOfflineModa
}

const onPress = () => {
const values = SearchUtils.getFiltersFormValues(queryJSON);
const values = SearchUtils.buildFilterFormValuesFromQuery(queryJSON);
SearchActions.updateAdvancedFilters(values);
Navigation.navigate(ROUTES.SEARCH_ADVANCED_FILTERS);
};

const displaySearchRouter = SearchUtils.isCannedSearchQuery(queryJSON);

return (
<HeaderWrapper
title={headerTitle}
subtitle={headerSubtitle}
icon={headerIcon}
subtitleStyles={subtitleStyles}
>
{headerButtonsOptions.length > 0 ? (
<ButtonWithDropdownMenu
onPress={() => null}
shouldAlwaysShowDropdownMenu
pressOnEnter
buttonSize={CONST.DROPDOWN_BUTTON_SIZE.MEDIUM}
customText={translate('workspace.common.selected', {selectedNumber: selectedTransactionsKeys.length})}
options={headerButtonsOptions}
isSplitButton={false}
shouldUseStyleUtilityForAnchorPosition
/>
) : (
<Button
text={translate('search.filtersHeader')}
icon={Expensicons.Filters}
onPress={onPress}
/>
)}
<>
{headerButtonsOptions.length > 0 ? (
<ButtonWithDropdownMenu
onPress={() => null}
shouldAlwaysShowDropdownMenu
pressOnEnter
buttonSize={CONST.DROPDOWN_BUTTON_SIZE.MEDIUM}
customText={translate('workspace.common.selected', {selectedNumber: selectedTransactionsKeys.length})}
options={headerButtonsOptions}
isSplitButton={false}
shouldUseStyleUtilityForAnchorPosition
/>
) : (
<Button
text={translate('search.filtersHeader')}
icon={Expensicons.Filters}
onPress={onPress}
/>
)}
{displaySearchRouter && <SearchButton />}
</>
</HeaderWrapper>
);
}
Expand Down
6 changes: 4 additions & 2 deletions src/components/Search/SearchRouter/SearchButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import {PressableWithoutFeedback} from '@components/Pressable';
import useLocalize from '@hooks/useLocalize';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import Permissions from '@libs/Permissions';
Expand All @@ -10,6 +11,7 @@ import {useSearchRouterContext} from './SearchRouterContext';
function SearchButton() {
const styles = useThemeStyles();
const theme = useTheme();
const {translate} = useLocalize();
const {openSearchRouter} = useSearchRouterContext();

if (!Permissions.canUseNewSearchRouter()) {
Expand All @@ -18,8 +20,8 @@ function SearchButton() {

return (
<PressableWithoutFeedback
accessibilityLabel=""
style={[styles.flexRow, styles.mr2, styles.touchableButtonImage]}
accessibilityLabel={translate('common.search')}
style={[styles.flexRow, styles.touchableButtonImage]}
onPress={() => {
openSearchRouter();
}}
Expand Down
21 changes: 1 addition & 20 deletions src/components/Search/SearchRouter/SearchRouter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {useNavigationState} from '@react-navigation/native';
import debounce from 'lodash/debounce';
import React, {useCallback, useState} from 'react';
import {View} from 'react-native';
Expand All @@ -10,37 +9,20 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import * as SearchUtils from '@libs/SearchUtils';
import Navigation from '@navigation/Navigation';
import type {AuthScreensParamList, NavigationStateRoute} from '@navigation/types';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import {useSearchRouterContext} from './SearchRouterContext';
import SearchRouterInput from './SearchRouterInput';

const SEARCH_DEBOUNCE_DELAY = 200;

function getCurrentSearchQuery(route?: NavigationStateRoute) {
if (route?.name !== SCREENS.SEARCH.CENTRAL_PANE) {
return;
}

const query = (route?.params as AuthScreensParamList[typeof SCREENS.SEARCH.CENTRAL_PANE]).q;
return SearchUtils.buildSearchQueryJSON(query);
}

function SearchRouter() {
const styles = useThemeStyles();

const {isSmallScreenWidth} = useResponsiveLayout();
const {isSearchRouterDisplayed, closeSearchRouter} = useSearchRouterContext();
const lastRoute = useNavigationState((state) => state.routes.at(-1));

// If we open SearchRouter on a `/search` page, then we prefill input with the existing Search query
const existingSearchQuery = getCurrentSearchQuery(lastRoute);
const initialQuery = existingSearchQuery ? SearchUtils.getSearchRouterInputText(existingSearchQuery) : undefined;
const initialQueryJSON = initialQuery ? SearchUtils.buildSearchQueryJSON(initialQuery) : undefined;

const [userSearchQuery, setUserSearchQuery] = useState<SearchQueryJSON | undefined>(initialQueryJSON);
const [userSearchQuery, setUserSearchQuery] = useState<SearchQueryJSON | undefined>(undefined);

const clearUserQuery = () => {
setUserSearchQuery(undefined);
Expand Down Expand Up @@ -96,7 +78,6 @@ function SearchRouter() {
<FocusTrapForModal active={isSearchRouterDisplayed}>
<View style={[styles.flex1, styles.p3]}>
<SearchRouterInput
initialValue={initialQuery}
isFullWidth={isFullWidth}
onChange={onSearchChange}
onSubmit={onSearchSubmit}
Expand Down
5 changes: 2 additions & 3 deletions src/components/Search/SearchRouter/SearchRouterInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import variables from '@styles/variables';
import CONST from '@src/CONST';

type SearchRouterInputProps = {
initialValue?: string;
isFullWidth: boolean;
onChange: (searchTerm: string) => void;
onSubmit: () => void;
};

function SearchRouterInput({initialValue = '', isFullWidth, onChange, onSubmit}: SearchRouterInputProps) {
function SearchRouterInput({isFullWidth, onChange, onSubmit}: SearchRouterInputProps) {
const styles = useThemeStyles();

const [value, setValue] = useState(initialValue);
const [value, setValue] = useState('');

const onChangeText = (text: string) => {
setValue(text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';

type TopBarProps = {breadcrumbLabel: string; activeWorkspaceID?: string; shouldDisplaySearch?: boolean; isCustomSearchQuery?: boolean};
type TopBarProps = {breadcrumbLabel: string; activeWorkspaceID?: string; shouldDisplaySearch?: boolean; isCustomSearchQuery?: boolean; shouldDisplaySearchRouter?: boolean};

function TopBar({breadcrumbLabel, activeWorkspaceID, shouldDisplaySearch = true, isCustomSearchQuery = false}: TopBarProps) {
function TopBar({breadcrumbLabel, activeWorkspaceID, shouldDisplaySearch = true, isCustomSearchQuery = false, shouldDisplaySearchRouter = false}: TopBarProps) {
const styles = useThemeStyles();
const theme = useTheme();
const {translate} = useLocalize();
Expand Down Expand Up @@ -74,8 +74,7 @@ function TopBar({breadcrumbLabel, activeWorkspaceID, shouldDisplaySearch = true,
<Text style={[styles.textBlue]}>{translate('common.cancel')}</Text>
</PressableWithoutFeedback>
)}
{/* This is only temporary for development and will be cleaned up in: https://github.com/Expensify/App/issues/49122 */}
<SearchButton />
{shouldDisplaySearchRouter && <SearchButton />}
{displaySearch && (
<Tooltip text={translate('common.find')}>
<PressableWithoutFeedback
Expand Down
Loading

0 comments on commit d11bfe1

Please sign in to comment.