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

feat: task view with offline with feedback #23705

Merged
merged 10 commits into from
Aug 3, 2023
16 changes: 10 additions & 6 deletions src/components/ReportActionItem/TaskView.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ function TaskView(props) {
const canEdit = PolicyUtils.isPolicyAdmin(policy) || Task.isTaskAssigneeOrTaskOwner(props.report, props.currentUserPersonalDetails.accountID);
const disableState = !canEdit || !isOpen;
return (
<View>
<OfflineWithFeedback
shouldShowErrorMessages
errors={lodashGet(props, 'report.errorFields')}
onClose={() => Task.clearEditTaskErrors(props.report)}
errorRowStyles={styles.ph5}
>
<Hoverable>
{(hovered) => (
<PressableWithSecondaryInteraction
Expand All @@ -71,7 +76,7 @@ function TaskView(props) {
accessibilityLabel={taskTitle || props.translate('task.task')}
>
{({pressed}) => (
<OfflineWithFeedback pendingAction={lodashGet(props, 'report.pendingFields.reportName', null)}>
<OfflineWithFeedback pendingAction={lodashGet(props, 'report.pendingFields.reportName')}>
<Text style={styles.taskTitleDescription}>{props.translate('task.title')}</Text>
<View style={[styles.flexRow, styles.alignItemsTop, styles.flex1]}>
<Checkbox
Expand Down Expand Up @@ -107,7 +112,7 @@ function TaskView(props) {
</PressableWithSecondaryInteraction>
)}
</Hoverable>
<OfflineWithFeedback pendingAction={lodashGet(props, 'report.pendingFields.description', null)}>
<OfflineWithFeedback pendingAction={lodashGet(props, 'report.pendingFields.description')}>
<MenuItemWithTopDescription
description={props.translate('task.description')}
title={props.report.description || ''}
Expand All @@ -120,7 +125,7 @@ function TaskView(props) {
/>
</OfflineWithFeedback>
{props.report.managerID ? (
<OfflineWithFeedback pendingAction={lodashGet(props, 'report.pendingFields.managerID', null)}>
<OfflineWithFeedback pendingAction={lodashGet(props, 'report.pendingFields.managerID')}>
<MenuItem
label={props.translate('task.assignee')}
title={ReportUtils.getDisplayNameForParticipant(props.report.managerID)}
Expand All @@ -146,9 +151,8 @@ function TaskView(props) {
shouldGreyOutWhenDisabled={false}
/>
)}

{props.shouldShowHorizontalRule && <View style={styles.reportHorizontalRule} />}
</View>
</OfflineWithFeedback>
);
}

Expand Down
18 changes: 13 additions & 5 deletions src/libs/actions/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,6 @@ function editTaskAndNavigate(report, ownerAccountID, {title, description, assign
description: report.description,
assignee: report.managerEmail,
assigneeAccountID: report.managerID,
pendingFields: {
...(title && {reportName: null}),
...(description && {description: null}),
...(assigneeAccountID && {managerID: null}),
},
},
},
];
Expand Down Expand Up @@ -756,6 +751,18 @@ function isTaskAssigneeOrTaskOwner(taskReport, sessionAccountID) {
return sessionAccountID === getTaskOwnerAccountID(taskReport) || sessionAccountID === getTaskAssigneeAccountID(taskReport);
}

/**
* Clears any possible stored errors for a specific field on a task report
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: More simply; "Clear errors from editing a task".

Actually, we don't need a description at all. It's quite simple.

- Avoid descriptions that don't add any additional information. Method descriptions should only be added when it's behavior is unclear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed!

*
* @param {Object} report
*/
function clearEditTaskErrors(report) {
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: Let's pass only what we need, which is the reportID.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, {
pendingFields: null,
errorFields: null,
});
}

export {
createTaskAndNavigate,
editTaskAndNavigate,
Expand All @@ -775,4 +782,5 @@ export {
dismissModalAndClearOutTaskInfo,
getTaskAssigneeAccountID,
isTaskAssigneeOrTaskOwner,
clearEditTaskErrors,
};
1 change: 1 addition & 0 deletions src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ export default compose(
_.isEqual(prevProps.emojiReactions, nextProps.emojiReactions) &&
_.isEqual(prevProps.action, nextProps.action) &&
_.isEqual(prevProps.report.pendingFields, nextProps.report.pendingFields) &&
_.isEqual(prevProps.report.errorFields, nextProps.report.errorFields) &&
lodashGet(prevProps.report, 'statusNum') === lodashGet(nextProps.report, 'statusNum') &&
lodashGet(prevProps.report, 'stateNum') === lodashGet(nextProps.report, 'stateNum') &&
prevProps.translate === nextProps.translate &&
Expand Down
8 changes: 8 additions & 0 deletions src/pages/home/report/ReportActionsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,14 @@ function arePropsEqual(oldProps, newProps) {
return false;
}

if (!_.isEqual(oldProps.report.pendingFields, newProps.report.pendingFields)) {
return false;
}

if (!_.isEqual(oldProps.report.errorFields, newProps.report.errorFields)) {
return false;
}

if (lodashGet(oldProps.network, 'isOffline') !== lodashGet(newProps.network, 'isOffline')) {
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions src/pages/reportPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,7 @@ export default PropTypes.shape({

/** Which user role is capable of posting messages on the report */
writeCapability: PropTypes.oneOf(_.values(CONST.REPORT.WRITE_CAPABILITIES)),

/** Field-specific pending states for offline UI status */
pendingFields: PropTypes.objectOf(PropTypes.objectOf(PropTypes.string)),
});
Loading