UNPKG

@skbkontur/cassandra-distributed-task-queue-ui

Version:

.NET library implementing distributed task queue machinery using Apache Cassandra

68 lines 4.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TaskChainTree = TaskChainTree; const tslib_1 = require("tslib"); const jsx_runtime_1 = require("react/jsx-runtime"); const edi_ui_1 = require("@skbkontur/edi-ui"); const react_stack_layout_1 = require("@skbkontur/react-stack-layout"); const react_ui_1 = require("@skbkontur/react-ui"); const reverse_1 = tslib_1.__importDefault(require("lodash/reverse")); const sortBy_1 = tslib_1.__importDefault(require("lodash/sortBy")); const uniq_1 = tslib_1.__importDefault(require("lodash/uniq")); const react_1 = require("react"); const RouterLink_1 = require("../RouterLink/RouterLink"); const TimeLine_1 = require("../TaskTimeLine/TimeLine/TimeLine"); const TaskChainTree_styles_1 = require("./TaskChainTree.styles"); const TaskStateIcon_1 = require("./TaskStateIcon"); function TaskChainTree({ taskDetails, getTaskLocation }) { const theme = (0, react_1.useContext)(react_ui_1.ThemeContext); const buildTaskTimeLineEntry = ({ taskMeta }) => { const TimeLineEntry = TimeLine_1.TimeLine.Entry; return ((0, jsx_runtime_1.jsxs)(TimeLineEntry, { icon: (0, jsx_runtime_1.jsx)(TaskStateIcon_1.TaskStateIcon, { taskState: taskMeta.state }), "data-tid": "TimeLineTaskItem", children: [(0, jsx_runtime_1.jsx)("div", { "data-tid": "TaskName", children: (0, jsx_runtime_1.jsx)(RouterLink_1.RouterLink, { to: getTaskLocation(taskMeta.id), children: taskMeta.name }) }), (0, jsx_runtime_1.jsx)("div", { className: TaskChainTree_styles_1.jsStyles.taskId(theme), "data-tid": "TaskId", children: (0, jsx_runtime_1.jsx)(edi_ui_1.AllowCopyToClipboard, { children: taskMeta.id }) })] }, taskMeta.id)); }; const buildChildEntries = ({ taskMeta, childTaskIds }, taskMetaHashSet) => { if (!childTaskIds || childTaskIds.length === 0) { return []; } if (childTaskIds.length === 1) { return buildTaskTimeLine(taskMetaHashSet[childTaskIds[0]], taskMetaHashSet); } const TimeLineBranch = TimeLine_1.TimeLine.Branch; const TimeLineBranchNode = TimeLine_1.TimeLine.BranchNode; return [ (0, jsx_runtime_1.jsx)(TimeLineBranchNode, { children: childTaskIds .map(x => taskMetaHashSet[x]) .filter(x => x) .map((x, i) => ((0, jsx_runtime_1.jsx)(TimeLineBranch, { children: buildTaskTimeLine(x, taskMetaHashSet) }, i))) }, `${taskMeta.id}-branches`), ]; }; const buildTaskTimeLine = (taskMeta, taskMetaHashSet) => { return [buildTaskTimeLineEntry(taskMeta), ...buildChildEntries(taskMeta, taskMetaHashSet)]; }; const findMostParentTask = (taskMetaHashSet, startTaskMeta) => { let result = startTaskMeta; while (result.taskMeta.parentTaskId) { if (!taskMetaHashSet[result.taskMeta.parentTaskId]) { return result; } result = taskMetaHashSet[result.taskMeta.parentTaskId]; } return result; }; const findAllMostParents = (taskMetaHashSet) => { let mostParentTasks = Object.getOwnPropertyNames(taskMetaHashSet) .map(x => taskMetaHashSet[x]) .map(x => findMostParentTask(taskMetaHashSet, x)); mostParentTasks = (0, uniq_1.default)(mostParentTasks); mostParentTasks = (0, sortBy_1.default)(mostParentTasks, x => x.taskMeta.ticks); mostParentTasks = (0, reverse_1.default)(mostParentTasks); return mostParentTasks; }; const taskMetaHashSet = taskDetails.reduce((result, taskDetails) => { result[taskDetails.taskMeta.id] = taskDetails; return result; }, {}); const mostParentTasks = findAllMostParents(taskMetaHashSet); return ((0, jsx_runtime_1.jsx)(react_stack_layout_1.ColumnStack, { block: true, stretch: true, gap: 8, "data-tid": "TimeLines", children: mostParentTasks.map((x, i) => ((0, jsx_runtime_1.jsx)(react_stack_layout_1.Fit, { "data-tid": "TimeLine", children: (0, jsx_runtime_1.jsx)(TimeLine_1.TimeLine, { children: buildTaskTimeLine(x, taskMetaHashSet) }) }, i))) })); } //# sourceMappingURL=TaskChainTree.js.map