Skip to content

Commit

Permalink
Merge pull request #49446 from dominictb/fix/49208
Browse files Browse the repository at this point in the history
fix: dropdown title does not follow search name
  • Loading branch information
luacmartins authored Sep 26, 2024
2 parents 235e46e + fa3f9f6 commit 4684d9a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const ROUTES = {

SEARCH_CENTRAL_PANE: {
route: 'search',
getRoute: ({query}: {query: SearchQueryString}) => `search?q=${encodeURIComponent(query)}` as const,
getRoute: ({query, name}: {query: SearchQueryString; name?: string}) => `search?q=${encodeURIComponent(query)}${name ? `&name=${name}` : ''}` as const,
},
SEARCH_SAVED_SEARCH_RENAME: {
route: 'search/saved-search/rename',
Expand Down
1 change: 1 addition & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type CentralPaneScreensParamList = {

[SCREENS.SEARCH.CENTRAL_PANE]: {
q: SearchQueryString;
name?: string;
};
[SCREENS.SETTINGS.SAVE_THE_WORLD]: undefined;
[SCREENS.SETTINGS.SUBSCRIPTION.ROOT]: undefined;
Expand Down
1 change: 1 addition & 0 deletions src/pages/Search/SavedSearchRenamePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function SavedSearchRenamePage({route}: {route: {params: {q: string; name: strin
Navigation.navigate(
ROUTES.SEARCH_CENTRAL_PANE.getRoute({
query: q,
name: newName,
}),
);
};
Expand Down
6 changes: 5 additions & 1 deletion src/pages/Search/SearchPageBottomTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function SearchPageBottomTab() {
const [selectionMode] = useOnyx(ONYXKEYS.MOBILE_SELECTION_MODE);
const searchParams = activeCentralPaneRoute?.params as AuthScreensParamList[typeof SCREENS.SEARCH.CENTRAL_PANE];
const parsedQuery = SearchUtils.buildSearchQueryJSON(searchParams?.q);
const searchName = searchParams?.name;
const policyIDFromSearchQuery = parsedQuery && SearchUtils.getPolicyIDFromSearchQuery(parsedQuery);
const isActiveCentralPaneRoute = activeCentralPaneRoute?.name === SCREENS.SEARCH.CENTRAL_PANE;
const queryJSON = isActiveCentralPaneRoute ? parsedQuery : undefined;
Expand Down Expand Up @@ -55,7 +56,10 @@ function SearchPageBottomTab() {
shouldDisplaySearchRouter={shouldUseNarrowLayout}
isCustomSearchQuery={shouldUseNarrowLayout && !SearchUtils.isCannedSearchQuery(queryJSON)}
/>
<SearchTypeMenu queryJSON={queryJSON} />
<SearchTypeMenu
queryJSON={queryJSON}
searchName={searchName}
/>
</>
) : (
<HeaderWithBackButton
Expand Down
7 changes: 4 additions & 3 deletions src/pages/Search/SearchTypeMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type SavedSearchMenuItem = MenuItemBaseProps & {

type SearchTypeMenuProps = {
queryJSON: SearchQueryJSON;
searchName?: string;
};

type SearchTypeMenuItem = {
Expand All @@ -52,7 +53,7 @@ type SearchTypeMenuItem = {
route?: Route;
};

function SearchTypeMenu({queryJSON}: SearchTypeMenuProps) {
function SearchTypeMenu({queryJSON, searchName}: SearchTypeMenuProps) {
const {type, hash} = queryJSON;
const styles = useThemeStyles();
const {shouldUseNarrowLayout} = useResponsiveLayout();
Expand Down Expand Up @@ -115,7 +116,7 @@ function SearchTypeMenu({queryJSON}: SearchTypeMenuProps) {
focused: Number(key) === hash,
onPress: () => {
SearchActions.clearAllFilters();
Navigation.navigate(ROUTES.SEARCH_CENTRAL_PANE.getRoute({query: item?.query ?? ''}));
Navigation.navigate(ROUTES.SEARCH_CENTRAL_PANE.getRoute({query: item?.query ?? '', name: item?.name}));
},
rightComponent: <SavedSearchItemThreeDotMenu menuItems={getOverflowMenu(title, Number(key), item.query)} />,
styles: [styles.alignItemsCenter],
Expand Down Expand Up @@ -202,7 +203,7 @@ function SearchTypeMenu({queryJSON}: SearchTypeMenuProps) {
const activeItemIndex = isCannedQuery ? typeMenuItems.findIndex((item) => item.type === type) : -1;

if (shouldUseNarrowLayout) {
const title = isCannedQuery ? undefined : SearchUtils.getSearchHeaderTitle(queryJSON, personalDetails, cardList, reports, taxRates);
const title = searchName ?? (isCannedQuery ? undefined : SearchUtils.getSearchHeaderTitle(queryJSON, personalDetails, cardList, reports, taxRates));

return (
<SearchTypeMenuNarrow
Expand Down

0 comments on commit 4684d9a

Please sign in to comment.