From 41e9ecc16633da8c0aa31bf03870d253161add49 Mon Sep 17 00:00:00 2001 From: Sparkle <1284531+baurine@users.noreply.github.com> Date: Fri, 13 Dec 2019 21:15:25 +0800 Subject: [PATCH] Update DM Portal (#417) * portal: rename dm-fe folder to frontend * portal: udpate frontend README * portal: add option to control whether auto sync with upstream newly added schemas or tables * portal: validate the task name * portal: differ the undo and reset action more clearly --- dm/portal/{dm-fe => frontend}/.gitignore | 0 dm/portal/{dm-fe => frontend}/README.md | 2 +- .../{dm-fe => frontend}/config-overrides.js | 0 dm/portal/{dm-fe => frontend}/package.json | 0 .../{dm-fe => frontend}/public/favicon.ico | Bin .../{dm-fe => frontend}/public/index.html | 0 .../{dm-fe => frontend}/public/manifest.json | 0 .../{dm-fe => frontend}/src/App.test.tsx | 0 dm/portal/{dm-fe => frontend}/src/App.tsx | 0 .../src/components/BinlogFilterModal.tsx | 0 .../src/components/InstancesStep.tsx | 0 .../src/components/Layout.tsx | 0 .../src/components/MigrateStep.tsx | 90 +++++++++++------- .../src/components/NamingStep.tsx | 58 ++++++++--- .../src/components/StartStep.tsx | 3 +- .../src/components/UploadStep.tsx | 0 dm/portal/{dm-fe => frontend}/src/index.css | 0 dm/portal/{dm-fe => frontend}/src/index.tsx | 0 dm/portal/{dm-fe => frontend}/src/logo.svg | 0 .../src/react-app-env.d.ts | 0 .../{dm-fe => frontend}/src/serviceWorker.ts | 0 .../{dm-fe => frontend}/src/services/api.ts | 0 dm/portal/{dm-fe => frontend}/src/types.ts | 0 .../src/utils/config-util.ts | 17 ++-- .../{dm-fe => frontend}/src/utils/request.ts | 0 dm/portal/{dm-fe => frontend}/tsconfig.json | 0 dm/portal/{dm-fe => frontend}/yarn.lock | 0 27 files changed, 114 insertions(+), 56 deletions(-) rename dm/portal/{dm-fe => frontend}/.gitignore (100%) rename dm/portal/{dm-fe => frontend}/README.md (87%) rename dm/portal/{dm-fe => frontend}/config-overrides.js (100%) rename dm/portal/{dm-fe => frontend}/package.json (100%) rename dm/portal/{dm-fe => frontend}/public/favicon.ico (100%) rename dm/portal/{dm-fe => frontend}/public/index.html (100%) rename dm/portal/{dm-fe => frontend}/public/manifest.json (100%) rename dm/portal/{dm-fe => frontend}/src/App.test.tsx (100%) rename dm/portal/{dm-fe => frontend}/src/App.tsx (100%) rename dm/portal/{dm-fe => frontend}/src/components/BinlogFilterModal.tsx (100%) rename dm/portal/{dm-fe => frontend}/src/components/InstancesStep.tsx (100%) rename dm/portal/{dm-fe => frontend}/src/components/Layout.tsx (100%) rename dm/portal/{dm-fe => frontend}/src/components/MigrateStep.tsx (93%) rename dm/portal/{dm-fe => frontend}/src/components/NamingStep.tsx (53%) rename dm/portal/{dm-fe => frontend}/src/components/StartStep.tsx (77%) rename dm/portal/{dm-fe => frontend}/src/components/UploadStep.tsx (100%) rename dm/portal/{dm-fe => frontend}/src/index.css (100%) rename dm/portal/{dm-fe => frontend}/src/index.tsx (100%) rename dm/portal/{dm-fe => frontend}/src/logo.svg (100%) rename dm/portal/{dm-fe => frontend}/src/react-app-env.d.ts (100%) rename dm/portal/{dm-fe => frontend}/src/serviceWorker.ts (100%) rename dm/portal/{dm-fe => frontend}/src/services/api.ts (100%) rename dm/portal/{dm-fe => frontend}/src/types.ts (100%) rename dm/portal/{dm-fe => frontend}/src/utils/config-util.ts (98%) rename dm/portal/{dm-fe => frontend}/src/utils/request.ts (100%) rename dm/portal/{dm-fe => frontend}/tsconfig.json (100%) rename dm/portal/{dm-fe => frontend}/yarn.lock (100%) diff --git a/dm/portal/dm-fe/.gitignore b/dm/portal/frontend/.gitignore similarity index 100% rename from dm/portal/dm-fe/.gitignore rename to dm/portal/frontend/.gitignore diff --git a/dm/portal/dm-fe/README.md b/dm/portal/frontend/README.md similarity index 87% rename from dm/portal/dm-fe/README.md rename to dm/portal/frontend/README.md index 021f3cbc91..af1ab3e86a 100644 --- a/dm/portal/dm-fe/README.md +++ b/dm/portal/frontend/README.md @@ -11,7 +11,7 @@ in the repo root folder: ### Run dm-fe -in the repo `dm-portal/dm-fe` folder: +in the repo `dm/dm/portal/frontend` folder: 1. `yarn install` 1. `yarn start` diff --git a/dm/portal/dm-fe/config-overrides.js b/dm/portal/frontend/config-overrides.js similarity index 100% rename from dm/portal/dm-fe/config-overrides.js rename to dm/portal/frontend/config-overrides.js diff --git a/dm/portal/dm-fe/package.json b/dm/portal/frontend/package.json similarity index 100% rename from dm/portal/dm-fe/package.json rename to dm/portal/frontend/package.json diff --git a/dm/portal/dm-fe/public/favicon.ico b/dm/portal/frontend/public/favicon.ico similarity index 100% rename from dm/portal/dm-fe/public/favicon.ico rename to dm/portal/frontend/public/favicon.ico diff --git a/dm/portal/dm-fe/public/index.html b/dm/portal/frontend/public/index.html similarity index 100% rename from dm/portal/dm-fe/public/index.html rename to dm/portal/frontend/public/index.html diff --git a/dm/portal/dm-fe/public/manifest.json b/dm/portal/frontend/public/manifest.json similarity index 100% rename from dm/portal/dm-fe/public/manifest.json rename to dm/portal/frontend/public/manifest.json diff --git a/dm/portal/dm-fe/src/App.test.tsx b/dm/portal/frontend/src/App.test.tsx similarity index 100% rename from dm/portal/dm-fe/src/App.test.tsx rename to dm/portal/frontend/src/App.test.tsx diff --git a/dm/portal/dm-fe/src/App.tsx b/dm/portal/frontend/src/App.tsx similarity index 100% rename from dm/portal/dm-fe/src/App.tsx rename to dm/portal/frontend/src/App.tsx diff --git a/dm/portal/dm-fe/src/components/BinlogFilterModal.tsx b/dm/portal/frontend/src/components/BinlogFilterModal.tsx similarity index 100% rename from dm/portal/dm-fe/src/components/BinlogFilterModal.tsx rename to dm/portal/frontend/src/components/BinlogFilterModal.tsx diff --git a/dm/portal/dm-fe/src/components/InstancesStep.tsx b/dm/portal/frontend/src/components/InstancesStep.tsx similarity index 100% rename from dm/portal/dm-fe/src/components/InstancesStep.tsx rename to dm/portal/frontend/src/components/InstancesStep.tsx diff --git a/dm/portal/dm-fe/src/components/Layout.tsx b/dm/portal/frontend/src/components/Layout.tsx similarity index 100% rename from dm/portal/dm-fe/src/components/Layout.tsx rename to dm/portal/frontend/src/components/Layout.tsx diff --git a/dm/portal/dm-fe/src/components/MigrateStep.tsx b/dm/portal/frontend/src/components/MigrateStep.tsx similarity index 93% rename from dm/portal/dm-fe/src/components/MigrateStep.tsx rename to dm/portal/frontend/src/components/MigrateStep.tsx index 97bd18503d..19e920cd98 100644 --- a/dm/portal/dm-fe/src/components/MigrateStep.tsx +++ b/dm/portal/frontend/src/components/MigrateStep.tsx @@ -1,5 +1,5 @@ import React, { useState, useMemo, useRef } from 'react' -import { Button, Icon, Tree, Tooltip, message } from 'antd' +import { Button, Icon, Tree, Tooltip, message, Checkbox } from 'antd' import styled from 'styled-components' import { IPageAction, @@ -85,6 +85,10 @@ const Container = styled.div` top: 10px; right: 10px; } + + .auto-sync-option { + margin-top: 10px; + } ` type LastStateRef = { @@ -172,11 +176,14 @@ function MigrateStep({ onNext, onPrev, sourceConfig, ...remainProps }: Props) { // 左移,右移,拖拽,重命名需要记录 lastStateRef const lastStateRef = useRef(null) + // 是否自动同步上游新增库和新增表的选项 + const [autoSyncUpstream, setAutoSyncUpstream] = useState(false) + ///////////////////////////////// function cleanTargetInstance() { // confirm - if (!window.confirm('你确定要清空下游实例吗?')) { + if (!window.confirm('你确定要重置所有操作吗?此操作会清空下游实例。')) { return } @@ -196,7 +203,7 @@ function MigrateStep({ onNext, onPrev, sourceConfig, ...remainProps }: Props) { function undo() { // confirm - if (!window.confirm('你确定要撤消此次操作吗?')) { + if (!window.confirm('你确定要撤消此次操作,回到上一步吗?')) { return } @@ -808,7 +815,8 @@ function MigrateStep({ onNext, onPrev, sourceConfig, ...remainProps }: Props) { instancesConfig, sourceSchemas, targetSchemas, - allTables + allTables, + autoSyncUpstream ) let res = await generateConfig(finalConfig) setLoading(false) @@ -858,8 +866,8 @@ function MigrateStep({ onNext, onPrev, sourceConfig, ...remainProps }: Props) { <> {sourceSchemas[schemaKey].schema}{' '} @@ -877,8 +885,8 @@ function MigrateStep({ onNext, onPrev, sourceConfig, ...remainProps }: Props) { <> {allTables[tableKey].table}{' '} @@ -922,7 +930,7 @@ function MigrateStep({ onNext, onPrev, sourceConfig, ...remainProps }: Props) { title={ {schema.newName} @@ -936,10 +944,8 @@ function MigrateStep({ onNext, onPrev, sourceConfig, ...remainProps }: Props) { {table.newName} @@ -954,10 +960,8 @@ function MigrateStep({ onNext, onPrev, sourceConfig, ...remainProps }: Props) { {tb.newName} @@ -977,40 +981,56 @@ function MigrateStep({ onNext, onPrev, sourceConfig, ...remainProps }: Props) { return ( -
+

上游实例

-
{renderSourceTables()}
+
{renderSourceTables()}
+
+ setAutoSyncUpstream(e.target.checked)} + > + 自动同步上游新增库和新增表 + + + + +
-
+

