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

[TS migration] Migrate 'withPolicyAndFullscreenLoading.js' HOC to TypeScript #31428

Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions src/pages/workspace/withPolicy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,4 @@ export default function <TProps extends WithPolicyProps, TRef>(WrappedComponent:
}

export {policyPropTypes, policyDefaultProps};
export type {WithPolicyOnyxProps, WithPolicyProps};
67 changes: 0 additions & 67 deletions src/pages/workspace/withPolicyAndFullscreenLoading.js

This file was deleted.

50 changes: 50 additions & 0 deletions src/pages/workspace/withPolicyAndFullscreenLoading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import isEmpty from 'lodash/isEmpty';
import React, {ComponentType, ForwardedRef, forwardRef, RefAttributes} from 'react';
import {OnyxEntry, withOnyx} from 'react-native-onyx';
import FullscreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import compose from '@libs/compose';
import ONYXKEYS from '@src/ONYXKEYS';
import withPolicy, {WithPolicyOnyxProps, WithPolicyProps} from './withPolicy';

type WithPolicyAndFullscreenLoadingOnyxProps = {
/** Indicated whether the report data is loading */
isLoadingReportData: OnyxEntry<boolean>;
};

type WithPolicyAndFullscreenLoadingProps = WithPolicyProps & WithPolicyAndFullscreenLoadingOnyxProps;

type ComponentWithPolicyAndFullscreenLoading<TProps extends WithPolicyAndFullscreenLoadingProps, TRef> = ComponentType<
Omit<Omit<TProps & RefAttributes<TRef>, keyof WithPolicyAndFullscreenLoadingOnyxProps>, keyof WithPolicyOnyxProps>
>;

export default function withPolicyAndFullscreenLoading<TProps extends WithPolicyAndFullscreenLoadingProps, TRef>(
WrappedComponent: ComponentType<TProps & RefAttributes<TRef>>,
): ComponentWithPolicyAndFullscreenLoading<TProps, TRef> {
function WithPolicyAndFullscreenLoading({isLoadingReportData = true, policy, policyDraft, ...rest}: TProps, ref: ForwardedRef<TRef>) {
if (isLoadingReportData && isEmpty(policy) && isEmpty(policyDraft)) {
return <FullscreenLoadingIndicator />;
}

return (
<WrappedComponent
// eslint-disable-next-line react/jsx-props-no-spreading
{...(rest as TProps)}
isLoadingReportData={isLoadingReportData}
policy={policy}
policyDraft={policyDraft}
ref={ref}
/>
);
}

WithPolicyAndFullscreenLoading.displayName = `WithPolicyAndFullscreenLoading`;

return compose(
withOnyx<TProps & RefAttributes<TRef>, WithPolicyAndFullscreenLoadingOnyxProps>({
isLoadingReportData: {
key: ONYXKEYS.IS_LOADING_REPORT_DATA,
},
}),
withPolicy,
)(forwardRef(WithPolicyAndFullscreenLoading));
}
Loading