Skip to content

Commit 718d98e

Browse files
authored
Merge pull request Expensify#92064 from Expensify/ionatan_addkeyboardshortcuts
[Payment due @truph01] Add keyboard shortcuts for searching expense reports and for jumping to a report's policy
2 parents 22a3477 + e4483b0 commit 718d98e

17 files changed

Lines changed: 159 additions & 6 deletions

File tree

src/CONST/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,28 @@ const CONST = {
12041204
DEFAULT: {input: keyInputSpace},
12051205
},
12061206
},
1207+
EXPENSE_REPORT_SEARCH: {
1208+
descriptionKey: 'expenseReportSearch',
1209+
shortcutKey: 'U',
1210+
modifiers: ['CTRL'],
1211+
trigger: {
1212+
DEFAULT: {input: 'u', modifierFlags: keyModifierControl},
1213+
[PLATFORM_OS_MACOS]: {input: 'u', modifierFlags: keyModifierCommand},
1214+
[PLATFORM_IOS]: {input: 'u', modifierFlags: keyModifierCommand},
1215+
},
1216+
type: KEYBOARD_SHORTCUT_NAVIGATION_TYPE,
1217+
},
1218+
GO_TO_WORKSPACE: {
1219+
descriptionKey: 'goToWorkspace',
1220+
shortcutKey: 'B',
1221+
modifiers: ['CTRL'],
1222+
trigger: {
1223+
DEFAULT: {input: 'b', modifierFlags: keyModifierControl},
1224+
[PLATFORM_OS_MACOS]: {input: 'b', modifierFlags: keyModifierCommand},
1225+
[PLATFORM_IOS]: {input: 'b', modifierFlags: keyModifierCommand},
1226+
},
1227+
type: KEYBOARD_SHORTCUT_NAVIGATION_TYPE,
1228+
},
12071229
},
12081230
KEYBOARD_SHORTCUTS_TYPES: {
12091231
NAVIGATION_SHORTCUT: KEYBOARD_SHORTCUT_NAVIGATION_TYPE,

src/components/Search/SearchRouter/SearchRouter.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import type Report from '@src/types/onyx/Report';
4848
import type {SubstitutionMap} from './getQueryWithSubstitutions';
4949
import {getQueryWithSubstitutions} from './getQueryWithSubstitutions';
5050
import {getUpdatedSubstitutionsMap} from './getUpdatedSubstitutionsMap';
51+
import {clearPendingRouterQuery, peekPendingRouterQuery} from './SearchRouterContext';
5152
import {getContextualReportData, getContextualSearchAutocompleteKey, getContextualSearchQuery} from './SearchRouterUtils';
5253
import updateAutocompleteSubstitutionsForSelection from './updateAutocompleteSubstitutionsForSelection';
5354
import useAskConcierge from './useAskConcierge';
@@ -77,11 +78,17 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla
7778
const expensifyIcons = useMemoizedLazyExpensifyIcons(['MagnifyingGlass', 'ConciergeAvatar']);
7879
const {askConcierge, shouldShowAskConcierge} = useAskConcierge();
7980

81+
const initialQuery = peekPendingRouterQuery();
82+
8083
// The actual input text that the user sees
81-
const [textInputValue, , setTextInputValue] = useDebouncedState('', 500);
84+
const [textInputValue, , setTextInputValue] = useDebouncedState(initialQuery, 500);
8285
// The input text that was last used for autocomplete; needed for the SearchAutocompleteList when browsing list via arrow keys
83-
const [autocompleteQueryValue, setAutocompleteQueryValue] = useState(textInputValue);
84-
const [selection, setSelection] = useState({start: textInputValue.length, end: textInputValue.length});
86+
const [autocompleteQueryValue, setAutocompleteQueryValue] = useState(initialQuery);
87+
const [selection, setSelection] = useState({start: initialQuery.length, end: initialQuery.length});
88+
89+
useEffect(() => {
90+
clearPendingRouterQuery();
91+
}, []);
8592
const [autocompleteSubstitutions, setAutocompleteSubstitutions] = useState<SubstitutionMap>({});
8693
const textInputRef = useRef<AnimatedTextInputRef>(null);
8794

src/components/Search/SearchRouter/SearchRouterContext.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,26 @@ import SCREENS from '@src/SCREENS';
1010
import type ChildrenProps from '@src/types/utils/ChildrenProps';
1111
import {closeSearch, openSearch} from './toggleSearch';
1212

13+
// Module-level pending query used to seed the SearchRouter input on open.
14+
// Set before opening, peeked during SearchRouter render, cleared on mount.
15+
let pendingRouterQuery = '';
16+
17+
function peekPendingRouterQuery(): string {
18+
return pendingRouterQuery;
19+
}
20+
21+
function clearPendingRouterQuery() {
22+
pendingRouterQuery = '';
23+
}
24+
25+
export {peekPendingRouterQuery, clearPendingRouterQuery};
26+
1327
type SearchRouterStateContextType = {
1428
isSearchRouterDisplayed: boolean;
1529
};
1630

1731
type SearchRouterActionsContextType = {
18-
openSearchRouter: () => void;
32+
openSearchRouter: (query?: string) => void;
1933
closeSearchRouter: () => void;
2034
toggleSearch: () => void;
2135
registerSearchPageInput: (ref: AnimatedTextInputRef) => void;
@@ -81,7 +95,8 @@ function SearchRouterContextProvider({children}: ChildrenProps) {
8195
});
8296
};
8397

