Skip to content

fix: Tapping an item from recent list directs blank page #58878

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

Merged
merged 4 commits into from
Apr 1, 2025
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
23 changes: 12 additions & 11 deletions src/components/Search/SearchRouter/SearchRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import type Report from '@src/types/onyx/Report';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
import KeyboardUtils from '@src/utils/keyboard';
import {getQueryWithSubstitutions} from './getQueryWithSubstitutions';
import type {SubstitutionMap} from './getQueryWithSubstitutions';
import {getUpdatedSubstitutionsMap} from './getUpdatedSubstitutionsMap';
Expand Down Expand Up @@ -74,9 +73,10 @@ function getContextualSearchQuery(item: SearchQueryItem) {
type SearchRouterProps = {
onRouterClose: () => void;
shouldHideInputCaret?: TextInputProps['caretHidden'];
isSearchRouterDisplayed?: boolean;
};

function SearchRouter({onRouterClose, shouldHideInputCaret}: SearchRouterProps, ref: React.Ref<View>) {
function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDisplayed}: SearchRouterProps, ref: React.Ref<View>) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const [, recentSearchesMetadata] = useOnyx(ONYXKEYS.RECENT_SEARCHES);
Expand Down Expand Up @@ -113,6 +113,10 @@ function SearchRouter({onRouterClose, shouldHideInputCaret}: SearchRouterProps,
return undefined;
}

if (!isSearchRouterDisplayed) {
return undefined;
}

const reportForContextualSearch = recentReports.find((option) => option.reportID === contextualReportID);
if (!reportForContextualSearch) {
return undefined;
Expand Down Expand Up @@ -159,7 +163,7 @@ function SearchRouter({onRouterClose, shouldHideInputCaret}: SearchRouterProps,
},
];
},
[contextualReportID, styles.activeComponentBG, textInputValue, translate],
[contextualReportID, styles.activeComponentBG, textInputValue, translate, isSearchRouterDisplayed],
);

const searchQueryItem = textInputValue
Expand Down Expand Up @@ -270,14 +274,11 @@ function SearchRouter({onRouterClose, shouldHideInputCaret}: SearchRouterProps,
}
} else {
onRouterClose();

KeyboardUtils.dismiss().then(() => {
if (item?.reportID) {
Navigation.navigateToReportWithPolicyCheck({reportID: item?.reportID});
} else if ('login' in item) {
navigateToAndOpenReport(item.login ? [item.login] : [], false);
}
});
if (item?.reportID) {
Navigation.navigateToReportWithPolicyCheck({reportID: item?.reportID});
} else if ('login' in item) {
navigateToAndOpenReport(item.login ? [item.login] : [], false);
}
}
},
[autocompleteSubstitutions, onRouterClose, onSearchQueryChange, submitSearch, textInputValue],
Expand Down
15 changes: 7 additions & 8 deletions src/components/Search/SearchRouter/SearchRouterModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@ function SearchRouterModal() {
behavior="padding"
style={[styles.flex1, {maxHeight: windowHeight}]}
>
{isSearchRouterDisplayed && (
<FocusTrapForModal active={isSearchRouterDisplayed}>
<SearchRouter
onRouterClose={closeSearchRouter}
shouldHideInputCaret={shouldHideInputCaret}
/>
</FocusTrapForModal>
)}
<FocusTrapForModal active={isSearchRouterDisplayed}>
<SearchRouter
onRouterClose={closeSearchRouter}
shouldHideInputCaret={shouldHideInputCaret}
isSearchRouterDisplayed={isSearchRouterDisplayed}
/>
</FocusTrapForModal>
</KeyboardAvoidingView>
</Modal>
);
Expand Down
Loading