Skip to content

Commit

Permalink
Drop usage of withOnyx on modified pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Kicu committed Sep 20, 2024
1 parent 0df5b82 commit 6cdeaae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 55 deletions.
25 changes: 6 additions & 19 deletions src/pages/settings/Troubleshoot/TroubleshootPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, {useCallback, useMemo, useState} from 'react';
import {View} from 'react-native';
import Onyx, {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import Onyx, {useOnyx} from 'react-native-onyx';
import type {SvgProps} from 'react-native-svg';
import ClientSideLoggingToolMenu from '@components/ClientSideLoggingToolMenu';
import ConfirmModal from '@components/ConfirmModal';
Expand Down Expand Up @@ -39,14 +38,7 @@ type BaseMenuItem = {
action: () => void | Promise<void>;
};

type TroubleshootPageOnyxProps = {
shouldStoreLogs: OnyxEntry<boolean>;
shouldMaskOnyxState: boolean;
};

type TroubleshootPageProps = TroubleshootPageOnyxProps;

function TroubleshootPage({shouldStoreLogs, shouldMaskOnyxState}: TroubleshootPageProps) {
function TroubleshootPage() {
const {translate} = useLocalize();
const styles = useThemeStyles();
const {isProduction} = useEnvironment();
Expand All @@ -55,6 +47,9 @@ function TroubleshootPage({shouldStoreLogs, shouldMaskOnyxState}: TroubleshootPa
const {shouldUseNarrowLayout} = useResponsiveLayout();
const illustrationStyle = getLightbulbIllustrationStyle();

const [shouldStoreLogs] = useOnyx(ONYXKEYS.SHOULD_STORE_LOGS);
const [shouldMaskOnyxState = true] = useOnyx(ONYXKEYS.SHOULD_MASK_ONYX_STATE);

const exportOnyxState = useCallback(() => {
ExportOnyxState.readFromOnyxDatabase().then((value: Record<string, unknown>) => {
const dataToShare = ExportOnyxState.maskOnyxState(value, shouldMaskOnyxState);
Expand Down Expand Up @@ -177,12 +172,4 @@ function TroubleshootPage({shouldStoreLogs, shouldMaskOnyxState}: TroubleshootPa

TroubleshootPage.displayName = 'TroubleshootPage';

export default withOnyx<TroubleshootPageProps, TroubleshootPageOnyxProps>({
shouldStoreLogs: {
key: ONYXKEYS.SHOULD_STORE_LOGS,
},
shouldMaskOnyxState: {
key: ONYXKEYS.SHOULD_MASK_ONYX_STATE,
selector: (shouldMaskOnyxState) => shouldMaskOnyxState ?? true,
},
})(TroubleshootPage);
export default TroubleshootPage;
45 changes: 9 additions & 36 deletions src/pages/workspace/WorkspacesListPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, {useCallback, useMemo, useState} from 'react';
import {FlatList, View} from 'react-native';
import {useOnyx, withOnyx} from 'react-native-onyx';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import Button from '@components/Button';
import ConfirmModal from '@components/ConfirmModal';
Expand Down Expand Up @@ -38,7 +37,7 @@ import * as Session from '@userActions/Session';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Policy as PolicyType, ReimbursementAccount, Report, Session as SessionType} from '@src/types/onyx';
import type {Policy as PolicyType} from '@src/types/onyx';
import type * as OnyxCommon from '@src/types/onyx/OnyxCommon';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import WorkspacesListRow from './WorkspacesListRow';
Expand Down Expand Up @@ -67,22 +66,6 @@ type ChatType = {

type ChatPolicyType = Record<string, ChatType>;

type WorkspaceListPageOnyxProps = {
/** The list of this user's policies */
policies: OnyxCollection<PolicyType>;

/** Bank account attached to free plan */
reimbursementAccount: OnyxEntry<ReimbursementAccount>;

/** All reports shared with the user (coming from Onyx) */
reports: OnyxCollection<Report>;

/** Session info for the currently logged in user. */
session: OnyxEntry<SessionType>;
};

type WorkspaceListPageProps = WorkspaceListPageOnyxProps;

const workspaceFeatures: FeatureListItem[] = [
{
icon: Illustrations.MoneyReceipts,
Expand Down Expand Up @@ -117,13 +100,17 @@ function dismissWorkspaceError(policyID: string, pendingAction: OnyxCommon.Pendi

const stickyHeaderIndices = [0];

function WorkspacesListPage({policies, reimbursementAccount, reports, session}: WorkspaceListPageProps) {
function WorkspacesListPage() {
const theme = useTheme();
const styles = useThemeStyles();
const {translate} = useLocalize();
const {isOffline} = useNetwork();
const {shouldUseNarrowLayout, isMediumScreenWidth} = useResponsiveLayout();
const [allConnectionSyncProgresses] = useOnyx(ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS);
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const [reimbursementAccount] = useOnyx(ONYXKEYS.REIMBURSEMENT_ACCOUNT);
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
const [session] = useOnyx(ONYXKEYS.SESSION);

const {activeWorkspaceID, setActiveWorkspaceID} = useActiveWorkspace();

Expand Down Expand Up @@ -313,7 +300,7 @@ function WorkspacesListPage({policies, reimbursementAccount, reports, session}:
}

return Object.values(policies)
.filter((policy): policy is PolicyType => PolicyUtils.shouldShowPolicy(policy, !!isOffline, session?.email))
.filter((policy): policy is PolicyType => PolicyUtils.shouldShowPolicy(policy, isOffline, session?.email))
.map((policy): WorkspaceItem => {
if (policy?.isJoinRequestPending && policy?.policyDetailsForNonMembers) {
const policyInfo = Object.values(policy.policyDetailsForNonMembers)[0];
Expand Down Expand Up @@ -454,18 +441,4 @@ function WorkspacesListPage({policies, reimbursementAccount, reports, session}:

WorkspacesListPage.displayName = 'WorkspacesListPage';

export default withOnyx<WorkspaceListPageProps, WorkspaceListPageOnyxProps>({
policies: {
key: ONYXKEYS.COLLECTION.POLICY,
},
// @ts-expect-error: ONYXKEYS.REIMBURSEMENT_ACCOUNT is conflicting with ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM
reimbursementAccount: {
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
},
reports: {
key: ONYXKEYS.COLLECTION.REPORT,
},
session: {
key: ONYXKEYS.SESSION,
},
})(WorkspacesListPage);
export default WorkspacesListPage;

0 comments on commit 6cdeaae

Please sign in to comment.