Skip to content

Commit

Permalink
Reformat task-related actions
Browse files Browse the repository at this point in the history
  • Loading branch information
paultsimura committed Feb 29, 2024
1 parent e76fa93 commit c35a510
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 27 deletions.
10 changes: 7 additions & 3 deletions src/components/ReportActionItem/TaskAction.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import React from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import RenderHTML from '@components/RenderHTML';
import Text from '@components/Text';
import useThemeStyles from '@hooks/useThemeStyles';
import * as TaskUtils from '@libs/TaskUtils';
import type {ReportAction} from '@src/types/onyx';

type TaskActionProps = {
/** Name of the reportAction action */
actionName: string;
action: OnyxEntry<ReportAction>;
};

function TaskAction({actionName}: TaskActionProps) {
function TaskAction({action}: TaskActionProps) {
const styles = useThemeStyles();
const message = TaskUtils.getTaskReportActionMessage(action);

return (
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter]}>
<Text style={[styles.chatItemMessage, styles.colorMuted]}>{TaskUtils.getTaskReportActionMessage(actionName)}</Text>
{message.html ? <RenderHTML html={`<muted-text>${message.html}</muted-text>`} /> : <Text style={[styles.chatItemMessage, styles.colorMuted]}>{message.text}</Text>}
</View>
);
}
Expand Down
10 changes: 2 additions & 8 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ function getLastMessageTextForReport(report: OnyxEntry<Report>, lastActorDetails
// some types of actions are filtered out for lastReportAction, in some cases we need to check the actual last action
const lastOriginalReportAction = lastReportActions[report?.reportID ?? ''] ?? null;
let lastMessageTextFromReport = '';
const lastActionName = lastReportAction?.actionName ?? '';

if (ReportUtils.isArchivedRoom(report)) {
const archiveReason =
Expand Down Expand Up @@ -576,13 +575,8 @@ function getLastMessageTextForReport(report: OnyxEntry<Report>, lastActorDetails
} else if (ReportActionUtils.isModifiedExpenseAction(lastReportAction)) {
const properSchemaForModifiedExpenseMessage = ModifiedExpenseMessage.getForReportAction(report?.reportID, lastReportAction);
lastMessageTextFromReport = ReportUtils.formatReportLastMessageText(properSchemaForModifiedExpenseMessage, true);
} else if (
lastActionName === CONST.REPORT.ACTIONS.TYPE.TASKCOMPLETED ||
lastActionName === CONST.REPORT.ACTIONS.TYPE.TASKREOPENED ||
lastActionName === CONST.REPORT.ACTIONS.TYPE.TASKCANCELLED ||
lastActionName === CONST.REPORT.ACTIONS.TYPE.TASKEDITED
) {
lastMessageTextFromReport = lastReportAction?.message?.[0].text ?? '';
} else if (ReportActionUtils.isTaskAction(lastReportAction)) {
lastMessageTextFromReport = TaskUtils.getTaskReportActionMessage(lastReportAction).text;
} else if (ReportActionUtils.isCreatedTaskReportAction(lastReportAction)) {
lastMessageTextFromReport = TaskUtils.getTaskCreatedMessage(lastReportAction);
}
Expand Down
3 changes: 2 additions & 1 deletion src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,8 @@ function isTaskAction(reportAction: OnyxEntry<ReportAction>): boolean {
return (
reportActionName === CONST.REPORT.ACTIONS.TYPE.TASKCOMPLETED ||
reportActionName === CONST.REPORT.ACTIONS.TYPE.TASKCANCELLED ||
reportActionName === CONST.REPORT.ACTIONS.TYPE.TASKREOPENED
reportActionName === CONST.REPORT.ACTIONS.TYPE.TASKREOPENED ||
reportActionName === CONST.REPORT.ACTIONS.TYPE.TASKEDITED
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ function getOptionData({
const newName = lastAction?.originalMessage?.newName ?? '';
result.alternateText = Localize.translate(preferredLocale, 'newRoomPage.roomRenamedTo', {newName});
} else if (ReportActionsUtils.isTaskAction(lastAction)) {
result.alternateText = TaskUtils.getTaskReportActionMessage(lastAction.actionName);
result.alternateText = TaskUtils.getTaskReportActionMessage(lastAction).text;
} else if (
lastAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM ||
lastAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.REMOVE_FROM_ROOM ||
Expand Down
18 changes: 12 additions & 6 deletions src/libs/TaskUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Onyx from 'react-native-onyx';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Report} from '@src/types/onyx';
import type {Message} from '@src/types/onyx/ReportAction';
import type ReportAction from '@src/types/onyx/ReportAction';
import * as CollectionUtils from './CollectionUtils';
import * as Localize from './Localize';
Expand All @@ -22,16 +23,21 @@ Onyx.connect({
/**
* Given the Task reportAction name, return the appropriate message to be displayed and copied to clipboard.
*/
function getTaskReportActionMessage(actionName: string): string {
switch (actionName) {
function getTaskReportActionMessage(action: OnyxEntry<ReportAction>): Pick<Message, 'text' | 'html'> {
switch (action?.actionName) {
case CONST.REPORT.ACTIONS.TYPE.TASKCOMPLETED:
return Localize.translateLocal('task.messages.completed');
return {text: Localize.translateLocal('task.messages.completed')};
case CONST.REPORT.ACTIONS.TYPE.TASKCANCELLED:
return Localize.translateLocal('task.messages.canceled');
return {text: Localize.translateLocal('task.messages.canceled')};
case CONST.REPORT.ACTIONS.TYPE.TASKREOPENED:
return Localize.translateLocal('task.messages.reopened');
return {text: Localize.translateLocal('task.messages.reopened')};
case CONST.REPORT.ACTIONS.TYPE.TASKEDITED:
return {
text: action?.message?.[0].text ?? '',
html: action?.message?.[0].html,
};
default:
return Localize.translateLocal('task.task');
return {text: Localize.translateLocal('task.task')};
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/libs/actions/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,11 @@ function editTask(report: OnyxTypes.Report, {title, description}: OnyxTypes.Task
];

const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`,
value: {[editTaskReportAction.reportActionID]: {pendingAction: null}},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`,
Expand Down Expand Up @@ -483,6 +488,11 @@ function editTaskAssignee(report: OnyxTypes.Report, ownerAccountID: number, assi
];

const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`,
value: {[editTaskReportAction.reportActionID]: {pendingAction: null}},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`,
Expand Down
6 changes: 4 additions & 2 deletions src/pages/home/report/ContextMenu/ContextMenuActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,8 @@ const ContextMenuActions: ContextMenuAction[] = [
// `ContextMenuItem` with `successText` and `successIcon` which will fall back to
// the `text` and `icon`
onPress: (closePopover, {reportAction, selection, reportID}) => {
const isTaskAction = ReportActionsUtils.isTaskAction(reportAction);
const isReportPreviewAction = ReportActionsUtils.isReportPreviewAction(reportAction);
const messageHtml = isTaskAction ? TaskUtils.getTaskReportActionMessage(reportAction?.actionName) : getActionHtml(reportAction);
const messageHtml = getActionHtml(reportAction);
const messageText = getActionText(reportAction);

const isAttachment = ReportActionsUtils.isReportActionAttachment(reportAction);
Expand All @@ -350,6 +349,9 @@ const ContextMenuActions: ContextMenuAction[] = [
const iouReport = ReportUtils.getReport(ReportActionsUtils.getIOUReportIDFromReportActionPreview(reportAction));
const displayMessage = ReportUtils.getReportPreviewMessage(iouReport, reportAction);
Clipboard.setString(displayMessage);
} else if (ReportActionsUtils.isTaskAction(reportAction)) {
const displayMessage = TaskUtils.getTaskReportActionMessage(reportAction).text;
Clipboard.setString(displayMessage);
} else if (ReportActionsUtils.isModifiedExpenseAction(reportAction)) {
const modifyExpenseMessage = ModifiedExpenseMessage.getForReportAction(reportID, reportAction);
Clipboard.setString(modifyExpenseMessage);
Expand Down
8 changes: 2 additions & 6 deletions src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,8 @@ function ReportActionItem(props) {
transactionViolations={props.transactionViolations}
/>
);
} else if (
props.action.actionName === CONST.REPORT.ACTIONS.TYPE.TASKCOMPLETED ||
props.action.actionName === CONST.REPORT.ACTIONS.TYPE.TASKCANCELLED ||
props.action.actionName === CONST.REPORT.ACTIONS.TYPE.TASKREOPENED
) {
children = <TaskAction actionName={props.action.actionName} />;
} else if (ReportActionsUtils.isTaskAction(props.action)) {
children = <TaskAction action={props.action} />;
} else if (ReportActionsUtils.isCreatedTaskReportAction(props.action)) {
children = (
<ShowContextMenuContext.Provider value={contextValue}>
Expand Down

0 comments on commit c35a510

Please sign in to comment.