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

Add ReportNameValuePairs key to Report Type #40661

Merged
merged 16 commits into from
May 14, 2024
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
2 changes: 2 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ const ONYXKEYS = {
WORKSPACE_INVITE_MEMBERS_DRAFT: 'workspaceInviteMembersDraft_',
WORKSPACE_INVITE_MESSAGE_DRAFT: 'workspaceInviteMessageDraft_',
REPORT: 'report_',
REPORT_NAME_VALUE_PAIRS: 'reportNameValuePairs_',
REPORT_DRAFT: 'reportDraft_',
// REPORT_METADATA is a perf optimization used to hold loading states (isLoadingInitialReportActions, isLoadingOlderReportActions, isLoadingNewerReportActions).
// A lot of components are connected to the Report entity and do not care about the actions. Setting the loading state
Expand Down Expand Up @@ -548,6 +549,7 @@ type OnyxCollectionValuesMapping = {
[ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MEMBERS_DRAFT]: OnyxTypes.InvitedEmailsToAccountIDs;
[ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MESSAGE_DRAFT]: string;
[ONYXKEYS.COLLECTION.REPORT]: OnyxTypes.Report;
[ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS]: OnyxTypes.ReportNameValuePairs;
[ONYXKEYS.COLLECTION.REPORT_DRAFT]: OnyxTypes.Report;
[ONYXKEYS.COLLECTION.REPORT_METADATA]: OnyxTypes.ReportMetadata;
[ONYXKEYS.COLLECTION.REPORT_ACTIONS]: OnyxTypes.ReportActions;
Expand Down
11 changes: 8 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import type {
Report,
ReportAction,
ReportMetadata,
ReportNameValuePairs,
Session,
Task,
TaxRate,
Expand Down Expand Up @@ -1223,7 +1224,11 @@ function isClosedExpenseReportWithNoExpenses(report: OnyxEntry<Report>): boolean
/**
* Whether the provided report is an archived room
*/
function isArchivedRoom(report: OnyxEntry<Report> | EmptyObject): boolean {
function isArchivedRoom(report: OnyxEntry<Report> | EmptyObject, reportNameValuePairs?: OnyxEntry<ReportNameValuePairs> | EmptyObject): boolean {
if (reportNameValuePairs) {
return reportNameValuePairs.isArchived;
}

return report?.statusNum === CONST.REPORT.STATUS_NUM.CLOSED && report?.stateNum === CONST.REPORT.STATE_NUM.APPROVED;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to delete this (and the report param) at some point, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we do, I put some information about that in the "Plan of action" section of his Design Doc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok please do not forget (I'd create an issue, but I have no memory)

}

Expand Down Expand Up @@ -5729,15 +5734,15 @@ function isMoneyRequestReportPendingDeletion(report: OnyxEntry<Report> | EmptyOb
return parentReportAction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
}

function canUserPerformWriteAction(report: OnyxEntry<Report>) {
function canUserPerformWriteAction(report: OnyxEntry<Report>, reportNameValuePairs?: OnyxEntry<ReportNameValuePairs>) {
const reportErrors = getAddWorkspaceRoomOrChatReportErrors(report);

// If the expense report is marked for deletion, let us prevent any further write action.
if (isMoneyRequestReportPendingDeletion(report)) {
return false;
}

return !isArchivedRoom(report) && isEmptyObject(reportErrors) && report && isAllowedToComment(report) && !isAnonymousUser && canWriteInReport(report);
return !isArchivedRoom(report, reportNameValuePairs) && isEmptyObject(reportErrors) && report && isAllowedToComment(report) && !isAnonymousUser && canWriteInReport(report);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ type ReportScreenOnyxPropsWithoutParentReportAction = {
/** The report currently being looked at */
report: OnyxEntry<OnyxTypes.Report>;

reportNameValuePairs: OnyxEntry<OnyxTypes.ReportNameValuePairs>;

/** The report metadata loading states */
reportMetadata: OnyxEntry<OnyxTypes.ReportMetadata>;
};
Expand Down Expand Up @@ -133,6 +135,7 @@ function ReportScreen({
betas = [],
route,
report: reportProp,
reportNameValuePairs,
sortedAllReportActions,
reportMetadata = {
isLoadingInitialReportActions: true,
Expand Down Expand Up @@ -725,6 +728,7 @@ function ReportScreen({
onComposerFocus={() => setIsComposerFocus(true)}
onComposerBlur={() => setIsComposerFocus(false)}
report={report}
reportNameValuePairs={reportNameValuePairs}
pendingAction={reportPendingAction}
isComposerFullSize={!!isComposerFullSize}
listHeight={listHeight}
Expand Down Expand Up @@ -761,6 +765,10 @@ export default withCurrentReportID(
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${getReportID(route)}`,
allowStaleData: true,
},
reportNameValuePairs: {
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${getReportID(route)}`,
allowStaleData: true,
},
reportMetadata: {
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT_METADATA}${getReportID(route)}`,
initialValue: {
Expand Down
7 changes: 5 additions & 2 deletions src/pages/home/report/ReportFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type ReportFooterProps = ReportFooterOnyxProps & {
/** Report object for the current report */
report?: OnyxTypes.Report;

reportNameValuePairs?: OnyxEntry<OnyxTypes.ReportNameValuePairs>;

/** The last report action */
lastReportAction?: OnyxEntry<OnyxTypes.ReportAction>;

Expand Down Expand Up @@ -66,6 +68,7 @@ function ReportFooter({
pendingAction,
session,
report = {reportID: '0'},
reportNameValuePairs,
shouldShowComposeInput = false,
isEmptyChat = true,
isReportReadyForDisplay = true,
Expand All @@ -78,11 +81,11 @@ function ReportFooter({
const {isOffline} = useNetwork();
const {windowWidth, isSmallScreenWidth} = useWindowDimensions();
const chatFooterStyles = {...styles.chatFooter, minHeight: !isOffline ? CONST.CHAT_FOOTER_MIN_HEIGHT : 0};
const isArchivedRoom = ReportUtils.isArchivedRoom(report);
const isArchivedRoom = ReportUtils.isArchivedRoom(report, reportNameValuePairs);
const isAnonymousUser = session?.authTokenType === CONST.AUTH_TOKEN_TYPES.ANONYMOUS;

const isSmallSizeLayout = windowWidth - (isSmallScreenWidth ? 0 : variables.sideBarWidth) < variables.anonymousReportFooterBreakpoint;
const hideComposer = !ReportUtils.canUserPerformWriteAction(report);
const hideComposer = !ReportUtils.canUserPerformWriteAction(report, reportNameValuePairs);
const canWriteInReport = ReportUtils.canWriteInReport(report);
const isSystemChat = ReportUtils.isSystemChat(report);

Expand Down
7 changes: 7 additions & 0 deletions src/types/onyx/ReportNameValuePairs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type * as OnyxCommon from './OnyxCommon';

type ReportNameValuePairs = OnyxCommon.OnyxValueWithOfflineFeedback<{
isArchived: boolean;
}>;

export default ReportNameValuePairs;
2 changes: 2 additions & 0 deletions src/types/onyx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import type ReportActionReactions from './ReportActionReactions';
import type ReportActionsDraft from './ReportActionsDraft';
import type ReportActionsDrafts from './ReportActionsDrafts';
import type ReportMetadata from './ReportMetadata';
import type ReportNameValuePairs from './ReportNameValuePairs';
import type ReportNextStep from './ReportNextStep';
import type ReportUserIsTyping from './ReportUserIsTyping';
import type Request from './Request';
Expand Down Expand Up @@ -134,6 +135,7 @@ export type {
RecentlyUsedTags,
ReimbursementAccount,
Report,
ReportNameValuePairs,
ReportAction,
ReportActionReactions,
ReportActions,
Expand Down
Loading