Skip to content

Commit

Permalink
Merge pull request #34490 from software-mansion-labs/refactor/remove-…
Browse files Browse the repository at this point in the history
…isNotEmptyObject

Remove isNotEmptyObject in favor of !isEmptyObject
  • Loading branch information
tgolen authored Jan 18, 2024
2 parents de639e0 + 190cdd7 commit 31b19ea
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/components/OfflineWithFeedback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import shouldRenderOffscreen from '@libs/shouldRenderOffscreen';
import CONST from '@src/CONST';
import type * as OnyxCommon from '@src/types/onyx/OnyxCommon';
import type ChildrenProps from '@src/types/utils/ChildrenProps';
import {isNotEmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import MessagesRow from './MessagesRow';

/**
Expand Down Expand Up @@ -82,10 +82,10 @@ function OfflineWithFeedback({
const StyleUtils = useStyleUtils();
const {isOffline} = useNetwork();

const hasErrors = isNotEmptyObject(errors ?? {});
const hasErrors = !isEmptyObject(errors ?? {});
// Some errors have a null message. This is used to apply opacity only and to avoid showing redundant messages.
const errorMessages = omitBy(errors, (e) => e === null);
const hasErrorMessages = isNotEmptyObject(errorMessages);
const hasErrorMessages = !isEmptyObject(errorMessages);
const isOfflinePendingAction = !!isOffline && !!pendingAction;
const isUpdateOrDeleteError = hasErrors && (pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE);
const isAddError = hasErrors && pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD;
Expand Down
4 changes: 2 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2564,11 +2564,11 @@ function updateOptimisticParentReportAction(parentReportAction: OnyxEntry<Report
*/
function getOptimisticDataForParentReportAction(reportID: string, lastVisibleActionCreated: string, type: string, parentReportID = '', parentReportActionID = ''): OnyxUpdate | EmptyObject {
const report = getReport(reportID);
if (!report || !!isEmptyObject(report)) {
if (!report || isEmptyObject(report)) {
return {};
}
const parentReportAction = ReportActionsUtils.getParentReportAction(report);
if (!parentReportAction || !!isEmptyObject(parentReportAction)) {
if (!parentReportAction || isEmptyObject(parentReportAction)) {
return {};
}

Expand Down
4 changes: 2 additions & 2 deletions src/pages/home/report/withReportAndReportActionOrNotFound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import NotFoundPage from '@pages/ErrorPage/NotFoundPage';
import * as Report from '@userActions/Report';
import ONYXKEYS from '@src/ONYXKEYS';
import type * as OnyxTypes from '@src/types/onyx';
import {isEmptyObject, isNotEmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

type OnyxProps = {
/** The report currently being looked at */
Expand Down Expand Up @@ -60,7 +60,7 @@ export default function <TProps extends ComponentProps, TRef>(WrappedComponent:
// For small screen, we don't call openReport API when we go to a sub report page by deeplink
// So we need to call openReport here for small screen
useEffect(() => {
if (!props.isSmallScreenWidth || (isNotEmptyObject(props.report) && isNotEmptyObject(reportAction))) {
if (!props.isSmallScreenWidth || (!isEmptyObject(props.report) && !isEmptyObject(reportAction))) {
return;
}
Report.openReport(props.route.params.reportID);
Expand Down
9 changes: 1 addition & 8 deletions src/types/utils/EmptyObject.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import type Falsy from './Falsy';

type EmptyObject = Record<string, never>;

type EmptyValue = EmptyObject | null | undefined;

// eslint-disable-next-line rulesdir/no-negated-variables
function isNotEmptyObject<T extends Record<string, unknown> | Falsy>(arg: T | EmptyObject): arg is NonNullable<T> {
return Object.keys(arg ?? {}).length > 0;
}

function isEmptyObject<T>(obj: T | EmptyValue): obj is EmptyValue {
return Object.keys(obj ?? {}).length === 0;
}

export {isNotEmptyObject, isEmptyObject};
export {isEmptyObject};
export type {EmptyObject};

0 comments on commit 31b19ea

Please sign in to comment.