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
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@ function extractAttachments(
parentReportAction,
reportActions,
report,
}: {privateNotes?: Record<number, Note>; accountID?: number; parentReportAction?: OnyxEntry<ReportAction>; reportActions?: OnyxEntry<ReportActions>; report: OnyxEntry<Report>},
isReportArchived,
}: {
privateNotes?: Record<number, Note>;
accountID?: number;
parentReportAction?: OnyxEntry<ReportAction>;
reportActions?: OnyxEntry<ReportActions>;
report: OnyxEntry<Report>;
isReportArchived?: boolean;
},
) {
const targetNote = privateNotes?.[Number(accountID)]?.note ?? '';
const description = report?.description ?? '';
const attachments: Attachment[] = [];
const canUserPerformAction = canUserPerformWriteAction(report);
const canUserPerformAction = canUserPerformWriteAction(report, isReportArchived);
let currentLink = '';

const htmlParser = new HtmlParser({
Expand Down
10 changes: 6 additions & 4 deletions src/components/Attachments/AttachmentCarousel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {View} from 'react-native';
import type {Attachment} from '@components/Attachments/types';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import useOnyx from '@hooks/useOnyx';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useThemeStyles from '@hooks/useThemeStyles';
import {canUseTouchScreen as canUseTouchScreenUtil} from '@libs/DeviceCapabilities';
import Navigation from '@libs/Navigation/Navigation';
Expand All @@ -19,6 +20,7 @@ function AttachmentCarousel({report, attachmentID, source, onNavigate, setDownlo
const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, {canEvict: false, canBeMissing: true});
const canUseTouchScreen = canUseTouchScreenUtil();
const styles = useThemeStyles();
const isReportArchived = useReportIsArchived(report.reportID);

const [page, setPage] = useState<number>();
const [attachments, setAttachments] = useState<Attachment[]>([]);
Expand All @@ -41,11 +43,11 @@ function AttachmentCarousel({report, attachmentID, source, onNavigate, setDownlo
const parentReportAction = report.parentReportActionID && parentReportActions ? parentReportActions[report.parentReportActionID] : undefined;
let newAttachments: Attachment[] = [];
if (type === CONST.ATTACHMENT_TYPE.NOTE && accountID) {
newAttachments = extractAttachments(CONST.ATTACHMENT_TYPE.NOTE, {privateNotes: report.privateNotes, accountID, report});
newAttachments = extractAttachments(CONST.ATTACHMENT_TYPE.NOTE, {privateNotes: report.privateNotes, accountID, report, isReportArchived});
} else if (type === CONST.ATTACHMENT_TYPE.ONBOARDING) {
newAttachments = extractAttachments(CONST.ATTACHMENT_TYPE.ONBOARDING, {parentReportAction, reportActions: reportActions ?? undefined, report});
newAttachments = extractAttachments(CONST.ATTACHMENT_TYPE.ONBOARDING, {parentReportAction, reportActions: reportActions ?? undefined, report, isReportArchived});
} else {
newAttachments = extractAttachments(CONST.ATTACHMENT_TYPE.REPORT, {parentReportAction, reportActions: reportActions ?? undefined, report});
newAttachments = extractAttachments(CONST.ATTACHMENT_TYPE.REPORT, {parentReportAction, reportActions: reportActions ?? undefined, report, isReportArchived});
}

if (deepEqual(attachments, newAttachments)) {
Expand Down Expand Up @@ -84,7 +86,7 @@ function AttachmentCarousel({report, attachmentID, source, onNavigate, setDownlo
onNavigate(attachment);
}
}
}, [reportActions, parentReportActions, compareImage, attachments, setDownloadButtonVisibility, onNavigate, accountID, type, report]);
}, [reportActions, parentReportActions, compareImage, attachments, setDownloadButtonVisibility, onNavigate, accountID, type, report, isReportArchived]);

if (page == null) {
return (
Expand Down
2 changes: 2 additions & 0 deletions src/components/LHNOptionsList/OptionRowLHNData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function OptionRowLHNData({
invoiceReceiverPolicy,
card,
localeCompare,
isReportArchived,
});
// eslint-disable-next-line react-compiler/react-compiler
if (deepEqual(item, optionItemRef.current)) {
Expand Down Expand Up @@ -108,6 +109,7 @@ function OptionRowLHNData({
reportAttributes,
card,
localeCompare,
isReportArchived,
]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ function MoneyRequestReportActionsList({
userBillingFundID,
emojiReactions,
draftMessage,
isReportArchived,
],
);

Expand Down
7 changes: 5 additions & 2 deletions src/hooks/useIsReportReadyToDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {OnyxEntry} from 'react-native-onyx';
import {canUserPerformWriteAction} from '@libs/ReportUtils';
import type {Report} from '@src/types/onyx';

function useIsReportReadyToDisplay(report: OnyxEntry<Report>, reportIDFromRoute: string | undefined) {
function useIsReportReadyToDisplay(report: OnyxEntry<Report>, reportIDFromRoute: string | undefined, isReportArchived = false) {
/**
* When false the report is not ready to be fully displayed
*/
Expand All @@ -13,7 +13,10 @@ function useIsReportReadyToDisplay(report: OnyxEntry<Report>, reportIDFromRoute:
return reportIDFromRoute !== '' && !!report?.reportID && !isTransitioning;
}, [report, reportIDFromRoute]);

const isEditingDisabled = useMemo(() => !isCurrentReportLoadedFromOnyx || !canUserPerformWriteAction(report), [isCurrentReportLoadedFromOnyx, report]);
const isEditingDisabled = useMemo(
() => !isCurrentReportLoadedFromOnyx || !canUserPerformWriteAction(report, isReportArchived),
[isCurrentReportLoadedFromOnyx, report, isReportArchived],
);

return {
isCurrentReportLoadedFromOnyx,
Expand Down
4 changes: 3 additions & 1 deletion src/hooks/usePaginatedReportActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import {getSortedReportActionsForDisplay} from '@libs/ReportActionsUtils';
import {canUserPerformWriteAction} from '@libs/ReportUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import useOnyx from './useOnyx';
import useReportIsArchived from './useReportIsArchived';

/**
* Get the longest continuous chunk of reportActions including the linked reportAction. If not linking to a specific action, returns the continuous chunk of newest reportActions.
*/
function usePaginatedReportActions(reportID: string | undefined, reportActionID?: string) {
const nonEmptyStringReportID = getNonEmptyStringOnyxID(reportID);
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${nonEmptyStringReportID}`, {canBeMissing: true});
const hasWriteAccess = canUserPerformWriteAction(report);
const isReportArchived = useReportIsArchived(report?.reportID);
const hasWriteAccess = canUserPerformWriteAction(report, isReportArchived);

const [sortedAllReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${nonEmptyStringReportID}`, {
canEvict: false,
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useSelectedTransactionsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function useSelectedTransactionsActions({
return canMoveExpense;
});

const canUserPerformWriteAction = canUserPerformWriteActionReportUtils(report);
const canUserPerformWriteAction = canUserPerformWriteActionReportUtils(report, isReportArchived);
if (canSelectedExpensesBeMoved && canUserPerformWriteAction) {
options.push({
text: translate('iou.moveExpenses', {count: selectedTransactionIDs.length}),
Expand Down
4 changes: 2 additions & 2 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@
*/
let currentUserLogin: string | undefined;
let currentUserAccountID: number | undefined;
Onyx.connect({

Check warning on line 338 in src/libs/OptionsListUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
currentUserLogin = value?.email;
Expand All @@ -344,19 +344,19 @@
});

let loginList: OnyxEntry<Login>;
Onyx.connect({

Check warning on line 347 in src/libs/OptionsListUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.LOGIN_LIST,
callback: (value) => (loginList = isEmptyObject(value) ? {} : value),
});

let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
Onyx.connect({

Check warning on line 353 in src/libs/OptionsListUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => (allPersonalDetails = isEmptyObject(value) ? {} : value),
});

const policies: OnyxCollection<Policy> = {};
Onyx.connect({

Check warning on line 359 in src/libs/OptionsListUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
callback: (policy, key) => {
if (!policy || !key || !policy.name) {
Expand All @@ -368,14 +368,14 @@
});

let allPolicies: OnyxCollection<Policy> = {};
Onyx.connect({

Check warning on line 371 in src/libs/OptionsListUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (val) => (allPolicies = val),
});

let allReports: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 378 in src/libs/OptionsListUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -384,7 +384,7 @@
});

let allReportNameValuePairs: OnyxCollection<ReportNameValuePairs>;
Onyx.connect({

Check warning on line 387 in src/libs/OptionsListUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -396,7 +396,7 @@
const allSortedReportActions: Record<string, ReportAction[]> = {};
let allReportActions: OnyxCollection<ReportActions>;
const lastVisibleReportActions: ReportActions = {};
Onyx.connect({

Check warning on line 399 in src/libs/OptionsListUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand Down Expand Up @@ -455,13 +455,13 @@
});

let activePolicyID: OnyxEntry<string>;
Onyx.connect({

Check warning on line 458 in src/libs/OptionsListUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_ACTIVE_POLICY_ID,
callback: (value) => (activePolicyID = value),
});

let nvpDismissedProductTraining: OnyxEntry<DismissedProductTraining>;
Onyx.connect({

Check warning on line 464 in src/libs/OptionsListUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING,
callback: (value) => (nvpDismissedProductTraining = value),
});
Expand Down Expand Up @@ -737,7 +737,7 @@
const lastIOUMoneyReportAction = iouReport?.reportID
? allSortedReportActions[iouReport.reportID]?.find(
(reportAction, key): reportAction is ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.IOU> =>
shouldReportActionBeVisible(reportAction, key, canUserPerformWriteAction(report)) &&
shouldReportActionBeVisible(reportAction, key, canUserPerformWriteAction(report, isReportArchived)) &&
reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE &&
isMoneyRequestAction(reportAction),
)
Expand Down Expand Up @@ -1720,7 +1720,7 @@
return false;
}

if (!canUserPerformWriteAction(option.item) && !includeReadOnly) {
if (!canUserPerformWriteAction(option.item, !!option.private_isArchived) && !includeReadOnly) {
Comment thread
thelullabyy marked this conversation as resolved.
return false;
}

Expand Down
4 changes: 3 additions & 1 deletion src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ function getOptionData({
invoiceReceiverPolicy,
card,
localeCompare,
isReportArchived = false,
Comment thread
thelullabyy marked this conversation as resolved.
}: {
report: OnyxEntry<Report>;
oneTransactionThreadReport: OnyxEntry<Report>;
Expand All @@ -627,6 +628,7 @@ function getOptionData({
reportAttributes: OnyxEntry<ReportAttributes>;
card: Card | undefined;
localeCompare: LocaleContextProps['localeCompare'];
isReportArchived?: boolean;
}): OptionData | undefined {
// When a user signs out, Onyx is cleared. Due to the lazy rendering with a virtual list, it's possible for
// this method to be called after the Onyx data has been cleared out. In that case, it's fine to do
Expand Down Expand Up @@ -703,7 +705,7 @@ function getOptionData({
result.parentReportID = report.parentReportID;
result.isWaitingOnBankAccount = report.isWaitingOnBankAccount;
result.notificationPreference = getReportNotificationPreference(report);
result.isAllowedToComment = canUserPerformWriteActionUtil(report);
result.isAllowedToComment = canUserPerformWriteActionUtil(report, isReportArchived);
result.chatType = report.chatType;
result.isDeletedParentAction = report.isDeletedParentAction;
result.isSelfDM = isSelfDM(report);
Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ function getNavigationUrlOnTaskDelete(report: OnyxEntry<OnyxTypes.Report>): stri
/**
* Cancels a task by setting the report state to SUBMITTED and status to CLOSED
*/
function deleteTask(report: OnyxEntry<OnyxTypes.Report>) {
function deleteTask(report: OnyxEntry<OnyxTypes.Report>, isReportArchived: boolean) {
if (!report) {
return;
}
Expand All @@ -1082,7 +1082,7 @@ function deleteTask(report: OnyxEntry<OnyxTypes.Report>) {
const optimisticReportActionID = optimisticCancelReportAction.reportActionID;
const parentReportAction = getParentReportAction(report);
const parentReport = getParentReport(report);
const canUserPerformWriteAction = ReportUtils.canUserPerformWriteAction(report);
const canUserPerformWriteAction = ReportUtils.canUserPerformWriteAction(report, isReportArchived);

// If the task report is the last visible action in the parent report, we should navigate back to the parent report
const shouldDeleteTaskReport = !ReportActionsUtils.doesReportHaveVisibleActions(report.reportID, canUserPerformWriteAction);
Expand Down
3 changes: 2 additions & 1 deletion src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail

const deleteTransaction = useCallback(() => {
if (caseID === CASES.DEFAULT) {
deleteTask(report);
deleteTask(report, isReportArchived);
return;
}

Expand All @@ -792,6 +792,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
removeTransaction,
report,
requestParentReportAction,
isReportArchived,
]);

// A flag to indicate whether the user chose to delete the transaction or not
Expand Down
4 changes: 3 additions & 1 deletion src/pages/Search/SearchMoneyRequestReportPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import MoneyRequestReportView from '@components/MoneyRequestReportView/MoneyRequ
import ScreenWrapper from '@components/ScreenWrapper';
import useIsReportReadyToDisplay from '@hooks/useIsReportReadyToDisplay';
import useOnyx from '@hooks/useOnyx';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
Expand Down Expand Up @@ -46,8 +47,9 @@ function SearchMoneyRequestReportPage({route}: SearchMoneyRequestPageProps) {
const [policies = getEmptyObject<NonNullable<OnyxCollection<Policy>>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, canBeMissing: false});
const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`];
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true});
const isReportArchived = useReportIsArchived(report?.reportID);

const {isEditingDisabled, isCurrentReportLoadedFromOnyx} = useIsReportReadyToDisplay(report, reportIDFromRoute);
const {isEditingDisabled, isCurrentReportLoadedFromOnyx} = useIsReportReadyToDisplay(report, reportIDFromRoute, isReportArchived);

const [scrollPosition, setScrollPosition] = useState<ScrollPosition>({});
const flatListRef = useRef<FlatList>(null);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/HeaderView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked,
isVisible={isDeleteTaskConfirmModalVisible}
onConfirm={() => {
setIsDeleteTaskConfirmModalVisible(false);
deleteTask(report);
deleteTask(report, isReportArchived);
}}
onCancel={() => setIsDeleteTaskConfirmModalVisible(false)}
title={translate('task.deleteTask')}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,9 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
navigation.setParams({reportActionID: ''});
}, [transactionThreadReportID, route?.params?.reportActionID, linkedAction, reportID, navigation, report, childReport]);

const {isEditingDisabled, isCurrentReportLoadedFromOnyx} = useIsReportReadyToDisplay(report, reportIDFromRoute);

const isReportArchived = useReportIsArchived(report?.reportID);
const {isEditingDisabled, isCurrentReportLoadedFromOnyx} = useIsReportReadyToDisplay(report, reportIDFromRoute, isReportArchived);

const isLinkedActionDeleted = useMemo(
() => !!linkedAction && !shouldReportActionBeVisible(linkedAction, linkedAction.reportActionID, canUserPerformWriteAction(report, isReportArchived)),
[linkedAction, report, isReportArchived],
Expand Down
Loading