84-
const openSearchRouter = () => {
98+
const openSearchRouter = (query?: string) => {
99+
pendingRouterQuery = query ?? '';
85100
if (isBrowserWithHistory) {
86101
window.history.pushState({isSearchModalOpen: true} satisfies HistoryState, '');
87102
}

src/languages/de.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8018,6 +8018,8 @@ Fügen Sie weitere Ausgabelimits hinzu, um den Cashflow Ihres Unternehmens zu sc
80188018
newChat: 'Neuer Chat-Bildschirm',
80198019
copy: 'Kommentar kopieren',
80208020
openDebug: 'Testeinstellungen öffnen',
8021+
expenseReportSearch: 'Spesenberichte suchen',
8022+
goToWorkspace: 'Zum Workspace des aktuellen Berichts gehen',
80218023
},
80228024
},
80238025
guides: {

src/languages/en.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8058,6 +8058,8 @@ const translations = {
80588058
newChat: 'New chat screen',
80598059
copy: 'Copy comment',
80608060
openDebug: 'Open testing preferences dialog',
8061+
expenseReportSearch: 'Search expense reports',
8062+
goToWorkspace: "Go to the current report's workspace",
80618063
},
80628064
},
80638065
guides: {

src/languages/es.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7814,6 +7814,8 @@ ${amount} para ${merchant} - ${date}`,
78147814
newChat: 'Nueva pantalla de chat',
78157815
copy: 'Copiar comentario',
78167816
openDebug: 'Abrir el diálogo de preferencias de pruebas',
7817+
expenseReportSearch: 'Buscar informes de gastos',
7818+
goToWorkspace: 'Ir al espacio de trabajo del informe actual',
78177819
},
78187820
},
78197821
guides: {

src/languages/fr.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8053,6 +8053,8 @@ Ajoutez davantage de règles de dépenses pour protéger la trésorerie de l’e
80538053
newChat: 'Nouvel écran de discussion',
80548054
copy: 'Copier le commentaire',
80558055
openDebug: 'Ouvrir la boîte de dialogue des préférences de test',
8056+
expenseReportSearch: 'Rechercher des notes de frais',
8057+
goToWorkspace: "Aller à l'espace de travail de la note de frais actuelle",
80568058
},
80578059
},
80588060
guides: {

src/languages/it.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8008,6 +8008,8 @@ Aggiungi altre regole di spesa per proteggere il flusso di cassa aziendale.`,
80088008
newChat: 'Nuova schermata chat',
80098009
copy: 'Copia commento',
80108010
openDebug: 'Apri la finestra delle preferenze di test',
8011+
expenseReportSearch: 'Cerca i report spese',
8012+
goToWorkspace: 'Vai allo spazio di lavoro del report corrente',
80118013
},
80128014
},
80138015
guides: {

src/languages/ja.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7909,6 +7909,8 @@ ${reportName}
79097909
newChat: '新しいチャット画面',
79107910
copy: 'コメントをコピー',
79117911
openDebug: 'テスト設定ダイアログを開く',
7912+
expenseReportSearch: '経費レポートを検索',
7913+
goToWorkspace: '現在のレポートのワークスペースに移動',
79127914
},
79137915
},
79147916
guides: {

src/languages/nl.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7976,6 +7976,8 @@ er bestedingsregels toe om de kasstroom van het bedrijf te beschermen.`,
79767976
newChat: 'Nieuw chatscherm',
79777977
copy: 'Opmerking kopiëren',
79787978
openDebug: 'Dialoogvenster testvoorkeuren openen',
7979+
expenseReportSearch: 'Onkostendeclaraties zoeken',
7980+
goToWorkspace: 'Ga naar de werkruimte van het huidige rapport',
79797981
},
79807982
},
79817983
guides: {

0 commit comments

Comments
 (0)