From 659c610457c566160b9211764580eab93fdf8c01 Mon Sep 17 00:00:00 2001 From: songjianet <1778651752@qq.com> Date: Mon, 21 Mar 2022 20:00:25 +0800 Subject: [PATCH] [Fix][UI Next][V1.0.0-Alpha] Fix the monitoring center does not support multiple worker. (#9061) --- .../src/service/modules/monitor/types.ts | 8 +- .../views/monitor/servers/master/index.tsx | 4 +- .../monitor/servers/worker/index.module.scss | 32 +-- .../views/monitor/servers/worker/index.tsx | 212 ++++++++++-------- .../monitor/servers/worker/use-worker.ts | 18 +- .../monitor/servers/worker/worker-modal.tsx | 80 +++++++ .../option/components/form-modal.tsx | 21 +- 7 files changed, 233 insertions(+), 142 deletions(-) create mode 100644 dolphinscheduler-ui-next/src/views/monitor/servers/worker/worker-modal.tsx diff --git a/dolphinscheduler-ui-next/src/service/modules/monitor/types.ts b/dolphinscheduler-ui-next/src/service/modules/monitor/types.ts index 43615429f5..371b36786d 100644 --- a/dolphinscheduler-ui-next/src/service/modules/monitor/types.ts +++ b/dolphinscheduler-ui-next/src/service/modules/monitor/types.ts @@ -25,7 +25,7 @@ interface DatabaseRes { date: string } -interface MasterRes { +interface MasterNode { id: number host: string port: number @@ -35,14 +35,14 @@ interface MasterRes { lastHeartbeatTime: string } -interface WorkerRes { +interface WorkerNode { id: number host: string port: number - zkDirectories: string[] + zkDirectories: Array resInfo: string createTime: string lastHeartbeatTime: string } -export { DatabaseRes, MasterRes, WorkerRes } +export { DatabaseRes, MasterNode, WorkerNode } diff --git a/dolphinscheduler-ui-next/src/views/monitor/servers/master/index.tsx b/dolphinscheduler-ui-next/src/views/monitor/servers/master/index.tsx index 2d5f11607e..d1ca9fcc10 100644 --- a/dolphinscheduler-ui-next/src/views/monitor/servers/master/index.tsx +++ b/dolphinscheduler-ui-next/src/views/monitor/servers/master/index.tsx @@ -23,7 +23,7 @@ import styles from './index.module.scss' import Card from '@/components/card' import Gauge from '@/components/chart/modules/Gauge' import Modal from '@/components/modal' -import type { MasterRes } from '@/service/modules/monitor/types' +import type { MasterNode } from '@/service/modules/monitor/types' import type { Ref } from 'vue' import type { TableColumns } from 'naive-ui/es/data-table/src/interface' @@ -33,7 +33,7 @@ const master = defineComponent({ const showModalRef = ref(false) const { t } = useI18n() const { getMaster } = useMaster() - const masterRef: Ref> = ref(getMaster()) + const masterRef: Ref> = ref(getMaster()) const columnsRef: TableColumns = [ { title: '#', key: 'index' }, { title: t('monitor.master.directory'), key: 'directory' } diff --git a/dolphinscheduler-ui-next/src/views/monitor/servers/worker/index.module.scss b/dolphinscheduler-ui-next/src/views/monitor/servers/worker/index.module.scss index f882aff47f..c7cfae9198 100644 --- a/dolphinscheduler-ui-next/src/views/monitor/servers/worker/index.module.scss +++ b/dolphinscheduler-ui-next/src/views/monitor/servers/worker/index.module.scss @@ -23,29 +23,6 @@ min-height: 400px; } -.header-card { - margin-bottom: 8px; - - .content { - display: flex; - justify-content: space-between; - align-items: center; - - .left { - margin-right: 20px; - } - } - - .link-btn { - color: #579cd8; - cursor: pointer; - - &:hover { - color: #80bef7; - } - } -} - .card { @include base; } @@ -54,3 +31,12 @@ @include base; color: dodgerblue; } + +.link-btn { + color: #579cd8; + cursor: pointer; + + &:hover { + color: #80bef7; + } +} diff --git a/dolphinscheduler-ui-next/src/views/monitor/servers/worker/index.tsx b/dolphinscheduler-ui-next/src/views/monitor/servers/worker/index.tsx index 4c556d2a48..7de5c39a45 100644 --- a/dolphinscheduler-ui-next/src/views/monitor/servers/worker/index.tsx +++ b/dolphinscheduler-ui-next/src/views/monitor/servers/worker/index.tsx @@ -15,122 +15,136 @@ * limitations under the License. */ -import { defineComponent, ref } from 'vue' -import { NGrid, NGi, NCard, NNumberAnimation, NDataTable } from 'naive-ui' +import { defineComponent, onMounted, ref, toRefs } from 'vue' +import { NGrid, NGi, NCard, NNumberAnimation, NSpace } from 'naive-ui' import { useI18n } from 'vue-i18n' import { useWorker } from './use-worker' import styles from './index.module.scss' import Card from '@/components/card' import Gauge from '@/components/chart/modules/Gauge' -import Modal from '@/components/modal' -import type { WorkerRes } from '@/service/modules/monitor/types' +import WorkerModal from './worker-modal' import type { Ref } from 'vue' -import type { TableColumns } from 'naive-ui/es/data-table/src/interface' +import type { RowData } from 'naive-ui/es/data-table/src/interface' +import type { WorkerNode } from '@/service/modules/monitor/types' const master = defineComponent({ name: 'master', setup() { const showModalRef = ref(false) const { t } = useI18n() - const { getWorker } = useWorker() - const workerRef: Ref> = ref(getWorker()) - const columnsRef: TableColumns = [ - { title: '#', key: 'index', render: (row, index) => index + 1 }, - { title: t('monitor.worker.directory'), key: 'directory' } - ] + const { variables, getTableWorker } = useWorker() + const zkDirectoryRef: Ref> = ref([]) - return { t, workerRef, showModalRef, columnsRef } + const clickDetails = (zkDirectories: Array) => { + zkDirectoryRef.value = zkDirectories.map((zkItem) => { + return { + directory: zkItem + } + }) + showModalRef.value = true + } + + const onConfirmModal = () => { + showModalRef.value = false + } + + onMounted(() => { + getTableWorker() + }) + + return { + t, + ...toRefs(variables), + clickDetails, + onConfirmModal, + showModalRef, + zkDirectoryRef + } }, render() { - const { t, workerRef, columnsRef } = this + const { t, clickDetails, onConfirmModal, showModalRef, zkDirectoryRef } = + this return ( -
- -
-

- {`${t('monitor.worker.host')}: ${ - workerRef[0] ? workerRef[0].host : ' - ' - }`} - (this.showModalRef = true)} - > - {t('monitor.worker.directory_detail')} - -

