debian-mirror-gitlab/app/assets/javascripts/work_items/utils.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

76 lines
2.2 KiB
JavaScript
Raw Normal View History

2023-07-09 08:55:56 +05:30
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';
2023-01-13 00:05:48 +05:30
import workItemQuery from './graphql/work_item.query.graphql';
import workItemByIidQuery from './graphql/work_item_by_iid.query.graphql';
export function getWorkItemQuery(isFetchedByIid) {
return isFetchedByIid ? workItemByIidQuery : workItemQuery;
}
2023-03-04 22:38:38 +05:30
2023-07-09 08:55:56 +05:30
export const findHierarchyWidgets = (widgets) =>
widgets?.find((widget) => widget.type === WIDGET_TYPE_HIERARCHY);
2023-04-23 21:23:45 +05:30
export const findHierarchyWidgetChildren = (workItem) =>
2023-07-09 08:55:56 +05:30
findHierarchyWidgets(workItem.widgets).children.nodes;
2023-04-23 21:23:45 +05:30
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}`;
2023-07-09 08:55:56 +05:30
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,
},
};
};