Reassigning a Task throws an error (#5721)

This commit is contained in:
Vivek Ratnavel Subramanian 2022-06-29 10:41:39 -07:00 committed by GitHub
parent 03ccd89c80
commit 1d7e212e2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 3 deletions

View File

@ -23,6 +23,7 @@ import static org.openmetadata.catalog.type.Relationship.CREATED;
import static org.openmetadata.catalog.type.Relationship.IS_ABOUT;
import static org.openmetadata.catalog.type.Relationship.REPLIED_TO;
import static org.openmetadata.catalog.util.ChangeEventParser.getPlaintextDiff;
import static org.openmetadata.catalog.util.EntityUtil.compareEntityReference;
import static org.openmetadata.catalog.util.EntityUtil.populateEntityReferences;
import com.fasterxml.jackson.core.JsonProcessingException;
@ -705,6 +706,11 @@ public class FeedRepository {
throws IOException {
// Get all the fields in the original thread that can be updated during PATCH operation
Thread original = get(id.toString());
if (original.getTask() != null) {
List<EntityReference> assignees = original.getTask().getAssignees();
populateAssignees(original);
assignees.sort(compareEntityReference);
}
// Apply JSON patch to the original thread to get the updated thread
Thread updated = JsonUtils.applyPatch(original, patch, Thread.class);
@ -722,6 +728,11 @@ public class FeedRepository {
});
}
if (updated.getTask() != null) {
populateAssignees(updated);
updated.getTask().getAssignees().sort(compareEntityReference);
}
// Update the attributes
String change = patchUpdate(original, updated) ? RestUtil.ENTITY_UPDATED : RestUtil.ENTITY_NO_CHANGE;
sortPosts(updated);

View File

@ -19,7 +19,7 @@ import classNames from 'classnames';
import { compare, Operation } from 'fast-json-patch';
import { isEmpty, isEqual, isUndefined, toLower } from 'lodash';
import { observer } from 'mobx-react';
import { EditorContentRef, EntityTags } from 'Models';
import { EditorContentRef, EntityReference, EntityTags } from 'Models';
import React, { Fragment, useEffect, useMemo, useRef, useState } from 'react';
import { useHistory, useParams } from 'react-router-dom';
import AppState from '../../../AppState';
@ -49,6 +49,7 @@ import { EntityType } from '../../../enums/entity.enum';
import { CreateThread } from '../../../generated/api/feed/createThread';
import { Column } from '../../../generated/entity/data/table';
import {
TaskDetails,
TaskType,
Thread,
ThreadTaskStatus,
@ -256,7 +257,10 @@ const TaskDetailPage = () => {
);
if (existingAssignee) {
return existingAssignee;
return {
id: existingAssignee.id,
type: existingAssignee.type,
};
} else {
return {
id: assignee.value,
@ -270,7 +274,28 @@ const TaskDetailPage = () => {
task: { ...(taskDetail.task || {}), assignees: newAssignees },
};
const patch = compare(taskDetail, updatedTask);
// existing task assignees should only have id and type for the patch to work
const existingAssignees = taskDetail.task?.assignees;
let oldTask: Thread = taskDetail;
if (existingAssignees) {
const formattedAssignees: EntityReference[] = existingAssignees.map(
(assignee: EntityReference) => {
return {
id: assignee.id,
type: assignee.type,
};
}
);
oldTask = {
...taskDetail,
task: {
...(taskDetail.task as TaskDetails),
assignees: formattedAssignees,
},
};
}
const patch = compare(oldTask, updatedTask);
updateThread(taskDetail.id, patch)
.then(() => {
fetchTaskDetail();