@skbkontur/cassandra-distributed-task-queue-ui
Version:
.NET library implementing distributed task queue machinery using Apache Cassandra
69 lines • 4.33 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.TaskChainTree = void 0;
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 = tslib_1.__importDefault(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 = react_1.default.useContext(react_ui_1.ThemeContext);
const buildTaskTimeLineEntry = ({ taskMeta }) => {
const TimeLineEntry = TimeLine_1.TimeLine.Entry;
return (jsx_runtime_1.jsxs(TimeLineEntry, Object.assign({ icon: jsx_runtime_1.jsx(TaskStateIcon_1.TaskStateIcon, { taskState: taskMeta.state }, void 0), "data-tid": "TimeLineTaskItem" }, { children: [jsx_runtime_1.jsx("div", Object.assign({ "data-tid": "TaskName" }, { children: jsx_runtime_1.jsx(RouterLink_1.RouterLink, Object.assign({ to: getTaskLocation(taskMeta.id) }, { children: taskMeta.name }), void 0) }), void 0), jsx_runtime_1.jsx("div", Object.assign({ className: TaskChainTree_styles_1.jsStyles.taskId(theme), "data-tid": "TaskId" }, { children: jsx_runtime_1.jsx(edi_ui_1.AllowCopyToClipboard, { children: taskMeta.id }, void 0) }), void 0)] }), 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 [
jsx_runtime_1.jsx(TimeLineBranchNode, { children: childTaskIds
.map(x => taskMetaHashSet[x])
.filter(x => x)
.map((x, i) => (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 = uniq_1.default(mostParentTasks);
mostParentTasks = sortBy_1.default(mostParentTasks, x => x.taskMeta.ticks);
mostParentTasks = reverse_1.default(mostParentTasks);
return mostParentTasks;
};
const taskMetaHashSet = taskDetails.reduce((result, taskDetails) => {
result[taskDetails.taskMeta.id] = taskDetails;
return result;
}, {});
const mostParentTasks = findAllMostParents(taskMetaHashSet);
return (jsx_runtime_1.jsx(react_stack_layout_1.ColumnStack, Object.assign({ block: true, stretch: true, gap: 8, "data-tid": "TimeLines" }, { children: mostParentTasks.map((x, i) => (jsx_runtime_1.jsx(react_stack_layout_1.Fit, Object.assign({ "data-tid": "TimeLine" }, { children: jsx_runtime_1.jsx(TimeLine_1.TimeLine, { children: buildTaskTimeLine(x, taskMetaHashSet) }, void 0) }), i))) }), void 0));
}
exports.TaskChainTree = TaskChainTree;
//# sourceMappingURL=TaskChainTree.js.map
;