Skip to content

Commit

Permalink
Merge pull request #38196 from Expensify/marcaaron-addResetRequiredKey
Browse files Browse the repository at this point in the history
Add Onyx key to allow remotely resetting client data
  • Loading branch information
srikarparsi authored Apr 12, 2024
2 parents cd30333 + 3cd178a commit 6600b4c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
4 changes: 4 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ const ONYXKEYS = {
/** Indicates whether an forced upgrade is required */
UPDATE_REQUIRED: 'updateRequired',

/** Indicates whether an forced reset is required. Used in emergency situations where we must completely erase the Onyx data in the client because it is in a bad state. This will clear Oynx data without signing the user out. */
RESET_REQUIRED: 'resetRequired',

/** Stores the logs of the app for debugging purposes */
LOGS: 'logs',

Expand Down Expand Up @@ -642,6 +645,7 @@ type OnyxValuesMapping = {
[ONYXKEYS.LAST_VISITED_PATH]: string | undefined;
[ONYXKEYS.RECENTLY_USED_REPORT_FIELDS]: OnyxTypes.RecentlyUsedReportFields;
[ONYXKEYS.UPDATE_REQUIRED]: boolean;
[ONYXKEYS.RESET_REQUIRED]: boolean;
[ONYXKEYS.PLAID_CURRENT_EVENT]: string;
[ONYXKEYS.LOGS]: OnyxTypes.CapturedLogs;
[ONYXKEYS.SHOULD_STORE_LOGS]: boolean;
Expand Down
34 changes: 34 additions & 0 deletions src/libs/actions/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as SessionUtils from '@libs/SessionUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {OnyxKey} from '@src/ONYXKEYS';
import type {Route} from '@src/ROUTES';
import ROUTES from '@src/ROUTES';
import type * as OnyxTypes from '@src/types/onyx';
Expand Down Expand Up @@ -77,6 +78,38 @@ Onyx.connect({
},
});

const KEYS_TO_PRESERVE: OnyxKey[] = [
ONYXKEYS.ACCOUNT,
ONYXKEYS.IS_CHECKING_PUBLIC_ROOM,
ONYXKEYS.IS_LOADING_APP,
ONYXKEYS.IS_SIDEBAR_LOADED,
ONYXKEYS.MODAL,
ONYXKEYS.NETWORK,
ONYXKEYS.SESSION,
ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT,
ONYXKEYS.NVP_TRY_FOCUS_MODE,
ONYXKEYS.PREFERRED_THEME,
ONYXKEYS.NVP_PREFERRED_LOCALE,
ONYXKEYS.CREDENTIALS,
];

Onyx.connect({
key: ONYXKEYS.RESET_REQUIRED,
callback: (isResetRequired) => {
if (!isResetRequired) {
return;
}

Onyx.clear(KEYS_TO_PRESERVE).then(() => {
// Set this to false to reset the flag for this client
Onyx.set(ONYXKEYS.RESET_REQUIRED, false);

// eslint-disable-next-line @typescript-eslint/no-use-before-define
openApp();
});
},
});

let resolveIsReadyPromise: () => void;
const isReadyToOpenApp = new Promise<void>((resolve) => {
resolveIsReadyPromise = resolve;
Expand Down Expand Up @@ -525,4 +558,5 @@ export {
savePolicyDraftByNewWorkspace,
createWorkspaceWithPolicyDraftAndNavigateToIt,
updateLastVisitedPath,
KEYS_TO_PRESERVE,
};
18 changes: 1 addition & 17 deletions src/pages/settings/AboutPage/TroubleshootPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,9 @@ import * as App from '@userActions/App';
import * as Report from '@userActions/Report';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import type {OnyxKey} from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';

const keysToPreserve: OnyxKey[] = [
ONYXKEYS.ACCOUNT,
ONYXKEYS.IS_CHECKING_PUBLIC_ROOM,
ONYXKEYS.IS_LOADING_APP,
ONYXKEYS.IS_SIDEBAR_LOADED,
ONYXKEYS.MODAL,
ONYXKEYS.NETWORK,
ONYXKEYS.SESSION,
ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT,
ONYXKEYS.NVP_TRY_FOCUS_MODE,
ONYXKEYS.PREFERRED_THEME,
ONYXKEYS.NVP_PREFERRED_LOCALE,
ONYXKEYS.CREDENTIALS,
];

type BaseMenuItem = {
translationKey: TranslationPaths;
icon: React.FC<SvgProps>;
Expand Down Expand Up @@ -128,7 +112,7 @@ function TroubleshootPage({shouldStoreLogs}: TroubleshootPageProps) {
isVisible={isConfirmationModalVisible}
onConfirm={() => {
setIsConfirmationModalVisible(false);
Onyx.clear(keysToPreserve).then(() => {
Onyx.clear(App.KEYS_TO_PRESERVE).then(() => {
App.openApp();
});
}}
Expand Down

0 comments on commit 6600b4c

Please sign in to comment.