Skip to content

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

feat: add instance and project action menus with batch operations (#18958)

Danny Xu8b0d2d8ba197
diff --git a/backend/api/v1/instance_service.go b/backend/api/v1/instance_service.go
index 96f871d996..49153f5739 100644
--- a/backend/api/v1/instance_service.go
+++ b/backend/api/v1/instance_service.go
@@ -435,8 +435,9 @@ func (s *InstanceService) DeleteInstance(ctx context.Context, req *connect.Reque
}
// Regular soft delete flow
+ // Idempotent: if already deleted, return success
if instance.Deleted {
- return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("instance %q has been deleted", req.Msg.Name))
+ return connect.NewResponse(&emptypb.Empty{}), nil
}
databases, err := s.store.ListDatabases(ctx, &store.FindDatabaseMessage{InstanceID: &instance.ResourceID})
@@ -486,8 +487,10 @@ func (s *InstanceService) UndeleteInstance(ctx context.Context, req *connect.Req
if err != nil {
return nil, err
}
+ // Idempotent: if already active, return the instance
if !instance.Deleted {
- return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("instance %q is active", req.Msg.Name))
+ result := convertInstanceMessage(instance)
+ return connect.NewResponse(result), nil
}
if err := s.instanceCountGuard(ctx); err != nil {
return nil, err
diff --git a/backend/api/v1/project_service.go b/backend/api/v1/project_service.go
index 8a9aad7282..45bb82f86c 100644
--- a/backend/api/v1/project_service.go
+++ b/backend/api/v1/project_service.go
@@ -399,12 +399,13 @@ func (s *ProjectService) DeleteProject(ctx context.Context, req *connect.Request
}
// Regular soft delete (archive) flow
- if project.Deleted {
- return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("project %q has been deleted", req.Msg.Name))
- }
if project.ResourceID == common.DefaultProjectID {
return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("default project cannot be deleted"))
}
+ // Idempotent: if already deleted, return success
+ if project.Deleted {
+ return connect.NewResponse(&emptypb.Empty{}), nil
+ }
// For archive (soft delete), just mark the project as deleted without touching databases or issues
if _, err := s.store.UpdateProjects(ctx, &store.UpdateProjectMessage{
@@ -423,8 +424,9 @@ func (s *ProjectService) UndeleteProject(ctx context.Context, req *connect.Reque
if err != nil {
return nil, err
}
+ // Idempotent: if already active, return the project
if !project.Deleted {
- return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("project %q is active", req.Msg.Name))
+ return connect.NewResponse(convertToProject(project)), nil
}
projects, err := s.store.UpdateProjects(ctx, &store.UpdateProjectMessage{
@@ -491,12 +493,13 @@ func (s *ProjectService) BatchDeleteProjects(ctx context.Context, request *conne
if err != nil {
return nil, err
}
- if project.Deleted {
- return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("project %q has already been deleted", name))
- }
if project.ResourceID == common.DefaultProjectID {
return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("default project cannot be deleted"))
}
+ // Idempotent: skip already deleted projects
+ if project.Deleted {
+ continue
+ }
projects = append(projects, project)
}
@@ -510,8 +513,10 @@ func (s *ProjectService) BatchDeleteProjects(ctx context.Context, request *conne
})
}
- if _, err := s.store.UpdateProjects(ctx, updatePatches...); err != nil {
- return nil, connect.NewError(connect.CodeInternal, err)
+ if len(updatePatches) > 0 {
+ if _, err := s.store.UpdateProjects(ctx, updatePatches...); err != nil {
+ return nil, connect.NewError(connect.CodeInternal, err)
+ }
}
return connect.NewResponse(&emptypb.Empty{}), nil
diff --git a/frontend/src/components/Instance/InstanceActionDropdown.vue b/frontend/src/components/Instance/InstanceActionDropdown.vue
new file mode 100644
index 0000000000..9e18a0193e
--- /dev/null
+++ b/frontend/src/components/Instance/InstanceActionDropdown.vue
@@ -0,0 +1,175 @@
+<template>
+ <NDropdown
+ trigger="click"
+ :options="dropdownOptions"
+ @select="handleSelect"
+ >
+ <NButton size="small" quaternary class="px-1!">
+ <template #icon>
+ <EllipsisVerticalIcon class="w-4 h-4" />
+ </template>
+ </NButton>
+ </NDropdown>
+</template>
+
+<script setup lang="ts">
+import { EllipsisVerticalIcon } from "lucide-vue-next";
+import type { DropdownOption } from "naive-ui";
+import { NButton, NCheckbox, NDropdown, useDialog } from "naive-ui";
+import { computed, h, ref } from "vue";
+import { useI18n } from "vue-i18n";
+import { useRouter } from "vue-router";
+import { INSTANCE_ROUTE_DASHBOARD } from "@/router/dashboard/workspaceRoutes";
+import { pushNotification, useInstanceV1Store } from "@/store";
+import { State } from "@/types/proto-es/v1/common_pb";
+import type { Instance } from "@/types/proto-es/v1/instance_service_pb";
+import { hasWorkspacePermissionV2 } from "@/utils";
+
+const props = defineProps<{
+ instance: Instance;
+}>();
+
+const emit = defineEmits<{
+ (e: "deleted"): void;
+}>();
+
+const { t } = useI18n();
+const dialog = useDialog();
+const instanceStore = useInstanceV1Store();
+const router = useRouter();
+
+const force = ref(false);
+
+const canArchive = computed(() =>
+ hasWorkspacePermissionV2("bb.instances.delete")
+);
+const canRestore = computed(() =>
+ hasWorkspacePermissionV2("bb.instances.undelete")
+);
+
+const dropdownOptions = computed((): DropdownOption[] => {
+ const options: DropdownOption[] = [];
+
+ if (props.instance.state === State.ACTIVE && canArchive.value) {
+ options.push({
+ key: "archive",
+ label: t("common.archive"),
+ });
+ } else if (props.instance.state === State.DELETED && canRestore.value) {
+ options.push({
+ key: "restore",
+ label: t("common.restore"),
+ });
+ }
+
+ if (canArchive.value || canRestore.value) {
+ options.push({
+ key: "delete",
+ label: t("common.delete"),
+ });
+ }
+
+ return options;
+});
+
+const handleArchive = () => {
+ force.value = false;
+ dialog.warning({
+ title: t("instance.archive-instance-instance-name", [props.instance.title]),
+ content: () =>
+ h("div", [
+ h(
+ "div",
+ { class: "mb-3" },
+ t("instance.archived-instances-will-not-be-displayed")
+ ),
+ h(
+ NCheckbox,
+ {
+ checked: force.value,
+ "onUpdate:checked": (value: boolean) => {
+ force.value = value;
+ },
+ },
+ {
+ default: () =>
+ h(
+ "div",
+ { class: "text-sm font-normal text-control-light" },
+ t("instance.force-archive-description")
+ ),
+ }
+ ),
+ ]),
+ negativeText: t("common.cancel"),
+ positiveText: t("common.archive"),
+ onPositiveClick: async () => {
+ await instanceStore.archiveInstance(props.instance, force.value);
+ pushNotification({
+ module: "bytebase",
+ style: "INFO",
+ title: t("instance.successfully-archived-instance", [
+ props.instance.title,
+ ]),
+ });
+ router.replace({
+ name: INSTANCE_ROUTE_DASHBOARD,
+ });
+ },
+ });
+};
+
+const handleRestore = () => {
+ dialog.info({
+ title: t("instance.restore-instance-instance-name-to-normal-state", [
+ props.instance.title,
+ ]),
+ negativeText: t("common.cancel"),
+ positiveText: t("instance.restore"),
+ onPositiveClick: async () => {
+ await instanceStore.restoreInstance(props.instance);
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("instance.successfully-restored-instance", [
+ props.instance.title,
+ ]),
+ });
+ },
+ });
+};
+
+const handleDelete = () => {
+ dialog.warning({
+ title: t("common.delete-resource", {
+ resource: props.instance.title,
+ }),
+ content: t("common.cannot-undo-this-action"),
+ negativeText: t("common.cancel"),
+ positiveText: t("common.delete"),
+ onPositiveClick: async () => {
+ await instanceStore.deleteInstance(props.instance.name);
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("common.deleted"),
+ });
+ emit("deleted");
+ router.replace({
+ name: INSTANCE_ROUTE_DASHBOARD,
+ query: { q: "state:DELETED" },
+ });
+ },
+ });
+};
+
+const handleSelect = (key: string) => {
+ if (key === "archive") {
+ handleArchive();
+ } else if (key === "restore") {
+ handleRestore();
+ } else if (key === "delete") {
+ handleDelete();
+ }
+};
+</script>
diff --git a/frontend/src/components/Instance/InstanceArchiveRestoreButton.vue b/frontend/src/components/Instance/InstanceArchiveRestoreButton.vue
deleted file mode 100644
index f8a0152457..0000000000
--- a/frontend/src/components/Instance/InstanceArchiveRestoreButton.vue
+++ /dev/null
@@ -1,118 +0,0 @@
-<template>
- <div
- v-if="allowArchiveOrRestore"
- class="t-6 border-t border-block-border flex justify-between items-center pt-4 pb-2 gap-x-2"
- >
- <template v-if="instance.state === State.ACTIVE">
- <BBButtonConfirm
- :type="'ARCHIVE'"
- :button-text="$t('instance.archive-this-instance')"
- :ok-text="$t('common.archive')"
- :require-confirm="true"
- :confirm-title="
- $t('instance.archive-instance-instance-name', [instance.title])
- "
- :confirm-description="
- $t('instance.archived-instances-will-not-be-displayed')
- "
- class="border-none!"
- @confirm="archiveOrRestoreInstance(true)"
- >
- <div class="mt-3">
- <NCheckbox v-model:checked="force">
- <div class="text-sm font-normal text-control-light">
- {{ $t("instance.force-archive-description") }}
- </div>
- </NCheckbox>
- </div>
- </BBButtonConfirm>
- </template>
- <template v-else-if="instance.state === State.DELETED">
- <BBButtonConfirm
- :type="'RESTORE'"
- :button-text="$t('instance.restore-this-instance')"
- :ok-text="$t('instance.restore')"
- :require-confirm="true"
- :confirm-title="
- $t('instance.restore-instance-instance-name-to-normal-state', [
- instance.title,
- ])
- "
- :confirm-description="''"
- class="border-none!"
- @confirm="archiveOrRestoreInstance(false)"
- />
- </template>
- <ResourceHardDeleteButton
- :resource="instance"
- @delete="hardDeleteInstance"
- />
- </div>
-</template>
-
-<script setup lang="ts">
-import { NCheckbox } from "naive-ui";
-import { computed, ref } from "vue";
-import { useI18n } from "vue-i18n";
-import { useRouter } from "vue-router";
-import { BBButtonConfirm } from "@/bbkit";
-import ResourceHardDeleteButton from "@/components/v2/Button/ResourceHardDeleteButton.vue";
-import { INSTANCE_ROUTE_DASHBOARD } from "@/router/dashboard/workspaceRoutes";
-import { pushNotification, useInstanceV1Store } from "@/store";
-import { State } from "@/types/proto-es/v1/common_pb";
-import type { Instance } from "@/types/proto-es/v1/instance_service_pb";
-import { hasWorkspacePermissionV2 } from "@/utils";
-
-const props = defineProps<{
- instance: Instance;
-}>();
-
-const { t } = useI18n();
-const instanceStore = useInstanceV1Store();
-const router = useRouter();
-
-const force = ref(false);
-
-const allowArchiveOrRestore = computed(() => {
- return (
- hasWorkspacePermissionV2("bb.instances.delete") ||
- hasWorkspacePermissionV2("bb.instances.undelete")
- );
-});
-
-const archiveOrRestoreInstance = async (archive: boolean) => {
- if (archive) {
- await instanceStore.archiveInstance(props.instance, force.value);
- pushNotification({
- module: "bytebase",
- style: "INFO",
- title: t("instance.successfully-archived-instance", [
- props.instance.title,
- ]),
- });
- } else {
- await instanceStore.restoreInstance(props.instance);
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("instance.successfully-restored-instance", [
- props.instance.title,
- ]),
- });
- }
-
- if (archive) {
- router.replace({
- name: INSTANCE_ROUTE_DASHBOARD,
- });
- }
-};
-
-const hardDeleteInstance = async (resource: string) => {
- await instanceStore.deleteInstance(resource);
- router.replace({
- name: INSTANCE_ROUTE_DASHBOARD,
- query: { q: "state:DELETED" },
- });
-};
-</script>
diff --git a/frontend/src/components/Instance/index.ts b/frontend/src/components/Instance/index.ts
deleted file mode 100644
index 88e619bd38..0000000000
--- a/frontend/src/components/Instance/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-import InstanceArchiveRestoreButton from "./InstanceArchiveRestoreButton.vue";
-
-export { InstanceArchiveRestoreButton };
diff --git a/frontend/src/components/InstanceForm/Form.vue b/frontend/src/components/InstanceForm/Form.vue
index 53266f6146..dcec09bc44 100644
--- a/frontend/src/components/InstanceForm/Form.vue
+++ b/frontend/src/components/InstanceForm/Form.vue
@@ -497,11 +497,6 @@
/>
</div>
</div>
-
- <InstanceArchiveRestoreButton
- v-if="!hideArchiveRestore && !isCreating && instance"
- :instance="instance"
- />
</div>
</template>
@@ -522,7 +517,6 @@ import {
import { computed, ref } from "vue";
import { useI18n } from "vue-i18n";
import { BBAttention } from "@/bbkit";
-import { InstanceArchiveRestoreButton } from "@/components/Instance";
import { LabelListEditor } from "@/components/Label";
import RequiredStar from "@/components/RequiredStar.vue";
import {
@@ -572,10 +566,6 @@ import ScanIntervalInput from "./ScanIntervalInput.vue";
import SpannerHostInput from "./SpannerHostInput.vue";
import SyncDatabases from "./SyncDatabases.vue";
-defineProps<{
- hideArchiveRestore?: boolean;
-}>();
-
const context = useInstanceFormContext();
const {
state,
diff --git a/frontend/src/components/Project/ProjectActionDropdown.vue b/frontend/src/components/Project/ProjectActionDropdown.vue
new file mode 100644
index 0000000000..66775fbd31
--- /dev/null
+++ b/frontend/src/components/Project/ProjectActionDropdown.vue
@@ -0,0 +1,155 @@
+<template>
+ <NDropdown
+ trigger="click"
+ :options="dropdownOptions"
+ @select="handleSelect"
+ >
+ <NButton size="small" quaternary class="px-1!">
+ <template #icon>
+ <EllipsisVerticalIcon class="w-4 h-4" />
+ </template>
+ </NButton>
+ </NDropdown>
+</template>
+
+<script setup lang="ts">
+import { EllipsisVerticalIcon } from "lucide-vue-next";
+import type { DropdownOption } from "naive-ui";
+import { NButton, NDropdown, useDialog } from "naive-ui";
+import { computed } from "vue";
+import { useI18n } from "vue-i18n";
+import { useRouter } from "vue-router";
+import { PROJECT_V1_ROUTE_DASHBOARD } from "@/router/dashboard/workspaceRoutes";
+import {
+ pushNotification,
+ useGracefulRequest,
+ useProjectV1Store,
+} from "@/store";
+import { State } from "@/types/proto-es/v1/common_pb";
+import type { Project } from "@/types/proto-es/v1/project_service_pb";
+import { hasProjectPermissionV2 } from "@/utils";
+
+const props = defineProps<{
+ project: Project;
+}>();
+
+const emit = defineEmits<{
+ (e: "deleted"): void;
+}>();
+
+const { t } = useI18n();
+const dialog = useDialog();
+const projectStore = useProjectV1Store();
+const router = useRouter();
+
+const canArchive = computed(() =>
+ hasProjectPermissionV2(props.project, "bb.projects.delete")
+);
+const canRestore = computed(() =>
+ hasProjectPermissionV2(props.project, "bb.projects.undelete")
+);
+
+const dropdownOptions = computed((): DropdownOption[] => {
+ const options: DropdownOption[] = [];
+
+ if (props.project.state === State.ACTIVE && canArchive.value) {
+ options.push({
+ key: "archive",
+ label: t("common.archive"),
+ });
+ } else if (props.project.state === State.DELETED && canRestore.value) {
+ options.push({
+ key: "restore",
+ label: t("common.restore"),
+ });
+ }
+
+ if (canArchive.value || canRestore.value) {
+ options.push({
+ key: "delete",
+ label: t("common.delete"),
+ });
+ }
+
+ return options;
+});
+
+const handleArchive = () => {
+ dialog.warning({
+ title: t("common.confirm-archive"),
+ content: t("project.settings.confirm-archive-project", {
+ name: props.project.title || props.project.name,
+ }),
+ negativeText: t("common.cancel"),
+ positiveText: t("common.archive"),
+ onPositiveClick: () => {
+ useGracefulRequest(async () => {
+ await projectStore.archiveProject(props.project);
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: `${props.project.title || props.project.name} ${t("common.archived")}`,
+ });
+ router.push({ name: PROJECT_V1_ROUTE_DASHBOARD });
+ });
+ },
+ });
+};
+
+const handleRestore = () => {
+ dialog.info({
+ title: t("project.settings.restore.title"),
+ content:
+ t("project.settings.restore.title") +
+ ` '${props.project.title || props.project.name}'?`,
+ negativeText: t("common.cancel"),
+ positiveText: t("common.restore"),
+ onPositiveClick: () => {
+ useGracefulRequest(async () => {
+ await projectStore.restoreProject(props.project);
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: `${props.project.title || props.project.name} ${t("common.restored")}`,
+ });
+ });
+ },
+ });
+};
+
+const handleDelete = () => {
+ dialog.warning({
+ title: t("common.confirm-delete"),
+ content:
+ t("project.settings.confirm-delete-project", {
+ name: props.project.title || props.project.name,
+ }) +
+ "\n\n" +
+ t("common.cannot-undo-this-action"),
+ negativeText: t("common.cancel"),
+ positiveText: t("common.delete"),
+ onPositiveClick: () => {
+ useGracefulRequest(async () => {
+ await projectStore.deleteProject(props.project.name);
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: `${props.project.title || props.project.name} ${t("common.deleted")}`,
+ });
+ emit("deleted");
+ router.push({ name: PROJECT_V1_ROUTE_DASHBOARD });
+ });
+ },
+ });
+};
+
+const handleSelect = (key: string) => {
+ if (key === "archive") {
+ handleArchive();
+ } else if (key === "restore") {
+ handleRestore();
+ } else if (key === "delete") {
+ handleDelete();
+ }
+};
+</script>
diff --git a/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseOperations.vue b/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseOperations.vue
index 7577472c95..72b6d742b0 100644
--- a/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseOperations.vue
+++ b/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseOperations.vue
@@ -106,6 +106,7 @@ import {
ChevronsDownIcon,
DownloadIcon,
PencilIcon,
+ PlusIcon,
RefreshCcwIcon,
SquareStackIcon,
TagIcon,
@@ -149,6 +150,7 @@ import {
extractProjectResourceName,
generateIssueTitle,
PERMISSIONS_FOR_DATABASE_CHANGE_ISSUE,
+ PERMISSIONS_FOR_DATABASE_CREATE_ISSUE,
PERMISSIONS_FOR_DATABASE_EXPORT_ISSUE,
} from "@/utils";
@@ -172,8 +174,10 @@ const props = withDefaults(
defineProps<{
databases: ComposedDatabase[];
projectName?: string;
+ instanceName?: string;
+ onCreateDatabase?: () => void;
}>(),
- { projectName: "" }
+ { projectName: "", instanceName: "", onCreateDatabase: undefined }
);
const state = reactive<LocalState>({
@@ -240,6 +244,7 @@ const selectedDatabaseNameList = computed(() => {
const operations = computed(() => {
return [
+ "CREATE-DATABASE",
"CHANGE-DATABASE",
"EXPORT-DATA",
"SYNC-SCHEMA",
@@ -380,6 +385,17 @@ const actions = computed((): DatabaseAction[] => {
const resp: DatabaseAction[] = [];
for (const operation of operations.value) {
switch (operation) {
+ case "CREATE-DATABASE":
+ if (props.instanceName && props.onCreateDatabase) {
+ resp.push({
+ icon: h(PlusIcon),
+ text: t("instance.new-database"),
+ disabled: false,
+ click: props.onCreateDatabase,
+ requiredPermissions: [...PERMISSIONS_FOR_DATABASE_CREATE_ISSUE],
+ });
+ }
+ break;
case "CHANGE-DATABASE":
if (operationsInProjectDetail.value && !isInDefaultProject.value) {
resp.push({
diff --git a/frontend/src/components/v2/Model/Instance/InstanceV1Table/InstanceV1Table.vue b/frontend/src/components/v2/Model/Instance/InstanceV1Table/InstanceV1Table.vue
index 7508c1e7b1..a1e3be3e29 100644
--- a/frontend/src/components/v2/Model/Instance/InstanceV1Table/InstanceV1Table.vue
+++ b/frontend/src/components/v2/Model/Instance/InstanceV1Table/InstanceV1Table.vue
@@ -34,6 +34,7 @@ import { computed, reactive, watch } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import EllipsisText from "@/components/EllipsisText.vue";
+import InstanceActionDropdown from "@/components/Instance/InstanceActionDropdown.vue";
import { InstanceV1Name } from "@/components/v2";
import { LabelsCell } from "@/components/v2/Model/cells";
import { useEnvironmentV1Store } from "@/store";
@@ -63,6 +64,7 @@ const props = withDefaults(
disabledSelectedInstanceNames?: Set<string>;
showAddress?: boolean;
showExternalLink?: boolean;
+ showActions?: boolean;
onClick?: (instance: Instance, e: MouseEvent) => void;
sorters?: DataTableSortState[];
}>(),
@@ -72,6 +74,7 @@ const props = withDefaults(
onClick: undefined,
showAddress: true,
showExternalLink: true,
+ showActions: false,
disabledSelectedInstanceNames: () => new Set(),
defaultExpandDataSource: () => [],
selectedInstanceNames: () => [],
@@ -209,6 +212,22 @@ const columnList = computed((): InstanceDataTableColumn[] => {
width: 100,
render: (instance) => (instance.activation ? "Y" : ""),
};
+ const ACTIONS: InstanceDataTableColumn = {
+ key: "actions",
+ title: "",
+ width: 50,
+ hide: !props.showActions,
+ render: (instance) => (
+ <div
+ class="flex justify-end"
+ onClick={(e: MouseEvent) => {
+ e.stopPropagation();
+ }}
+ >
+ <InstanceActionDropdown instance={instance} />
+ </div>
+ ),
+ };
const columns: InstanceDataTableColumn[] = [
SELECTION,
@@ -218,6 +237,7 @@ const columnList = computed((): InstanceDataTableColumn[] => {
LABELS,
EXTERNAL_LINK,
LICENSE,
+ ACTIONS,
].filter((column) => !column.hide);
return mapSorterStatus(columns, props.sorters);
});
diff --git a/frontend/src/components/v2/Model/Instance/PagedInstanceTable.vue b/frontend/src/components/v2/Model/Instance/PagedInstanceTable.vue
index 114209ca57..02ebd67d9f 100644
--- a/frontend/src/components/v2/Model/Instance/PagedInstanceTable.vue
+++ b/frontend/src/components/v2/Model/Instance/PagedInstanceTable.vue
@@ -11,6 +11,8 @@
:loading="loading"
:instance-list="list"
:sorters="sorters"
+ :show-external-link="showExternalLink"
+ :show-actions="showActions"
@update:sorters="onSortersUpdate"
/>
</template>
@@ -25,10 +27,18 @@ import { type InstanceFilter, useInstanceV1Store } from "@/store";
import { type Instance } from "@/types/proto-es/v1/instance_service_pb";
import InstanceV1Table from "./InstanceV1Table";
-const props = defineProps<{
- filter?: InstanceFilter;
- sessionKey: string;
-}>();
+const props = withDefaults(
+ defineProps<{
+ filter?: InstanceFilter;
+ sessionKey: string;
+ showExternalLink?: boolean;
+ showActions?: boolean;
+ }>(),
+ {
+ showExternalLink: true,
+ showActions: false,
+ }
+);
const instanceStore = useInstanceV1Store();
const instancePagedTable = ref<ComponentExposed<typeof PagedTable<Instance>>>();
diff --git a/frontend/src/components/v2/Model/PagedProjectTable.vue b/frontend/src/components/v2/Model/PagedProjectTable.vue
index 59ca85241f..4c4aef2b5a 100644
--- a/frontend/src/components/v2/Model/PagedProjectTable.vue
+++ b/frontend/src/components/v2/Model/PagedProjectTable.vue
@@ -13,6 +13,7 @@
:selected-project-names="selectedProjectNames"
:show-selection="showSelection"
:show-labels="showLabels"
+ :show-actions="showActions"
:keyword="filter.query"
:sorters="sorters"
@update:selected-project-names="updateSelectedProjectNames"
@@ -37,11 +38,13 @@ const props = withDefaults(
selectedProjectNames?: string[];
showSelection?: boolean;
showLabels?: boolean;
+ showActions?: boolean;
}>(),
{
selectedProjectNames: () => [],
showSelection: false,
showLabels: true,
+ showActions: false,
}
);
diff --git a/frontend/src/components/v2/Model/Project/ProjectOperations.vue b/frontend/src/components/v2/Model/Project/ProjectOperations.vue
index 7aff13e9fe..5e7bb935ec 100644
--- a/frontend/src/components/v2/Model/Project/ProjectOperations.vue
+++ b/frontend/src/components/v2/Model/Project/ProjectOperations.vue
@@ -6,7 +6,7 @@
<span class="whitespace-nowrap">
{{ $t("project.batch.selected", { count: projectList.length }) }}
</span>
- <div class="flex items-center">
+ <div class="flex items-center gap-x-2">
<template v-for="action in actions" :key="action.text">
<component :is="action.render()" v-if="action.render" />
<NButton
@@ -78,10 +78,52 @@
</NAlert>
</div>
</BBAlert>
+
+ <BBAlert
+ v-model:show="state.showDeleteConfirm"
+ type="error"
+ :title="$t('project.batch.delete.title', { count: projectList.length })"
+ :description="$t('project.batch.delete.description')"
+ :ok-text="$t('common.delete')"
+ @ok="handleBatchDelete"
+ @cancel="state.showDeleteConfirm = false"
+ >
+ <!-- Project List -->
+ <div class="flex flex-col gap-y-3">
+ <div class="max-h-40 overflow-y-auto border rounded-sm p-2 bg-gray-50">
+ <div class="text-xs font-medium text-gray-600 mb-2">
+ {{ $t("project.batch.projects-to-delete") }}:
+ </div>
+ <div class="flex flex-col gap-y-1">
+ <div
+ v-for="project in projectList"
+ :key="project.name"
+ class="text-sm flex items-center gap-x-2"
+ >
+ <CheckIcon class="w-3 h-3 text-red-600" />
+ <span>{{ project.title }}</span>
+ <span class="text-gray-500"
+ >({{ extractProjectResourceName(project.name) }})</span
+ >
+ </div>
+ </div>
+ </div>
+
+ <!-- Warning about permanent deletion -->
+ <NAlert type="error" size="small">
+ <template #header>
+ {{ $t("common.cannot-undo-this-action") }}
+ </template>
+ <div class="text-sm">
+ {{ $t("project.batch.delete.warning") }}
+ </div>
+ </NAlert>
+ </div>
+ </BBAlert>
</template>
<script setup lang="tsx">
-import { ArchiveIcon, CheckIcon } from "lucide-vue-next";
+import { ArchiveIcon, CheckIcon, Trash2Icon } from "lucide-vue-next";
import { NAlert, NButton } from "naive-ui";
import type { VNode } from "vue";
import { computed, h, reactive } from "vue";
@@ -102,6 +144,7 @@ interface Action {
interface LocalState {
loading: boolean;
showArchiveConfirm: boolean;
+ showDeleteConfirm: boolean;
}
const props = defineProps<{
@@ -117,6 +160,7 @@ const projectStore = useProjectV1Store();
const state = reactive<LocalState>({
loading: false,
showArchiveConfirm: false,
+ showDeleteConfirm: false,
});
// For now, we'll assume no projects have resources - this would need to be enhanced
@@ -136,11 +180,14 @@ const actions = computed((): Action[] => {
disabled: props.projectList.length === 0,
click: () => (state.showArchiveConfirm = true),
});
+ list.push({
+ icon: h(Trash2Icon),
+ text: t("common.delete"),
+ disabled: props.projectList.length === 0,
+ click: () => (state.showDeleteConfirm = true),
+ });
}
- // Add more batch operations here in the future
- // For example: batch update settings, batch export, etc.
-
return list;
});
@@ -175,4 +222,34 @@ const handleBatchArchive = async () => {
state.loading = false;
}
};
+
+const handleBatchDelete = async () => {
+ try {
+ state.loading = true;
+
+ // Use the batch purge API
+ await projectStore.batchPurgeProjects(props.projectList.map((p) => p.name));
+
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("project.batch.delete.success", {
+ count: props.projectList.length,
+ }),
+ });
+
+ state.showDeleteConfirm = false;
+ emit("update");
+ } catch (error: unknown) {
+ const err = error as { message?: string };
+ pushNotification({
+ module: "bytebase",
+ style: "CRITICAL",
+ title: t("project.batch.delete.error"),
+ description: err.message,
+ });
+ } finally {
+ state.loading = false;
+ }
+};
</script>
diff --git a/frontend/src/components/v2/Model/ProjectV1Table.vue b/frontend/src/components/v2/Model/ProjectV1Table.vue
index 5c711d6575..e8183b258b 100644
--- a/frontend/src/components/v2/Model/ProjectV1Table.vue
+++ b/frontend/src/components/v2/Model/ProjectV1Table.vue
@@ -27,6 +27,7 @@ import {
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
+import ProjectActionDropdown from "@/components/Project/ProjectActionDropdown.vue";
import { LabelsCell, ProjectNameCell } from "@/components/v2/Model/cells";
import { PROJECT_V1_ROUTE_DETAIL } from "@/router/dashboard/projectV1";
import { PROJECT_V1_ROUTE_DASHBOARD } from "@/router/dashboard/workspaceRoutes";
@@ -55,6 +56,8 @@ const props = withDefaults(
showSelection?: boolean;
// Whether to show labels column (hidden in dropdowns for cleaner UI)
showLabels?: boolean;
+ // Whether to show actions dropdown
+ showActions?: boolean;
sorters?: DataTableSortState[];
}>(),
{
@@ -64,6 +67,7 @@ const props = withDefaults(
selectedProjectNames: () => [],
showSelection: false,
showLabels: true,
+ showActions: false,
}
);
@@ -156,6 +160,22 @@ const columnList = computed((): ProjectDataTableColumn[] => {
<LabelsCell labels={project.labels} showCount={3} placeholder="-" />
),
},
+ {
+ key: "actions",
+ title: "",
+ width: 50,
+ hide: !props.showActions,
+ render: (project) => (
+ <div
+ class="flex justify-end"
+ onClick={(e: MouseEvent) => {
+ e.stopPropagation();
+ }}
+ >
+ <ProjectActionDropdown project={project} />
+ </div>
+ ),
+ },
] as ProjectDataTableColumn[]
).filter((column) => !column.hide);
return mapSorterStatus(columns, props.sorters);
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index d5ef83d2f3..8b89b67e1b 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1363,10 +1363,8 @@
"successfully-restored-instance": "Successfully restored the instance '{0}'.",
"successfully-archived-instance": "Successfully archived the instance '{0}'.",
"successfully-synced-schema-for-instance-instance-value-name": "Successfully synced schema for instance '{0}'.",
- "archive-this-instance": "Archive this instance",
"archive-instance-instance-name": "Archive instance '{0}'?",
"archived-instances-will-not-be-displayed": "Archived instances will not be displayed.",
- "restore-this-instance": "Restore this instance",
"restore": "Restore",
"restore-instance-instance-name-to-normal-state": "Restore instance '{0}' to normal state?",
"account-locator": "Account Locator",
@@ -1971,7 +1969,15 @@
"success": "Successfully archived {count} project | Successfully archived {count} projects",
"error": "Failed to archive projects"
},
+ "delete": {
+ "title": "Delete {count} Project? | Delete {count} Projects?",
+ "description": "This will permanently delete the selected projects and move all databases to the default project.",
+ "warning": "This action cannot be undone. All project data including issues, configurations, and history will be permanently removed.",
+ "success": "Successfully deleted {count} project | Successfully deleted {count} projects",
+ "error": "Failed to delete projects"
+ },
"projects-to-archive": "Projects to archive",
+ "projects-to-delete": "Projects to delete",
"resource-warning": {
"title": "Projects with Resources",
"description": "The following projects contain databases or open issues:"
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index d94c591d0f..b5c0b196af 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -1363,10 +1363,8 @@
"successfully-restored-instance": "Se restauró exitosamente la instancia '{0}'.",
"successfully-archived-instance": "Se archivó exitosamente la instancia '{0}'.",
"successfully-synced-schema-for-instance-instance-value-name": "Esquema sincronizado con éxito para la instancia '{0}'.",
- "archive-this-instance": "Archivar esta instancia",
"archive-instance-instance-name": "¿Archivar la instancia '{0}'?",
"archived-instances-will-not-be-displayed": "Las instancias archivadas no se mostrarán.",
- "restore-this-instance": "Restaurar esta instancia",
"restore": "Restaurar",
"restore-instance-instance-name-to-normal-state": "¿Restaurar la instancia '{0}' al estado normal?",
"account-locator": "Localizadora de cuentas",
@@ -1971,7 +1969,15 @@
"success": "Proyecto {count} archivado correctamente | Proyectos {count} archivados correctamente",
"error": "No se pudieron archivar los proyectos"
},
+ "delete": {
+ "title": "¿Eliminar {count} Proyecto? | ¿Eliminar {count} Proyectos?",
+ "description": "Esto eliminará permanentemente los proyectos seleccionados y moverá todas las bases de datos al proyecto predeterminado.",
+ "warning": "Esta acción no se puede deshacer. Todos los datos del proyecto, incluidos problemas, configuraciones e historial, se eliminarán permanentemente.",
+ "success": "Proyecto {count} eliminado correctamente | Proyectos {count} eliminados correctamente",
+ "error": "No se pudieron eliminar los proyectos"
+ },
"projects-to-archive": "Proyectos para archivar",
+ "projects-to-delete": "Proyectos para eliminar",
"resource-warning": {
"title": "Proyectos con recursos",
"description": "Los siguientes proyectos contienen bases de datos o problemas abiertos:"
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 0bc406c8fa..af54da6168 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -1363,10 +1363,8 @@
"successfully-restored-instance": "インスタンス '{0}' を正常に復元しました。",
"successfully-archived-instance": "インスタンス '{0}' を正常にアーカイブしました。",
"successfully-synced-schema-for-instance-instance-value-name": "インスタンス '{0}' のスキーマが正常に同期されました。",
- "archive-this-instance": "このインスタンスをアーカイブする",
"archive-instance-instance-name": "インスタンス '{0}' をアーカイブしますか?",
"archived-instances-will-not-be-displayed": "アーカイブされたインスタンスは表示されなくなります。",
- "restore-this-instance": "インスタンスを復元する",
"restore": "復元する",
"restore-instance-instance-name-to-normal-state": "インスタンス '{0}' を通常の状態に復元しますか?",
"account-locator": "アカウントロケーター",
@@ -1971,7 +1969,15 @@
"success": "{count} 件のプロジェクトを正常にアーカイブしました | {count} 件のプロジェクトを正常にアーカイブしました",
"error": "プロジェクトをアーカイブできませんでした"
},
+ "delete": {
+ "title": "{count} 件のプロジェクトを削除しますか? | {count} 件のプロジェクトを削除しますか?",
+ "description": "選択したプロジェクトを完全に削除し、すべてのデータベースをデフォルトプロジェクトに移動します。",
+ "warning": "この操作は元に戻せません。問題、設定、履歴を含むすべてのプロジェクトデータが完全に削除されます。",
+ "success": "{count} 件のプロジェクトを正常に削除しました | {count} 件のプロジェクトを正常に削除しました",
+ "error": "プロジェクトを削除できませんでした"
+ },
"projects-to-archive": "アーカイブするプロジェクト",
+ "projects-to-delete": "削除するプロジェクト",
"resource-warning": {
"title": "リソースのあるプロジェクト",
"description": "次のプロジェクトには、データベースまたは未解決の問題が含まれています。"
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 6ce7751fd2..6ded7bb34f 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -1363,10 +1363,8 @@
"successfully-restored-instance": "Đã khôi phục thành công trường hợp '{0}'.",
"successfully-archived-instance": "Đã lưu trữ thành công phiên bản '{0}'.",
"successfully-synced-schema-for-instance-instance-value-name": "Đã đồng bộ hóa thành công lược đồ cho phiên bản '{0}'.",
- "archive-this-instance": "Lưu trữ phiên bản này",
"archive-instance-instance-name": "Lưu trữ phiên bản '{0}'?",
"archived-instances-will-not-be-displayed": "Các phiên bản đã lưu trữ sẽ không được hiển thị.",
- "restore-this-instance": "Khôi phục phiên bản này",
"restore": "Khôi phục",
"restore-instance-instance-name-to-normal-state": "Khôi phục phiên bản '{0}' về trạng thái bình thường?",
"account-locator": "Định vị tài khoản",
@@ -1971,7 +1969,15 @@
"success": "Đã lưu trữ thành công {count} dự án | Đã lưu trữ thành công {count} dự án",
"error": "Không lưu trữ được dự án"
},
+ "delete": {
+ "title": "Xóa {count} Dự án? | Xóa {count} Dự án?",
+ "description": "Thao tác này sẽ xóa vĩnh viễn các dự án đã chọn và chuyển tất cả cơ sở dữ liệu sang dự án mặc định.",
+ "warning": "Hành động này không thể hoàn tác. Tất cả dữ liệu dự án bao gồm vấn đề, cấu hình và lịch sử sẽ bị xóa vĩnh viễn.",
+ "success": "Đã xóa thành công {count} dự án | Đã xóa thành công {count} dự án",
+ "error": "Không xóa được dự án"
+ },
"projects-to-archive": "Dự án để lưu trữ",
+ "projects-to-delete": "Dự án để xóa",
"resource-warning": {
"title": "Dự án có nguồn lực",
"description": "Các dự án sau đây chứa cơ sở dữ liệu hoặc các vấn đề chưa giải quyết:"
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 00e6bac056..31e6e1647b 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1363,10 +1363,8 @@
"successfully-restored-instance": "已成功恢复实例“{0}”。",
"successfully-archived-instance": "成功归档实例'{0}'。",
"successfully-synced-schema-for-instance-instance-value-name": "成功为实例'{0}'同步 schema 。",
- "archive-this-instance": "归档该实例",
"archive-instance-instance-name": "归档实例'{0}'?",
"archived-instances-will-not-be-displayed": "不再会显示已归档实例。",
- "restore-this-instance": "恢复该实例",
"restore": "恢复",
"restore-instance-instance-name-to-normal-state": "恢复实例'{0}'到正常状态?",
"account-locator": "账户定位符",
@@ -1971,7 +1969,15 @@
"success": "成功归档 {count} 个项目 | 成功归档 {count} 个项目",
"error": "无法存档项目"
},
+ "delete": {
+ "title": "删除 {count} 个项目?| 删除 {count} 个项目?",
+ "description": "这将永久删除所选项目,并将所有数据库移动到默认项目。",
+ "warning": "此操作无法撤消。包括问题、配置和历史记录在内的所有项目数据将被永久删除。",
+ "success": "成功删除 {count} 个项目 | 成功删除 {count} 个项目",
+ "error": "无法删除项目"
+ },
"projects-to-archive": "要存档的项目",
+ "projects-to-delete": "要删除的项目",
"resource-warning": {
"title": "项目与资源",
"description": "以下项目包含数据库或未解决的问题:"
diff --git a/frontend/src/store/modules/v1/project.ts b/frontend/src/store/modules/v1/project.ts
index 0e9478056b..f46d1a00b7 100644
--- a/frontend/src/store/modules/v1/project.ts
+++ b/frontend/src/store/modules/v1/project.ts
@@ -297,6 +297,17 @@ export const useProjectV1Store = defineStore("project_v1", () => {
upsertProjectsCache(projects);
};
+ const batchPurgeProjects = async (projectNames: string[]) => {
+ const request = create(BatchDeleteProjectsRequestSchema, {
+ names: projectNames,
+ purge: true,
+ });
+ await projectServiceClientConnect.batchDeleteProjects(request);
+ // Remove from local cache
+ for (const name of projectNames) {
+ projectMapByName.delete(name);
+ }
+ };
const restoreProject = async (project: Project) => {
const request = create(UndeleteProjectRequestSchema, {
name: project.name,
@@ -315,6 +326,7 @@ export const useProjectV1Store = defineStore("project_v1", () => {
archiveProject,
deleteProject,
batchDeleteProjects,
+ batchPurgeProjects,
restoreProject,
updateProjectCache,
fetchProjectList,
diff --git a/frontend/src/views/InstanceDashboard.vue b/frontend/src/views/InstanceDashboard.vue
index 3fb0f87ed8..0a001369df 100644
--- a/frontend/src/views/InstanceDashboard.vue
+++ b/frontend/src/views/InstanceDashboard.vue
@@ -42,6 +42,8 @@
:footer-class="'mx-4'"
:on-click="onRowClick"
:selected-instance-names="Array.from(state.selectedInstance)"
+ :show-external-link="false"
+ :show-actions="true"
@update:selected-instance-names="
(list: string[]) => (state.selectedInstance = new Set(list))
"
diff --git a/frontend/src/views/InstanceDetail.vue b/frontend/src/views/InstanceDetail.vue
index 34a8860b20..d53a76d1ed 100644
--- a/frontend/src/views/InstanceDetail.vue
+++ b/frontend/src/views/InstanceDetail.vue
@@ -14,55 +14,34 @@
<EngineIcon :engine="instance.engine" custom-class="h-6!" />
<span class="text-lg font-medium">{{ instanceV1Name(instance) }}</span>
</div>
+ <div class="flex items-center gap-x-2">
+ <InstanceSyncButton
+ v-if="instance.state === State.ACTIVE"
+ @sync-schema="syncSchema"
+ />
+ <InstanceActionDropdown :instance="instance" />
+ </div>
</div>
<NTabs :value="state.selectedTab" @update:value="onTabChange">
- <template #suffix>
- <div v-if="instance.state === State.ACTIVE" class="flex items-center gap-x-2">
- <InstanceSyncButton
- @sync-schema="syncSchema"
- />
- <PermissionGuardWrapper
- v-if="allowCreateDatabase"
- v-slot="slotProps"
- :permissions="[
- ...PERMISSIONS_FOR_DATABASE_CREATE_ISSUE,
- ]"
- >
- <NButton
- type="primary"
- :disabled="slotProps.disabled"
- @click.prevent="createDatabase"
- >
- <template #icon>
- <PlusIcon class="h-4 w-4" />
- </template>
- {{ $t("instance.new-database") }}
- </NButton>
- </PermissionGuardWrapper>
- </div>
- </template>
<NTabPane name="overview" :tab="$t('common.overview')">
<InstanceForm ref="instanceFormRef" class="-mt-2" :instance="instance">
- <InstanceFormBody :hide-archive-restore="hideArchiveRestore" />
+ <InstanceFormBody />
<InstanceFormButtons class="sticky bottom-0 z-10" />
</InstanceForm>
</NTabPane>
<NTabPane name="databases" :tab="$t('common.databases')">
<div class="flex flex-col gap-y-2">
- <div
- class="w-full flex flex-col sm:flex-row items-start sm:items-end justify-between gap-2"
- >
- <AdvancedSearch
- v-model:params="state.params"
- class="flex-1"
- :autofocus="false"
- :placeholder="$t('database.filter-database')"
- :scope-options="scopeOptions"
- />
- </div>
+ <AdvancedSearch
+ v-model:params="state.params"
+ :autofocus="false"
+ :placeholder="$t('database.filter-database')"
+ :scope-options="scopeOptions"
+ />
<DatabaseOperations
:databases="selectedDatabases"
+ :instance-name="instance.name"
+ :on-create-database="allowCreateDatabase && instance.state === State.ACTIVE ? createDatabase : undefined"
@refresh="() => pagedDatabaseTableRef?.refresh()"
@update="
(databases) => pagedDatabaseTableRef?.updateCache(databases)
@@ -100,8 +79,7 @@
<script lang="tsx" setup>
import { useTitle } from "@vueuse/core";
import { cloneDeep } from "lodash-es";
-import { PlusIcon } from "lucide-vue-next";
-import { NButton, NTabPane, NTabs } from "naive-ui";
+import { NTabPane, NTabs } from "naive-ui";
import { computed, reactive, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
import { useRoute, useRouter } from "vue-router";
@@ -111,13 +89,13 @@ import { useCommonSearchScopeOptions } from "@/components/AdvancedSearch/useComm
import ArchiveBanner from "@/components/ArchiveBanner.vue";
import { CreateDatabasePrepPanel } from "@/components/CreateDatabasePrepForm";
import { EngineIcon } from "@/components/Icon";
+import InstanceActionDropdown from "@/components/Instance/InstanceActionDropdown.vue";
import InstanceSyncButton from "@/components/Instance/InstanceSyncButton.vue";
import {
InstanceForm,
Form as InstanceFormBody,
Buttons as InstanceFormButtons,
} from "@/components/InstanceForm/";
-import PermissionGuardWrapper from "@/components/Permission/PermissionGuardWrapper.vue";
import { Drawer, InstanceRoleTable } from "@/components/v2";
import {
DatabaseOperations,
@@ -149,7 +127,6 @@ import {
getValuesFromSearchParams,
instanceV1HasCreateDatabase,
instanceV1Name,
- PERMISSIONS_FOR_DATABASE_CREATE_ISSUE,
} from "@/utils";
const instanceHashList = ["overview", "databases", "users"] as const;
@@ -167,7 +144,6 @@ interface LocalState {
const props = defineProps<{
instanceId: string;
- hideArchiveRestore?: boolean;
}>();
defineOptions({
diff --git a/frontend/src/views/ProjectDashboard.vue b/frontend/src/views/ProjectDashboard.vue
index 405deab295..250bdb7d57 100644
--- a/frontend/src/views/ProjectDashboard.vue
+++ b/frontend/src/views/ProjectDashboard.vue
@@ -37,6 +37,7 @@
:footer-class="'mx-4'"
:prevent-default="!!onRowClick"
:show-selection="true"
+ :show-actions="true"
:selected-project-names="selectedProjectNames"
@update:selected-project-names="updateSelectedProjects"
@row-click="onRowClick"