Browse Source

[Feature][UI] Add a method for adding a single node to the dag. (#12628)

3.2.0-release
songjianet 2 years ago committed by GitHub
parent
commit
883c754951
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      dolphinscheduler-ui/package.json
  2. 17
      dolphinscheduler-ui/pnpm-lock.yaml
  3. 24
      dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/dag-canvas.tsx
  4. 33
      dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/dag-node.tsx
  5. 1
      dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/dag-setting.ts
  6. 6
      dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/dag-sidebar.tsx
  7. 38
      dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/index.tsx
  8. 10
      dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/use-add-dag-shape.ts
  9. 11
      dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/use-dag-node.ts
  10. 5
      dolphinscheduler-ui/vite.config.ts

1
dolphinscheduler-ui/package.json

@ -11,7 +11,6 @@
"dependencies": { "dependencies": {
"@antv/layout": "0.1.31", "@antv/layout": "0.1.31",
"@antv/x6": "^1.34.1", "@antv/x6": "^1.34.1",
"@antv/x6-vue-shape": "^1.5.3",
"@vueuse/core": "^9.2.0", "@vueuse/core": "^9.2.0",
"axios": "^0.27.2", "axios": "^0.27.2",
"date-fns": "^2.29.3", "date-fns": "^2.29.3",

17
dolphinscheduler-ui/pnpm-lock.yaml

@ -20,7 +20,6 @@ lockfileVersion: 5.4
specifiers: specifiers:
'@antv/layout': 0.1.31 '@antv/layout': 0.1.31
'@antv/x6': ^1.34.1 '@antv/x6': ^1.34.1
'@antv/x6-vue-shape': ^1.5.3
'@types/js-cookie': ^3.0.2 '@types/js-cookie': ^3.0.2
'@types/lodash': ^4.14.185 '@types/lodash': ^4.14.185
'@types/node': ^18.7.18 '@types/node': ^18.7.18
@ -66,7 +65,6 @@ specifiers:
dependencies: dependencies:
'@antv/layout': 0.1.31 '@antv/layout': 0.1.31
'@antv/x6': 1.34.1 '@antv/x6': 1.34.1
'@antv/x6-vue-shape': 1.5.3_@antv+x6@1.34.1+vue@3.2.39
'@vueuse/core': 9.2.0_vue@3.2.39 '@vueuse/core': 9.2.0_vue@3.2.39
axios: 0.27.2 axios: 0.27.2
date-fns: 2.29.3 date-fns: 2.29.3
@ -173,21 +171,6 @@ packages:
ml-matrix: 6.10.2 ml-matrix: 6.10.2
dev: false dev: false
/@antv/x6-vue-shape/1.5.3_@antv+x6@1.34.1+vue@3.2.39:
resolution: {integrity: sha512-VnuXd8gE6bONYp4U51n3PxjM1UTuotca51f+hjaMqOy1X+HQf/nAN69oD+Y2wsPDRFZnZcipVol/dLxHS3Fd9w==}
peerDependencies:
'@antv/x6': '>=1.0.0'
'@vue/composition-api': ^1.0.0-rc.6
vue: ^2.6.12 || ^3.0.0
peerDependenciesMeta:
'@vue/composition-api':
optional: true
dependencies:
'@antv/x6': 1.34.1
vue: 3.2.39
vue-demi: 0.13.11_vue@3.2.39
dev: false
/@antv/x6/1.34.1: /@antv/x6/1.34.1:
resolution: {integrity: sha512-4dNE9h//SY5ID8W+9YU5dE58d0+V9lCXlg0CiI6+4jFCud3RfLkPjni1dpmUo+HDWtrQ0wB80o42HLat9+FYZA==} resolution: {integrity: sha512-4dNE9h//SY5ID8W+9YU5dE58d0+V9lCXlg0CiI6+4jFCud3RfLkPjni1dpmUo+HDWtrQ0wB80o42HLat9+FYZA==}
dependencies: dependencies:

24
dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/dag-canvas.tsx

@ -15,14 +15,14 @@
* limitations under the License. * limitations under the License.
*/ */
import { defineComponent, ref, onMounted } from 'vue' import { defineComponent, ref, onMounted, watch } from 'vue'
import { Graph } from '@antv/x6' import { Graph } from '@antv/x6'
import { useDagResize } from './use-dag-resize' import { useDagResize } from './use-dag-resize'
import { useDagGraph } from './use-dag-graph' import { useDagGraph } from './use-dag-graph'
import { useDagNode } from './use-dag-node' import { useDagNode } from './use-dag-node'
import { useDagEdge } from './use-dag-edge' import { useAddDagShape } from './use-add-dag-shape'
//import { useAddDagShape } from './use-add-dag-shape' import { useDagStore } from '@/store/project/dynamic/dag'
import { DagNodeName, DagEdgeName } from './dag-setting' import { DagNodeName } from './dag-setting'
import styles from './dag-canvas.module.scss' import styles from './dag-canvas.module.scss'
const DagCanvas = defineComponent({ const DagCanvas = defineComponent({
@ -33,6 +33,7 @@ const DagCanvas = defineComponent({
const dagContainer = ref() const dagContainer = ref()
const minimapContainer = ref() const minimapContainer = ref()
const graph = ref<Graph>() const graph = ref<Graph>()
const dagTasks = useDagStore().getDagTasks
if (graph.value) { if (graph.value) {
useDagResize(dagContainer.value, graph.value) useDagResize(dagContainer.value, graph.value)
@ -47,15 +48,6 @@ const DagCanvas = defineComponent({
Graph.registerNode(DagNodeName, useDagNode()) Graph.registerNode(DagNodeName, useDagNode())
} }
const registerEdge = () => {
Graph.unregisterEdge(DagEdgeName)
Graph.registerEdge(
DagEdgeName,
useDagEdge(),
true
)
}
const handlePreventDefault = (e: DragEvent) => { const handlePreventDefault = (e: DragEvent) => {
e.preventDefault() e.preventDefault()
} }
@ -67,8 +59,10 @@ const DagCanvas = defineComponent({
onMounted(() => { onMounted(() => {
initGraph() initGraph()
registerNode() registerNode()
registerEdge() })
//useAddDagShape((graph.value as Graph))
watch(dagTasks, () => {
useAddDagShape((graph.value as Graph))
}) })
return { return {

33
dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/dag-node.tsx

@ -1,33 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { defineComponent } from 'vue'
import styles from './dag-node.module.scss'
const DagNode = defineComponent({
name: 'DagNode',
setup() {
},
render() {
return (
<div class={styles['dag-node']}>1111</div>
)
}
})
export { DagNode }

1
dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/dag-setting.ts

@ -19,3 +19,4 @@ export const DagNodeName = 'dag-node'
export const DagEdgeName = 'dag-edge' export const DagEdgeName = 'dag-edge'
export const NodeWidth = '200' export const NodeWidth = '200'
export const NodeHeight = '50' export const NodeHeight = '50'
export const NodeShape = 'rect'

6
dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/dag-sidebar.tsx

@ -25,8 +25,8 @@ const DagSidebar = defineComponent({
setup(props, context) { setup(props, context) {
const { variables, getTaskList } = useSidebar() const { variables, getTaskList } = useSidebar()
const handleDragstart = (e: DragEvent, task: string) => { const handleDragstart = (task: string) => {
context.emit('Dragstart', e, task) context.emit('Dragstart', task)
} }
onMounted(() => { onMounted(() => {
@ -44,7 +44,7 @@ const DagSidebar = defineComponent({
{ {
this.taskList.map(task => { this.taskList.map(task => {
return ( return (
<div class={styles['task-item']} draggable='true' onDragstart={(e: DragEvent) => this.handleDragstart(e, task)}> <div class={styles['task-item']} draggable='true' onDragstart={() => this.handleDragstart(task)}>
{task} {task}
</div> </div>
) )

38
dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/index.tsx

@ -15,38 +15,42 @@
* limitations under the License. * limitations under the License.
*/ */
import { defineComponent, reactive } from 'vue' import { defineComponent, ref } from 'vue'
import { DagSidebar } from './dag-sidebar' import { DagSidebar } from './dag-sidebar'
import { DagCanvas } from './dag-canvas' import { DagCanvas } from './dag-canvas'
import { useDagStore } from '@/store/project/dynamic/dag' import { useDagStore } from '@/store/project/dynamic/dag'
import { NodeShape, NodeHeight, NodeWidth } from './dag-setting'
import styles from './index.module.scss' import styles from './index.module.scss'
const DynamicDag = defineComponent({ const DynamicDag = defineComponent({
name: 'DynamicDag', name: 'DynamicDag',
setup() { setup() {
const dragged = reactive({ const draggedTask = ref('')
x: 0,
y: 0,
task: ''
})
const handelDragstart = (e: DragEvent, task: string) => { const handelDragstart = (task: string) => {
dragged.x = e.offsetX draggedTask.value = task
dragged.y = e.offsetY
dragged.task = task
} }
const handelDrop = (e: DragEvent) => { const handelDrop = (e: DragEvent) => {
if (!dragged.task) return if (!draggedTask) return
dragged.x = e.offsetX
dragged.y = e.offsetY
const shapes = useDagStore().getDagTasks const shapes = useDagStore().getDagTasks
if (shapes) {
shapes.push(dragged) shapes.push({
} id: String(shapes.length + 1),
x: e.offsetX,
y: e.offsetY,
width: NodeWidth,
height: NodeHeight,
shape: NodeShape,
label: draggedTask.value + String(shapes.length + 1),
zIndex: 1,
task: draggedTask.value
})
useDagStore().setDagTasks(shapes) useDagStore().setDagTasks(shapes)
} }
return { return {

10
dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/use-add-dag-shape.ts

@ -21,13 +21,5 @@ import { useDagStore } from '@/store/project/dynamic/dag'
export function useAddDagShape(graph: Graph) { export function useAddDagShape(graph: Graph) {
const cells: Array<Cell> = useDagStore().getDagTasks const cells: Array<Cell> = useDagStore().getDagTasks
cells.forEach(item => { ;(graph as Graph).addNode(cells.at(-1) as any)
if (item.shape === 'dag-edge') {
cells.push((graph as Graph).addEdge(item))
} else {
cells.push((graph as Graph).addNode(item as any))
}
})
;(graph as Graph).resetCells(cells)
} }

11
dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/use-dag-node.ts

@ -15,17 +15,10 @@
* limitations under the License. * limitations under the License.
*/ */
import { createVNode } from 'vue' import { NodeShape } from './dag-setting'
import { DagNode } from './dag-node'
import '@antv/x6-vue-shape'
export function useDagNode() { export function useDagNode() {
return { return {
inherit: 'vue-shape', inherit: NodeShape
component: {
render: () => {
return createVNode(DagNode)
}
}
} }
} }

5
dolphinscheduler-ui/vite.config.ts

@ -37,11 +37,8 @@ export default defineConfig({
], ],
resolve: { resolve: {
alias: { alias: {
'@': path.resolve(__dirname, 'src'), '@': path.resolve(__dirname, 'src')
// resolve vue-i18n warning: You are running the esm-bundler build of vue-i18n. // resolve vue-i18n warning: You are running the esm-bundler build of vue-i18n.
'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
'@antv/x6': '@antv/x6/dist/x6.js',
'@antv/x6-vue-shape': '@antv/x6-vue-shape/lib'
} }
}, },
server: { server: {

Loading…
Cancel
Save