Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
HSunboy committed Nov 13, 2023
1 parent 8efc91a commit 597ec21
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 86 deletions.
12 changes: 6 additions & 6 deletions src/common/network/recycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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;
}
103 changes: 23 additions & 80 deletions src/page/Workspace/components/RecycleBinPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -61,10 +58,8 @@ class RecycleBin extends Component<
IProps,
{
showEditModal: boolean;
showExecuteSQLModal: boolean;
searchKey: string;
listLoading: boolean;
updateDML: string;
selectedObjectNames: Set<string>;
selectAll: boolean;
showDeleteDrawer: boolean;
Expand All @@ -74,10 +69,8 @@ class RecycleBin extends Component<
> {
public readonly state = {
showEditModal: false,
showExecuteSQLModal: false,
searchKey: '',
listLoading: false,
updateDML: '',
selectedObjectNames: new Set<string>(),
selectAll: false,
showDeleteDrawer: false,
Expand Down Expand Up @@ -107,6 +100,14 @@ class RecycleBin extends Component<
this.setState({ listLoading: false });
}

public onSuccess = async () => {
await this.session.getRecycleObjectList();
this.setState({
selectedObjectNames: new Set<string>(), // 清除掉当前选择的对象
});
message.success(formatMessage({ id: 'workspace.window.recyclebin.success' }));
};

/**
* 打开清空回收站确认框
*/
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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<string>(), // 清除掉当前选择的对象
});
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<string>(), // 清除掉当前选择的对象
});

message.success(formatMessage({ id: 'workspace.window.recyclebin.success' }));
} else {
notification.error(result?.executeResult?.[0]);
}
};

Expand Down Expand Up @@ -294,10 +249,8 @@ class RecycleBin extends Component<
const {
showDeleteDrawer,
showRestoreDrawer,
showExecuteSQLModal,
searchKey,
listLoading,
updateDML,
selectedObjectNames,
recycleConfig,
} = this.state;
Expand Down Expand Up @@ -515,16 +468,6 @@ class RecycleBin extends Component<
/>
</div>
</Spin>
<ExecuteSQLModal
sessionStore={this.session}
sql={updateDML}
theme={theme}
visible={showExecuteSQLModal}
onSave={this.handleExecuteUpdateDML}
onCancel={() => this.setState({ showExecuteSQLModal: false, updateDML: '' })}
onChange={(sql) => this.setState({ updateDML: sql })}
/>

<Drawer
title={formatMessage({
id: 'workspace.window.recyclebin.drawer.delete.title',
Expand Down

0 comments on commit 597ec21

Please sign in to comment.