-

- {`${t('monitor.worker.create_time')}: ${ - workerRef[0] ? workerRef[0].createTime : ' - ' - }`} - {`${t('monitor.worker.last_heartbeat_time')}: ${ - workerRef[0] ? workerRef[0].lastHeartbeatTime : ' - ' - }`} -

-
-
- - - -
- {workerRef[0] && ( - - )} -
-
-
- - -
- {workerRef[0] && ( - - )} -
-
-
- - -
- {workerRef[0] && ( - - )} -
-
-
-
- (this.showModalRef = false)} - > - {{ - default: () => - workerRef[0] && ( - { - return { directory: item } - })} - striped - size={'small'} - /> - ) - }} - -
+ <> + + {this.data.map((item: WorkerNode) => { + return ( + + + + + {`${t('monitor.worker.host')}: ${ + item ? item.host : ' - ' + }`} + clickDetails(item.zkDirectories)} + > + {t('monitor.worker.directory_detail')} + + + + {`${t('monitor.worker.create_time')}: ${ + item ? item.createTime : ' - ' + }`} + {`${t('monitor.worker.last_heartbeat_time')}: ${ + item ? item.lastHeartbeatTime : ' - ' + }`} + + + + + + +
+ {item && ( + + )} +
+
+
+ + +
+ {item && ( + + )} +
+
+
+ + +
+ {item && ( + + )} +
+
+
+
+
+ ) + })} +
+ + ) } }) diff --git a/dolphinscheduler-ui-next/src/views/monitor/servers/worker/use-worker.ts b/dolphinscheduler-ui-next/src/views/monitor/servers/worker/use-worker.ts index 20bb85811c..06ec70bea1 100644 --- a/dolphinscheduler-ui-next/src/views/monitor/servers/worker/use-worker.ts +++ b/dolphinscheduler-ui-next/src/views/monitor/servers/worker/use-worker.ts @@ -15,14 +15,26 @@ * limitations under the License. */ +import { reactive } from 'vue' import { useAsyncState } from '@vueuse/core' import { listWorker } from '@/service/modules/monitor' +import type { WorkerNode } from '@/service/modules/monitor/types' export function useWorker() { - const getWorker = () => { - const { state } = useAsyncState(listWorker(), []) + const variables = reactive({ + data: [] + }) + + const getTableWorker = () => { + const { state } = useAsyncState( + listWorker().then((res: Array) => { + variables.data = res as any + }), + [] + ) + return state } - return { getWorker } + return { variables, getTableWorker } } diff --git a/dolphinscheduler-ui-next/src/views/monitor/servers/worker/worker-modal.tsx b/dolphinscheduler-ui-next/src/views/monitor/servers/worker/worker-modal.tsx new file mode 100644 index 0000000000..f90ab5cbe1 --- /dev/null +++ b/dolphinscheduler-ui-next/src/views/monitor/servers/worker/worker-modal.tsx @@ -0,0 +1,80 @@ +/* + * 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 { useI18n } from 'vue-i18n' +import { NDataTable } from 'naive-ui' +import Modal from '@/components/modal' +import type { PropType } from 'vue' +import type { + RowData, + TableColumns +} from 'naive-ui/es/data-table/src/interface' + +const props = { + showModal: { + type: Boolean as PropType, + default: false + }, + data: { + type: Array as PropType>, + default: () => [] + } +} + +const WorkerModal = defineComponent({ + props, + emits: ['confirmModal'], + setup(props, ctx) { + const { t } = useI18n() + const columnsRef: TableColumns = [ + { title: '#', key: 'index', render: (row, index) => index + 1 }, + { title: t('monitor.worker.directory'), key: 'directory' } + ] + + const onConfirm = () => { + ctx.emit('confirmModal') + } + + return { t, columnsRef, onConfirm } + }, + render() { + const { t, columnsRef, onConfirm } = this + + return ( + + {{ + default: () => ( + + ) + }} + + ) + } +}) + +export default WorkerModal diff --git a/dolphinscheduler-ui-next/src/views/resource/task-group/option/components/form-modal.tsx b/dolphinscheduler-ui-next/src/views/resource/task-group/option/components/form-modal.tsx index 011a366b3e..47be759f58 100644 --- a/dolphinscheduler-ui-next/src/views/resource/task-group/option/components/form-modal.tsx +++ b/dolphinscheduler-ui-next/src/views/resource/task-group/option/components/form-modal.tsx @@ -115,21 +115,20 @@ const FormModal = defineComponent({ placeholder={t('resource.task_group_option.please_enter_name')} /> - { this.status === 0 && ( - + > - - ) - } + + )}