Browse Source

[Fix] [UI Next][V1.0.0-Alpha] Fix pre task error when creating task in dag page. (#8928)

3.0.0/version-upgrade
Amy0104 3 years ago committed by GitHub
parent
commit
9cf5c6d00e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/dag-save-modal.tsx
  2. 12
      dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/index.tsx
  3. 6
      dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/types.ts
  4. 31
      dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/use-cell-update.ts
  5. 90
      dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/use-task-edit.ts

2
dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/dag-save-modal.tsx

@ -29,11 +29,11 @@ import {
NCheckbox NCheckbox
} from 'naive-ui' } from 'naive-ui'
import { queryTenantList } from '@/service/modules/tenants' import { queryTenantList } from '@/service/modules/tenants'
import { SaveForm, WorkflowDefinition, WorkflowInstance } from './types'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import { verifyName } from '@/service/modules/process-definition' import { verifyName } from '@/service/modules/process-definition'
import './x6-style.scss' import './x6-style.scss'
import { positiveIntegerRegex } from '@/utils/regex' import { positiveIntegerRegex } from '@/utils/regex'
import type { SaveForm, WorkflowDefinition, WorkflowInstance } from './types'
const props = { const props = {
visible: { visible: {

12
dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/index.tsx

@ -106,7 +106,7 @@ export default defineComponent({
appendTask, appendTask,
editTask, editTask,
copyTask, copyTask,
taskDefinitions, processDefinition,
removeTasks removeTasks
} = useTaskEdit({ graph, definition: toRef(props, 'definition') }) } = useTaskEdit({ graph, definition: toRef(props, 'definition') })
@ -212,10 +212,14 @@ export default defineComponent({
saveModelToggle(false) saveModelToggle(false)
return return
} }
const connects = getConnects(nodes, edges, taskDefinitions.value as any) const connects = getConnects(
nodes,
edges,
processDefinition.value.taskDefinitionList as any
)
const locations = getLocations(nodes) const locations = getLocations(nodes)
context.emit('save', { context.emit('save', {
taskDefinitions: taskDefinitions.value, taskDefinitions: processDefinition.value.taskDefinitionList,
saveForm, saveForm,
connects, connects,
locations locations
@ -288,7 +292,7 @@ export default defineComponent({
taskInstance={currentTaskInstance.value} taskInstance={currentTaskInstance.value}
onViewLog={handleViewLog} onViewLog={handleViewLog}
data={currTask.value as any} data={currTask.value as any}
definition={props.definition} definition={processDefinition}
onSubmit={taskConfirm} onSubmit={taskConfirm}
onCancel={taskCancel} onCancel={taskCancel}
/> />

6
dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/types.ts

@ -115,6 +115,12 @@ export interface WorkflowInstance {
warningGroupId: number warningGroupId: number
} }
export interface EditWorkflowDefinition {
processDefinition: ProcessDefinition
processTaskRelationList: Connect[]
taskDefinitionList: NodeData[]
}
export interface Dragged { export interface Dragged {
x: number x: number
y: number y: number

31
dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/use-cell-update.ts

@ -22,6 +22,7 @@ import type { Coordinate } from './types'
import { TASK_TYPES_MAP } from '@/views/projects/task/constants/task-type' import { TASK_TYPES_MAP } from '@/views/projects/task/constants/task-type'
import { useCustomCellBuilder } from './dag-hooks' import { useCustomCellBuilder } from './dag-hooks'
import utils from '@/utils' import utils from '@/utils'
import type { Edge } from '@antv/x6'
interface Options { interface Options {
graph: Ref<Graph | undefined> graph: Ref<Graph | undefined>
@ -70,10 +71,19 @@ export function useCellUpdate(options: Options) {
graph.value?.addNode(node) graph.value?.addNode(node)
} }
const setNodeEdge = (id: string, preTaskCode: number[]) => { function removeNode(id: string) {
graph.value?.removeNode(id)
}
const getNodeEdge = (id: string): Edge[] => {
const node = graph.value?.getCellById(id) const node = graph.value?.getCellById(id)
if (!node) return if (!node) return []
const edges = graph.value?.getConnectedEdges(node) const edges = graph.value?.getConnectedEdges(node)
return edges || []
}
const setNodeEdge = (id: string, preTaskCode: number[]) => {
const edges = getNodeEdge(id)
if (edges?.length) { if (edges?.length) {
edges.forEach((edge) => { edges.forEach((edge) => {
graph.value?.removeEdge(edge) graph.value?.removeEdge(edge)
@ -84,9 +94,24 @@ export function useCellUpdate(options: Options) {
}) })
} }
const getSources = (id: string): number[] => {
const edges = getNodeEdge(id)
if (!edges.length) return []
const targets = [] as number[]
edges.forEach((edge) => {
const targetNode = edge.getSourceNode()
if (targetNode) {
targets.push(Number(targetNode.id))
}
})
return targets
}
return { return {
setNodeName, setNodeName,
setNodeEdge, setNodeEdge,
addNode addNode,
removeNode,
getSources
} }
} }

90
dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/use-task-edit.ts

@ -22,7 +22,12 @@ import { formatParams } from '@/views/projects/task/components/node/format-data'
import { useCellUpdate } from './dag-hooks' import { useCellUpdate } from './dag-hooks'
import type { Ref } from 'vue' import type { Ref } from 'vue'
import type { Graph } from '@antv/x6' import type { Graph } from '@antv/x6'
import type { Coordinate, NodeData, WorkflowDefinition } from './types' import type {
Coordinate,
NodeData,
WorkflowDefinition,
EditWorkflowDefinition
} from './types'
interface Options { interface Options {
graph: Ref<Graph | undefined> graph: Ref<Graph | undefined>
@ -36,10 +41,18 @@ interface Options {
*/ */
export function useTaskEdit(options: Options) { export function useTaskEdit(options: Options) {
const { graph, definition } = options const { graph, definition } = options
const { addNode, setNodeName, setNodeEdge } = useCellUpdate({ graph }) const { addNode, removeNode, getSources, setNodeName, setNodeEdge } =
const taskDefinitions = ref<NodeData[]>( useCellUpdate({
definition.value?.taskDefinitionList || [] graph
) })
const processDefinition = ref(
definition?.value || {
processDefinition: {},
processTaskRelationList: [],
taskDefinitionList: []
}
) as Ref<EditWorkflowDefinition>
const currTask = ref<NodeData>({ const currTask = ref<NodeData>({
taskType: 'SHELL', taskType: 'SHELL',
code: 0, code: 0,
@ -52,7 +65,7 @@ export function useTaskEdit(options: Options) {
*/ */
function appendTask(code: number, type: TaskType, coordinate: Coordinate) { function appendTask(code: number, type: TaskType, coordinate: Coordinate) {
addNode(code + '', type, '', 'YES', coordinate) addNode(code + '', type, '', 'YES', coordinate)
taskDefinitions.value.push({ processDefinition.value.taskDefinitionList.push({
code, code,
taskType: type, taskType: type,
name: '' name: ''
@ -72,7 +85,9 @@ export function useTaskEdit(options: Options) {
coordinate: Coordinate coordinate: Coordinate
) { ) {
addNode(code + '', type, name, flag, coordinate) addNode(code + '', type, name, flag, coordinate)
const definition = taskDefinitions.value.find((t) => t.code === targetCode) const definition = processDefinition.value.taskDefinitionList.find(
(t) => t.code === targetCode
)
const newDefinition = { const newDefinition = {
...definition, ...definition,
@ -80,7 +95,7 @@ export function useTaskEdit(options: Options) {
name name
} as NodeData } as NodeData
taskDefinitions.value.push(newDefinition) processDefinition.value.taskDefinitionList.push(newDefinition)
} }
/** /**
@ -88,9 +103,10 @@ export function useTaskEdit(options: Options) {
* @param {number} code * @param {number} code
*/ */
function removeTasks(codes: number[]) { function removeTasks(codes: number[]) {
taskDefinitions.value = taskDefinitions.value.filter( processDefinition.value.taskDefinitionList =
(task) => !codes.includes(task.code) processDefinition.value.taskDefinitionList.filter(
) (task) => !codes.includes(task.code)
)
} }
function openTaskModal(task: NodeData) { function openTaskModal(task: NodeData) {
@ -103,10 +119,13 @@ export function useTaskEdit(options: Options) {
* @param {number} code * @param {number} code
*/ */
function editTask(code: number) { function editTask(code: number) {
const definition = taskDefinitions.value.find((t) => t.code === code) const definition = processDefinition.value.taskDefinitionList.find(
(t) => t.code === code
)
if (definition) { if (definition) {
currTask.value = definition currTask.value = definition
} }
updatePreTasks(getSources(String(code)), code)
taskModalVisible.value = true taskModalVisible.value = true
} }
@ -118,19 +137,22 @@ export function useTaskEdit(options: Options) {
function taskConfirm({ data }: any) { function taskConfirm({ data }: any) {
const taskDef = formatParams(data).taskDefinitionJsonObj as NodeData const taskDef = formatParams(data).taskDefinitionJsonObj as NodeData
// override target config // override target config
taskDefinitions.value = taskDefinitions.value.map((task) => { processDefinition.value.taskDefinitionList =
if (task.code === currTask.value?.code) { processDefinition.value.taskDefinitionList.map((task) => {
setNodeName(task.code + '', taskDef.name) if (task.code === currTask.value?.code) {
updatePreTasks(data.preTasks, task.code) setNodeName(task.code + '', taskDef.name)
return {
...taskDef, setNodeEdge(String(task.code), data.preTasks)
version: task.version, updatePreTasks(data.preTasks, task.code)
code: task.code, return {
taskType: currTask.value.taskType ...taskDef,
version: task.version,
code: task.code,
taskType: currTask.value.taskType
}
} }
} return task
return task })
})
taskModalVisible.value = false taskModalVisible.value = false
} }
@ -139,19 +161,25 @@ export function useTaskEdit(options: Options) {
*/ */
function taskCancel() { function taskCancel() {
taskModalVisible.value = false taskModalVisible.value = false
if (!currTask.value.name) {
removeNode(String(currTask.value.code))
remove(
processDefinition.value.taskDefinitionList,
(task) => task.code === currTask.value.code
)
}
} }
function updatePreTasks(preTasks: number[], code: number) { function updatePreTasks(preTasks: number[], code: number) {
if (!preTasks?.length) return if (processDefinition.value?.processTaskRelationList?.length) {
setNodeEdge(String(code), preTasks)
if (definition.value?.processTaskRelationList?.length) {
remove( remove(
definition.value.processTaskRelationList, processDefinition.value.processTaskRelationList,
(process) => process.postTaskCode === code (process) => process.postTaskCode === code
) )
} }
if (!preTasks?.length) return
preTasks.forEach((task) => { preTasks.forEach((task) => {
definition.value?.processTaskRelationList.push({ processDefinition.value?.processTaskRelationList.push({
postTaskCode: code, postTaskCode: code,
preTaskCode: task, preTaskCode: task,
name: '', name: '',
@ -173,18 +201,18 @@ export function useTaskEdit(options: Options) {
}) })
watch(definition, () => { watch(definition, () => {
taskDefinitions.value = definition.value?.taskDefinitionList || [] if (definition.value) processDefinition.value = definition.value
}) })
return { return {
currTask, currTask,
taskModalVisible, taskModalVisible,
processDefinition,
taskConfirm, taskConfirm,
taskCancel, taskCancel,
appendTask, appendTask,
editTask, editTask,
copyTask, copyTask,
taskDefinitions,
removeTasks removeTasks
} }
} }

Loading…
Cancel
Save