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

Add Onyx key to allow remotely resetting client data #38196

Merged
merged 7 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 4 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ const ONYXKEYS = {
/** Indicates whether an forced upgrade is required */
UPDATE_REQUIRED: 'updateRequired',

/** Indicates whether an forced reset is required a.k.a. clear Oynx data without signing the user out */
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think it would be a good idea to include the intention for this feature in the comment? If it's meant to be debug-only, maybe we could highlight it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given the confusion experienced here I think it's a great idea to update this and explain the intention!

It's a server side way to force clients to reload in case some backend code leaves the app in a broken state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please let me know if the change looks good to you 🙇

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks much better! The comment doesn't mention that it's a server-to-client pipe, but maybe that's obvious.

RESET_REQUIRED: 'resetRequired',

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

Expand Down Expand Up @@ -638,6 +641,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,
Copy link
Contributor

Choose a reason for hiding this comment

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

@marcaaron Was there any specific reason not to include ONYXKEYS.USER here? We're considering adding it in #49087, but wanted to check first if there are any good arguments against doing so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can't think of a reason! Thanks for asking! The array of keys also predates this PR so we could also ask the author of the original PR that introduced this change.

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 @@ -527,4 +560,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
Loading