下游实例

-
+
{renderTargetTables()} -
- - +
+ + + +   + + +
-
+
- diff --git a/dm/portal/dm-fe/src/components/NamingStep.tsx b/dm/portal/frontend/src/components/NamingStep.tsx similarity index 53% rename from dm/portal/dm-fe/src/components/NamingStep.tsx rename to dm/portal/frontend/src/components/NamingStep.tsx index 2d578e7f17..2ee62fe256 100644 --- a/dm/portal/dm-fe/src/components/NamingStep.tsx +++ b/dm/portal/frontend/src/components/NamingStep.tsx @@ -36,42 +36,74 @@ type Props = IPageAction & { taskInfo: ITaskInfo } +type TaskName = { + status: 'success' | 'error' + errMsg: string + value: string +} + function NamingStep({ onNext, onPrev, onData, taskInfo }: Props) { const edit = useContext(EditContext) - const [taskName, setTaskName] = useState(taskInfo.taskName) const [taskMode, setTaskMode] = useState(taskInfo.taskMode) + const [taskName, setTaskName] = useState(() => + handleTaskNameChange(taskInfo.taskName) + ) + + function handleTaskNameChange(name: string): TaskName { + if (name.length === 0 || /^[a-zA-Z0-9$_]+$/.test(name)) { + return { + status: 'success', + errMsg: '', + value: name + } + } else { + return { + status: 'error', + errMsg: '任务名称不合法', + value: name + } + } + } return (
- + setTaskName(e.target.value)} + placeholder='test-task' + value={taskName.value} + onChange={(e: any) => + setTaskName(handleTaskNameChange(e.target.value)) + } /> - + setTaskMode(e.target.value)} value={taskMode} > - 全量 - 增量 - All + 全量 + 增量 + All diff --git a/dm/portal/dm-fe/src/components/StartStep.tsx b/dm/portal/frontend/src/components/StartStep.tsx similarity index 77% rename from dm/portal/dm-fe/src/components/StartStep.tsx rename to dm/portal/frontend/src/components/StartStep.tsx index 0c03ed0409..9936f755e5 100644 --- a/dm/portal/dm-fe/src/components/StartStep.tsx +++ b/dm/portal/frontend/src/components/StartStep.tsx @@ -27,7 +27,8 @@ function StartStep(props: Props) {

DM 任务配置生成

- + {/* 编辑功能目前看没有使用场景,先隐藏,后续再移除 */} + {/* */}
) } diff --git a/dm/portal/dm-fe/src/components/UploadStep.tsx b/dm/portal/frontend/src/components/UploadStep.tsx similarity index 100% rename from dm/portal/dm-fe/src/components/UploadStep.tsx rename to dm/portal/frontend/src/components/UploadStep.tsx diff --git a/dm/portal/dm-fe/src/index.css b/dm/portal/frontend/src/index.css similarity index 100% rename from dm/portal/dm-fe/src/index.css rename to dm/portal/frontend/src/index.css diff --git a/dm/portal/dm-fe/src/index.tsx b/dm/portal/frontend/src/index.tsx similarity index 100% rename from dm/portal/dm-fe/src/index.tsx rename to dm/portal/frontend/src/index.tsx diff --git a/dm/portal/dm-fe/src/logo.svg b/dm/portal/frontend/src/logo.svg similarity index 100% rename from dm/portal/dm-fe/src/logo.svg rename to dm/portal/frontend/src/logo.svg diff --git a/dm/portal/dm-fe/src/react-app-env.d.ts b/dm/portal/frontend/src/react-app-env.d.ts similarity index 100% rename from dm/portal/dm-fe/src/react-app-env.d.ts rename to dm/portal/frontend/src/react-app-env.d.ts diff --git a/dm/portal/dm-fe/src/serviceWorker.ts b/dm/portal/frontend/src/serviceWorker.ts similarity index 100% rename from dm/portal/dm-fe/src/serviceWorker.ts rename to dm/portal/frontend/src/serviceWorker.ts diff --git a/dm/portal/dm-fe/src/services/api.ts b/dm/portal/frontend/src/services/api.ts similarity index 100% rename from dm/portal/dm-fe/src/services/api.ts rename to dm/portal/frontend/src/services/api.ts diff --git a/dm/portal/dm-fe/src/types.ts b/dm/portal/frontend/src/types.ts similarity index 100% rename from dm/portal/dm-fe/src/types.ts rename to dm/portal/frontend/src/types.ts diff --git a/dm/portal/dm-fe/src/utils/config-util.ts b/dm/portal/frontend/src/utils/config-util.ts similarity index 98% rename from dm/portal/dm-fe/src/utils/config-util.ts rename to dm/portal/frontend/src/utils/config-util.ts index 2c8702e83e..126b6c2fe6 100644 --- a/dm/portal/dm-fe/src/utils/config-util.ts +++ b/dm/portal/frontend/src/utils/config-util.ts @@ -302,7 +302,10 @@ export function genFiltersConfig( return filters } -export function genBlackWhiteList(allTables: IFullTables): IBWList { +export function genBlackWhiteList( + allTables: IFullTables, + autoSycnUpstream: boolean +): IBWList { const bwList: IBWList = {} const tables = Object.keys(allTables) .map(tableKey => allTables[tableKey]) @@ -314,6 +317,9 @@ export function genBlackWhiteList(allTables: IFullTables): IBWList { } const bwType: 'do-tables' | 'ignore-tables' = table.parentKey !== '' ? 'do-tables' : 'ignore-tables' + if (autoSycnUpstream && bwType === 'do-tables') { + return + } bwList[bwListKey][bwType].push({ 'db-name': table.schema, 'tbl-name': table.table @@ -327,11 +333,12 @@ export function genFinalConfig( instancesConfig: IInstances, sourceSchemas: IFullSchemas, targetSchemas: IFullSchemas, - allTables: IFullTables + allTables: IFullTables, + autoSycnUpstream: boolean ) { const routes: IRoutes = genRoutesConfig(targetSchemas, allTables) const filters: IFilters = genFiltersConfig(sourceSchemas, allTables) - const bwList: IBWList = genBlackWhiteList(allTables) + const bwList: IBWList = genBlackWhiteList(allTables, autoSycnUpstream) const finalConfig = { name: taskInfo.taskName, @@ -603,9 +610,7 @@ export function parseFinalConfig(finalConfig: IFinalConfig) { schema.filters = filterRule.events } else { // 说明此条 filter 属于 table - const tableKey = `${sourceId}:${filterRule['schema-pattern']}:${ - filterRule['table-pattern'] - }` + const tableKey = `${sourceId}:${filterRule['schema-pattern']}:${filterRule['table-pattern']}` const table = allTables[tableKey] table.filters = filterRule.events } diff --git a/dm/portal/dm-fe/src/utils/request.ts b/dm/portal/frontend/src/utils/request.ts similarity index 100% rename from dm/portal/dm-fe/src/utils/request.ts rename to dm/portal/frontend/src/utils/request.ts diff --git a/dm/portal/dm-fe/tsconfig.json b/dm/portal/frontend/tsconfig.json similarity index 100% rename from dm/portal/dm-fe/tsconfig.json rename to dm/portal/frontend/tsconfig.json diff --git a/dm/portal/dm-fe/yarn.lock b/dm/portal/frontend/yarn.lock similarity index 100% rename from dm/portal/dm-fe/yarn.lock rename to dm/portal/frontend/yarn.lock