Skip to content

Commit

Permalink
CM-458: adjust tasks to work with deduplication (#31)
Browse files Browse the repository at this point in the history
Co-authored-by: Jan <[email protected]>
  • Loading branch information
jdolkowski and Jan authored Jan 29, 2024
1 parent 1fba3ca commit f9fa968
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ export const formatTaskGQL = (task) => `
${task?.taskGroup?.id ? `taskGroupId: "${decodeId(task.taskGroup.id)}"` : ''}
`;

export const formatTaskResolveGQL = (task, user, approveOrFail) => `
export const formatTaskResolveGQL = (task, user, approveOrFail, additionalData) => `
${task?.id ? `id: "${task.id}"` : ''}
${user && approveOrFail ? `businessStatus: "{\\"${user.id}\\": \\"${approveOrFail}\\"}"` : ''}
${additionalData ? `additionalData: "${additionalData}"` : ''}
`;

const PERFORM_MUTATION = (mutationType, mutationInput, ACTION, clientMutationLabel) => {
Expand Down Expand Up @@ -175,10 +176,10 @@ export function updateTask(task, clientMutationLabel) {
);
}

export function resolveTask(task, clientMutationLabel, user, approveOrFail) {
export function resolveTask(task, clientMutationLabel, user, approveOrFail, additionalData) {
return PERFORM_MUTATION(
MUTATION_SERVICE.TASK.RESOLVE,
formatTaskResolveGQL(task, user, approveOrFail),
formatTaskResolveGQL(task, user, approveOrFail, additionalData),
ACTION_TYPE.RESOLVE_TASK,
clientMutationLabel,
);
Expand Down
2 changes: 2 additions & 0 deletions src/components/TaskApprovementPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function TaskApprovementPanel({
mutation,
journalize,
confirmed,
additionalData,
}) {
const modulesManager = useModulesManager();
const classes = useStyles();
Expand Down Expand Up @@ -78,6 +79,7 @@ function TaskApprovementPanel({
formatMessage('task.resolve.mutationLabel'),
user,
approveOrFail,
additionalData,
);
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/components/TaskPreviewCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import React from 'react';
import { HYPHEN } from '../constants';

function TaskPreviewCell({
formatterIndex, itemData, incomingData, formatter, jsonExt,
formatterIndex, itemData, incomingData, formatter, jsonExt, setAdditionalData,
}) {
const showHistorical = (itemIncomingData) => {
if (formatter(itemData, jsonExt, formatterIndex) === formatter(itemIncomingData, jsonExt, formatterIndex)
|| !formatter(itemIncomingData, jsonExt, formatterIndex)) {
if (formatter(itemData, jsonExt, formatterIndex, setAdditionalData)
=== formatter(itemIncomingData, jsonExt, formatterIndex, setAdditionalData)
|| !formatter(itemIncomingData, jsonExt, formatterIndex, setAdditionalData)) {
return HYPHEN;
}
return formatter(itemIncomingData, jsonExt, formatterIndex);
return formatter(itemIncomingData, jsonExt, formatterIndex, setAdditionalData);
};

const shouldDisplay = (value) => {
Expand All @@ -21,7 +22,7 @@ function TaskPreviewCell({
<>
{(shouldDisplay(itemData) || shouldDisplay(jsonExt)) && (
<p>
{formatter(itemData, jsonExt, formatterIndex) ?? HYPHEN}
{formatter(itemData, jsonExt, formatterIndex, setAdditionalData) ?? HYPHEN}
</p>
)}
{shouldDisplay(incomingData) && (
Expand Down
3 changes: 2 additions & 1 deletion src/components/TaskPreviewPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const useStyles = makeStyles((theme) => ({
title: theme.paper.title,
}));

function TaskPreviewPanel({ rights, edited }) {
function TaskPreviewPanel({ rights, edited, setAdditionalData }) {
const modulesManager = useModulesManager();
const classes = useStyles();
const [header, setHeader] = useState(EMPTY_STRING);
Expand Down Expand Up @@ -41,6 +41,7 @@ function TaskPreviewPanel({ rights, edited }) {
previewItem={task}
tableHeaders={tableTaskHeaders}
itemFormatters={taskItemFormatters}
setAdditionalData={setAdditionalData}
/>
</Paper>
);
Expand Down
6 changes: 3 additions & 3 deletions src/components/TaskPreviewTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function TaskPreviewTable({
previewItem,
itemFormatters,
tableHeaders,
setAdditionalData,
}) {
const { fetchingTasks, errorTasks } = useSelector((state) => state?.tasksManagement);

Expand All @@ -71,9 +72,7 @@ function TaskPreviewTable({
progress={fetchingTasks}
error={errorTasks}
/>
<TableRow
className={classes.tableRow}
>
<TableRow>
{itemFormatters.map((formatter, formatterIndex) => (
<TableCell
key={formatterIndex}
Expand All @@ -84,6 +83,7 @@ function TaskPreviewTable({
jsonExt={!previewItem?.jsonExt || JSON.parse(previewItem.jsonExt)}
itemData={previewItem.businessData?.current_data}
incomingData={previewItem.businessData?.incoming_data || previewItem.businessData}
setAdditionalData={setAdditionalData}
/>
</TableCell>
))}
Expand Down
3 changes: 3 additions & 0 deletions src/pages/TaskDetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function TaskDetailsPage({
const history = useHistory();
const { formatMessage } = useTranslations('tasksManagement', modulesManager);
const [editedTask, setEditedTask] = useState({});
const [additionalData, setAdditionalData] = useState({});
const submittingMutationRef = useRef();
const back = () => history.goBack();

Expand Down Expand Up @@ -111,6 +112,8 @@ function TaskDetailsPage({
formatMessage={formatMessage}
Panels={panels()}
rights={rights}
additionalData={additionalData}
setAdditionalData={setAdditionalData}
saveTooltip={formatMessage(
`tasksManagement.saveButton.tooltip.${canSave() ? 'enabled' : 'disabled'}`,
)}
Expand Down

0 comments on commit f9fa968

Please sign in to comment.