Skip to content

Commit

Permalink
Merge pull request #40661 from Expensify/srikar-reportNameValuePairs
Browse files Browse the repository at this point in the history
Add ReportNameValuePairs key to Report Type
  • Loading branch information
roryabraham authored May 14, 2024
2 parents 3e99a09 + 1f01ef6 commit 5cf2550
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
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,
Transaction,
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;
}

Expand Down Expand Up @@ -5770,15 +5775,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

0 comments on commit 5cf2550

Please sign in to comment.