Browse Source

[Fix-8598][UI Next][V1.0.0-Alpha] Fix menu readonly bug in workflow instance

3.0.0/version-upgrade
Devosend 3 years ago committed by GitHub
parent
commit
985b4e8520
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 55
      dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/dag-context-menu.tsx
  2. 82
      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. 56
      dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/use-node-menu.ts
  5. 3
      dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/use-node-status.ts

55
dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/dag-context-menu.tsx

@ -17,28 +17,30 @@
import { genTaskCodeList } from '@/service/modules/task-definition' import { genTaskCodeList } from '@/service/modules/task-definition'
import type { Cell } from '@antv/x6' import type { Cell } from '@antv/x6'
import { import { defineComponent, onMounted, PropType, inject, ref } from 'vue'
defineComponent,
onMounted,
PropType,
inject,
ref,
computed
} from 'vue'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import styles from './menu.module.scss' import styles from './menu.module.scss'
import { uuid } from '@/utils/common' import { uuid } from '@/utils/common'
import { IWorkflowTaskInstance } from './types'
const props = { const props = {
startReadonly: {
type: Boolean as PropType<boolean>,
default: false
},
menuReadonly: {
type: Boolean as PropType<boolean>,
default: false
},
taskInstance: {
type: Object as PropType<IWorkflowTaskInstance>,
require: true
},
cell: { cell: {
type: Object as PropType<Cell>, type: Object as PropType<Cell>,
require: true require: true
}, },
taskList: {
type: Array as PropType<Array<any>>,
default: []
},
visible: { visible: {
type: Boolean as PropType<boolean>, type: Boolean as PropType<boolean>,
default: true default: true
@ -50,10 +52,6 @@ const props = {
top: { top: {
type: Number as PropType<number>, type: Number as PropType<number>,
default: 0 default: 0
},
releaseState: {
type: String as PropType<string>,
default: 'OFFLINE'
} }
} }
@ -66,12 +64,6 @@ export default defineComponent({
const route = useRoute() const route = useRoute()
const projectCode = Number(route.params.projectCode) const projectCode = Number(route.params.projectCode)
const startAvailable = computed(
() =>
route.name === 'workflow-definition-detail' &&
props.releaseState !== 'NOT_RELEASE'
)
const hide = () => { const hide = () => {
ctx.emit('hide', false) ctx.emit('hide', false)
} }
@ -85,12 +77,8 @@ export default defineComponent({
} }
const handleViewLog = () => { const handleViewLog = () => {
const taskCode = Number(props.cell?.id) if (props.taskInstance) {
const taskInstance = props.taskList.find( ctx.emit('viewLog', props.taskInstance.id, props.taskInstance.taskType)
(task: any) => task.taskCode === taskCode
)
if (taskInstance) {
ctx.emit('viewLog', taskInstance.id, taskInstance.taskType)
} }
} }
@ -122,7 +110,6 @@ export default defineComponent({
}) })
return { return {
startAvailable,
startRunning, startRunning,
handleEdit, handleEdit,
handleCopy, handleCopy,
@ -141,7 +128,7 @@ export default defineComponent({
> >
<div <div
class={`${styles['menu-item']} ${ class={`${styles['menu-item']} ${
!this.startAvailable ? styles['disabled'] : '' this.startReadonly ? styles['disabled'] : ''
} `} } `}
onClick={this.startRunning} onClick={this.startRunning}
> >
@ -149,7 +136,7 @@ export default defineComponent({
</div> </div>
<div <div
class={`${styles['menu-item']} ${ class={`${styles['menu-item']} ${
this.releaseState === 'ONLINE' ? styles['disabled'] : '' this.menuReadonly ? styles['disabled'] : ''
} `} } `}
onClick={this.handleEdit} onClick={this.handleEdit}
> >
@ -157,7 +144,7 @@ export default defineComponent({
</div> </div>
<div <div
class={`${styles['menu-item']} ${ class={`${styles['menu-item']} ${
this.releaseState === 'ONLINE' ? styles['disabled'] : '' this.menuReadonly ? styles['disabled'] : ''
} `} } `}
onClick={this.handleCopy} onClick={this.handleCopy}
> >
@ -165,13 +152,13 @@ export default defineComponent({
</div> </div>
<div <div
class={`${styles['menu-item']} ${ class={`${styles['menu-item']} ${
this.releaseState === 'ONLINE' ? styles['disabled'] : '' this.menuReadonly ? styles['disabled'] : ''
} `} } `}
onClick={this.handleDelete} onClick={this.handleDelete}
> >
{t('project.node.delete')} {t('project.node.delete')}
</div> </div>
{this.taskList.length > 0 && ( {this.taskInstance && (
<div class={`${styles['menu-item']}`} onClick={this.handleViewLog}> <div class={`${styles['menu-item']}`} onClick={this.handleViewLog}>
{t('project.node.view_log')} {t('project.node.view_log')}
</div> </div>

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

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import type { Graph } from '@antv/x6' import type { Cell, Graph } from '@antv/x6'
import { import {
defineComponent, defineComponent,
ref, ref,
@ -23,9 +23,11 @@ import {
PropType, PropType,
toRef, toRef,
watch, watch,
onBeforeUnmount onBeforeUnmount,
computed
} from 'vue' } from 'vue'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { useRoute } from 'vue-router'
import DagToolbar from './dag-toolbar' import DagToolbar from './dag-toolbar'
import DagCanvas from './dag-canvas' import DagCanvas from './dag-canvas'
import DagSidebar from './dag-sidebar' import DagSidebar from './dag-sidebar'
@ -76,6 +78,7 @@ export default defineComponent({
emits: ['refresh', 'save'], emits: ['refresh', 'save'],
setup(props, context) { setup(props, context) {
const { t } = useI18n() const { t } = useI18n()
const route = useRoute()
const theme = useThemeStore() const theme = useThemeStore()
// Whether the graph can be operated // Whether the graph can be operated
@ -108,23 +111,49 @@ export default defineComponent({
} = useTaskEdit({ graph, definition: toRef(props, 'definition') }) } = useTaskEdit({ graph, definition: toRef(props, 'definition') })
// Right click cell // Right click cell
const { const { nodeVariables, menuHide, menuStart, viewLog, hideLog } =
menuCell, useNodeMenu({
pageX,
pageY,
menuVisible,
startModalShow,
logModalShow,
logViewTaskId,
logViewTaskType,
menuHide,
menuStart,
viewLog,
hideLog
} = useNodeMenu({
graph graph
}) })
// start button in the dag node menu
const startReadonly = computed(() => {
if (props.definition) {
return (
route.name === 'workflow-definition-detail' &&
props.definition!.processDefinition.releaseState === 'NOT_RELEASE'
)
} else {
return false
}
})
// other button in the dag node menu
const menuReadonly = computed(() => {
if (props.instance) {
return (
props.instance.state !== 'WAITING_THREAD' &&
props.instance.state !== 'SUCCESS' &&
props.instance.state !== 'PAUSE' &&
props.instance.state !== 'FAILURE' &&
props.instance.state !== 'STOP'
)
} else if (props.definition) {
return props.definition!.processDefinition.releaseState === 'ONLINE'
} else {
return false
}
})
const taskInstance = computed(() => {
if (nodeVariables.menuCell) {
const taskCode = Number(nodeVariables.menuCell!.id)
return taskList.value.find((task: any) => task.taskCode === taskCode)
} else {
return undefined
}
})
const statusTimerRef = ref() const statusTimerRef = ref()
const { taskList, refreshTaskStatus } = useNodeStatus({ graph }) const { taskList, refreshTaskStatus } = useNodeStatus({ graph })
@ -240,12 +269,13 @@ export default defineComponent({
onCancel={taskCancel} onCancel={taskCancel}
/> />
<ContextMenuItem <ContextMenuItem
taskList={taskList.value} startReadonly={startReadonly.value}
cell={menuCell.value} menuReadonly={menuReadonly.value}
visible={menuVisible.value} taskInstance={taskInstance.value}
left={pageX.value} cell={nodeVariables.menuCell as Cell}
top={pageY.value} visible={nodeVariables.menuVisible}
releaseState={props.definition?.processDefinition.releaseState} left={nodeVariables.pageX}
top={nodeVariables.pageY}
onHide={menuHide} onHide={menuHide}
onStart={menuStart} onStart={menuStart}
onEdit={editTask} onEdit={editTask}
@ -256,13 +286,13 @@ export default defineComponent({
{!!props.definition && ( {!!props.definition && (
<StartModal <StartModal
v-model:row={props.definition.processDefinition} v-model:row={props.definition.processDefinition}
v-model:show={startModalShow.value} v-model:show={nodeVariables.startModalShow}
/> />
)} )}
{!!props.instance && logModalShow.value && ( {!!props.instance && nodeVariables.logModalShow && (
<LogModal <LogModal
taskInstanceId={logViewTaskId.value} taskInstanceId={nodeVariables.logTaskId}
taskInstanceType={logViewTaskType.value} taskInstanceType={nodeVariables.logTaskType}
onHideLog={hideLog} onHideLog={hideLog}
/> />
)} )}

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

@ -143,3 +143,9 @@ export interface IStartupParam {
warningType: string warningType: string
warningGroupId: number warningGroupId: number
} }
export interface IWorkflowTaskInstance {
id: number
taskCode: number
taskType: string
}

56
dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/use-node-menu.ts

@ -15,8 +15,8 @@
* limitations under the License. * limitations under the License.
*/ */
import type { Ref } from 'vue' import { reactive, Ref } from 'vue'
import { onMounted, ref } from 'vue' import { onMounted } from 'vue'
import type { Graph, Cell } from '@antv/x6' import type { Graph, Cell } from '@antv/x6'
interface Options { interface Options {
@ -28,63 +28,59 @@ interface Options {
*/ */
export function useNodeMenu(options: Options) { export function useNodeMenu(options: Options) {
const { graph } = options const { graph } = options
const startModalShow = ref(false)
const logModalShow = ref(false) const nodeVariables = reactive({
const logViewTaskId = ref() menuVisible: false,
const logViewTaskType = ref() startModalShow: false,
const menuVisible = ref(false) logModalShow: false,
const pageX = ref() logTaskId: -1,
const pageY = ref() logTaskType: '',
const menuCell = ref<Cell>() pageX: 0,
pageY: 0,
menuCell: {} as Cell
})
const menuHide = () => { const menuHide = () => {
menuVisible.value = false nodeVariables.menuVisible = false
// unlock scroller // unlock scroller
graph.value?.unlockScroller() graph.value?.unlockScroller()
} }
const menuStart = () => { const menuStart = () => {
startModalShow.value = true nodeVariables.startModalShow = true
} }
const viewLog = (taskId: number, taskType: string) => { const viewLog = (taskId: number, taskType: string) => {
logViewTaskId.value = taskId nodeVariables.logTaskId = taskId
logViewTaskType.value = taskType nodeVariables.logTaskType = taskType
logModalShow.value = true nodeVariables.logModalShow = true
} }
const hideLog = () => { const hideLog = () => {
logModalShow.value = false nodeVariables.logModalShow = false
} }
onMounted(() => { onMounted(() => {
if (graph.value) { if (graph.value) {
// contextmenu // contextmenu
graph.value.on('node:contextmenu', ({ cell, x, y }) => { graph.value.on('node:contextmenu', ({ cell, x, y }) => {
menuCell.value = cell nodeVariables.menuCell = cell
const data = graph.value?.localToPage(x, y) const data = graph.value!.localToPage(x, y)
pageX.value = data?.x nodeVariables.pageX = data.x
pageY.value = data?.y nodeVariables.pageY = data.y
// show menu // show menu
menuVisible.value = true nodeVariables.menuVisible = true
// lock scroller // lock scroller
graph.value?.lockScroller() graph.value!.lockScroller()
}) })
} }
}) })
return { return {
pageX, nodeVariables,
pageY,
startModalShow,
logModalShow,
logViewTaskId,
logViewTaskType,
menuVisible,
menuCell,
menuHide, menuHide,
menuStart, menuStart,
viewLog, viewLog,

3
dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/use-node-status.ts

@ -24,6 +24,7 @@ import { tasksState } from '@/utils/common'
import { NODE, NODE_STATUS_MARKUP } from './dag-config' import { NODE, NODE_STATUS_MARKUP } from './dag-config'
import { queryTaskListByProcessId } from '@/service/modules/process-instances' import { queryTaskListByProcessId } from '@/service/modules/process-instances'
import NodeStatus from '@/views/projects/workflow/components/dag/dag-node-status' import NodeStatus from '@/views/projects/workflow/components/dag/dag-node-status'
import { IWorkflowTaskInstance } from './types'
interface Options { interface Options {
graph: Ref<Graph | undefined> graph: Ref<Graph | undefined>
@ -35,7 +36,7 @@ interface Options {
export function useNodeStatus(options: Options) { export function useNodeStatus(options: Options) {
const { graph } = options const { graph } = options
const route = useRoute() const route = useRoute()
const taskList = ref<Array<Object>>([]) const taskList = ref<Array<IWorkflowTaskInstance>>([])
const { t } = useI18n() const { t } = useI18n()

Loading…
Cancel
Save