mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-06 05:22:53 +00:00
Reassigning a Task throws an error (#5721)
This commit is contained in:
parent
03ccd89c80
commit
1d7e212e2f
@ -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.IS_ABOUT;
|
||||||
import static org.openmetadata.catalog.type.Relationship.REPLIED_TO;
|
import static org.openmetadata.catalog.type.Relationship.REPLIED_TO;
|
||||||
import static org.openmetadata.catalog.util.ChangeEventParser.getPlaintextDiff;
|
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 static org.openmetadata.catalog.util.EntityUtil.populateEntityReferences;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
@ -705,6 +706,11 @@ public class FeedRepository {
|
|||||||
throws IOException {
|
throws IOException {
|
||||||
// Get all the fields in the original thread that can be updated during PATCH operation
|
// Get all the fields in the original thread that can be updated during PATCH operation
|
||||||
Thread original = get(id.toString());
|
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
|
// Apply JSON patch to the original thread to get the updated thread
|
||||||
Thread updated = JsonUtils.applyPatch(original, patch, Thread.class);
|
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
|
// Update the attributes
|
||||||
String change = patchUpdate(original, updated) ? RestUtil.ENTITY_UPDATED : RestUtil.ENTITY_NO_CHANGE;
|
String change = patchUpdate(original, updated) ? RestUtil.ENTITY_UPDATED : RestUtil.ENTITY_NO_CHANGE;
|
||||||
sortPosts(updated);
|
sortPosts(updated);
|
||||||
|
|||||||
@ -19,7 +19,7 @@ import classNames from 'classnames';
|
|||||||
import { compare, Operation } from 'fast-json-patch';
|
import { compare, Operation } from 'fast-json-patch';
|
||||||
import { isEmpty, isEqual, isUndefined, toLower } from 'lodash';
|
import { isEmpty, isEqual, isUndefined, toLower } from 'lodash';
|
||||||
import { observer } from 'mobx-react';
|
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 React, { Fragment, useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import { useHistory, useParams } from 'react-router-dom';
|
import { useHistory, useParams } from 'react-router-dom';
|
||||||
import AppState from '../../../AppState';
|
import AppState from '../../../AppState';
|
||||||
@ -49,6 +49,7 @@ import { EntityType } from '../../../enums/entity.enum';
|
|||||||
import { CreateThread } from '../../../generated/api/feed/createThread';
|
import { CreateThread } from '../../../generated/api/feed/createThread';
|
||||||
import { Column } from '../../../generated/entity/data/table';
|
import { Column } from '../../../generated/entity/data/table';
|
||||||
import {
|
import {
|
||||||
|
TaskDetails,
|
||||||
TaskType,
|
TaskType,
|
||||||
Thread,
|
Thread,
|
||||||
ThreadTaskStatus,
|
ThreadTaskStatus,
|
||||||
@ -256,7 +257,10 @@ const TaskDetailPage = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (existingAssignee) {
|
if (existingAssignee) {
|
||||||
return existingAssignee;
|
return {
|
||||||
|
id: existingAssignee.id,
|
||||||
|
type: existingAssignee.type,
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
id: assignee.value,
|
id: assignee.value,
|
||||||
@ -270,7 +274,28 @@ const TaskDetailPage = () => {
|
|||||||
task: { ...(taskDetail.task || {}), assignees: newAssignees },
|
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)
|
updateThread(taskDetail.id, patch)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
fetchTaskDetail();
|
fetchTaskDetail();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user