1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
import { uniqueId } from 'lodash';
import {
WIDGET_TYPE_HIERARCHY,
WIDGET_TYPE_CURRENT_USER_TODOS,
CURRENT_USER_TODOS_TYPENAME,
TODO_CONNECTION_TYPENAME,
TODO_EDGE_TYPENAME,
TODO_TYPENAME,
WORK_ITEM_TYPENAME,
WORK_ITEM_UPDATE_PAYLOAD_TYPENAME,
} from '~/work_items/constants';
export const findHierarchyWidgets = (widgets) =>
widgets?.find((widget) => widget.type === WIDGET_TYPE_HIERARCHY);
export const findHierarchyWidgetChildren = (workItem) =>
findHierarchyWidgets(workItem?.widgets)?.children.nodes;
const autocompleteSourcesPath = (autocompleteType, fullPath, workItemIid) => {
return `${
gon.relative_url_root || ''
}/${fullPath}/-/autocomplete_sources/${autocompleteType}?type=WorkItem&type_id=${workItemIid}`;
};
export const autocompleteDataSources = (fullPath, iid) => ({
labels: autocompleteSourcesPath('labels', fullPath, iid),
members: autocompleteSourcesPath('members', fullPath, iid),
commands: autocompleteSourcesPath('commands', fullPath, iid),
});
export const markdownPreviewPath = (fullPath, iid) =>
`${
gon.relative_url_root || ''
}/${fullPath}/preview_markdown?target_type=WorkItem&target_id=${iid}`;
export const getWorkItemTodoOptimisticResponse = ({ workItem, pendingTodo }) => {
const todo = pendingTodo
? [
{
node: {
id: -uniqueId(),
state: 'pending',
__typename: TODO_TYPENAME,
},
__typename: TODO_EDGE_TYPENAME,
},
]
: [];
return {
workItemUpdate: {
errors: [],
workItem: {
...workItem,
widgets: [
{
type: WIDGET_TYPE_CURRENT_USER_TODOS,
currentUserTodos: {
edges: todo,
__typename: TODO_CONNECTION_TYPENAME,
},
__typename: CURRENT_USER_TODOS_TYPENAME,
},
],
__typename: WORK_ITEM_TYPENAME,
},
__typename: WORK_ITEM_UPDATE_PAYLOAD_TYPENAME,
},
};
};
|