index.tsx 4.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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.
 */

18
import type { Graph } from '@antv/x6'
19
import { defineComponent, ref, provide, PropType, toRef } from 'vue'
20 21 22 23
import DagToolbar from './dag-toolbar'
import DagCanvas from './dag-canvas'
import DagSidebar from './dag-sidebar'
import Styles from './dag.module.scss'
24
import DagAutoLayoutModal from './dag-auto-layout-modal'
25 26 27 28 29
import {
  useGraphAutoLayout,
  useGraphBackfill,
  useDagDragAndDrop
} from './dag-hooks'
30
import { useThemeStore } from '@/store/theme/theme'
31 32
import VersionModal from '../../definition/components/version-modal'
import { WorkflowDefinition } from './types'
33
import DagSaveModal from './dag-save-modal'
34
import './x6-style.scss'
35

36 37 38 39 40 41 42 43 44 45
const props = {
  // If this prop is passed, it means from definition detail
  definition: {
    type: Object as PropType<WorkflowDefinition>,
    default: undefined
  },
  readonly: {
    type: Boolean as PropType<boolean>,
    default: false
  }
46 47 48
}

export default defineComponent({
49
  name: 'workflow-dag',
50 51
  props,
  emits: ['refresh'],
52
  setup(props, context) {
53 54
    const theme = useThemeStore()

55
    // Whether the graph can be operated
56
    provide('readonly', toRef(props, 'readonly'))
57

58 59
    const graph = ref<Graph>()
    provide('graph', graph)
60

61
    // Auto layout modal
62 63 64 65 66 67 68 69
    const {
      visible: layoutVisible,
      toggle: layoutToggle,
      formValue,
      formRef,
      submit,
      cancel
    } = useGraphAutoLayout({ graph })
70

71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    const { onDragStart, onDrop } = useDagDragAndDrop({
      graph,
      readonly: toRef(props, 'readonly')
    })

    // backfill
    useGraphBackfill({ graph, definition: toRef(props, 'definition') })

    // version modal
    const versionModalShow = ref(false)
    const versionToggle = (bool: boolean) => {
      if (typeof bool === 'boolean') {
        versionModalShow.value = bool
      } else {
        versionModalShow.value = !versionModalShow.value
      }
    }
    const refreshDetail = () => {
      context.emit('refresh')
      versionModalShow.value = false
    }

93 94 95 96 97 98 99 100 101 102 103 104 105 106
    // Save modal
    const saveModalShow = ref(false)
    const saveModelToggle = (bool: boolean) => {
      if (typeof bool === 'boolean') {
        saveModalShow.value = bool
      } else {
        saveModalShow.value = !versionModalShow.value
      }
    }
    const onSave = (form: any) => {
      // TODO
      console.log(form)
    }

107
    return () => (
108 109 110 111 112 113
      <div
        class={[
          Styles.dag,
          Styles[`dag-${theme.darkTheme ? 'dark' : 'light'}`]
        ]}
      >
114 115 116 117
        <DagToolbar
          layoutToggle={layoutToggle}
          definition={props.definition}
          onVersionToggle={versionToggle}
118
          onSaveModelToggle={saveModelToggle}
119
        />
120
        <div class={Styles.content}>
121 122
          <DagSidebar onDragStart={onDragStart} />
          <DagCanvas onDrop={onDrop} />
123
        </div>
124 125 126 127 128 129 130
        <DagAutoLayoutModal
          visible={layoutVisible.value}
          submit={submit}
          cancel={cancel}
          formValue={formValue}
          formRef={formRef}
        />
131 132 133 134 135 136 137
        {!!props.definition && (
          <VersionModal
            v-model:row={props.definition.processDefinition}
            v-model:show={versionModalShow.value}
            onUpdateList={refreshDetail}
          />
        )}
138
        <DagSaveModal v-model:show={saveModalShow.value} onSave={onSave} />
139 140 141
      </div>
    )
  }
142
})