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

feat: add shortcut to open troubleshoot modal #43543

Merged
merged 8 commits into from
Jun 17, 2024
Merged
10 changes: 10 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,16 @@ const CONST = {
shortcutKey: 'Tab',
modifiers: [],
},
DEBUG: {
descriptionKey: 'openDebug',
Julesssss marked this conversation as resolved.
Show resolved Hide resolved
shortcutKey: 'D',
modifiers: ['CTRL'],
trigger: {
DEFAULT: {input: 'd', modifierFlags: keyModifierControl},
[PLATFORM_OS_MACOS]: {input: 'd', modifierFlags: keyModifierCommand},
[PLATFORM_IOS]: {input: 'd', modifierFlags: keyModifierCommand},
},
},
},
KEYBOARD_SHORTCUTS_TYPES: {
NAVIGATION_SHORTCUT: KEYBOARD_SHORTCUT_NAVIGATION_TYPE,
Expand Down
49 changes: 6 additions & 43 deletions src/components/ClientSideLoggingToolMenu/index.android.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,10 @@
import React, {useState} from 'react';
import RNFetchBlob from 'react-native-blob-util';
import Share from 'react-native-share';
import type {Log} from '@libs/Console';
import localFileCreate from '@libs/localFileCreate';
import CONST from '@src/CONST';
import BaseClientSideLoggingToolMenu from './BaseClientSideLoggingToolMenu';

/**
* Since client-side logging is currently supported on web and desktop natively right now,
* this menu will be hidden in iOS and Android.
* See comment here: https://github.com/Expensify/App/issues/43256#issuecomment-2154610196
*/
function ClientSideLoggingToolMenu() {
const [file, setFile] = useState<{path: string; newFileName: string; size: number}>();

const createAndSaveFile = (logs: Log[]) => {
localFileCreate('logs', JSON.stringify(logs, null, 2)).then((localFile) => {
RNFetchBlob.MediaCollection.copyToMediaStore(
{
name: localFile.newFileName,
parentFolder: '',
mimeType: 'text/plain',
},
'Download',
localFile.path,
);
setFile(localFile);
});
};

const shareLogs = () => {
if (!file) {
return;
}
Share.open({
url: `file://${file.path}`,
});
};

return (
<BaseClientSideLoggingToolMenu
file={file}
onEnableLogging={() => setFile(undefined)}
onDisableLogging={createAndSaveFile}
onShareLogs={shareLogs}
displayPath={`${CONST.DOWNLOADS_PATH}/${file?.newFileName ?? ''}`}
/>
);
return null;
}
Julesssss marked this conversation as resolved.
Show resolved Hide resolved

ClientSideLoggingToolMenu.displayName = 'ClientSideLoggingToolMenu';
Expand Down
42 changes: 6 additions & 36 deletions src/components/ClientSideLoggingToolMenu/index.ios.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,10 @@
import React, {useState} from 'react';
import Share from 'react-native-share';
import useEnvironment from '@hooks/useEnvironment';
import type {Log} from '@libs/Console';
import getDownloadFolderPathSuffixForIOS from '@libs/getDownloadFolderPathSuffixForIOS';
import localFileCreate from '@libs/localFileCreate';
import CONST from '@src/CONST';
import BaseClientSideLoggingToolMenu from './BaseClientSideLoggingToolMenu';

/**
* Since client-side logging is currently supported on web and desktop natively right now,
* this menu will be hidden in iOS and Android.
* See comment here: https://github.com/Expensify/App/issues/43256#issuecomment-2154610196
*/
function ClientSideLoggingToolMenu() {
const [file, setFile] = useState<{path: string; newFileName: string; size: number}>();
const {environment} = useEnvironment();

const createFile = (logs: Log[]) => {
localFileCreate('logs', JSON.stringify(logs, null, 2)).then((localFile) => {
setFile(localFile);
});
};

const shareLogs = () => {
if (!file) {
return;
}
Share.open({
url: `file://${file.path}`,
});
};

return (
<BaseClientSideLoggingToolMenu
file={file}
onEnableLogging={() => setFile(undefined)}
onDisableLogging={createFile}
onShareLogs={shareLogs}
displayPath={`${CONST.NEW_EXPENSIFY_PATH}${getDownloadFolderPathSuffixForIOS(environment)}/${file?.newFileName ?? ''}`}
/>
);
return null;
}

ClientSideLoggingToolMenu.displayName = 'ClientSideLoggingToolMenu';
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2789,6 +2789,7 @@ export default {
search: 'Open search dialog',
newChat: 'New chat screen',
copy: 'Copy comment',
openDebug: 'Open testing preferences dialog',
},
},
guides: {
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2831,6 +2831,7 @@ export default {
search: 'Abrir diálogo de búsqueda',
newChat: 'Nueva pantalla de chat',
copy: 'Copiar comentario',
openDebug: 'Abrir el diálogo de preferencias de pruebas',
},
},
guides: {
Expand Down
13 changes: 13 additions & 0 deletions src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import * as PersonalDetails from '@userActions/PersonalDetails';
import * as PriorityMode from '@userActions/PriorityMode';
import * as Report from '@userActions/Report';
import * as Session from '@userActions/Session';
import toggleTestToolsModal from '@userActions/TestTool';
import Timing from '@userActions/Timing';
import * as User from '@userActions/User';
import CONFIG from '@src/CONFIG';
Expand Down Expand Up @@ -190,6 +191,7 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie
const shortcutsOverviewShortcutConfig = CONST.KEYBOARD_SHORTCUTS.SHORTCUTS;
const searchShortcutConfig = CONST.KEYBOARD_SHORTCUTS.SEARCH;
const chatShortcutConfig = CONST.KEYBOARD_SHORTCUTS.NEW_CHAT;
const debugShortcutConfig = CONST.KEYBOARD_SHORTCUTS.DEBUG;
const currentUrl = getCurrentUrl();
const isLoggingInAsNewUser = !!session?.email && SessionUtils.isLoggingInAsNewUser(currentUrl, session.email);
// Sign out the current user if we're transitioning with a different user
Expand Down Expand Up @@ -273,10 +275,21 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie
true,
);

const unsubscribeDebugShortcut = KeyboardShortcut.subscribe(
debugShortcutConfig.shortcutKey,
() => {
toggleTestToolsModal();
},
debugShortcutConfig.descriptionKey,
debugShortcutConfig.modifiers,
true,
);

return () => {
unsubscribeShortcutsOverviewShortcut();
unsubscribeSearchShortcut();
unsubscribeChatShortcut();
unsubscribeDebugShortcut();
Session.cleanupSession();
};

Expand Down
Loading