Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

refactor(sql-editor): use naive confirm dialog instead the BBModal. (#793)

Yunwei Xiao7b8a74c64068
diff --git a/frontend/naive-ui.config.ts b/frontend/naive-ui.config.ts
index 8c4d420563..8509d0eaef 100644
--- a/frontend/naive-ui.config.ts
+++ b/frontend/naive-ui.config.ts
@@ -19,15 +19,32 @@ export const themeOverrides = computed((): GlobalThemeOverrides => {
common: {
primaryColor: callVar("--color-accent"),
primaryColorHover: callVar("--color-accent-hover"),
+ primaryColorPressed: callVar("--color-accent"),
successColor: callVar("--color-success"),
successColorHover: callVar("--color-success-hover"),
+ successColorPressed: callVar("--color-success"),
warningColor: callVar("--color-warning"),
warningColorHover: callVar("--color-warning-hover"),
+ warningColorPressed: callVar("--color-warning"),
errorColor: callVar("--color-error"),
errorColorHover: callVar("--color-error-hover"),
+ errorColorPressed: callVar("--color-error"),
+ },
+ Button: {
+ colorInfo: callVar("--color-accent"),
+ colorHoverInfo: callVar("--color-accent-hover"),
+ colorPressedInfo: callVar("--color-accent-disabled"),
+ colorFocusInfo: callVar("--color-accent"),
+ colorDisabledInfo: callVar("--color-accent-disabled"),
+ borderInfo: callVar("--color-accent"),
+ borderHoverInfo: callVar("--color-accent-hover"),
+ borderFocusInfo: callVar("--color-accent"),
+ },
+ Dialog: {
+ iconColorInfo: callVar("--color-accent"),
},
};
});
diff --git a/frontend/src/views/SqlEditor/AsidePanel/DeleteHint.vue b/frontend/src/views/SqlEditor/AsidePanel/DeleteHint.vue
deleted file mode 100644
index 1229674da1..0000000000
--- a/frontend/src/views/SqlEditor/AsidePanel/DeleteHint.vue
+++ /dev/null
@@ -1,39 +0,0 @@
-<template>
- <div class="w-80 flex flex-col justify-start items-start">
- <div class="w-full leading-8">
- <p>{{ props.content }}</p>
- </div>
- <div class="w-full mt-4 flex justify-end space-x-2">
- <NButton @click="handleColse">{{ $t("common.close") }}</NButton>
- <NButton type="primary" @click="handleConfirm">{{
- $t("common.confirm")
- }}</NButton>
- </div>
- </div>
-</template>
-
-<script lang="ts" setup>
-import { defineEmits, defineProps } from "vue";
-
-const props = defineProps({
- content: {
- type: String,
- default: "",
- },
-});
-
-const emit = defineEmits<{
- (e: "confirm"): void;
- (e: "close"): void;
-}>();
-
-const handleConfirm = () => {
- emit("confirm");
-};
-
-const handleColse = () => {
- emit("close");
-};
-</script>
-
-<style scoped></style>
diff --git a/frontend/src/views/SqlEditor/AsidePanel/QueryHistoryContainer.vue b/frontend/src/views/SqlEditor/AsidePanel/QueryHistoryContainer.vue
index 94bfacd598..bec7b1aa27 100644
--- a/frontend/src/views/SqlEditor/AsidePanel/QueryHistoryContainer.vue
+++ b/frontend/src/views/SqlEditor/AsidePanel/QueryHistoryContainer.vue
@@ -57,18 +57,6 @@
<BBSpin :title="$t('common.loading')" />
</div>
</div>
-
- <BBModal
- v-if="state.isShowDeletingHint"
- :title="$t('common.tips')"
- @close="handleHintClose"
- >
- <DeleteHint
- :content="$t('sql-editor.hint-tips.confirm-to-delete-this-history')"
- @close="handleHintClose"
- @confirm="handleDeleteHistory"
- />
- </BBModal>
</template>
<script lang="ts" setup>
@@ -81,6 +69,7 @@ import {
useNamespacedActions,
useNamespacedState,
} from "vuex-composition-helpers";
+import { useDialog } from "naive-ui";
import {
TabActions,
@@ -89,16 +78,15 @@ import {
SqlEditorState,
} from "../../../types";
import { getHighlightHTMLByKeyWords } from "../../../utils";
-import DeleteHint from "./DeleteHint.vue";
interface State {
search: string;
- isShowDeletingHint: boolean;
currentActionHistory: QueryHistory | null;
}
const { t } = useI18n();
const store = useStore();
+const dialog = useDialog();
const { queryHistoryList, isFetchingQueryHistory: isLoading } =
useNamespacedState<SqlEditorState>("sqlEditor", [
@@ -113,7 +101,6 @@ const { addTab } = useNamespacedActions<TabActions>("tab", ["addTab"]);
const state = reactive<State>({
search: "",
- isShowDeletingHint: false,
currentActionHistory: null,
});
@@ -176,11 +163,31 @@ const actionDropdownOptions = computed(() => {
return options;
});
+const handleDeleteHistory = () => {
+ if (state.currentActionHistory) {
+ deleteQueryHistory(state.currentActionHistory.id);
+ }
+};
+
const handleActionBtnClick = (key: string, history: QueryHistory) => {
state.currentActionHistory = history;
if (key === "delete") {
- state.isShowDeletingHint = true;
+ const $dialog = dialog.create({
+ title: t("sql-editor.hint-tips.confirm-to-delete-this-history"),
+ type: "info",
+ onPositiveClick() {
+ handleDeleteHistory();
+ $dialog.destroy();
+ },
+ async onNegativeClick() {
+ state.currentActionHistory = null;
+ $dialog.destroy();
+ },
+ negativeText: t("common.cancel"),
+ positiveText: t("common.confirm"),
+ showIcon: false,
+ });
} else if (key === "copy") {
copyTextToClipboard(history.statement);
store.dispatch("notification/pushNotification", {
@@ -195,18 +202,6 @@ const handleActionBtnOutsideClick = () => {
state.currentActionHistory = null;
};
-const handleHintClose = () => {
- state.currentActionHistory = null;
- state.isShowDeletingHint = false;
-};
-
-const handleDeleteHistory = () => {
- if (state.currentActionHistory) {
- deleteQueryHistory(state.currentActionHistory.id);
- }
- state.isShowDeletingHint = false;
-};
-
const handleQueryHistoryClick = async (queryHistory: QueryHistory) => {
addTab({
statement: queryHistory.statement,
diff --git a/frontend/src/views/SqlEditor/AsidePanel/SheetContainer.vue b/frontend/src/views/SqlEditor/AsidePanel/SheetContainer.vue
index 9128059c44..96ee43f1ef 100644
--- a/frontend/src/views/SqlEditor/AsidePanel/SheetContainer.vue
+++ b/frontend/src/views/SqlEditor/AsidePanel/SheetContainer.vue
@@ -78,18 +78,6 @@
<BBSpin :title="$t('common.loading')" />
</div>
</div>
-
- <BBModal
- v-if="state.isShowDeletingHint"
- :title="$t('common.tips')"
- @close="handleHintClose"
- >
- <DeleteHint
- :content="$t('sql-editor.hint-tips.confirm-to-delete-this-sheet')"
- @close="handleHintClose"
- @confirm="handleDeleteSheet"
- />
- </BBModal>
</template>
<script lang="ts" setup>
@@ -101,6 +89,7 @@ import {
useNamespacedGetters,
useNamespacedState,
} from "vuex-composition-helpers";
+import { useDialog } from "naive-ui";
import {
TabActions,
@@ -114,12 +103,10 @@ import {
UNKNOWN_ID,
} from "../../../types";
import { getHighlightHTMLByKeyWords } from "../../../utils";
-import DeleteHint from "./DeleteHint.vue";
import { useSQLEditorConnection } from "../../../composables/useSQLEditorConnection";
interface State {
search: string;
- isShowDeletingHint: boolean;
currentSheetName: string;
editingSheetId: number | null;
currentActionSheet: Sheet | null;
@@ -127,6 +114,7 @@ interface State {
const { t } = useI18n();
const { setConnectionContextFromCurrentTab } = useSQLEditorConnection();
+const dialog = useDialog();
const { sharedSheet, isFetchingSheet: isLoading } =
useNamespacedState<SqlEditorState>("sqlEditor", [
@@ -157,7 +145,6 @@ const state = reactive<State>({
search: "",
currentSheetName: "",
editingSheetId: null,
- isShowDeletingHint: false,
currentActionSheet: null,
});
@@ -247,23 +234,6 @@ const handleSheetNameChanged = () => {
}
};
-const handleActionBtnClick = (key: string, sheet: Sheet) => {
- state.currentActionSheet = sheet;
-
- if (key === "delete") {
- state.isShowDeletingHint = true;
- }
-};
-
-const handleActionBtnOutsideClick = () => {
- state.currentActionSheet = null;
-};
-
-const handleHintClose = () => {
- state.currentActionSheet = null;
- state.isShowDeletingHint = false;
-};
-
const handleDeleteSheet = () => {
if (state.currentActionSheet) {
deleteSheet(state.currentActionSheet.id);
@@ -274,7 +244,32 @@ const handleDeleteSheet = () => {
});
}
}
- state.isShowDeletingHint = false;
+};
+
+const handleActionBtnClick = (key: string, sheet: Sheet) => {
+ state.currentActionSheet = sheet;
+
+ if (key === "delete") {
+ const $dialog = dialog.create({
+ title: t("sql-editor.hint-tips.confirm-to-delete-this-sheet"),
+ type: "info",
+ onPositiveClick() {
+ handleDeleteSheet();
+ $dialog.destroy();
+ },
+ async onNegativeClick() {
+ state.currentActionSheet = null;
+ $dialog.destroy();
+ },
+ negativeText: t("common.cancel"),
+ positiveText: t("common.confirm"),
+ showIcon: false,
+ });
+ }
+};
+
+const handleActionBtnOutsideClick = () => {
+ state.currentActionSheet = null;
};
const handleSheetClick = async (sheet: Sheet) => {
diff --git a/frontend/src/views/SqlEditor/TabListContainer.vue b/frontend/src/views/SqlEditor/TabListContainer.vue
index 12b83ecf26..8908f77400 100644
--- a/frontend/src/views/SqlEditor/TabListContainer.vue
+++ b/frontend/src/views/SqlEditor/TabListContainer.vue
@@ -171,6 +171,7 @@ const { createSheet, patchSheetById } = useNamespacedActions<SheetActions>(
const store = useStore();
const { t } = useI18n();
const { setConnectionContextFromCurrentTab } = useSQLEditorConnection();
+const dialog = useDialog();
const enterTabId = ref("");
const selectedTab = computed(() => currentTabId.value);
@@ -279,22 +280,21 @@ const handleAddTab = (tab: AnyTabInfo) => {
});
};
-const modal = useDialog();
-
const handleRemoveTab = async (tab: TabInfo) => {
if (!tab.isSaved) {
- const $modal = modal.create({
+ const $dialog = dialog.create({
title: t("sql-editor.hint-tips.confirm-to-close-unsaved-tab"),
- type: "warning",
+ type: "info",
onPositiveClick() {
- $modal.destroy();
+ $dialog.destroy();
},
async onNegativeClick() {
await remove();
- $modal.destroy();
+ $dialog.destroy();
},
negativeText: t("common.confirm"),
positiveText: t("common.cancel"),
+ showIcon: false,
});
} else {
await remove();