Skip to content

Commit

Permalink
feat: dockit should show notifications when the restore elasticsearch…
Browse files Browse the repository at this point in the history
… index already exists

Signed-off-by: seven <[email protected]>
  • Loading branch information
Blankll committed Nov 23, 2024
1 parent e86a73f commit e559476
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/lang/enUS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export const enUS = {
openSuccess: 'Opened successfully',
switchSuccess: 'Switched successfully',
overwriteFile: 'File already exists, do you want to overwrite it?',
overwriteIndex: 'Index already exists, confirm to overwrite?',
},
editor: {
establishedRequired: 'Select a DB instance before execute actions',
Expand Down
1 change: 1 addition & 0 deletions src/lang/zhCN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export const zhCN = {
openSuccess: '开启成功',
switchSuccess: '切换成功',
overwriteFile: '文件已存在,确定覆盖?',
overwriteIndex: '索引已存在,确定覆盖?',
},
editor: {
establishedRequired: '请选择执行操作的数据库实例',
Expand Down
51 changes: 41 additions & 10 deletions src/views/backup-restore/components/restore.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ import { CustomError } from '../../../common';
import { useLang } from '../../../lang';
const message = useMessage();
const dialog = useDialog();
const lang = useLang();
const fileFormRef = ref();
Expand Down Expand Up @@ -226,19 +227,49 @@ const submitRestore = async () => {
const connection = connections.value.find(
({ name }) => name === restoreFormData.value.connection,
);
if (!isPass || !connection) return;
const restoreInput = { ...restoreFormData.value, connection };
try {
await restoreFromFile(restoreInput);
message.success(lang.t('backup.restoreFromFileSuccess'));
} catch (err) {
const error = err as CustomError;
message.error(`status: ${error.status}, details: ${error.details}`, {
closable: true,
keepAliveOnHover: true,
duration: 3600,
});
const index = established.value?.indices.find(
({ index }) => index === restoreFormData.value.index,
);
if (!index) {
try {
await restoreFromFile(restoreInput);
message.success(lang.t('backup.restoreFromFileSuccess'));
} catch (err) {
const error = err as CustomError;
message.error(`status: ${error.status}, details: ${error.details}`, {
closable: true,
keepAliveOnHover: true,
duration: 3600,
});
}
return;
}
dialog.warning({
title: lang.t('dialogOps.warning'),
content: lang.t('dialogOps.overwriteIndex'),
positiveText: lang.t('dialogOps.confirm'),
negativeText: lang.t('dialogOps.cancel'),
onPositiveClick: async () => {
restoreFromFile(restoreInput)
.then(() => message.success(lang.t('backup.restoreFromFileSuccess')))
.catch(err => {
const error = err as CustomError;
message.error(`status: ${error.status}, details: ${error.details}`, {
closable: true,
keepAliveOnHover: true,
duration: 3600,
});
});
},
onNegativeClick: () => {},
});
};
watch(restoreFormData, () => (restoreProgress.value = null), { deep: true });
Expand Down

0 comments on commit e559476

Please sign in to comment.