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

Use SearchRouter everywhere and drop Chat finder #49984

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ const CONST = {
},
TIMING: {
CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION: 'calc_most_recent_last_modified_action',
CHAT_FINDER_RENDER: 'search_render',
SEARCH_ROUTER_OPEN: 'search_router_render',
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
SEARCH_ROUTER_OPEN: 'search_router_render',
SEARCH_ROUTER_RENDER: 'search_router_render',

CHAT_RENDER: 'chat_render',
OPEN_REPORT: 'open_report',
HOMEPAGE_INITIAL_RENDER: 'homepage_initial_render',
Expand Down
1 change: 0 additions & 1 deletion src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ const ROUTES = {
route: 'flag/:reportID/:reportActionID',
getRoute: (reportID: string, reportActionID: string, backTo?: string) => getUrlWithBackToParam(`flag/${reportID}/${reportActionID}` as const, backTo),
},
CHAT_FINDER: 'chat-finder',
PROFILE: {
route: 'a/:accountID',
getRoute: (accountID?: string | number, backTo?: string, login?: string) => {
Expand Down
1 change: 0 additions & 1 deletion src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ const SCREENS = {
ROOT: 'SaveTheWorld_Root',
},
LEFT_MODAL: {
CHAT_FINDER: 'ChatFinder',
WORKSPACE_SWITCHER: 'WorkspaceSwitcher',
},
RIGHT_MODAL: {
Expand Down
16 changes: 9 additions & 7 deletions src/components/Search/SearchRouter/SearchButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ 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';
import Performance from '@libs/Performance';
import * as Session from '@userActions/Session';
import Timing from '@userActions/Timing';
import CONST from '@src/CONST';
import {useSearchRouterContext} from './SearchRouterContext';

function SearchButton() {
Expand All @@ -14,17 +17,16 @@ function SearchButton() {
const {translate} = useLocalize();
const {openSearchRouter} = useSearchRouterContext();

if (!Permissions.canUseNewSearchRouter()) {
return;
}

return (
<PressableWithoutFeedback
accessibilityLabel={translate('common.search')}
style={[styles.flexRow, styles.touchableButtonImage]}
onPress={() => {
onPress={Session.checkIfActionIsAllowed(() => {
Timing.start(CONST.TIMING.SEARCH_ROUTER_OPEN);
Performance.markStart(CONST.TIMING.SEARCH_ROUTER_OPEN);

openSearchRouter();
}}
})}
>
<Icon
src={Expensicons.MagnifyingGlass}
Expand Down
37 changes: 18 additions & 19 deletions src/components/Search/SearchRouter/SearchRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,27 @@ import * as SearchUtils from '@libs/SearchUtils';
import Navigation from '@navigation/Navigation';
import variables from '@styles/variables';
import * as Report from '@userActions/Report';
import Timing from '@userActions/Timing';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import {useSearchRouterContext} from './SearchRouterContext';
import SearchRouterInput from './SearchRouterInput';
import SearchRouterList from './SearchRouterList';

const SEARCH_DEBOUNCE_DELAY = 150;

function SearchRouter() {
type SearchRouterProps = {
onRouterClose: () => void;
};

function SearchRouter({onRouterClose}: SearchRouterProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const [betas] = useOnyx(ONYXKEYS.BETAS);
const [recentSearches] = useOnyx(ONYXKEYS.RECENT_SEARCHES);
const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false});

const {isSmallScreenWidth} = useResponsiveLayout();
const {isSearchRouterDisplayed, closeSearchRouter} = useSearchRouterContext();
const listRef = useRef<SelectionListHandle>(null);

const [textInputValue, debouncedInputValue, setTextInputValue] = useDebouncedState('', 500);
Expand Down Expand Up @@ -65,7 +68,9 @@ function SearchRouter() {
};
}

Timing.start(CONST.TIMING.SEARCH_FILTER_OPTIONS);
const newOptions = OptionsListUtils.filterOptions(searchOptions, debouncedInputValue, {sortByReportTypeInSearch: true, preferChatroomsOverThreads: true});
Timing.end(CONST.TIMING.SEARCH_FILTER_OPTIONS);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm I think we might wanna end the timing once the list is rendered onLayout?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No this line is correct.

There were 2 measures done in the old ChatFinder. What you're thinking about is still there in onLayout inside SearchRouterList - https://github.com/Expensify/App/pull/49984/files#diff-6d769534d8506784b70ef165d2e6883fe38e3fde4683528be637b7f8b923ff9fR185

And this one is just the timing for performing the search of chats, copied directly from here: https://github.com/Expensify/App/blob/main/src/pages/ChatFinderPage/index.tsx#L107-L109


return {
recentReports: newOptions.recentReports,
Expand All @@ -87,15 +92,6 @@ function SearchRouter() {
Report.searchInServer(debouncedInputValue.trim());
}, [debouncedInputValue]);

useEffect(() => {
if (!textInputValue && isSearchRouterDisplayed) {
return;
}
listRef.current?.updateAndScrollToFocusedIndex(0);
// eslint-disable-next-line react-compiler/react-compiler
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isSearchRouterDisplayed]);

const contextualReportData = contextualReportID ? searchOptions.recentReports?.find((option) => option.reportID === contextualReportID) : undefined;

const clearUserQuery = () => {
Expand Down Expand Up @@ -132,40 +128,43 @@ function SearchRouter() {
};

const closeAndClearRouter = useCallback(() => {
closeSearchRouter();
onRouterClose();
clearUserQuery();
// eslint-disable-next-line react-compiler/react-compiler
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [closeSearchRouter]);
}, [onRouterClose]);

const onSearchSubmit = useCallback(
(query: SearchQueryJSON | undefined) => {
if (!query) {
return;
}
closeSearchRouter();
onRouterClose();
const queryString = SearchUtils.buildSearchQueryString(query);
Navigation.navigate(ROUTES.SEARCH_CENTRAL_PANE.getRoute({query: queryString}));
clearUserQuery();
},
// eslint-disable-next-line react-compiler/react-compiler
// eslint-disable-next-line react-hooks/exhaustive-deps
[closeSearchRouter],
[onRouterClose],
);

useKeyboardShortcut(CONST.KEYBOARD_SHORTCUTS.ESCAPE, () => {
closeSearchRouter();
onRouterClose();
clearUserQuery();
});

const modalWidth = isSmallScreenWidth ? styles.w100 : {width: variables.popoverWidth};
Copy link
Contributor

Choose a reason for hiding this comment

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

variables.popoverWidth is 375px but I see that some mockups use 444px and others use 611px
@Expensify/design What is the correct width for the search router modal?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see what you're talking about. @dubielzyk-expensify any thoughts here? 611px seems like a wildly arbitrary number—I'd much rather do something more "round" like 440 or 540.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep. I've tested both and I recon let's do 512 as that is nicely divisible by 8 and its somewhat inbetween.

Copy link
Contributor

Choose a reason for hiding this comment

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

Beautiful! Sounds good.


return (
<View style={[styles.flex1, modalWidth, styles.h100, !isSmallScreenWidth && styles.mh85vh]}>
<View
style={[styles.flex1, modalWidth, styles.h100, !isSmallScreenWidth && styles.mh85vh]}
testID={SearchRouter.displayName}
>
{isSmallScreenWidth && (
<HeaderWithBackButton
title={translate('common.search')}
onBackButtonPress={() => closeSearchRouter()}
onBackButtonPress={() => onRouterClose()}
/>
)}
<SearchRouterInput
Expand Down
1 change: 1 addition & 0 deletions src/components/Search/SearchRouter/SearchRouterInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function SearchRouterInput({
<View style={[styles.flexRow, styles.alignItemsCenter, wrapperStyle ?? styles.searchRouterTextInputContainer, isFocused && wrapperFocusedStyle]}>
<View style={styles.flex1}>
<TextInput
testID="search-router-text-input"
value={value}
onChangeText={onChangeText}
autoFocus
Expand Down
9 changes: 9 additions & 0 deletions src/components/Search/SearchRouter/SearchRouterList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import Performance from '@libs/Performance';
import {getAllTaxRates} from '@libs/PolicyUtils';
import type {OptionData} from '@libs/ReportUtils';
import * as SearchUtils from '@libs/SearchUtils';
import * as Report from '@userActions/Report';
import Timing from '@userActions/Timing';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';

Expand Down Expand Up @@ -47,6 +50,11 @@ type SearchRouterListProps = {
closeAndClearRouter: () => void;
};

const setPerformanceTimersEnd = () => {
Timing.end(CONST.TIMING.SEARCH_ROUTER_OPEN);
Performance.markEnd(CONST.TIMING.SEARCH_ROUTER_OPEN);
};

function isSearchQueryItem(item: OptionData | SearchQueryItem): item is SearchQueryItem {
if ('singleIcon' in item && item.singleIcon && 'query' in item && item.query) {
return true;
Expand Down Expand Up @@ -174,6 +182,7 @@ function SearchRouterList(
ListItem={SearchRouterItem}
containerStyle={[styles.mh100]}
sectionListStyle={[isSmallScreenWidth ? styles.ph5 : styles.ph2, styles.pb2]}
onLayout={setPerformanceTimersEnd}
ref={ref}
showScrollIndicator={!isSmallScreenWidth}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Search/SearchRouter/SearchRouterModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function SearchRouterModal() {
popoverAnchorPosition={{right: 20, top: 20}}
onClose={closeSearchRouter}
>
<FocusTrapForModal active={isSearchRouterDisplayed}>{isSearchRouterDisplayed && <SearchRouter />}</FocusTrapForModal>
<FocusTrapForModal active={isSearchRouterDisplayed}>{isSearchRouterDisplayed && <SearchRouter onRouterClose={closeSearchRouter} />}</FocusTrapForModal>
</Modal>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/E2E/reactNativeLaunchingTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if (!appInstanceId) {
// import your test here, define its name and config first in e2e/config.js
const tests: Tests = {
[E2EConfig.TEST_NAMES.AppStartTime]: require<TestModule>('./tests/appStartTimeTest.e2e').default,
[E2EConfig.TEST_NAMES.OpenChatFinderPage]: require<TestModule>('./tests/openChatFinderPageTest.e2e').default,
[E2EConfig.TEST_NAMES.OpenSearchRouter]: require<TestModule>('./tests/openSearchRouterTest.e2e').default,
[E2EConfig.TEST_NAMES.ChatOpening]: require<TestModule>('./tests/chatOpeningTest.e2e').default,
[E2EConfig.TEST_NAMES.ReportTyping]: require<TestModule>('./tests/reportTypingTest.e2e').default,
[E2EConfig.TEST_NAMES.Linking]: require<TestModule>('./tests/linkingTest.e2e').default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import E2ELogin from '@libs/E2E/actions/e2eLogin';
import waitForAppLoaded from '@libs/E2E/actions/waitForAppLoaded';
import E2EClient from '@libs/E2E/client';
import getPromiseWithResolve from '@libs/E2E/utils/getPromiseWithResolve';
import Navigation from '@libs/Navigation/Navigation';
import Performance from '@libs/Performance';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';

const test = () => {
// check for login (if already logged in the action will simply resolve)
console.debug('[E2E] Logging in for chat finder');
console.debug('[E2E] Logging in for new search router');

E2ELogin().then((neededLogin: boolean): Promise<Response> | undefined => {
if (neededLogin) {
Expand All @@ -20,36 +18,29 @@ const test = () => {
);
}

console.debug('[E2E] Logged in, getting chat finder metrics and submitting them…');
console.debug('[E2E] Logged in, getting search router metrics and submitting them…');

const [openSearchPagePromise, openSearchPageResolve] = getPromiseWithResolve();
const [openSearchRouterPromise, openSearchRouterResolve] = getPromiseWithResolve();
const [loadSearchOptionsPromise, loadSearchOptionsResolve] = getPromiseWithResolve();

Promise.all([openSearchPagePromise, loadSearchOptionsPromise]).then(() => {
Promise.all([openSearchRouterPromise, loadSearchOptionsPromise]).then(() => {
console.debug(`[E2E] Submitting!`);

E2EClient.submitTestDone();
});

Performance.subscribeToMeasurements((entry) => {
if (entry.name === CONST.TIMING.SIDEBAR_LOADED) {
console.debug(`[E2E] Sidebar loaded, navigating to chat finder route…`);
Performance.markStart(CONST.TIMING.CHAT_FINDER_RENDER);
Navigation.navigate(ROUTES.CHAT_FINDER);
return;
}

console.debug(`[E2E] Entry: ${JSON.stringify(entry)}`);

if (entry.name === CONST.TIMING.CHAT_FINDER_RENDER) {
if (entry.name === CONST.TIMING.SEARCH_ROUTER_OPEN) {
E2EClient.submitTestResults({
branch: Config.E2E_BRANCH,
name: 'Open Chat Finder Page TTI',
name: 'Open Search Router TTI',
metric: entry.duration,
unit: 'ms',
})
.then(() => {
openSearchPageResolve();
openSearchRouterResolve();
console.debug('[E2E] Done with search, exiting…');
})
.catch((err) => {
Expand Down
10 changes: 8 additions & 2 deletions src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ActiveGuidesEventListener from '@components/ActiveGuidesEventListener';
import ComposeProviders from '@components/ComposeProviders';
import OptionsListContextProvider from '@components/OptionListContextProvider';
import {SearchContextProvider} from '@components/Search/SearchContext';
import {useSearchRouterContext} from '@components/Search/SearchRouter/SearchRouterContext';
import SearchRouterModal from '@components/Search/SearchRouter/SearchRouterModal';
import useActiveWorkspace from '@hooks/useActiveWorkspace';
import useOnboardingFlowRouter from '@hooks/useOnboardingFlow';
Expand Down Expand Up @@ -233,6 +234,8 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie
const screenOptions = getRootNavigatorScreenOptions(shouldUseNarrowLayout, styles, StyleUtils);
const {canUseDefaultRooms} = usePermissions();
const {activeWorkspaceID} = useActiveWorkspace();
const {openSearchRouter} = useSearchRouterContext();

const onboardingModalScreenOptions = useMemo(() => screenOptions.onboardingModalNavigator(onboardingIsMediumOrLargerScreenWidth), [screenOptions, onboardingIsMediumOrLargerScreenWidth]);
const onboardingScreenOptions = useMemo(
() => getOnboardingModalScreenOptions(shouldUseNarrowLayout, styles, StyleUtils, onboardingIsMediumOrLargerScreenWidth),
Expand All @@ -241,6 +244,7 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie
const modal = useRef<OnyxTypes.Modal>({});
const [didPusherInit, setDidPusherInit] = useState(false);
const {isOnboardingCompleted} = useOnboardingFlowRouter();

let initialReportID: string | undefined;
const isInitialRender = useRef(true);
if (isInitialRender.current) {
Expand Down Expand Up @@ -363,13 +367,15 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie
);

// Listen for the key K being pressed so that focus can be given to
// the chat switcher, or new group chat
// Search Router, or new group chat
// based on the key modifiers pressed and the operating system
const unsubscribeSearchShortcut = KeyboardShortcut.subscribe(
searchShortcutConfig.shortcutKey,
() => {
Modal.close(
Session.checkIfActionIsAllowed(() => Navigation.navigate(ROUTES.CHAT_FINDER)),
Session.checkIfActionIsAllowed(() => {
openSearchRouter();
}),
true,
true,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import Overlay from './Overlay';

type LeftModalNavigatorProps = StackScreenProps<AuthScreensParamList, typeof NAVIGATORS.LEFT_MODAL_NAVIGATOR>;

const loadChatFinder = () => require<ReactComponentModule>('../../../../pages/ChatFinderPage').default;
const loadWorkspaceSwitcherPage = () => require<ReactComponentModule>('../../../../pages/WorkspaceSwitcherPage').default;

const Stack = createStackNavigator<LeftModalNavigatorParamList>();
Expand All @@ -37,10 +36,6 @@ function LeftModalNavigator({navigation}: LeftModalNavigatorProps) {
screenOptions={screenOptions}
id={NAVIGATORS.LEFT_MODAL_NAVIGATOR}
>
<Stack.Screen
name={SCREENS.LEFT_MODAL.CHAT_FINDER}
getComponent={loadChatFinder}
/>
<Stack.Screen
name={SCREENS.LEFT_MODAL.WORKSPACE_SWITCHER}
getComponent={loadWorkspaceSwitcherPage}
Expand Down
Loading
Loading