From 23b7590f95918435ad892244cdafff5095cb7ec0 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Mon, 25 Sep 2023 14:52:17 +0200 Subject: [PATCH 1/5] add checks for edit request page for categories and tags --- src/pages/EditRequestPage.js | 37 ++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index 5e6e0dd3f17b..5aea5c17f5e3 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -1,6 +1,7 @@ -import React, {useEffect} from 'react'; +import React, {useEffect, useMemo} from 'react'; import PropTypes from 'prop-types'; import lodashGet from 'lodash/get'; +import lodashValues from 'lodash/values'; import {withOnyx} from 'react-native-onyx'; import CONST from '../CONST'; import ONYXKEYS from '../ONYXKEYS'; @@ -13,6 +14,8 @@ import * as TransactionUtils from '../libs/TransactionUtils'; import * as Policy from '../libs/actions/Policy'; import * as IOU from '../libs/actions/IOU'; import * as CurrencyUtils from '../libs/CurrencyUtils'; +import * as OptionsListUtils from '../libs/OptionsListUtils'; +import Permissions from '../libs/Permissions'; import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsPropTypes} from '../components/withCurrentUserPersonalDetails'; import tagPropTypes from '../components/tagPropTypes'; import FullPageNotFoundView from '../components/BlockingViews/FullPageNotFoundView'; @@ -24,6 +27,7 @@ import EditRequestReceiptPage from './EditRequestReceiptPage'; import EditRequestCategoryPage from './EditRequestCategoryPage'; import EditRequestTagPage from './EditRequestTagPage'; import reportPropTypes from './reportPropTypes'; +import categoryPropTypes from '../components/categoryPropTypes'; const propTypes = { /** Route from navigation */ @@ -39,6 +43,9 @@ const propTypes = { }).isRequired, /** Onyx props */ + /** List of betas available to current user */ + betas: PropTypes.arrayOf(PropTypes.string), + /** The report object for the thread report */ report: reportPropTypes, @@ -60,6 +67,9 @@ const propTypes = { email: PropTypes.string, }), + /** Collection of categories attached to a policy */ + policyCategories: PropTypes.objectOf(categoryPropTypes), + /** Collection of tags attached to a policy */ policyTags: tagPropTypes, @@ -67,16 +77,18 @@ const propTypes = { }; const defaultProps = { + betas: [], report: {}, parentReport: {}, policy: null, session: { email: null, }, + policyCategories: {}, policyTags: {}, }; -function EditRequestPage({report, route, parentReport, policy, session, policyTags}) { +function EditRequestPage({betas, report, route, parentReport, policy, session, policyCategories, policyTags}) { const parentReportAction = ReportActionsUtils.getParentReportAction(report); const transaction = TransactionUtils.getLinkedTransaction(parentReportAction); const { @@ -102,8 +114,19 @@ function EditRequestPage({report, route, parentReport, policy, session, policyTa const canEdit = !isSettled && !isDeleted && (isAdmin || isRequestor); // For now, it always defaults to the first tag of the policy + const policyTag = PolicyUtils.getTag(policyTags); + const policyTagList = lodashGet(policyTag, 'tags', {}); const tagListName = PolicyUtils.getTagListName(policyTags); + // A flag for verifying that the current report is a sub-report of a workspace chat + const isPolicyExpenseChat = useMemo(() => ReportUtils.isPolicyExpenseChat(ReportUtils.getRootParentReport(report)), [report]); + + // A flag for showing the categories page + const shouldShowCategories = isPolicyExpenseChat && Permissions.canUseCategories(betas) && OptionsListUtils.hasEnabledOptions(lodashValues(policyCategories)); + + // A flag for showing the tags page + const shouldShowTags = isPolicyExpenseChat && Permissions.canUseTags(betas) && OptionsListUtils.hasEnabledOptions(lodashValues(policyTagList)); + // Dismiss the modal when the request is paid or deleted useEffect(() => { if (canEdit) { @@ -191,7 +214,7 @@ function EditRequestPage({report, route, parentReport, policy, session, policyTa ); } - if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.CATEGORY) { + if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.CATEGORY && shouldShowCategories) { return ( `${ONYXKEYS.COLLECTION.REPORT}${report ? report.parentReportID : '0'}`, }, policy: { key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`, }, + policyCategories: { + key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report ? report.policyID : '0'}`, + }, policyTags: { key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report ? report.policyID : '0'}`, }, From 5e2fc2aaa10dcf4e7cda236ba4e30de9f334c164 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Mon, 25 Sep 2023 14:54:02 +0200 Subject: [PATCH 2/5] add testID for EditRequestTagPage --- src/pages/EditRequestTagPage.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/EditRequestTagPage.js b/src/pages/EditRequestTagPage.js index 72ed072eec16..a3525f2df23f 100644 --- a/src/pages/EditRequestTagPage.js +++ b/src/pages/EditRequestTagPage.js @@ -31,6 +31,7 @@ function EditRequestTagPage({defaultTag, policyID, tagName, onSubmit}) { Date: Mon, 25 Sep 2023 15:27:52 +0200 Subject: [PATCH 3/5] handle selected tag and category --- src/pages/EditRequestPage.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index 5aea5c17f5e3..c56d256502fe 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -122,10 +122,10 @@ function EditRequestPage({betas, report, route, parentReport, policy, session, p const isPolicyExpenseChat = useMemo(() => ReportUtils.isPolicyExpenseChat(ReportUtils.getRootParentReport(report)), [report]); // A flag for showing the categories page - const shouldShowCategories = isPolicyExpenseChat && Permissions.canUseCategories(betas) && OptionsListUtils.hasEnabledOptions(lodashValues(policyCategories)); + const shouldShowCategories = isPolicyExpenseChat && Permissions.canUseCategories(betas) && (transactionCategory || OptionsListUtils.hasEnabledOptions(lodashValues(policyCategories))); // A flag for showing the tags page - const shouldShowTags = isPolicyExpenseChat && Permissions.canUseTags(betas) && OptionsListUtils.hasEnabledOptions(lodashValues(policyTagList)); + const shouldShowTags = isPolicyExpenseChat && Permissions.canUseTags(betas) && (transactionTag || OptionsListUtils.hasEnabledOptions(lodashValues(policyTagList))); // Dismiss the modal when the request is paid or deleted useEffect(() => { From d0c10472bcd75d6f56c617bf2e5e458319792598 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Mon, 25 Sep 2023 16:08:20 +0200 Subject: [PATCH 4/5] add screen wrapper for not found view --- src/pages/EditRequestPage.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index c56d256502fe..352990e38cc5 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -28,6 +28,7 @@ import EditRequestCategoryPage from './EditRequestCategoryPage'; import EditRequestTagPage from './EditRequestTagPage'; import reportPropTypes from './reportPropTypes'; import categoryPropTypes from '../components/categoryPropTypes'; +import ScreenWrapper from '../components/ScreenWrapper'; const propTypes = { /** Route from navigation */ @@ -259,7 +260,15 @@ function EditRequestPage({betas, report, route, parentReport, policy, session, p ); } - return ; + return ( + + + + ); } EditRequestPage.displayName = 'EditRequestPage'; From b7188e62f8d45e77329c8d9344aae24da3da135c Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 29 Sep 2023 11:05:43 +0200 Subject: [PATCH 5/5] fix testID of EditRequestDistancePage --- src/pages/EditRequestDistancePage.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/EditRequestDistancePage.js b/src/pages/EditRequestDistancePage.js index 84aa4de1acb0..3a606aeb8f07 100644 --- a/src/pages/EditRequestDistancePage.js +++ b/src/pages/EditRequestDistancePage.js @@ -101,6 +101,7 @@ function EditRequestDistancePage({report, route, transaction}) {