Skip to content

Commit

Permalink
Merge pull request #43543 from dominictb/fix/43256
Browse files Browse the repository at this point in the history
feat: add shortcut to open troubleshoot modal
  • Loading branch information
Julesssss authored Jun 17, 2024
2 parents 3e1d94a + b54e4cd commit f415fa9
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 79 deletions.
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',
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;
}

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 @@ -2786,6 +2786,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 @@ -2825,6 +2825,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

0 comments on commit f415fa9

Please sign in to comment.