From 59f599bacd24c26a2eae72f0668ccca4097a8c62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=92=8F=E5=92=8C?= Date: Wed, 15 Nov 2023 09:42:12 +0800 Subject: [PATCH 1/5] PullRequest: 231 fix: dataArchiveTask and dataClearTask (date unit) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Merge branch 'fix/dev-4.2.2-task-dateunit of git@code.alipay.com:oceanbase/oceanbase-developer-center.git into dev-4.2.2 https://code.alipay.com/oceanbase/oceanbase-developer-center/pull_requests/231 Signed-off-by: 晓康 * fix: dataArchiveTask and dataClearTask (date unit) --- .../CreateModal/VariableConfig.tsx | 8 +++- .../CreateModal/VariableConfig.tsx | 46 +------------------ .../component/VariableConfigTable/index.tsx | 2 +- 3 files changed, 9 insertions(+), 47 deletions(-) diff --git a/src/component/Task/DataArchiveTask/CreateModal/VariableConfig.tsx b/src/component/Task/DataArchiveTask/CreateModal/VariableConfig.tsx index 54c22aa3d..ece223f3f 100644 --- a/src/component/Task/DataArchiveTask/CreateModal/VariableConfig.tsx +++ b/src/component/Task/DataArchiveTask/CreateModal/VariableConfig.tsx @@ -25,9 +25,13 @@ import styles from './index.less'; export const timeUnitOptions = [ { - label: formatMessage({ id: 'odc.DataArchiveTask.CreateModal.VariableConfig.Points' }), //分 + label: '秒', value: 's', }, + { + label: formatMessage({ id: 'odc.DataArchiveTask.CreateModal.VariableConfig.Points' }), //分 + value: 'm', + }, { label: formatMessage({ id: 'odc.DataArchiveTask.CreateModal.VariableConfig.Hours' }), //小时 value: 'h', @@ -42,7 +46,7 @@ export const timeUnitOptions = [ }, { label: formatMessage({ id: 'odc.DataArchiveTask.CreateModal.VariableConfig.Month' }), //月 - value: 'm', + value: 'M', }, { label: formatMessage({ id: 'odc.DataArchiveTask.CreateModal.VariableConfig.Year' }), //年 diff --git a/src/component/Task/DataClearTask/CreateModal/VariableConfig.tsx b/src/component/Task/DataClearTask/CreateModal/VariableConfig.tsx index b3adb44f5..2a87365bf 100644 --- a/src/component/Task/DataClearTask/CreateModal/VariableConfig.tsx +++ b/src/component/Task/DataClearTask/CreateModal/VariableConfig.tsx @@ -22,6 +22,7 @@ import { Button, Form, Input, InputNumber, Select, Space } from 'antd'; import classNames from 'classnames'; import { variable } from './index'; import styles from './index.less'; +import { timeUnitOptions } from '../../DataArchiveTask/CreateModal/VariableConfig'; const ENABLE_PATTERN_OPERATOR = false; const timeFormatOptions = ['yyyy-MM-dd', 'yyyyMMdd'].map((item) => ({ @@ -32,50 +33,7 @@ const operatorOptions = ['+', '-'].map((item) => ({ label: item, value: item, })); -const timeUnitOptions = [ - { - label: formatMessage({ - id: 'odc.DataClearTask.CreateModal.VariableConfig.Points', - }), - //分 - value: 's', - }, - { - label: formatMessage({ - id: 'odc.DataClearTask.CreateModal.VariableConfig.Hours', - }), - //小时 - value: 'h', - }, - { - label: formatMessage({ - id: 'odc.DataClearTask.CreateModal.VariableConfig.Day', - }), - //日 - value: 'd', - }, - { - label: formatMessage({ - id: 'odc.DataClearTask.CreateModal.VariableConfig.Zhou', - }), - //周 - value: 'w', - }, - { - label: formatMessage({ - id: 'odc.DataClearTask.CreateModal.VariableConfig.Month', - }), - //月 - value: 'm', - }, - { - label: formatMessage({ - id: 'odc.DataClearTask.CreateModal.VariableConfig.Year', - }), - //年 - value: 'y', - }, -]; + interface IProps {} const VariableConfig: React.FC = (props) => { // diff --git a/src/component/Task/component/VariableConfigTable/index.tsx b/src/component/Task/component/VariableConfigTable/index.tsx index 955dcc586..d8bdb6bb8 100644 --- a/src/component/Task/component/VariableConfigTable/index.tsx +++ b/src/component/Task/component/VariableConfigTable/index.tsx @@ -19,7 +19,7 @@ import { timeUnitOptions } from '@/component/Task/DataArchiveTask/CreateModal/Va import { formatMessage } from '@/util/intl'; import React from 'react'; -const oprationReg = /^[-+]\d+[shdwmy]$/; +const oprationReg = /^[-+]\d+[shdwmMy]$/; const columns = [ { From b8735628c42b0c6ab877ceb867b23d66643df6b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=92=8F=E5=92=8C?= Date: Mon, 20 Nov 2023 11:46:24 +0800 Subject: [PATCH 2/5] PullRequest: 233 bug fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Merge branch 'fix/dev-4.2.2-bugs-xyh-1120 of git@code.alipay.com:oceanbase/oceanbase-developer-center.git into dev-4.2.2 https://code.alipay.com/oceanbase/oceanbase-developer-center/pull_requests/233 Signed-off-by: 晓康 * feat: dataArchiveTask and dataClearTask (add date type) * fix(101305742) --- .../CreateModal/VariableConfig.tsx | 2 +- .../CreateModal/VariableConfig.tsx | 2 +- .../Auth/Role/component/FormModal/index.tsx | 17 +++++++++++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/component/Task/DataArchiveTask/CreateModal/VariableConfig.tsx b/src/component/Task/DataArchiveTask/CreateModal/VariableConfig.tsx index ece223f3f..03bf96b48 100644 --- a/src/component/Task/DataArchiveTask/CreateModal/VariableConfig.tsx +++ b/src/component/Task/DataArchiveTask/CreateModal/VariableConfig.tsx @@ -55,7 +55,7 @@ export const timeUnitOptions = [ ]; const ENABLE_PATTERN_OPERATOR = false; -const timeFormatOptions = ['yyyy-MM-dd', 'yyyyMMdd'].map((item) => ({ +const timeFormatOptions = ['yyyy-MM-dd HH:mm:ss', 'yyyy-MM-dd', 'yyyyMMdd'].map((item) => ({ label: item, value: item, })); diff --git a/src/component/Task/DataClearTask/CreateModal/VariableConfig.tsx b/src/component/Task/DataClearTask/CreateModal/VariableConfig.tsx index 2a87365bf..bd29d1cb4 100644 --- a/src/component/Task/DataClearTask/CreateModal/VariableConfig.tsx +++ b/src/component/Task/DataClearTask/CreateModal/VariableConfig.tsx @@ -25,7 +25,7 @@ import styles from './index.less'; import { timeUnitOptions } from '../../DataArchiveTask/CreateModal/VariableConfig'; const ENABLE_PATTERN_OPERATOR = false; -const timeFormatOptions = ['yyyy-MM-dd', 'yyyyMMdd'].map((item) => ({ +const timeFormatOptions = ['yyyy-MM-dd HH:mm:ss', 'yyyy-MM-dd', 'yyyyMMdd'].map((item) => ({ label: item, value: item, })); diff --git a/src/page/Auth/Role/component/FormModal/index.tsx b/src/page/Auth/Role/component/FormModal/index.tsx index 3b9cf11e3..5286fc026 100644 --- a/src/page/Auth/Role/component/FormModal/index.tsx +++ b/src/page/Auth/Role/component/FormModal/index.tsx @@ -24,6 +24,7 @@ import { Button, Drawer, message, Modal, Radio, Space } from 'antd'; import type { FormInstance } from 'antd/lib/form'; import { isNull, set } from 'lodash'; import React, { useContext, useEffect, useRef, useState } from 'react'; +import odc from '@/plugins/odc'; import { ResourceContext } from '../../../context'; import { resourceManagementActionMap } from '../../../utils'; import { SystemAction, systemActionMap } from '../ResourceSelector/const'; @@ -330,13 +331,17 @@ const FormModal: React.FC = (props) => { systemActionMap, ); if (createAbleResource?.length) { - createAbleResource?.forEach((type) => { - formData.resourceManagementPermissions?.push({ - resourceType: type, - resourceId: null, - actions: ['create'], + createAbleResource + ?.filter((resourceType) => + odc.appConfig.manage.user.create ? true : resourceType !== IManagerResourceType.user, + ) + ?.forEach((type) => { + formData.resourceManagementPermissions?.push({ + resourceType: type, + resourceId: null, + actions: ['create'], + }); }); - }); } if ( From 176f908e3ccc8b32d19adb0930cc598088cc3f36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=9C=9D=E4=BF=8A?= Date: Tue, 21 Nov 2023 13:46:13 +0800 Subject: [PATCH 3/5] PullRequest: 236 fix: change collapse's maxHeight MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Merge branch 'fix/dev-4.2.2-github-758-bp of git@code.alipay.com:oceanbase/oceanbase-developer-center.git into dev-4.2.2 https://code.alipay.com/oceanbase/oceanbase-developer-center/pull_requests/236 Signed-off-by: 晓康 * fix: change collapse's maxHeight --- .../Project/Sensitive/SensitiveContext.ts | 6 + .../components/FormSensitiveColumnDrawer.tsx | 20 +- .../SensitiveColumn/components/SacnRule.tsx | 3 - .../SensitiveColumn/components/ScanForm.tsx | 554 +++++++++--------- .../SensitiveColumn/components/index.less | 1 - .../components/ViewSensitiveRuleDrawer.tsx | 9 +- .../SensitiveRule/components/index.less | 9 + .../components/SensitiveRule/index.tsx | 9 +- src/page/Project/Sensitive/index.tsx | 1 + 9 files changed, 323 insertions(+), 289 deletions(-) diff --git a/src/page/Project/Sensitive/SensitiveContext.ts b/src/page/Project/Sensitive/SensitiveContext.ts index 4eb839495..f499acf84 100644 --- a/src/page/Project/Sensitive/SensitiveContext.ts +++ b/src/page/Project/Sensitive/SensitiveContext.ts @@ -43,6 +43,11 @@ interface ISensitiveContext { sensitiveRuleIdMap: { [key in any]: string; }; + setSensitiveRuleIdMap: ( + sensitiveRuleIdMap: { + [key in any]: string; + }, + ) => void; } const SensitiveContext = React.createContext>({ @@ -58,6 +63,7 @@ const SensitiveContext = React.createContext>({ tables: [], sensitiveRules: [], sensitiveRuleIdMap: {}, + setSensitiveRuleIdMap: (sensitiveRuleIdMap = {}) => {}, }); export default SensitiveContext; diff --git a/src/page/Project/Sensitive/components/SensitiveColumn/components/FormSensitiveColumnDrawer.tsx b/src/page/Project/Sensitive/components/SensitiveColumn/components/FormSensitiveColumnDrawer.tsx index d9fee4b94..897f199f1 100644 --- a/src/page/Project/Sensitive/components/SensitiveColumn/components/FormSensitiveColumnDrawer.tsx +++ b/src/page/Project/Sensitive/components/SensitiveColumn/components/FormSensitiveColumnDrawer.tsx @@ -30,10 +30,10 @@ import { Button, Drawer, message, Space } from 'antd'; import { useForm } from 'antd/es/form/Form'; import { useContext, useEffect, useRef, useState } from 'react'; import styles from './index.less'; -import ManualForm from './ManualForm'; import ScanForm from './ScanForm'; import tracert from '@/util/tracert'; import SensitiveRule from '../../SensitiveRule'; +import { merge } from 'lodash'; const defaultScanTableData: Array = []; const checkResult = (resData: Array = []) => resData?.length > 0 ? resData : defaultScanTableData; @@ -116,7 +116,7 @@ const FormSensitiveColumnDrawer = ({ setSearchText(''); clearTimeout(timer.current); }; - const handleScanTableDataChange = ( + const handleScanTableDataChange = async ( key: string, columnName: string, maskingAlgorithmId: number, @@ -141,8 +141,6 @@ const FormSensitiveColumnDrawer = ({ }); } }); - setScanTableData(checkResult(resData)); - setOriginScanTableData(checkResult(resData)); } else { const newDataSource = sensitiveColumnMap.get(key).dataSource.map((item) => { if (item.columnName === columnName) { @@ -154,10 +152,20 @@ const FormSensitiveColumnDrawer = ({ sensitiveColumnMap?.forEach((ds) => { resData.push(ds); }); - setScanTableData(checkResult(resData)); - setOriginScanTableData(checkResult(resData)); } + setScanTableData(checkResult(resData)); + setOriginScanTableData(checkResult(resData)); setSensitiveColumnMap(sensitiveColumnMap); + const fieldsValue = await _formRef.getFieldsValue(); + await _formRef.setFieldsValue( + merge(fieldsValue, { + scanTableData: { + [`${key}`]: { + [`${columnName}`]: maskingAlgorithmId, + }, + }, + }), + ); }; const handleScanTableDataDelete = (database: string, tableName: string, columnName: string) => { const key = `${database}_${tableName}`; diff --git a/src/page/Project/Sensitive/components/SensitiveColumn/components/SacnRule.tsx b/src/page/Project/Sensitive/components/SensitiveColumn/components/SacnRule.tsx index dc50adc69..71d513edc 100644 --- a/src/page/Project/Sensitive/components/SensitiveColumn/components/SacnRule.tsx +++ b/src/page/Project/Sensitive/components/SensitiveColumn/components/SacnRule.tsx @@ -23,9 +23,6 @@ import { formatMessage } from '@/util/intl'; import { Button, Divider, Form, Select } from 'antd'; import { useContext, useEffect, useState } from 'react'; import SensitiveContext from '../../../SensitiveContext'; -import HelpDoc from '@/component/helpDoc'; -import { ProjectRole } from '@/d.ts/project'; -import { projectRoleTextMap } from '@/page/Project/User'; const ScanRule = ({ formRef, reset, setManageSensitiveRuleDrawerOpen }) => { const context = useContext(ProjectContext); const sensitiveContext = useContext(SensitiveContext); diff --git a/src/page/Project/Sensitive/components/SensitiveColumn/components/ScanForm.tsx b/src/page/Project/Sensitive/components/SensitiveColumn/components/ScanForm.tsx index 50ab19a0d..a1bc2f24b 100644 --- a/src/page/Project/Sensitive/components/SensitiveColumn/components/ScanForm.tsx +++ b/src/page/Project/Sensitive/components/SensitiveColumn/components/ScanForm.tsx @@ -23,7 +23,6 @@ import { Empty, Form, Input, - Popover, Progress, Select, Space, @@ -39,6 +38,7 @@ import TableOutlined from '@/svgr/menuTable.svg'; import ViewSvg from '@/svgr/menuView.svg'; import { MaskRyleTypeMap } from '@/d.ts'; import { PopoverContainer } from '..'; +import { useCallback } from 'react'; const ScanForm = ({ formRef, _formRef, @@ -100,6 +100,285 @@ const ScanForm = ({ ); }; + const WrapCollapse = useCallback( + () => ( + index) + } + className={ + scanTableData?.length === 0 + ? classnames(styles.collapse) + : classnames(styles.collapse, styles.collapses) + } + > + {scanTableData?.length === 0 ? ( + + + {''} + + + {''} + + + } + > + + + ) : ( + <> + {scanTableData?.map(({ header: { database, tableName, type }, dataSource }, index) => { + return ( + + + {database} + + +
+
+ + + + + {tableName} + +
+ + { + e.preventDefault(); + e.stopPropagation(); + handleScanTableDataDeleteByTableName(database, tableName); + }} + /> + +
+
+ + } + key={index} + > + sensitiveContext?.sensitiveRuleIdMap?.[text], + }, + { + title: formatMessage({ + id: 'odc.SensitiveColumn.components.ScanForm.DesensitizationAlgorithm', + }), + //脱敏算法 + width: 180, + dataIndex: 'maskingAlgorithmId', + key: 'maskingAlgorithmId', + render: (text, record, _index) => { + return ( + + + + ); + }, + }, + { + title: formatMessage({ + id: 'odc.SensitiveColumn.components.ScanForm.Operation', + }), + //操作 + width: 88, + key: 'action', + render: (_, record) => ( + + + handleScanTableDataDelete( + database, + tableName, + (record as ScanTableDataItem)?.columnName, + ) + } + > + { + formatMessage({ + id: 'odc.SensitiveColumn.components.ScanForm.Delete', + }) /*删除*/ + } + + + ), + }, + ]} + dataSource={dataSource} + pagination={{ + showSizeChanger: false, + pageSize: 10, + hideOnSinglePage: dataSource?.length > 10 ? false : true, + }} + /> + + ); + })} + + )} + + ), + [scanTableData], + ); return ( <> @@ -197,278 +476,7 @@ const ScanForm = ({ }} > - - {scanTableData?.length === 0 ? ( - - - {''} - - - {''} - - - } - > - - - ) : ( - <> - {scanTableData?.map( - ({ header: { database, tableName, type }, dataSource }, index) => { - return ( - - - {database} - - -
-
- - - - - {tableName} - -
- - { - e.preventDefault(); - e.stopPropagation(); - handleScanTableDataDeleteByTableName(database, tableName); - }} - /> - -
-
- - } - key={index} - > -
sensitiveContext?.sensitiveRuleIdMap?.[text], - }, - { - title: formatMessage({ - id: - 'odc.SensitiveColumn.components.ScanForm.DesensitizationAlgorithm', - }), - //脱敏算法 - width: 180, - dataIndex: 'maskingAlgorithmId', - key: 'maskingAlgorithmId', - render: (text, record, _index) => { - return ( - - ); - }, - }, - { - title: formatMessage({ - id: 'odc.SensitiveColumn.components.ScanForm.Operation', - }), - //操作 - width: 88, - key: 'action', - render: (_, record) => ( - - - handleScanTableDataDelete( - database, - tableName, - (record as ScanTableDataItem)?.columnName, - ) - } - > - { - formatMessage({ - id: 'odc.SensitiveColumn.components.ScanForm.Delete', - }) /*删除*/ - } - - - ), - }, - ]} - dataSource={dataSource} - pagination={{ - showSizeChanger: false, - }} - /> - - ); - }, - )} - - )} - + diff --git a/src/page/Project/Sensitive/components/SensitiveColumn/components/index.less b/src/page/Project/Sensitive/components/SensitiveColumn/components/index.less index 3d42858f5..7e8a7732f 100644 --- a/src/page/Project/Sensitive/components/SensitiveColumn/components/index.less +++ b/src/page/Project/Sensitive/components/SensitiveColumn/components/index.less @@ -31,7 +31,6 @@ .collapses { :global { .ant-collapse-content-box { - max-height: 480px; overflow: auto; } } diff --git a/src/page/Project/Sensitive/components/SensitiveRule/components/ViewSensitiveRuleDrawer.tsx b/src/page/Project/Sensitive/components/SensitiveRule/components/ViewSensitiveRuleDrawer.tsx index 293f2968b..778f5ecb2 100644 --- a/src/page/Project/Sensitive/components/SensitiveRule/components/ViewSensitiveRuleDrawer.tsx +++ b/src/page/Project/Sensitive/components/SensitiveRule/components/ViewSensitiveRuleDrawer.tsx @@ -24,6 +24,7 @@ import { getLocalFormatDateTime } from '@/util/utils'; import { Button, Descriptions, Divider, Drawer } from 'antd'; import { useEffect, useLayoutEffect, useState } from 'react'; import styles from './index.less'; +import { CommonTableMode } from '@/component/CommonTable/interface'; const renderByType = (type: SensitiveRuleType, params?: any) => { switch (type) { @@ -117,13 +118,10 @@ const renderByType = (type: SensitiveRuleType, params?: any) => { >   -
+
{ dataSource: dataSource, rowKey: 'id', pagination: { + hideOnSinglePage: true, pageSize: 4, }, scroll: { diff --git a/src/page/Project/Sensitive/components/SensitiveRule/components/index.less b/src/page/Project/Sensitive/components/SensitiveRule/components/index.less index ef5ef6f07..12b23d32c 100644 --- a/src/page/Project/Sensitive/components/SensitiveRule/components/index.less +++ b/src/page/Project/Sensitive/components/SensitiveRule/components/index.less @@ -59,3 +59,12 @@ } } } + +.viewDrawerTable { + width: 500px; + :global { + .ant-spin-nested-loading > .ant-spin-container { + padding-bottom: 0px !important; + } + } +} diff --git a/src/page/Project/Sensitive/components/SensitiveRule/index.tsx b/src/page/Project/Sensitive/components/SensitiveRule/index.tsx index f05720b26..0876d1495 100644 --- a/src/page/Project/Sensitive/components/SensitiveRule/index.tsx +++ b/src/page/Project/Sensitive/components/SensitiveRule/index.tsx @@ -249,7 +249,9 @@ const getColumns: (columnsFunction: { }; const SensitiveRule = ({ projectId }) => { const tableRef = useRef(); - const { maskingAlgorithmIdMap, maskingAlgorithms } = useContext(SensitiveContext); + const { maskingAlgorithmIdMap, maskingAlgorithms, setSensitiveRuleIdMap } = useContext( + SensitiveContext, + ); const [selectedRecord, setSelectedRecord] = useState(); const [isEdit, setIsEdit] = useState(false); const [formDrawerVisible, setFormDrawerVisible] = useState(false); @@ -304,6 +306,11 @@ const SensitiveRule = ({ projectId }) => { data.enabled = enabled?.length ? enabled : undefined; data.sort = column ? `${column.dataIndex},${order === 'ascend' ? 'asc' : 'desc'}` : undefined; const rawData = await listSensitiveRules(projectId, data); + const map = {}; + rawData?.contents?.forEach((d) => { + map[d.id] = d.name; + }); + setSensitiveRuleIdMap(map); setSensitiveRules(rawData); }; const handleFormDrawerClose = (fn?: () => void) => { diff --git a/src/page/Project/Sensitive/index.tsx b/src/page/Project/Sensitive/index.tsx index 486621beb..b65816e6c 100644 --- a/src/page/Project/Sensitive/index.tsx +++ b/src/page/Project/Sensitive/index.tsx @@ -161,6 +161,7 @@ const Sensitive: React.FC<{ id: number }> = ({ id }) => { maskingAlgorithmIdMap, maskingAlgorithmOptions, sensitiveRuleIdMap, + setSensitiveRuleIdMap, }} >
From 8a1ab5a919bc291e12a20b943f84271b6c453f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=9C=9D=E4=BF=8A?= Date: Wed, 22 Nov 2023 09:27:59 +0800 Subject: [PATCH 4/5] PullRequest: 238 fix: fix a bug and optimized code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Merge branch 'fix/dev-4.2.2-github-758-bp of git@code.alipay.com:oceanbase/oceanbase-developer-center.git into dev-4.2.2 https://code.alipay.com/oceanbase/oceanbase-developer-center/pull_requests/238 Signed-off-by: 晓康 * fix: change collapse's maxHeight * fix: optimized code --- src/component/CommonTable/index.tsx | 4 +- src/d.ts/database.ts | 1 + .../components/FormSensitiveColumnDrawer.tsx | 250 ++++++----- .../SensitiveColumn/components/ScanForm.tsx | 398 +++++++++--------- .../SensitiveColumn/components/index.less | 3 +- src/page/Project/Sensitive/interface.ts | 3 + 6 files changed, 372 insertions(+), 287 deletions(-) diff --git a/src/component/CommonTable/index.tsx b/src/component/CommonTable/index.tsx index d59329667..74955b8c8 100644 --- a/src/component/CommonTable/index.tsx +++ b/src/component/CommonTable/index.tsx @@ -189,7 +189,7 @@ const CommonTable: ( (tableProps?.pagination as TablePaginationConfig)?.pageSize ?? Math.max( Math.floor( - (tableRef.current.offsetHeight - + (tableRef.current?.offsetHeight - TOOLBAR_HEIGHT - TABLE_HEAD_HEIGHT - INFO_BAR_HEIGHT - @@ -200,7 +200,7 @@ const CommonTable: ( 1, ); setPageSize(computedPageSize); - setWrapperHeight(tableRef.current.offsetHeight); + setWrapperHeight(tableRef.current?.offsetHeight); } function computeTableScrollHeight() { diff --git a/src/d.ts/database.ts b/src/d.ts/database.ts index fd464eca4..a54ba54a5 100644 --- a/src/d.ts/database.ts +++ b/src/d.ts/database.ts @@ -26,6 +26,7 @@ export enum DatabaseSyncStatus { export interface IDatabase { id: number; + databaseId?: string; name: string; project: IProject; dataSource: IDatasource; diff --git a/src/page/Project/Sensitive/components/SensitiveColumn/components/FormSensitiveColumnDrawer.tsx b/src/page/Project/Sensitive/components/SensitiveColumn/components/FormSensitiveColumnDrawer.tsx index 897f199f1..2734e840c 100644 --- a/src/page/Project/Sensitive/components/SensitiveColumn/components/FormSensitiveColumnDrawer.tsx +++ b/src/page/Project/Sensitive/components/SensitiveColumn/components/FormSensitiveColumnDrawer.tsx @@ -20,11 +20,9 @@ import { ScannResultType, startScanning, } from '@/common/network/sensitiveColumn'; -import { IDatabase } from '@/d.ts/database'; -import { ISensitiveColumn } from '@/d.ts/sensitiveColumn'; +import { ESensitiveColumnType, ISensitiveColumn } from '@/d.ts/sensitiveColumn'; import ProjectContext from '@/page/Project/ProjectContext'; import { AddSensitiveColumnType, ScanTableData } from '@/page/Project/Sensitive/interface'; -import SensitiveContext from '@/page/Project/Sensitive/SensitiveContext'; import { formatMessage } from '@/util/intl'; import { Button, Drawer, message, Space } from 'antd'; import { useForm } from 'antd/es/form/Form'; @@ -33,7 +31,6 @@ import styles from './index.less'; import ScanForm from './ScanForm'; import tracert from '@/util/tracert'; import SensitiveRule from '../../SensitiveRule'; -import { merge } from 'lodash'; const defaultScanTableData: Array = []; const checkResult = (resData: Array = []) => resData?.length > 0 ? resData : defaultScanTableData; @@ -49,12 +46,11 @@ const FormSensitiveColumnDrawer = ({ const [_formRef] = useForm(); const timer = useRef(null); const context = useContext(ProjectContext); - const sensitiveContext = useContext(SensitiveContext); const [scanTableData, setScanTableData] = useState([]); const [originScanTableData, setOriginScanTableData] = useState([]); const [submiting, setSubmiting] = useState(false); const [sensitiveColumns, setSensitiveColumns] = useState([]); - const [sensitiveColumnMap, setSensitiveColumnMap] = useState(new Map()); + const [sensitiveColumnMap, setSensitiveColumnMap] = useState>(new Map()); const [taskId, setTaskId] = useState(); const [scanStatus, setScanStatus] = useState(); const [scanLoading, setScanLoading] = useState(false); @@ -65,6 +61,8 @@ const FormSensitiveColumnDrawer = ({ const [manageSensitiveRuleDrawerOpen, setManageSensitiveRuleDrawerOpen] = useState( false, ); + const [scanTableDataMap, setScanTableDataMap] = useState({}); + const [activeKeys, setActiveKeys] = useState(['0']); const handleSearchChange = (e) => { setSearchText(e.target.value); }; @@ -116,57 +114,6 @@ const FormSensitiveColumnDrawer = ({ setSearchText(''); clearTimeout(timer.current); }; - const handleScanTableDataChange = async ( - key: string, - columnName: string, - maskingAlgorithmId: number, - ) => { - const resData = []; - if (!!searchText) { - const newDataSource = sensitiveColumnMap.get(key).dataSource.map((item) => { - if (item.columnName === columnName) { - item.maskingAlgorithmId = maskingAlgorithmId; - } - return item; - }); - sensitiveColumnMap.get(key).dataSource = newDataSource; - sensitiveColumnMap.forEach((sc, key) => { - const filterColumn = sc?.dataSource?.filter((item) => - item?.columnName?.toLowerCase()?.includes(searchText?.toLocaleLowerCase()), - ); - if (filterColumn?.length > 0) { - resData.push({ - header: sc?.header, - dataSource: filterColumn, - }); - } - }); - } else { - const newDataSource = sensitiveColumnMap.get(key).dataSource.map((item) => { - if (item.columnName === columnName) { - item.maskingAlgorithmId = maskingAlgorithmId; - } - return item; - }); - sensitiveColumnMap.get(key).dataSource = newDataSource; - sensitiveColumnMap?.forEach((ds) => { - resData.push(ds); - }); - } - setScanTableData(checkResult(resData)); - setOriginScanTableData(checkResult(resData)); - setSensitiveColumnMap(sensitiveColumnMap); - const fieldsValue = await _formRef.getFieldsValue(); - await _formRef.setFieldsValue( - merge(fieldsValue, { - scanTableData: { - [`${key}`]: { - [`${columnName}`]: maskingAlgorithmId, - }, - }, - }), - ); - }; const handleScanTableDataDelete = (database: string, tableName: string, columnName: string) => { const key = `${database}_${tableName}`; const filterDataSource = @@ -194,8 +141,10 @@ const FormSensitiveColumnDrawer = ({ resData.push(dsItem); }); } - setScanTableData(checkResult(resData)); - setOriginScanTableData(checkResult(resData)); + const newTableData = checkResult(resData); + setScanTableData(newTableData); + setOriginScanTableData(newTableData); + newTableData?.length === 0 && setActiveKeys(['0']); setSensitiveColumnMap(sensitiveColumnMap); }; const handleScanTableDataDeleteByTableName = (database: string, tableName: string) => { @@ -213,7 +162,9 @@ const FormSensitiveColumnDrawer = ({ originResData.push(dsItem); } }); - setOriginScanTableData(checkResult(originResData)); + const newTableData = checkResult(originResData); + newTableData?.length === 0 && setActiveKeys(['0']); + setOriginScanTableData(newTableData); sensitiveColumnMap?.forEach((dsItem, dsKey) => { if (dsItem?.dataSource?.length > 0) { resData.push(dsItem); @@ -226,7 +177,9 @@ const FormSensitiveColumnDrawer = ({ sensitiveColumnMap?.forEach((dsItem) => { resData.push(dsItem); }); - setOriginScanTableData(checkResult(resData)); + const newTableData = checkResult(resData); + setOriginScanTableData(newTableData); + newTableData?.length === 0 && setActiveKeys(['0']); } setScanTableData(checkResult(resData)); setSensitiveColumnMap(sensitiveColumnMap); @@ -258,8 +211,49 @@ const FormSensitiveColumnDrawer = ({ reset(); } }; + const parseData = (rawFormData: Object) => { + const data = []; + Object.keys(rawFormData)?.forEach((database) => { + if (rawFormData[database]?.[ESensitiveColumnType.TABLE_COLUMN]) { + for (const tableName in rawFormData[database]?.[ESensitiveColumnType.TABLE_COLUMN]) { + for (const columnName in rawFormData[database]?.[ESensitiveColumnType.TABLE_COLUMN][ + tableName + ]) { + const item = { + ...scanTableDataMap[ + `${database}_${ESensitiveColumnType.TABLE_COLUMN}_${tableName}_${columnName}` + ], + maskingAlgorithmId: + rawFormData[database]?.[ESensitiveColumnType.TABLE_COLUMN][tableName][columnName], + enabled: true, + }; + data.push(item); + } + } + } + if (rawFormData[database]?.[ESensitiveColumnType.VIEW_COLUMN]) { + for (const viewName in rawFormData[database]?.[ESensitiveColumnType.VIEW_COLUMN]) { + for (const columnName in rawFormData[database]?.[ESensitiveColumnType.VIEW_COLUMN][ + viewName + ]) { + const item = { + ...scanTableDataMap[ + `${database}_${ESensitiveColumnType.VIEW_COLUMN}_${viewName}_${columnName}` + ], + maskingAlgorithmId: + rawFormData[database]?.[ESensitiveColumnType.VIEW_COLUMN][viewName][columnName], + enabled: true, + }; + data.push(item); + } + } + } + }); + return data; + }; const handleScanSubmit = async () => { await formRef.validateFields().catch(); + const { scanTableData: rawFormData } = await _formRef.validateFields().catch(); const rawData = []; sensitiveColumns.forEach((sensitiveColumn) => { const key = `${sensitiveColumn.database.name}_${sensitiveColumn.tableName}`; @@ -276,19 +270,13 @@ const FormSensitiveColumnDrawer = ({ } } }); - let data = []; - if (!!searchText) { - data = rawData.filter((d) => - d.columnName.toLocaleLowerCase().includes(searchText.toLocaleLowerCase()), - ); - } else { - data = rawData; - } + const data = parseData(rawFormData); if (data?.length === 0) { return; } setSubmiting(true); const res = await batchCreateSensitiveColumns(context.projectId, data); + setSubmiting(false); if (res) { tracert.click('a3112.b64002.c330861.d367391'); message.success( @@ -300,7 +288,6 @@ const FormSensitiveColumnDrawer = ({ onOk(); reset(); resetScanTableData(); - setSubmiting(false); } else { message.error( formatMessage({ @@ -318,6 +305,7 @@ const FormSensitiveColumnDrawer = ({ setScanTableData(defaultScanTableData); setOriginScanTableData(defaultScanTableData); setSensitiveColumnMap(new Map()); + setScanTableDataMap({}); setSensitiveColumns([]); setTaskId(null); setScanStatus(null); @@ -327,6 +315,32 @@ const FormSensitiveColumnDrawer = ({ clearTimeout(timer.current); }); }; + + const initScanTableDataMap = (rawFormData: ScanTableData[]) => { + const scanTableData = {}; + const newScanTableDataMap = {}; + rawFormData?.forEach(({ dataSource = [], header = {} }) => { + const { database = '', tableName, type, databaseId } = header; + scanTableData[database] = scanTableData?.[database] || { + [ESensitiveColumnType.TABLE_COLUMN]: {}, + [ESensitiveColumnType.VIEW_COLUMN]: {}, + }; + scanTableData[database][type][tableName] = {}; + dataSource?.forEach(({ columnName, maskingAlgorithmId }) => { + scanTableData[database][type][tableName][columnName] = maskingAlgorithmId; + newScanTableDataMap[ + `${database}_${type}_${tableName}_${columnName}` + ] = sensitiveColumns?.find( + (item) => + item?.database?.databaseId === databaseId && + item.type === type && + item.tableName === tableName && + item.columnName === columnName, + ); + }); + }); + return { scanTableData, newScanTableDataMap }; + }; const handleScanning = async (taskId: string) => { const rawData = await getScanningResults(context.projectId, taskId); const { status, sensitiveColumns, allTableCount, finishedTableCount } = rawData; @@ -345,6 +359,7 @@ const FormSensitiveColumnDrawer = ({ dataSourceMap.set(key, { header: { database: d.database.name, + databaseId: d.database.databaseId, tableName: d.tableName, type: d.type, }, @@ -358,13 +373,58 @@ const FormSensitiveColumnDrawer = ({ }); } }); + dataSourceMap.forEach((value, key) => { + value.dataSource = value.dataSource.sort((a, b) => + a?.columnName?.localeCompare(b?.columnName), + ); + dataSourceMap.set(key, value); + }); setSensitiveColumnMap(dataSourceMap); const resData = []; dataSourceMap?.forEach((ds) => { resData.push(ds); }); - setScanTableData(checkResult(resData)); - setOriginScanTableData(checkResult(resData)); + const rawFormData = checkResult(resData); + setActiveKeys( + rawFormData?.length === 0 + ? ['0'] + : rawFormData?.map( + ({ header: { database, tableName, type }, dataSource }, index) => + `${database}_${type}_${tableName}`, + ), + ); + setScanTableData(rawFormData); + setOriginScanTableData(rawFormData); + // const { + // scanTableData, + // newScanTableDataMap + // } = initScanTableDataMap(rawFormData); + const scanTableData = {}; + const newScanTableDataMap = {}; + rawFormData?.forEach(({ dataSource = [], header = {} }) => { + const { database = '', tableName, type, databaseId } = header; + scanTableData[database] = scanTableData?.[database] || { + [ESensitiveColumnType.TABLE_COLUMN]: {}, + [ESensitiveColumnType.VIEW_COLUMN]: {}, + }; + scanTableData[database][type][tableName] = {}; + dataSource?.forEach(({ columnName, maskingAlgorithmId }) => { + scanTableData[database][type][tableName][columnName] = maskingAlgorithmId; + newScanTableDataMap[ + `${database}_${type}_${tableName}_${columnName}` + ] = sensitiveColumns?.find( + (item) => + item?.database?.databaseId === databaseId && + item.type === type && + item.tableName === tableName && + item.columnName === columnName, + ); + }); + }); + setScanTableDataMap(newScanTableDataMap); + await _formRef.setFieldsValue({ + scanTableData, + }); setScanStatus(ScannResultType.SUCCESS); setSuccessful(true); setPercent(Math.floor((finishedTableCount * 100) / allTableCount)); @@ -372,6 +432,8 @@ const FormSensitiveColumnDrawer = ({ } else { setScanStatus(ScannResultType.RUNNING); setHasScan(true); + setActiveKeys(['0']); + setScanTableDataMap({}); setPercent(Math.floor((finishedTableCount * 100) / allTableCount)); timer.current = setTimeout(() => { handleScanning(taskId); @@ -447,7 +509,7 @@ const FormSensitiveColumnDrawer = ({
sensitiveContext?.sensitiveRuleIdMap?.[text], - }, - { - title: formatMessage({ - id: 'odc.SensitiveColumn.components.ScanForm.DesensitizationAlgorithm', - }), - //脱敏算法 - width: 180, - dataIndex: 'maskingAlgorithmId', - key: 'maskingAlgorithmId', - render: (text, record, _index) => { - return ( - - - - ); - }, - }, - { - title: formatMessage({ - id: 'odc.SensitiveColumn.components.ScanForm.Operation', - }), - //操作 - width: 88, - key: 'action', - render: (_, record) => ( - - - handleScanTableDataDelete( - database, - tableName, - (record as ScanTableDataItem)?.columnName, - ) - } - > - { - formatMessage({ - id: 'odc.SensitiveColumn.components.ScanForm.Delete', - }) /*删除*/ - } - - - ), - }, - ]} + columns={getColumns(database, type, tableName)} dataSource={dataSource} pagination={{ showSizeChanger: false, @@ -376,9 +391,8 @@ const ScanForm = ({ )} - ), - [scanTableData], - ); + ); + }, [scanTableData, activeKeys]); return ( <> @@ -475,7 +489,13 @@ const ScanForm = ({ overflowY: 'scroll', }} > - + diff --git a/src/page/Project/Sensitive/components/SensitiveColumn/components/index.less b/src/page/Project/Sensitive/components/SensitiveColumn/components/index.less index 7e8a7732f..e49d39c16 100644 --- a/src/page/Project/Sensitive/components/SensitiveColumn/components/index.less +++ b/src/page/Project/Sensitive/components/SensitiveColumn/components/index.less @@ -31,7 +31,8 @@ .collapses { :global { .ant-collapse-content-box { - overflow: auto; + display: flex; + flex-direction: column; } } } diff --git a/src/page/Project/Sensitive/interface.ts b/src/page/Project/Sensitive/interface.ts index b9c961067..9bc4dd54d 100644 --- a/src/page/Project/Sensitive/interface.ts +++ b/src/page/Project/Sensitive/interface.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { ESensitiveColumnType } from '@/d.ts/sensitiveColumn'; import { formatMessage } from '@/util/intl'; export enum AddSensitiveColumnType { Manual, @@ -38,6 +39,8 @@ export interface ScanTableData { header: { database: string; tableName: string; + type: ESensitiveColumnType; + databaseId: string; }; dataSource: ScanTableDataItem[]; } From 9bb04e873c4c1d6d3d1812038c7f0e5a8f03b0db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=93=E5=BA=B7?= Date: Wed, 22 Nov 2023 10:31:46 +0800 Subject: [PATCH 5/5] add init script in ocp mode --- .../NewDatasourceDrawer/Form/ExtraConfig/index.tsx | 5 +++-- .../Datasource/Datasource/NewDatasourceDrawer/Form/index.tsx | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/page/Datasource/Datasource/NewDatasourceDrawer/Form/ExtraConfig/index.tsx b/src/page/Datasource/Datasource/NewDatasourceDrawer/Form/ExtraConfig/index.tsx index 4c657b699..6e89e14f5 100644 --- a/src/page/Datasource/Datasource/NewDatasourceDrawer/Form/ExtraConfig/index.tsx +++ b/src/page/Datasource/Datasource/NewDatasourceDrawer/Form/ExtraConfig/index.tsx @@ -24,6 +24,7 @@ import SSLItem from '../SSLItem'; import styles from './index.less'; import InitScriptItem from '../InitScriptItem'; import JDBCParamsItem from '../JDBCParamsItem'; +import { haveOCP } from '@/util/env'; interface IProps {} const ExtraConfig: React.FC = function () { const context = useContext(DatasourceFormContext); @@ -84,12 +85,12 @@ const ExtraConfig: React.FC = function () { ); }} diff --git a/src/page/Datasource/Datasource/NewDatasourceDrawer/Form/index.tsx b/src/page/Datasource/Datasource/NewDatasourceDrawer/Form/index.tsx index 1f52cffee..0f81a5726 100644 --- a/src/page/Datasource/Datasource/NewDatasourceDrawer/Form/index.tsx +++ b/src/page/Datasource/Datasource/NewDatasourceDrawer/Form/index.tsx @@ -286,7 +286,7 @@ export default forwardRef(function DatasourceForm( })} - {!haveOCP() && } + ); }}