Skip to content

Commit

Permalink
Merge branch 'Expensify:main' into fix/crash-ssidebarutils
Browse files Browse the repository at this point in the history
  • Loading branch information
aimane-chnaif authored Mar 21, 2024
2 parents 81f4e10 + 34731fe commit 2a8577c
Showing 12 changed files with 43 additions and 20 deletions.
4 changes: 3 additions & 1 deletion src/components/AvatarWithImagePicker.tsx
Original file line number Diff line number Diff line change
@@ -287,11 +287,12 @@ function AvatarWithImagePicker({

return (
<View style={StyleSheet.flatten([styles.alignItemsCenter, style])}>
<View style={[styles.pRelative, avatarStyle]}>
<View style={styles.w100}>
<OfflineWithFeedback
pendingAction={pendingAction}
errors={errors}
errorRowStyles={errorRowStyles}
style={type === CONST.ICON_TYPE_AVATAR && styles.alignItemsCenter}
onClose={onErrorClose}
>
<Tooltip
@@ -310,6 +311,7 @@ function AvatarWithImagePicker({
accessibilityLabel={translate('avatarWithImagePicker.editImage')}
disabled={isAvatarCropModalOpen || (disabled && !enablePreview)}
disabledStyle={disabledStyle}
style={[styles.pRelative, avatarStyle]}
ref={anchorRef}
>
<View>
2 changes: 1 addition & 1 deletion src/components/Form/FormWrapper.tsx
Original file line number Diff line number Diff line change
@@ -110,7 +110,7 @@ function FormWrapper({
buttonText={submitButtonText}
isAlertVisible={((!isEmptyObject(errors) || !isEmptyObject(formState?.errorFields)) && !shouldHideFixErrorsAlert) || !!errorMessage}
isLoading={!!formState?.isLoading}
message={typeof errorMessage === 'string' && isEmptyObject(formState?.errorFields) ? errorMessage : undefined}
message={isEmptyObject(formState?.errorFields) ? errorMessage : undefined}
onSubmit={onSubmit}
footerContent={footerContent}
onFixTheErrorsLinkPressed={onFixTheErrorsLinkPressed}
2 changes: 1 addition & 1 deletion src/libs/API/types.ts
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ type ApiRequest = ValueOf<typeof CONST.API_REQUEST_TYPE>;
const WRITE_COMMANDS = {
SET_WORKSPACE_AUTO_REPORTING: 'SetWorkspaceAutoReporting',
SET_WORKSPACE_AUTO_REPORTING_FREQUENCY: 'SetWorkspaceAutoReportingFrequency',
SET_WORKSPACE_AUTO_REPORTING_MONTHLY_OFFSET: 'UpdatePolicy',
SET_WORKSPACE_AUTO_REPORTING_MONTHLY_OFFSET: 'SetWorkspaceAutoReportingOffset',
SET_WORKSPACE_APPROVAL_MODE: 'SetWorkspaceApprovalMode',
SET_WORKSPACE_PAYER: 'SetWorkspacePayer',
SET_WORKSPACE_REIMBURSEMENT: 'SetWorkspaceReimbursement',
7 changes: 5 additions & 2 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
@@ -104,9 +104,12 @@ function isCreatedAction(reportAction: OnyxEntry<ReportAction>): boolean {
}

function isDeletedAction(reportAction: OnyxEntry<ReportAction | OptimisticIOUReportAction>): boolean {
// A deleted comment has either an empty array or an object with html field with empty string as value
const message = reportAction?.message ?? [];
return message.length === 0 || message[0]?.html === '';

// A legacy deleted comment has either an empty array or an object with html field with empty string as value
const isLegacyDeletedComment = message.length === 0 || message[0]?.html === '';

return isLegacyDeletedComment || !!message[0]?.deleted;
}

function isDeletedParentAction(reportAction: OnyxEntry<ReportAction>): boolean {
12 changes: 5 additions & 7 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
@@ -3626,7 +3626,7 @@ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.Repor

if (updatedReportPreviewAction?.message?.[0]) {
updatedReportPreviewAction.message[0].text = messageText;
updatedReportPreviewAction.message[0].html = shouldDeleteIOUReport ? '' : messageText;
updatedReportPreviewAction.message[0].deleted = shouldDeleteIOUReport ? DateUtils.getDBTime() : '';
}

if (updatedReportPreviewAction && reportPreviewAction?.childMoneyRequestCount && reportPreviewAction?.childMoneyRequestCount > 0) {
@@ -3731,12 +3731,10 @@ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.Repor
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport?.reportID}`,
value: {
[reportPreviewAction?.reportActionID ?? '']: shouldDeleteIOUReport
? null
: {
pendingAction: null,
errors: null,
},
[reportPreviewAction?.reportActionID ?? '']: {
pendingAction: null,
errors: null,
},
},
},
];
8 changes: 7 additions & 1 deletion src/pages/workspace/WorkspacePageWithSections.tsx
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import ScrollViewWithContext from '@components/ScrollViewWithContext';
import useNetwork from '@hooks/useNetwork';
import usePrevious from '@hooks/usePrevious';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import BankAccount from '@libs/models/BankAccount';
@@ -127,6 +128,7 @@ function WorkspacePageWithSections({
const {isSmallScreenWidth} = useWindowDimensions();
const firstRender = useRef(true);
const isFocused = useIsFocused();
const prevPolicy = usePrevious(policy);

useEffect(() => {
// Because isLoading is false before merging in Onyx, we need firstRender ref to display loading page as well before isLoading is change to true
@@ -143,7 +145,11 @@ function WorkspacePageWithSections({
return true;
}

return (!isEmptyObject(policy) && !PolicyUtils.isPolicyAdmin(policy) && !shouldShowNonAdmin) || PolicyUtils.isPendingDeletePolicy(policy);
// We check isPendingDelete for both policy and prevPolicy to prevent the NotFound view from showing right after we delete the workspace
return (
(!isEmptyObject(policy) && !PolicyUtils.isPolicyAdmin(policy) && !shouldShowNonAdmin) ||
(PolicyUtils.isPendingDeletePolicy(policy) && PolicyUtils.isPendingDeletePolicy(prevPolicy))
);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [policy, shouldShowNonAdmin]);

4 changes: 2 additions & 2 deletions src/pages/workspace/WorkspaceProfilePage.tsx
Original file line number Diff line number Diff line change
@@ -140,7 +140,7 @@ function WorkspaceProfilePage({policy, currencyList = {}, route}: WorkSpaceProfi
type={CONST.ICON_TYPE_WORKSPACE}
fallbackIcon={Expensicons.FallbackWorkspaceAvatar}
style={[
isSmallScreenWidth ? styles.mb1 : styles.mb3,
policy?.errorFields?.avatar ?? isSmallScreenWidth ? styles.mb1 : styles.mb3,
isSmallScreenWidth ? styles.mtn17 : styles.mtn20,
styles.alignItemsStart,
styles.sectionMenuItemTopDescription,
@@ -158,7 +158,7 @@ function WorkspaceProfilePage({policy, currencyList = {}, route}: WorkSpaceProfi
originalFileName={policy?.originalFileName}
disabled={readOnly}
disabledStyle={styles.cursorDefault}
errorRowStyles={undefined}
errorRowStyles={styles.mt3}
/>
<OfflineWithFeedback pendingAction={policy?.pendingFields?.generalSettings}>
<MenuItemWithTopDescription
Original file line number Diff line number Diff line change
@@ -80,6 +80,9 @@ function WorkspaceAutoReportingFrequencyPage({policy, route}: WorkspaceAutoRepor
if (typeof policy?.autoReportingOffset === 'number') {
return toLocaleOrdinal(policy.autoReportingOffset);
}
if (typeof policy?.autoReportingOffset === 'string' && parseInt(policy?.autoReportingOffset, 10)) {
return toLocaleOrdinal(parseInt(policy.autoReportingOffset, 10));
}

return translate(`workflowsPage.frequencies.${policy?.autoReportingOffset}`);
};
3 changes: 3 additions & 0 deletions src/types/onyx/ReportAction.ts
Original file line number Diff line number Diff line change
@@ -70,6 +70,9 @@ type Message = {

/** resolution for actionable mention whisper */
resolution?: ValueOf<typeof CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION> | null;

/** The time this report action was deleted */
deleted?: string;
};

type ImageMetadata = {
7 changes: 5 additions & 2 deletions tests/utils/LHNTestUtils.tsx
Original file line number Diff line number Diff line change
@@ -142,11 +142,14 @@ function getFakeReport(participantAccountIDs = [1, 2], millisecondsInThePast = 0
function getFakeReportAction(actor = 'email1@test.com', millisecondsInThePast = 0): ReportAction {
const timestamp = Date.now() - millisecondsInThePast;
const created = DateUtils.getDBTime(timestamp);
const previousReportActionID = lastFakeReportActionID;
const reportActionID = ++lastFakeReportActionID;

return {
actor,
actorAccountID: 1,
reportActionID: `${++lastFakeReportActionID}`,
reportActionID: `${reportActionID}`,
previousReportActionID: `${previousReportActionID}`,
actionName: CONST.REPORT.ACTIONS.TYPE.CREATED,
shouldShow: true,
created,
@@ -183,7 +186,7 @@ function getFakeReportAction(actor = 'email1@test.com', millisecondsInThePast =
},
],
originalMessage: {
childReportID: `${++lastFakeReportActionID}`,
childReportID: `${reportActionID}`,
emojiReactions: {
heart: {
createdAt: '2023-08-28 15:27:52',
9 changes: 7 additions & 2 deletions tests/utils/ReportTestUtils.ts
Original file line number Diff line number Diff line change
@@ -39,16 +39,20 @@ const getFakeReportAction = (index: number, actionName?: ActionName): ReportActi
text: 'email@test.com',
},
],
previousReportActionID: '1',
reportActionID: index.toString(),
previousReportActionID: (index === 0 ? 0 : index - 1).toString(),
reportActionTimestamp: 1696243169753,
sequenceNumber: 0,
shouldShow: true,
timestamp: 1696243169,
whisperedToAccountIDs: [],
} as ReportAction);

const getMockedSortedReportActions = (length = 100): ReportAction[] => Array.from({length}, (element, index): ReportAction => getFakeReportAction(index));
const getMockedSortedReportActions = (length = 100): ReportAction[] =>
Array.from({length}, (element, index): ReportAction => {
const actionName: ActionName = index === 0 ? 'CREATED' : 'ADDCOMMENT';
return getFakeReportAction(index + 1, actionName);
}).reverse();

const getMockedReportActionsMap = (length = 100): ReportActions => {
const mockReports: ReportActions[] = Array.from({length}, (element, index): ReportActions => {
@@ -60,6 +64,7 @@ const getMockedReportActionsMap = (length = 100): ReportActions => {
originalMessage: {
linkedReportID: reportID.toString(),
},
previousReportActionID: index.toString(),
} as ReportAction;

return {[reportID]: reportAction};
2 changes: 1 addition & 1 deletion tests/utils/collections/reportActions.ts
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ export default function createRandomReportAction(index: number): ReportAction {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
actionName: rand(flattenActionNamesValues(CONST.REPORT.ACTIONS.TYPE)) as any,
reportActionID: index.toString(),
previousReportActionID: index.toString(),
previousReportActionID: (index === 0 ? 0 : index - 1).toString(),
actorAccountID: index,
person: [
{

0 comments on commit 2a8577c

Please sign in to comment.