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

fix: dropdown title does not follow search name #49446

Merged
merged 8 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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;
Copy link
Contributor

Choose a reason for hiding this comment

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

This change misses covering the case where the search name equals the query name which introduce this issue so we should get searchName based on search query

const policyIDFromSearchQuery = parsedQuery && SearchUtils.getPolicyIDFromSearchQuery(parsedQuery);
const isActiveCentralPaneRoute = activeCentralPaneRoute?.name === SCREENS.SEARCH.CENTRAL_PANE;
const queryJSON = isActiveCentralPaneRoute ? parsedQuery : undefined;
Expand All @@ -54,7 +55,10 @@ function SearchPageBottomTab() {
shouldDisplaySearch={false}
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(item.name, 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
2 changes: 1 addition & 1 deletion src/pages/Search/SearchTypeMenuNarrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function SearchTypeMenuNarrow({typeMenuItems, activeItemIndex, queryJSON, title,
};
});

if (title) {
if (title && !currentSavedSearch) {
items.push({
text: title,
onSelected: closeMenu,
Expand Down
Loading