Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 2 deletions src/components/OfflineWithFeedback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import CONST from '@src/CONST';
import type * as OnyxCommon from '@src/types/onyx/OnyxCommon';
import type {ReceiptErrors} from '@src/types/onyx/Transaction';
import type ChildrenProps from '@src/types/utils/ChildrenProps';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyValueObject} from '@src/types/utils/EmptyObject';
import CustomStylesForChildrenProvider from './CustomStylesForChildrenProvider';
import ErrorMessageRow from './ErrorMessageRow';
import ImageSVG from './ImageSVG';
Expand Down Expand Up @@ -97,7 +97,7 @@ function OfflineWithFeedback({
const StyleUtils = useStyleUtils();
const {isOffline} = useNetwork();

const hasErrors = !isEmptyObject(errors ?? {});
const hasErrors = !isEmptyValueObject(errors ?? {});

const isOfflinePendingAction = !!isOffline && !!pendingAction;
const isUpdateOrDeleteError = hasErrors && (pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE);
Expand Down
11 changes: 6 additions & 5 deletions src/libs/ErrorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {TranslationPaths} from '@src/languages/types';
import type {ErrorFields, Errors, TranslationKeyError, TranslationKeyErrors} from '@src/types/onyx/OnyxCommon';
import type Response from '@src/types/onyx/Response';
import type {ReceiptError} from '@src/types/onyx/Transaction';
import {isEmptyValueObject} from '@src/types/utils/EmptyObject';
import DateUtils from './DateUtils';
// eslint-disable-next-line @typescript-eslint/no-deprecated
import {translateLocal} from './Localize';
Expand Down Expand Up @@ -94,7 +95,7 @@ function getLatestErrorMessage<TOnyxData extends OnyxDataWithErrors>(onyxData: O
function getLatestErrorMessageField<TOnyxData extends OnyxDataWithErrors>(onyxData: OnyxEntry<TOnyxData>): Errors {
const errors = onyxData?.errors ?? {};

if (Object.keys(errors).length === 0) {
if (isEmptyValueObject(errors)) {
return {};
}

Expand All @@ -110,7 +111,7 @@ type OnyxDataWithErrorFields = {
function getLatestErrorField<TOnyxData extends OnyxDataWithErrorFields>(onyxData: OnyxEntry<TOnyxData>, fieldName: string): Errors {
const errorsForField = onyxData?.errorFields?.[fieldName] ?? {};

if (Object.keys(errorsForField).length === 0) {
if (isEmptyValueObject(errorsForField)) {
return {};
}

Expand All @@ -121,7 +122,7 @@ function getLatestErrorField<TOnyxData extends OnyxDataWithErrorFields>(onyxData
function getEarliestErrorField<TOnyxData extends OnyxDataWithErrorFields>(onyxData: OnyxEntry<TOnyxData>, fieldName: string): Errors {
const errorsForField = onyxData?.errorFields?.[fieldName] ?? {};

if (Object.keys(errorsForField).length === 0) {
if (isEmptyValueObject(errorsForField)) {
return {};
}

Expand All @@ -135,7 +136,7 @@ function getEarliestErrorField<TOnyxData extends OnyxDataWithErrorFields>(onyxDa
function getLatestErrorFieldForAnyField<TOnyxData extends OnyxDataWithErrorFields>(onyxData: OnyxEntry<TOnyxData>): Errors {
const errorFields = onyxData?.errorFields ?? {};

if (Object.keys(errorFields).length === 0) {
if (isEmptyValueObject(errorFields)) {
return {};
}

Expand All @@ -145,7 +146,7 @@ function getLatestErrorFieldForAnyField<TOnyxData extends OnyxDataWithErrorField
}

function getLatestError(errors?: Errors): Errors {
if (!errors || Object.keys(errors).length === 0) {
if (!errors || isEmptyValueObject(errors)) {
return {};
}

Expand Down
8 changes: 4 additions & 4 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import type {PendingChatMember} from '@src/types/onyx/ReportMetadata';
import type {OnyxData} from '@src/types/onyx/Request';
import type {Comment, TransactionChanges, WaypointCollection} from '@src/types/onyx/Transaction';
import type {FileObject} from '@src/types/utils/Attachment';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject, isEmptyValueObject} from '@src/types/utils/EmptyObject';
import type IconAsset from '@src/types/utils/IconAsset';
import {getBankAccountFromID} from './actions/BankAccounts';
import {
Expand Down Expand Up @@ -9328,7 +9328,7 @@ function getAllReportActionsErrorsAndReportActionThatRequiresAttention(
let reportAction: OnyxEntry<ReportAction>;

for (const action of reportActionsArray) {
if (action && !isEmptyObject(action.errors)) {
if (action && !isEmptyValueObject(action.errors)) {
Object.assign(reportActionErrors, action.errors);

if (!reportAction) {
Expand Down Expand Up @@ -11070,11 +11070,11 @@ function hasActionWithErrorsForTransaction(reportID: string | undefined, transac
.some((action) => {
if (isMoneyRequestAction(action) && getOriginalMessage(action)?.IOUTransactionID) {
if (getOriginalMessage(action)?.IOUTransactionID === transaction?.transactionID) {
return !isEmptyObject(action.errors);
return !isEmptyValueObject(action.errors);
}
return false;
}
return !isEmptyObject(action.errors);
return !isEmptyValueObject(action.errors);
});
}

Expand Down
11 changes: 6 additions & 5 deletions src/pages/home/report/PureReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import DisplayNames from '@components/DisplayNames';
import Hoverable from '@components/Hoverable';
import MentionReportContext from '@components/HTMLEngineProvider/HTMLRenderers/MentionReportRenderer/MentionReportContext';
import Icon from '@components/Icon';
import {Eye} from '@components/Icon/Expensicons';
import InlineSystemMessage from '@components/InlineSystemMessage';
import KYCWall from '@components/KYCWall';
import {KYCWallContext} from '@components/KYCWall/KYCWallContext';
Expand All @@ -40,6 +39,7 @@ import Text from '@components/Text';
import TextLink from '@components/TextLink';
import UnreadActionIndicator from '@components/UnreadActionIndicator';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import usePreferredPolicy from '@hooks/usePreferredPolicy';
import usePrevious from '@hooks/usePrevious';
Expand Down Expand Up @@ -197,7 +197,7 @@ import ROUTES from '@src/ROUTES';
import type * as OnyxTypes from '@src/types/onyx';
import type {Errors} from '@src/types/onyx/OnyxCommon';
import type {JoinWorkspaceResolution, OriginalMessageMovedTransaction} from '@src/types/onyx/OriginalMessage';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject, isEmptyValueObject} from '@src/types/utils/EmptyObject';
import {RestrictedReadOnlyContextMenuActions} from './ContextMenu/ContextMenuActions';
import MiniReportActionContextMenu from './ContextMenu/MiniReportActionContextMenu';
import type {ContextMenuAnchor} from './ContextMenu/ReportActionContextMenu';
Expand Down Expand Up @@ -504,6 +504,7 @@ function PureReportActionItem({
isActionableMentionWhisper(action) || isActionableMentionInviteToSubmitExpenseConfirmWhisper(action) || isActionableTrackExpense(action) || isActionableReportMentionWhisper(action);
const isReportArchived = useReportIsArchived(reportID);
const isOriginalReportArchived = useReportIsArchived(originalReportID);
const expensifyIcons = useMemoizedLazyExpensifyIcons(['Eye'] as const);

const highlightedBackgroundColorIfNeeded = useMemo(
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
Expand Down Expand Up @@ -675,7 +676,7 @@ function PureReportActionItem({
const showPopover = useCallback(
(event: GestureResponderEvent | MouseEvent) => {
// Block menu on the message being Edited or if the report action item has errors
if (draftMessage !== undefined || !isEmptyObject(action.errors) || !shouldDisplayContextMenu) {
if (draftMessage !== undefined || !isEmptyValueObject(action.errors) || !shouldDisplayContextMenu) {
return;
}

Expand Down Expand Up @@ -1705,7 +1706,7 @@ function PureReportActionItem({
return null;
}

const hasErrors = !isEmptyObject(action.errors);
const hasErrors = !isEmptyValueObject(action.errors);
const whisperedTo = getWhisperedTo(action);
const isMultipleParticipant = whisperedTo.length > 1;

Expand Down Expand Up @@ -1822,7 +1823,7 @@ function PureReportActionItem({
<View style={[styles.pl6, styles.mr3]}>
<Icon
fill={theme.icon}
src={Eye}
src={expensifyIcons.Eye}
small
/>
</View>
Expand Down
6 changes: 5 additions & 1 deletion src/types/utils/EmptyObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ function getEmptyObject<T>(): T {
return CONST.EMPTY_OBJECT as T;
}

export {isEmptyObject, getEmptyObject};
function isEmptyValueObject<T>(obj: T | EmptyValue) {
return Object.values(obj ?? {}).filter((value) => value !== undefined && value !== null).length === 0;
}

export {isEmptyObject, getEmptyObject, isEmptyValueObject};
export type {EmptyObject};
Loading