Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | 1x 1x 1x 1x 1x | import { PayloadAction } from "@reduxjs/toolkit";
import {
PlaybookUIState,
Step,
Task,
TaskType,
} from "../../../../../types/index.ts";
import generateUUIDWithoutHyphens from "../../../../../utils/common/generateUUIDWithoutHyphens.ts";
import { v4 as uuidv4 } from "uuid";
import { exampleInputTransformer } from "../../../../../utils/common/transformerDefaults.ts";
const emptyStep: Step = {
id: "",
tasks: [],
ui_requirement: {
isOpen: true,
showError: false,
},
};
export const createTaskWithSource = (
state: PlaybookUIState,
{ payload }: PayloadAction<any>,
) => {
const { parentId, stepId: existingStepId, resultType } = payload;
const parent = parentId ?? state.currentPlaybook?.steps[0].id;
const stepId = existingStepId ?? generateUUIDWithoutHyphens();
const taskId = generateUUIDWithoutHyphens();
const task: Task = {
id: taskId,
reference_id: uuidv4(),
name: uuidv4(),
source: payload.source,
interpreter_type: "BASIC_I",
task_connector_sources: [],
ui_requirement: {
isOpen: true,
taskType: payload.taskType,
stepId: stepId,
model_type: payload.modelType,
resultType,
example_input: exampleInputTransformer,
},
[payload.source.toLowerCase() as TaskType]: {
type: payload.taskType,
[payload.taskType.toLowerCase()]: {
process_function: "timeseries",
statistic: "Average",
},
},
description: payload.description,
execution_configuration: {
is_bulk_execution: false,
bulk_execution_var_field: "",
result_transformer_lambda_function: {
definition: "",
},
},
};
Iif (existingStepId) {
const step = state.currentPlaybook?.steps.find((e) => e.id === stepId);
step?.tasks.push(taskId);
state.currentPlaybook?.ui_requirement.tasks.push(task);
state.currentVisibleTask = taskId;
return;
}
const newStep: Step = {
...emptyStep,
id: stepId,
reference_id: uuidv4(),
description: `Step`,
tasks: [task.id!],
};
state.currentPlaybook?.steps.push(newStep);
state.currentPlaybook?.ui_requirement.tasks.push(task);
const parentStep = state.currentPlaybook?.steps.find(
(step) => step.id === parent,
);
Iif (
state.currentPlaybook &&
(!state.currentPlaybook?.step_relations ||
state.currentPlaybook?.step_relations?.length === 0)
) {
state.currentPlaybook.step_relations = [];
}
state.currentPlaybook?.step_relations?.push({
id: `edge-${parent}-${stepId}`,
parent: parentStep!,
child: newStep,
});
state.currentVisibleTask = taskId;
};
|