From 597ec21486460ffebed6156c85168a47b650f6fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=93=E5=BA=B7?= Date: Mon, 13 Nov 2023 14:21:20 +0800 Subject: [PATCH] =?UTF-8?q?fixes=20oceanbase/odc#705=EF=BC=8C=20fixes=20oc?= =?UTF-8?q?eanbase/odc#180?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/network/recycle.ts | 12 +- .../components/RecycleBinPage/index.tsx | 103 ++++-------------- 2 files changed, 29 insertions(+), 86 deletions(-) diff --git a/src/common/network/recycle.ts b/src/common/network/recycle.ts index 10f168ef7..5f80fbc3e 100644 --- a/src/common/network/recycle.ts +++ b/src/common/network/recycle.ts @@ -46,9 +46,9 @@ export async function updateRecycleConfig( export async function getPurgeAllSQL(sessionId: string, dbName: string) { const result = await request.patch( - `/api/v1/recyclebin/getPurgeAllSql/${generateDatabaseSid(dbName, sessionId)}`, + `/api/v1/recyclebin/purgeAll/${generateDatabaseSid(dbName, sessionId)}`, ); - return result?.data?.sql; + return !!result?.data; } export async function getDeleteSQL( @@ -57,10 +57,10 @@ export async function getDeleteSQL( dbName: string, ) { const sid = generateDatabaseSid(dbName, sessionId); - const result = await request.patch(`/api/v1/recyclebin/getDeleteSql/${sid}`, { + const result = await request.patch(`/api/v1/recyclebin/purge/${sid}`, { data: recycleObjects, }); - return result?.data?.sql; + return !!result?.data; } export async function getUpdateSQL( @@ -69,8 +69,8 @@ export async function getUpdateSQL( dbName: string, ) { const sid = generateDatabaseSid(dbName, sessionId); - const result = await request.patch(`/api/v1/recyclebin/getUpdateSql/${sid}`, { + const result = await request.patch(`/api/v1/recyclebin/flashback/${sid}`, { data: recycleObjects, }); - return result?.data?.sql; + return !!result?.data; } diff --git a/src/page/Workspace/components/RecycleBinPage/index.tsx b/src/page/Workspace/components/RecycleBinPage/index.tsx index 57bda9250..66bcfa8dc 100644 --- a/src/page/Workspace/components/RecycleBinPage/index.tsx +++ b/src/page/Workspace/components/RecycleBinPage/index.tsx @@ -21,15 +21,12 @@ import { getUpdateSQL, updateRecycleConfig, } from '@/common/network/recycle'; -import { executeSQL } from '@/common/network/sql'; -import ExecuteSQLModal from '@/component/ExecuteSQLModal'; import WorkSpacePageLoading from '@/component/Loading/WorkSpacePageLoading'; import MiniTable from '@/component/Table/MiniTable'; import Toolbar from '@/component/Toolbar'; -import { IRecycleConfig, IRecycleObject, ISqlExecuteResultStatus } from '@/d.ts'; +import { IRecycleConfig, IRecycleObject } from '@/d.ts'; import SessionStore from '@/store/sessionManager/session'; import { formatMessage } from '@/util/intl'; -import notification from '@/util/notification'; import { sortString } from '@/util/utils'; import { ExclamationCircleFilled, SettingOutlined, SyncOutlined } from '@ant-design/icons'; import { FormattedMessage } from '@umijs/max'; @@ -61,10 +58,8 @@ class RecycleBin extends Component< IProps, { showEditModal: boolean; - showExecuteSQLModal: boolean; searchKey: string; listLoading: boolean; - updateDML: string; selectedObjectNames: Set; selectAll: boolean; showDeleteDrawer: boolean; @@ -74,10 +69,8 @@ class RecycleBin extends Component< > { public readonly state = { showEditModal: false, - showExecuteSQLModal: false, searchKey: '', listLoading: false, - updateDML: '', selectedObjectNames: new Set(), selectAll: false, showDeleteDrawer: false, @@ -107,6 +100,14 @@ class RecycleBin extends Component< this.setState({ listLoading: false }); } + public onSuccess = async () => { + await this.session.getRecycleObjectList(); + this.setState({ + selectedObjectNames: new Set(), // 清除掉当前选择的对象 + }); + message.success(formatMessage({ id: 'workspace.window.recyclebin.success' })); + }; + /** * 打开清空回收站确认框 */ @@ -139,11 +140,10 @@ class RecycleBin extends Component< * 清空全部 */ public handleSubmitPurgeAll = async () => { - this.setState({ showExecuteSQLModal: true }); - - const updateDML = await getPurgeAllSQL(this.session.sessionId, this.session?.database?.dbName); - // TODO: 获取修改对应的 SQL - this.setState({ updateDML }); + const isSuccess = await getPurgeAllSQL(this.session.sessionId, this.session?.database?.dbName); + if (isSuccess) { + await this.onSuccess(); + } }; public handleDelete = async () => { @@ -153,14 +153,17 @@ class RecycleBin extends Component< selectedObjectNames.has(r.uniqueId), ); - this.setState({ showExecuteSQLModal: true }); - - const updateDML = await getDeleteSQL( + const isSuccess = await getDeleteSQL( selectedObjects, this.session.sessionId, this.session?.database?.dbName, ); - this.setState({ updateDML }); + if (isSuccess) { + await this.onSuccess(); + this.setState({ + showDeleteDrawer: false, + }); + } }; public handleRestore = async () => { @@ -170,64 +173,16 @@ class RecycleBin extends Component< selectedObjectNames.has(r.uniqueId), ); - this.setState({ showExecuteSQLModal: true }); - - const updateDML = await getUpdateSQL( + const isSuccess = await getUpdateSQL( selectedObjects, this.session.sessionId, this.session?.database?.dbName, ); - this.setState({ updateDML }); - }; - - /** - * 执行 SQL - */ - public handleExecuteUpdateDML = async () => { - const { updateDML } = this.state; - - // 执行 DML - const result = await executeSQL( - updateDML, - this.session?.sessionId, - this.session?.database?.dbName, - ); - if (!result) { - return; - } - if (result?.invalid) { - this.setState({ - showExecuteSQLModal: false, - showDeleteDrawer: false, - showRestoreDrawer: false, - updateDML: '', - selectedObjectNames: new Set(), // 清除掉当前选择的对象 - }); - return; - } - - if (result?.executeResult?.[0]?.status === ISqlExecuteResultStatus.SUCCESS) { - // 刷新 - await this.session.getRecycleObjectList(); - // if (updateDML.toUpperCase().indexOf('FLASHBACK DATABASE') > -1) { - // /** - // * 重新刷新一下数据库 - // */ - // await this.session.getDatabaseList(); - // } - - // 关闭已打开的 drawer、modal + if (isSuccess) { + await this.onSuccess(); this.setState({ - showExecuteSQLModal: false, - showDeleteDrawer: false, showRestoreDrawer: false, - updateDML: '', - selectedObjectNames: new Set(), // 清除掉当前选择的对象 }); - - message.success(formatMessage({ id: 'workspace.window.recyclebin.success' })); - } else { - notification.error(result?.executeResult?.[0]); } }; @@ -294,10 +249,8 @@ class RecycleBin extends Component< const { showDeleteDrawer, showRestoreDrawer, - showExecuteSQLModal, searchKey, listLoading, - updateDML, selectedObjectNames, recycleConfig, } = this.state; @@ -515,16 +468,6 @@ class RecycleBin extends Component< /> - this.setState({ showExecuteSQLModal: false, updateDML: '' })} - onChange={(sql) => this.setState({ updateDML: sql })} - /> -