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

Migrate tasks to use childManagerAccountID #21781

Merged
merged 11 commits into from
Jul 6, 2023
12 changes: 11 additions & 1 deletion src/components/ReportActionItem/TaskPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import lodashGet from 'lodash/get';
import _ from 'underscore';
import compose from '../../libs/compose';
import styles from '../../styles/styles';
Expand All @@ -19,8 +20,12 @@ import reportActionPropTypes from '../../pages/home/report/reportActionPropTypes
import * as TaskUtils from '../../libs/actions/Task';
import RenderHTML from '../RenderHTML';
import PressableWithoutFeedback from '../Pressable/PressableWithoutFeedback';
import personalDetailsPropType from '../../pages/personalDetailsPropType';

const propTypes = {
/** All personal details asssociated with user */
personalDetailsList: personalDetailsPropType,

/** The ID of the associated taskReport */
taskReportID: PropTypes.string.isRequired,

Expand All @@ -47,6 +52,7 @@ const propTypes = {
};

const defaultProps = {
personalDetailsList: {},
taskReport: {},
isHovered: false,
};
Expand All @@ -59,7 +65,8 @@ function TaskPreview(props) {
? props.taskReport.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && props.taskReport.statusNum === CONST.REPORT.STATUS.APPROVED
: props.action.childStateNum === CONST.REPORT.STATE_NUM.SUBMITTED && props.action.childStatusNum === CONST.REPORT.STATUS.APPROVED;
const taskTitle = props.taskReport.reportName || props.action.childReportName;
const taskAssignee = props.taskReport.managerEmail || props.action.childManagerEmail;
const taskAssigneeAccountID = TaskUtils.getTaskAssigneeAccountID(props.taskReport);
Copy link
Contributor

Choose a reason for hiding this comment

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

props.action already has childManagerAccountID. Is there any problem using it directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so - but since we were defaulting to managerEmail first, I thought it would be best if we default to managerID first as well, THEN use childManagerAccountID - and that logic exists in this function so I thought it would be better to reuse it, do you disagree?

Copy link
Contributor

Choose a reason for hiding this comment

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

ok agree. But as I reported, we should fallback to original logic if report.managerID or action.childManagerAccountID doesn't exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"original logic" being props.taskReport.managerEmail || props.action.childManagerEmail;? We're trying to get rid of those :D

Copy link
Collaborator

Choose a reason for hiding this comment

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

We didn't consider the case where the taskReport could be empty and hence it caused a regression here, because the task assignment didn't show an email address.

Copy link
Contributor Author

@Beamanator Beamanator Jul 31, 2023

Choose a reason for hiding this comment

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

hmm if task report could be empty, would this have crashed before too? 🤔 (since we used to directly access props.taskReport.managerEmail)

const taskAssignee = lodashGet(props.personalDetailsList, [taskAssigneeAccountID, 'login'], lodashGet(props.personalDetailsList, [taskAssigneeAccountID, 'displayName'], ''));
Copy link
Contributor

Choose a reason for hiding this comment

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

personally not crazy about this nested lodash, would rather see something like:

Suggested change
const taskAssignee = lodashGet(props.personalDetailsList, [taskAssigneeAccountID, 'login'], lodashGet(props.personalDetailsList, [taskAssigneeAccountID, 'displayName'], ''));
const assigneeLogin = lodashGet(props.personalDetailsList, [taskAssigneeAccountID, 'login'], '');
const assigneeDisplayName = lodashGet(props.personalDetailsList, [taskAssigneeAccountID, 'displayName'], '');
const taskAssignee = assigneeLogin || assigneeDisplayName;

as it's more clear to me that displayName is a fall back if we don't have a login. instead of trying to reason how the 2nd lodashGet might get called and be a fallback for the first call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooh that's totally fair - I'll try to remember to clean this up later - i can see it being useful but not highest priority at the moment

Copy link
Contributor

Choose a reason for hiding this comment

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

Cleanup PR here: #22439

const htmlForTaskPreview = taskAssignee ? `<comment><mention-user>@${taskAssignee}</mention-user> ${taskTitle}</comment>` : `<comment>${taskTitle}</comment>`;

return (
Expand Down Expand Up @@ -106,5 +113,8 @@ export default compose(
taskReport: {
key: ({taskReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`,
},
personalDetailsList: {
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
},
}),
)(TaskPreview);
1 change: 0 additions & 1 deletion src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,6 @@ function buildOptimisticTaskCommentReportAction(taskReportID, taskTitle, taskAss
reportAction.reportAction.parentReportID = parentReportID;
reportAction.reportAction.childType = CONST.REPORT.TYPE.TASK;
reportAction.reportAction.childReportName = taskTitle;
reportAction.reportAction.childManagerEmail = taskAssignee;
reportAction.reportAction.childManagerAccountID = taskAssigneeAccountID;
reportAction.reportAction.childStatusNum = CONST.REPORT.STATUS.OPEN;
reportAction.reportAction.childStateNum = CONST.REPORT.STATE_NUM.OPEN;
Expand Down
9 changes: 1 addition & 8 deletions src/libs/actions/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import ROUTES from '../../ROUTES';
import CONST from '../../CONST';
import DateUtils from '../DateUtils';
import * as UserUtils from '../UserUtils';
import * as PersonalDetailsUtils from '../PersonalDetailsUtils';
import * as ReportActionsUtils from '../ReportActionsUtils';

/**
Expand Down Expand Up @@ -648,13 +647,7 @@ function getTaskAssigneeAccountID(taskReport) {
}

const reportAction = ReportActionsUtils.getParentReportAction(taskReport);
const childManagerEmail = lodashGet(reportAction, 'childManagerEmail', '');

if (!childManagerEmail) {
return null;
}

return PersonalDetailsUtils.getAccountIDsByLogins([childManagerEmail])[0];
return lodashGet(reportAction, 'childManagerAccountID');
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/pages/workspace/WorkspaceMembersPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ import * as UserUtils from '../../libs/UserUtils';
import FormHelpMessage from '../../components/FormHelpMessage';
import TextInput from '../../components/TextInput';
import KeyboardDismissingFlatList from '../../components/KeyboardDismissingFlatList';
import withCurrentUserPersonalDetails from '../../components/withCurrentUserPersonalDetails';
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsPropTypes, withCurrentUserPersonalDetailsDefaultProps} from '../../components/withCurrentUserPersonalDetails';
import * as PolicyUtils from '../../libs/PolicyUtils';
import PressableWithFeedback from '../../components/Pressable/PressableWithFeedback';
import usePrevious from '../../hooks/usePrevious';
import Log from '../../libs/Log';
import * as PersonalDetailsUtils from '../../libs/PersonalDetailsUtils';

const propTypes = {
/** The personal details of the person who is logged in */
/** All personal details asssociated with user */
personalDetails: personalDetailsPropType,

/** URL Route params */
Expand All @@ -61,6 +61,7 @@ const propTypes = {
...policyPropTypes,
...withLocalizePropTypes,
...windowDimensionsPropTypes,
...withCurrentUserPersonalDetailsPropTypes,
network: networkPropTypes.isRequired,
};

Expand All @@ -70,6 +71,7 @@ const defaultProps = {
accountID: 0,
},
...policyDefaultProps,
...withCurrentUserPersonalDetailsDefaultProps,
};

function WorkspaceMembersPage(props) {
Expand Down