Skip to content

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

chore: unify resource occupied alert (#15724)

ecmadaod73ef9400cae
diff --git a/frontend/src/bbkit/BBDialog.vue b/frontend/src/bbkit/BBDialog.vue
index 2f73966d8d..9ab701129f 100644
--- a/frontend/src/bbkit/BBDialog.vue
+++ b/frontend/src/bbkit/BBDialog.vue
@@ -1,6 +1,6 @@
<template>
<BBModal
- v-if="state.visible"
+ :show="state.visible"
:title="title"
:subtitle="subtitle"
:show-close="closable"
@@ -10,11 +10,17 @@
<slot name="default"></slot>
<div class="pt-4 border-t border-block-border flex justify-end space-x-3">
- <NButton v-if="showNegativeBtn" @click.prevent="onNegativeClick">
+ <NButton
+ v-if="showNegativeBtn"
+ size="small"
+ @click.prevent="onNegativeClick"
+ >
{{ negativeText || $t("common.cancel") }}
</NButton>
<NButton
- type="primary"
+ v-if="showPositiveBtn"
+ :type="type"
+ size="small"
data-label="bb-modal-confirm-button"
@click.prevent="onPositiveClick"
>
@@ -26,46 +32,33 @@
<script lang="ts" setup>
import { NButton } from "naive-ui";
-import type { PropType } from "vue";
import { reactive } from "vue";
import type { Defer } from "@/utils";
import { defer } from "@/utils";
import BBModal from "./BBModal.vue";
-const props = defineProps({
- title: {
- type: String,
- required: true,
- },
- subtitle: {
- type: String,
- default: "",
- },
- closable: {
- type: Boolean,
- default: false,
- },
- showNegativeBtn: {
- type: Boolean,
- default: true,
- },
- negativeText: {
- type: String,
- default: undefined,
- },
- positiveText: {
- type: String,
- default: undefined,
- },
- onBeforePositiveClick: {
- type: Function as PropType<() => boolean>,
- default: undefined,
- },
- onBeforeNegativeClick: {
- type: Function as PropType<() => boolean>,
- default: undefined,
- },
-});
+withDefaults(
+ defineProps<{
+ title: string;
+ subtitle?: string;
+ closable?: boolean;
+ showNegativeBtn?: boolean;
+ showPositiveBtn?: boolean;
+ negativeText?: string;
+ positiveText?: string;
+ type: "info" | "warning";
+ }>(),
+ {
+ showNegativeBtn: true,
+ showPositiveBtn: true,
+ type: "info",
+ }
+);
+
+const emit = defineEmits<{
+ (event: "on-positive-click"): void;
+ (event: "on-negative-click"): void;
+}>();
const state = reactive({
visible: false,
@@ -84,25 +77,17 @@ const open = () => {
};
const onPositiveClick = () => {
- if (props.onBeforePositiveClick) {
- if (!props.onBeforePositiveClick()) {
- return;
- }
- }
-
state.visible = false;
state.defer?.resolve(true);
+
+ emit("on-positive-click");
};
const onNegativeClick = () => {
- if (props.onBeforeNegativeClick) {
- if (!props.onBeforeNegativeClick()) {
- return;
- }
- }
-
state.visible = false;
state.defer?.resolve(false);
+
+ emit("on-negative-click");
};
defineExpose({ open });
diff --git a/frontend/src/components/Role/Setting/components/RoleDataTable/cells/RoleOperationsCell.vue b/frontend/src/components/Role/Setting/components/RoleDataTable/cells/RoleOperationsCell.vue
index dd27f5617a..5ed8f1476e 100644
--- a/frontend/src/components/Role/Setting/components/RoleDataTable/cells/RoleOperationsCell.vue
+++ b/frontend/src/components/Role/Setting/components/RoleDataTable/cells/RoleOperationsCell.vue
@@ -4,21 +4,25 @@
{{ $t("common.edit") }}
</NButton>
- <NButton
- v-if="allowDelete"
- size="tiny"
- @click="() => handleDeleteRole(usersWithRole)"
- >
+ <NButton v-if="allowDelete" size="tiny" @click="handleDeleteRole">
{{ $t("common.delete") }}
</NButton>
</div>
+ <ResourceOccupiedModal
+ ref="resourceOccupiedModalRef"
+ :target="role.name"
+ :resources="resourceOccupied"
+ @on-submit="onRoleRemove"
+ @on-close="resetState"
+ />
</template>
<script lang="tsx" setup>
-import { NButton, useDialog } from "naive-ui";
+import { NButton } from "naive-ui";
import { Status } from "nice-grpc-web";
-import { computed } from "vue";
+import { computed, ref } from "vue";
import { useI18n } from "vue-i18n";
+import ResourceOccupiedModal from "@/components/v2/ResourceOccupiedModal/ResourceOccupiedModal.vue";
import { useRoleStore, useWorkspaceV1Store, pushNotification } from "@/store";
import type { Role } from "@/types/proto/v1/role_service";
import { hasWorkspacePermissionV2, isCustomRole } from "@/utils";
@@ -36,8 +40,9 @@ defineEmits<{
const { hasCustomRoleFeature, showFeatureModal } =
useCustomRoleSettingContext();
const workspaceStore = useWorkspaceV1Store();
-const $dialog = useDialog();
const { t } = useI18n();
+const resourceOccupiedModalRef =
+ ref<InstanceType<typeof ResourceOccupiedModal>>();
const allowUpdate = computed(() => hasWorkspacePermissionV2("bb.roles.update"));
const allowDelete = computed(() => hasWorkspacePermissionV2("bb.roles.delete"));
@@ -48,43 +53,19 @@ const usersWithRole = computed(() => {
];
});
-const handleDeleteRole = (resources: string[]) => {
+const resourceOccupied = ref<string[]>([...usersWithRole.value]);
+
+const resetState = () => {
+ resourceOccupied.value = [...usersWithRole.value];
+};
+
+const handleDeleteRole = () => {
if (!hasCustomRoleFeature.value) {
showFeatureModal.value = true;
return;
}
- $dialog.warning({
- title: t("common.warning"),
- style: "z-index: 100000",
- negativeText: t("common.cancel"),
- positiveText: resources.length === 0 ? t("common.continue-anyway") : "",
- content: () => {
- if (resources.length === 0) {
- return t("role.setting.delete-warning", {
- name: props.role.title,
- });
- }
- return (
- <div class="space-y-2">
- <p>
- {t("role.setting.delete-warning-with-resources", {
- name: props.role.title,
- })}
- </p>
- <ul class="list-disc ml-4 textinfolabel">
- {resources.map((resource) => (
- <li>{resource}</li>
- ))}
- </ul>
- <p>{t("role.setting.delete-warning-retry")}</p>
- </div>
- );
- },
- onPositiveClick: () => {
- onRoleRemove();
- },
- });
+ resourceOccupiedModalRef.value?.open();
};
const onRoleRemove = async () => {
@@ -97,13 +78,12 @@ const onRoleRemove = async () => {
});
} catch (error) {
if (getErrorCode(error) === Status.FAILED_PRECONDITION) {
- console.log("extractGrpcErrorMessage");
- console.log(extractGrpcErrorMessage(error));
const message = extractGrpcErrorMessage(error);
const resources =
message.split("used by resources: ")[1]?.split(",") ?? [];
if (resources.length > 0) {
- handleDeleteRole(resources);
+ resourceOccupied.value = [...resources];
+ handleDeleteRole();
}
}
}
diff --git a/frontend/src/components/SQLReview/SQLReviewInfo.vue b/frontend/src/components/SQLReview/SQLReviewInfo.vue
index 4eea580413..cbf418e3f8 100644
--- a/frontend/src/components/SQLReview/SQLReviewInfo.vue
+++ b/frontend/src/components/SQLReview/SQLReviewInfo.vue
@@ -9,7 +9,7 @@
{{ $t("sql-review.attach-resource.label") }}
</p>
<NRadioGroup
- v-model:value="attachResourceType"
+ v-model:value="resourceType"
:disabled="!allowChangeAttachedResource"
class="space-x-2 mt-2"
>
@@ -17,10 +17,10 @@
<NRadio value="project">{{ $t("common.project") }}</NRadio>
</NRadioGroup>
<BBAttention type="info" class="my-2">
- {{ $t(`sql-review.attach-resource.label-${attachResourceType}`) }}
+ {{ $t(`sql-review.attach-resource.label-${resourceType}`) }}
</BBAttention>
<EnvironmentSelect
- v-if="attachResourceType === 'environment'"
+ v-if="resourceType === 'environment'"
class="mt-2"
required
name="environment"
@@ -38,7 +38,7 @@
"
/>
<ProjectSelect
- v-if="attachResourceType === 'project'"
+ v-if="resourceType === 'project'"
class="mt-2"
style="width: 100%"
required
@@ -56,12 +56,11 @@
"
/>
<DatabaseSelect
- v-if="attachResourceType === 'database'"
+ v-if="resourceType === 'database'"
class="mt-2"
style="width: 100%"
required
- :multiple="true"
- :database-names="attachedResources"
+ :database-name="attachedResources[0]"
:disabled="!allowChangeAttachedResource"
:filter="(db: Database, _: number) => filterResource(db.name)"
@update:database-names="$emit('attached-resources-change', $event)"
@@ -109,24 +108,23 @@
<script lang="ts" setup>
import { NRadio, NRadioGroup } from "naive-ui";
import { Status } from "nice-grpc-common";
-import { ref, watch } from "vue";
+import { ref, watch, computed } from "vue";
import { useI18n } from "vue-i18n";
import { BBAttention, BBTextField } from "@/bbkit";
import ResourceIdField from "@/components/v2/Form/ResourceIdField.vue";
+import { useResourceByName } from "@/components/v2/ResourceOccupiedModal/useResourceByName";
import { useSQLReviewStore } from "@/store";
-import {
- reviewConfigNamePrefix,
- projectNamePrefix,
- isDatabaseName,
-} from "@/store/modules/v1/common";
-import type { SQLReviewPolicyTemplateV2 } from "@/types";
-import type { ResourceId, ValidatedMessage } from "@/types";
+import { reviewConfigNamePrefix } from "@/store/modules/v1/common";
+import type {
+ SQLReviewPolicyTemplateV2,
+ ResourceId,
+ ValidatedMessage,
+} from "@/types";
import type { Database } from "@/types/proto/v1/database_service";
import type { Environment } from "@/types/proto/v1/environment_service";
import { getErrorCode } from "@/utils/grpcweb";
import { DatabaseSelect, EnvironmentSelect, ProjectSelect } from "../v2";
import { SQLReviewTemplateSelector } from "./components";
-import { type ResourceType } from "./components/useReviewConfigAttachedResource";
const props = defineProps<{
name: string;
@@ -146,29 +144,13 @@ const emit = defineEmits<{
}>();
const sqlReviewStore = useSQLReviewStore();
-
-const attachResourceType = ref<ResourceType>(
- (function (): ResourceType {
- if (props.attachedResources.length === 0) {
- return "environment";
- }
- if (props.attachedResources.every((resource) => isDatabaseName(resource))) {
- return "database";
- }
- if (
- props.attachedResources.every((resource) =>
- resource.startsWith(projectNamePrefix)
- )
- ) {
- return "project";
- }
- return "environment";
- })()
-);
+const { resourceType } = useResourceByName({
+ resource: computed(() => props.attachedResources[0]),
+});
const { t } = useI18n();
watch(
- () => attachResourceType.value,
+ () => resourceType.value,
() => emit("attached-resources-change", [])
);
diff --git a/frontend/src/components/SQLReview/components/SQLReviewAttachResourcesPanel.vue b/frontend/src/components/SQLReview/components/SQLReviewAttachResourcesPanel.vue
index 4e65fd1961..ae0ad330bf 100644
--- a/frontend/src/components/SQLReview/components/SQLReviewAttachResourcesPanel.vue
+++ b/frontend/src/components/SQLReview/components/SQLReviewAttachResourcesPanel.vue
@@ -77,6 +77,7 @@ import {
EnvironmentSelect,
ProjectSelect,
} from "@/components/v2";
+import Resource from "@/components/v2/ResourceOccupiedModal/Resource.vue";
import { useSQLReviewStore, pushNotification } from "@/store";
import {
environmentNamePrefix,
@@ -84,7 +85,6 @@ import {
} from "@/store/modules/v1/common";
import type { SQLReviewPolicy } from "@/types";
import { hasWorkspacePermissionV2 } from "@/utils";
-import SQLReviewAttachedResource from "./SQLReviewAttachedResource.vue";
const props = defineProps<{
show: boolean;
@@ -147,6 +147,7 @@ const onConfirm = async () => {
if (resourcesBindingWithOtherPolicy.value.size === 0) {
await upsertReviewResource();
} else {
+ // TODO(ed): use ResourceOccupiedModal
$dialog.warning({
title: t("common.warning"),
style: "z-index: 100000",
@@ -169,7 +170,7 @@ const onConfirm = async () => {
<ul class="list-disc ml-4 textinfolabel">
{resources.map((resource) => (
<li>
- <SQLReviewAttachedResource
+ <Resource
resource={resource}
link={false}
showPrefix={true}
diff --git a/frontend/src/components/SQLReview/components/SQLReviewAttachedResource.vue b/frontend/src/components/SQLReview/components/SQLReviewAttachedResource.vue
deleted file mode 100644
index a95281de82..0000000000
--- a/frontend/src/components/SQLReview/components/SQLReviewAttachedResource.vue
+++ /dev/null
@@ -1,78 +0,0 @@
-<template>
- <div class="flex items-center space-x-1">
- <span v-if="showPrefix && resourcePrefix">{{ `${resourcePrefix}: ` }}</span>
- <component :is="reviewPolicyResourceComponent" />
- </div>
-</template>
-
-<script setup lang="tsx">
-import { computedAsync } from "@vueuse/core";
-import { computed } from "vue";
-import { EnvironmentV1Name, RichDatabaseName } from "@/components/v2";
-import { ProjectNameCell } from "@/components/v2/Model/DatabaseV1Table/cells";
-import {
- useEnvironmentV1Store,
- useDatabaseV1Store,
- useProjectV1Store,
-} from "@/store";
-import {
- isValidEnvironmentName,
- isValidProjectName,
- isValidDatabaseName,
-} from "@/types";
-import { useReviewConfigAttachedResource } from "./useReviewConfigAttachedResource";
-
-const props = defineProps<{
- resource: string;
- link?: boolean;
- showPrefix?: boolean;
-}>();
-
-const environmentV1Store = useEnvironmentV1Store();
-const databaseStore = useDatabaseV1Store();
-const projectStore = useProjectV1Store();
-
-const { resourceType, resourcePrefix } = useReviewConfigAttachedResource(
- computed(() => props.resource)
-);
-
-const reviewPolicyResourceComponent = computedAsync(async () => {
- switch (resourceType.value) {
- case "environment": {
- const environment = environmentV1Store.getEnvironmentByName(
- props.resource
- );
- if (!isValidEnvironmentName(environment.name)) {
- return <div>{props.resource}</div>;
- }
- return <EnvironmentV1Name environment={environment} link={props.link} />;
- }
- case "database": {
- const database = databaseStore.getDatabaseByName(props.resource);
- if (!isValidDatabaseName(database.name)) {
- return <div>{props.resource}</div>;
- }
- return (
- <RichDatabaseName
- database={database}
- showArrow={false}
- showInstance={false}
- />
- );
- }
- case "project": {
- const project = await projectStore.getOrFetchProjectByName(
- props.resource,
- true /* silent */
- );
- if (!isValidProjectName(project.name)) {
- return <div>{props.resource}</div>;
- }
- return (
- <ProjectNameCell mode="ALL_SHORT" project={project} link={props.link} />
- );
- }
- }
- return null;
-});
-</script>
diff --git a/frontend/src/components/SQLReview/components/SQLReviewPolicyDataTable.vue b/frontend/src/components/SQLReview/components/SQLReviewPolicyDataTable.vue
index 7cf773c77b..e32a54a09e 100644
--- a/frontend/src/components/SQLReview/components/SQLReviewPolicyDataTable.vue
+++ b/frontend/src/components/SQLReview/components/SQLReviewPolicyDataTable.vue
@@ -17,12 +17,12 @@ import type { DataTableColumn } from "naive-ui";
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { BBButtonConfirm } from "@/bbkit";
+import Resource from "@/components/v2/ResourceOccupiedModal/Resource.vue";
import { pushNotification, useSQLReviewStore } from "@/store";
import type { SQLReviewPolicy } from "@/types";
import { SQLReviewRuleLevel } from "@/types/proto/v1/org_policy_service";
import { hasWorkspacePermissionV2 } from "@/utils";
import { getHighlightHTMLByRegExp } from "@/utils";
-import SQLReviewAttachedResource from "./SQLReviewAttachedResource.vue";
const props = withDefaults(
defineProps<{
@@ -69,7 +69,7 @@ const columns = computed(
{review.resources.length === 0 && <span>-</span>}
{review.resources.map((resource) => {
return (
- <SQLReviewAttachedResource
+ <Resource
key={resource}
resource={resource}
showPrefix={true}
diff --git a/frontend/src/components/SQLReview/components/SQLReviewPolicyTable.vue b/frontend/src/components/SQLReview/components/SQLReviewPolicyTable.vue
index a8c16596ff..c8a07eba41 100644
--- a/frontend/src/components/SQLReview/components/SQLReviewPolicyTable.vue
+++ b/frontend/src/components/SQLReview/components/SQLReviewPolicyTable.vue
@@ -27,10 +27,7 @@
:key="resource"
:can-remove="false"
>
- <SQLReviewAttachedResource
- :show-prefix="true"
- :resource="resource"
- />
+ <Resource :show-prefix="true" :resource="resource" />
</BBBadge>
<BBBadge
v-if="!review.enforce"
@@ -70,11 +67,11 @@ import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import { BBBadge, BBButtonConfirm } from "@/bbkit";
+import Resource from "@/components/v2/ResourceOccupiedModal/Resource.vue";
import { WORKSPACE_ROUTE_SQL_REVIEW_DETAIL } from "@/router/dashboard/workspaceRoutes";
import { pushNotification, useSQLReviewStore } from "@/store";
import type { SQLReviewPolicy } from "@/types";
import { hasWorkspacePermissionV2, sqlReviewPolicySlug } from "@/utils";
-import SQLReviewAttachedResource from "./SQLReviewAttachedResource.vue";
import SQLReviewPolicyDataTable from "./SQLReviewPolicyDataTable.vue";
defineProps<{
diff --git a/frontend/src/components/SQLReview/components/SQLReviewTemplateSelector.vue b/frontend/src/components/SQLReview/components/SQLReviewTemplateSelector.vue
index f9436e9ebd..a9734ec22c 100644
--- a/frontend/src/components/SQLReview/components/SQLReviewTemplateSelector.vue
+++ b/frontend/src/components/SQLReview/components/SQLReviewTemplateSelector.vue
@@ -29,10 +29,7 @@
:key="resource"
:can-remove="false"
>
- <SQLReviewAttachedResource
- :resource="resource"
- :show-prefix="true"
- />
+ <Resource :resource="resource" :show-prefix="true" />
</BBBadge>
</div>
<p class="text-sm">
@@ -97,11 +94,11 @@
import { NDivider } from "naive-ui";
import { computed } from "vue";
import { BBBadge } from "@/bbkit";
+import Resource from "@/components/v2/ResourceOccupiedModal/Resource.vue";
import { useSQLReviewPolicyList } from "@/store";
import type { SQLReviewPolicyTemplateV2 } from "@/types";
import { TEMPLATE_LIST_V2 as builtInTemplateList } from "@/types";
import { SQLReviewRuleLevel } from "@/types/proto/v1/org_policy_service";
-import SQLReviewAttachedResource from "./SQLReviewAttachedResource.vue";
import { rulesToTemplate } from "./utils";
const props = withDefaults(
diff --git a/frontend/src/components/SQLReview/components/useReviewConfigAttachedResource.ts b/frontend/src/components/SQLReview/components/useReviewConfigAttachedResource.ts
deleted file mode 100644
index 83ef6e10d7..0000000000
--- a/frontend/src/components/SQLReview/components/useReviewConfigAttachedResource.ts
+++ /dev/null
@@ -1,71 +0,0 @@
-import { type Ref, watchEffect, computed } from "vue";
-import { t } from "@/plugins/i18n";
-import {
- useEnvironmentV1Store,
- useDatabaseV1Store,
- useProjectV1Store,
-} from "@/store";
-import {
- environmentNamePrefix,
- projectNamePrefix,
- isDatabaseName,
-} from "@/store/modules/v1/common";
-import { hasWorkspacePermissionV2 } from "@/utils";
-
-export type ResourceType = "environment" | "project" | "database";
-
-export const useReviewConfigAttachedResource = (resource: Ref<string>) => {
- const environmentV1Store = useEnvironmentV1Store();
- const databaseStore = useDatabaseV1Store();
- const projectStore = useProjectV1Store();
-
- const resourceType = computed((): ResourceType | undefined => {
- if (resource.value.startsWith(environmentNamePrefix)) {
- return "environment";
- } else if (isDatabaseName(resource.value)) {
- return "database";
- } else if (resource.value.startsWith(projectNamePrefix)) {
- return "project";
- }
- return undefined;
- });
-
- const resourcePrefix = computed(() => {
- switch (resourceType.value) {
- case "environment":
- return t("common.environment");
- case "project":
- return t("common.project");
- default:
- return "";
- }
- });
-
- watchEffect(async () => {
- switch (resourceType.value) {
- case "database":
- if (hasWorkspacePermissionV2("bb.databases.get")) {
- await databaseStore.getOrFetchDatabaseByName(resource.value);
- }
- return;
- case "environment":
- if (hasWorkspacePermissionV2("bb.environments.get")) {
- await environmentV1Store.getOrFetchEnvironmentByName(resource.value);
- }
- return;
- case "project":
- if (hasWorkspacePermissionV2("bb.projects.get")) {
- await projectStore.getOrFetchProjectByName(
- resource.value,
- true /* silent */
- );
- }
- return;
- }
- });
-
- return {
- resourceType,
- resourcePrefix,
- };
-};
diff --git a/frontend/src/components/User/Settings/RemoveGroupButton.vue b/frontend/src/components/User/Settings/RemoveGroupButton.vue
index fe7f21efe1..756561491f 100644
--- a/frontend/src/components/User/Settings/RemoveGroupButton.vue
+++ b/frontend/src/components/User/Settings/RemoveGroupButton.vue
@@ -146,6 +146,7 @@ const renderProjectResources = (
const handleDeleteGroup = async () => {
const resources = await getProjectsBindingGroup(props.group);
+ // TODO(ed): use ResourceOccupiedModal
const $dialog = dialog.create({
type: "warning",
title: t("common.warning"),
diff --git a/frontend/src/components/v2/ResourceOccupiedModal/Resource.vue b/frontend/src/components/v2/ResourceOccupiedModal/Resource.vue
new file mode 100644
index 0000000000..1721772754
--- /dev/null
+++ b/frontend/src/components/v2/ResourceOccupiedModal/Resource.vue
@@ -0,0 +1,22 @@
+<template>
+ <div class="flex items-center space-x-1">
+ <span v-if="showPrefix && resourcePrefix">{{ `${resourcePrefix}: ` }}</span>
+ <component :is="resourceComponent" />
+ </div>
+</template>
+
+<script lang="tsx" setup>
+import { computed } from "vue";
+import { useResourceByName } from "./useResourceByName.ts";
+
+const props = defineProps<{
+ resource: string;
+ link?: boolean;
+ showPrefix?: boolean;
+}>();
+
+const { resourcePrefix, resourceComponent } = useResourceByName({
+ resource: computed(() => props.resource),
+ link: props.link,
+});
+</script>
diff --git a/frontend/src/components/v2/ResourceOccupiedModal/ResourceOccupiedModal.vue b/frontend/src/components/v2/ResourceOccupiedModal/ResourceOccupiedModal.vue
new file mode 100644
index 0000000000..eddd37e46a
--- /dev/null
+++ b/frontend/src/components/v2/ResourceOccupiedModal/ResourceOccupiedModal.vue
@@ -0,0 +1,61 @@
+<template>
+ <BBDialog
+ ref="resourceOccupiedModalRef"
+ :title="$t('common.warning')"
+ :closable="true"
+ :show-positive-btn="resources.length === 0"
+ :positive-text="resources.length === 0 ? $t('common.continue-anyway') : ''"
+ :type="'warning'"
+ @on-positive-click="() => $emit('on-submit')"
+ @on-negative-click="() => $emit('on-close')"
+ >
+ <template #default>
+ <div
+ class="w-[30rem] max-w-full pt-2 pb-4 text-control break-words text-sm"
+ >
+ <div v-if="resources.length === 0">
+ {{ $t("resource.delete-warning", { name: target }) }}
+ </div>
+ <div v-else class="space-y-2">
+ <p>
+ {{
+ $t("resource.delete-warning-with-resources", {
+ name: target,
+ })
+ }}
+ </p>
+ <ul class="list-disc">
+ <Resource
+ v-for="(resource, i) in resources"
+ :key="i"
+ :show-prefix="true"
+ :link="true"
+ :resource="resource"
+ />
+ </ul>
+ <p>{{ $t("resource.delete-warning-retry") }}</p>
+ </div>
+ </div>
+ </template>
+ </BBDialog>
+</template>
+
+<script lang="tsx" setup>
+import { ref } from "vue";
+import { BBDialog } from "@/bbkit";
+import Resource from "./Resource.vue";
+
+defineProps<{
+ target: string;
+ resources: string[];
+}>();
+
+defineEmits<{
+ (event: "on-submit"): void;
+ (event: "on-close"): void;
+}>();
+
+const resourceOccupiedModalRef = ref<InstanceType<typeof BBDialog>>();
+
+defineExpose({ open: () => resourceOccupiedModalRef.value?.open() });
+</script>
diff --git a/frontend/src/components/v2/ResourceOccupiedModal/useResourceByName.ts b/frontend/src/components/v2/ResourceOccupiedModal/useResourceByName.ts
new file mode 100644
index 0000000000..26ada92380
--- /dev/null
+++ b/frontend/src/components/v2/ResourceOccupiedModal/useResourceByName.ts
@@ -0,0 +1,157 @@
+import { type Ref, watchEffect, computed, h } from "vue";
+import { EnvironmentV1Name, RichDatabaseName } from "@/components/v2";
+import { ProjectNameCell } from "@/components/v2/Model/DatabaseV1Table/cells";
+import { t } from "@/plugins/i18n";
+import {
+ useEnvironmentV1Store,
+ useDatabaseV1Store,
+ useProjectV1Store,
+ useUserStore,
+} from "@/store";
+import {
+ environmentNamePrefix,
+ projectNamePrefix,
+ userNamePrefix,
+ isDatabaseName,
+} from "@/store/modules/v1/common";
+import {
+ isValidEnvironmentName,
+ isValidDatabaseName,
+ isValidProjectName,
+} from "@/types";
+import { hasWorkspacePermissionV2 } from "@/utils";
+
+type ResourceType =
+ | "environment"
+ | "project"
+ | "database"
+ | "workspace"
+ | "user";
+
+export const useResourceByName = ({
+ resource,
+ link,
+}: {
+ resource: Ref<string>;
+ link?: boolean;
+}) => {
+ const environmentV1Store = useEnvironmentV1Store();
+ const databaseStore = useDatabaseV1Store();
+ const projectStore = useProjectV1Store();
+ const userStore = useUserStore();
+
+ const resourceType = computed((): ResourceType | undefined => {
+ if (resource.value === "workspace") {
+ return "workspace";
+ }
+ if (resource.value.startsWith(environmentNamePrefix)) {
+ return "environment";
+ } else if (isDatabaseName(resource.value)) {
+ return "database";
+ } else if (resource.value.startsWith(projectNamePrefix)) {
+ return "project";
+ } else if (resource.value.startsWith(userNamePrefix)) {
+ return "user";
+ }
+ return undefined;
+ });
+
+ const resourcePrefix = computed(() => {
+ switch (resourceType.value) {
+ case "environment":
+ return t("common.environment");
+ case "project":
+ return t("common.project");
+ case "database":
+ return t("common.database");
+ case "user":
+ return t("common.user");
+ default:
+ return "";
+ }
+ });
+
+ watchEffect(async () => {
+ switch (resourceType.value) {
+ case "database":
+ if (hasWorkspacePermissionV2("bb.databases.get")) {
+ await databaseStore.getOrFetchDatabaseByName(resource.value);
+ }
+ return;
+ case "environment":
+ if (hasWorkspacePermissionV2("bb.environments.get")) {
+ await environmentV1Store.getOrFetchEnvironmentByName(resource.value);
+ }
+ return;
+ case "project":
+ if (hasWorkspacePermissionV2("bb.projects.get")) {
+ await projectStore.getOrFetchProjectByName(
+ resource.value,
+ true /* silent */
+ );
+ }
+ return;
+ case "user":
+ await userStore.getOrFetchUserByIdentifier(resource.value, true);
+ return;
+ }
+ });
+
+ const resourceComponent = computed(() => {
+ switch (resourceType.value) {
+ case "environment": {
+ const environment = environmentV1Store.getEnvironmentByName(
+ resource.value
+ );
+ if (!isValidEnvironmentName(environment.name)) {
+ return h("div", resource.value);
+ }
+ return h(EnvironmentV1Name, { environment, link });
+ }
+ case "database": {
+ const database = databaseStore.getDatabaseByName(resource.value);
+ if (!isValidDatabaseName(database.name)) {
+ return h("div", resource.value);
+ }
+ return h(RichDatabaseName, {
+ database,
+ showArrow: false,
+ showInstance: false,
+ });
+ }
+ case "project": {
+ const project = projectStore.getProjectByName(resource.value);
+ if (!isValidProjectName(project.name)) {
+ return h("div", resource.value);
+ }
+ return h(ProjectNameCell, {
+ project,
+ mode: "ALL_SHORT",
+ link,
+ });
+ }
+ case "user": {
+ const user = userStore.getUserByIdentifier(resource.value);
+ if (!user) {
+ return h("div", resource.value);
+ }
+ return h(
+ "a",
+ {
+ class: "flex items-center space-x-2 normal-link underline",
+ href: `/${user.name}`,
+ },
+ `${user.title} (${user.email})`
+ );
+ }
+ default:
+ return h("div", resource.value);
+ }
+ });
+
+ return {
+ resourceType,
+ resourcePrefix,
+ resourceComponent,
+ };
+};
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index abfe1002fd..785637a554 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -2140,7 +2140,10 @@
"idp": "Identity Provider",
"database-group": "Database Group",
"changelist": "Changelist",
- "review-config": "Review Config"
+ "review-config": "Review Config",
+ "delete-warning": "The \"{name}\" will be deleted. This action cannot be undone.",
+ "delete-warning-with-resources": "The \"{name}\" is used by following resources:",
+ "delete-warning-retry": "Please remove it from these resources then retry again."
},
"resource-id": {
"self": "{resource} ID",
@@ -2397,10 +2400,7 @@
"add": "Add role",
"edit": "Edit role",
"title-placeholder": "Input role title",
- "description-placeholder": "Input role description",
- "delete-warning": "The role \"{name}\" will be deleted. This action cannot be undone.",
- "delete-warning-with-resources": "The role \"{name}\" is used by following resources:",
- "delete-warning-retry": "Please remove the role from these resources then retry again."
+ "description-placeholder": "Input role description"
},
"default-workspace-role": "Users will get the \"Workspace Member\" role by default",
"title": "Title",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 2d3f0390d6..a5339f180b 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -2140,7 +2140,10 @@
"idp": "Proveedor de Identidad",
"database-group": "grupo de bases de datos",
"changelist": "Lista de cambios",
- "review-config": "Revisar configuración"
+ "review-config": "Revisar configuración",
+ "delete-warning": "Se eliminará el elemento \"{name}\". Esta acción no se puede deshacer.",
+ "delete-warning-with-resources": "El \"{name}\" lo utilizan los siguientes recursos:",
+ "delete-warning-retry": "Elimínelo de estos recursos y vuelva a intentarlo."
},
"resource-id": {
"self": "ID de {resource}",
@@ -2397,10 +2400,7 @@
"add": "Agregar rol",
"edit": "Editar rol",
"title-placeholder": "Ingrese el título del rol",
- "description-placeholder": "Ingrese la descripción del rol",
- "delete-warning": "Se eliminará el rol \"{name}\". Esta acción no se puede deshacer.",
- "delete-warning-with-resources": "El rol \"{name}\" lo utilizan los siguientes recursos:",
- "delete-warning-retry": "Elimine el rol de estos recursos y vuelva a intentarlo."
+ "description-placeholder": "Ingrese la descripción del rol"
},
"default-workspace-role": "Los usuarios obtendrán el rol de \"Miembro del espacio de trabajo\" de forma predeterminada.",
"title": "Título",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index f04b303cfe..0c0e5267db 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -2140,7 +2140,10 @@
"idp": "アイデンティティプロバイダー",
"database-group": "データベースのグループ化",
"changelist": "変更リスト",
- "review-config": "設定を確認する"
+ "review-config": "設定を確認する",
+ "delete-warning": "「{name}」は削除されます。この操作は元に戻せません。",
+ "delete-warning-with-resources": "「{name}」は次のリソースによって使用されます:",
+ "delete-warning-retry": "これらのリソースから削除して、もう一度お試しください。"
},
"resource-id": {
"self": "{resource} ID",
@@ -2397,10 +2400,7 @@
"add": "役割の追加",
"edit": "役割の編集",
"title-placeholder": "役割のタイトルを入力してください",
- "description-placeholder": "役割の説明を入力してください",
- "delete-warning": "ロール「{name}」は削除されます。この操作は元に戻すことができません。",
- "delete-warning-with-resources": "ロール「{name}」は次のリソースによって使用されます:",
- "delete-warning-retry": "これらのリソースからロールを削除して、もう一度お試しください。"
+ "description-placeholder": "役割の説明を入力してください"
},
"default-workspace-role": "ユーザーにはデフォルトで「ワークスペースメンバー」の役割が与えられます",
"title": "タイトル",
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 157cb48041..50f152bee5 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -2140,7 +2140,10 @@
"idp": "Nhà cung cấp danh tính",
"database-group": "Nhóm cơ sở dữ liệu",
"changelist": "Danh sách thay đổi",
- "review-config": "Cấu hình đánh giá"
+ "review-config": "Cấu hình đánh giá",
+ "delete-warning": "\"{name}\" sẽ bị xóa. Hành động này không thể hoàn tác.",
+ "delete-warning-with-resources": "\"{name}\" được sử dụng bởi các tài nguyên sau:",
+ "delete-warning-retry": "Vui lòng xóa nó khỏi các tài nguyên này rồi thử lại."
},
"resource-id": {
"self": "ID {resource}",
@@ -2397,10 +2400,7 @@
"add": "Thêm vai trò",
"edit": "Chỉnh sửa vai trò",
"title-placeholder": "Nhập tiêu đề vai trò",
- "description-placeholder": "Nhập mô tả vai trò",
- "delete-warning": "Vai trò \"{name}\" sẽ bị xóa. Hành động này không thể hoàn tác.",
- "delete-warning-with-resources": "Vai trò \"{name}\" được sử dụng bởi các tài nguyên sau:",
- "delete-warning-retry": "Vui lòng xóa vai trò khỏi các tài nguyên này rồi thử lại."
+ "description-placeholder": "Nhập mô tả vai trò"
},
"default-workspace-role": "Người dùng sẽ nhận được vai trò \"Thành viên không gian làm việc\" theo mặc định",
"title": "Tiêu đề",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 7370e9e09b..850d2d41ab 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -2140,7 +2140,10 @@
"idp": "身份提供商",
"database-group": "数据库分组",
"changelist": "变更列表",
- "review-config": "审查配置"
+ "review-config": "审查配置",
+ "delete-warning": "“{name}”将被删除。此操作无法撤消。",
+ "delete-warning-with-resources": "以下资源使用了“{name}”:",
+ "delete-warning-retry": "请将其从这些资源中删除,然后重试。"
},
"resource-id": {
"self": "{resource} ID",
@@ -2397,10 +2400,7 @@
"add": "添加角色",
"edit": "编辑角色",
"title-placeholder": "输入角色称谓",
- "description-placeholder": "输入角色描述",
- "delete-warning": "角色“{name}”将被删除。此操作无法撤消。",
- "delete-warning-with-resources": "角色“{name}”已分配给以下资源:",
- "delete-warning-retry": "请从这些资源中删除该角色后重试。"
+ "description-placeholder": "输入角色描述"
},
"default-workspace-role": "用户将默认获得“工作区成员”角色",
"title": "称谓",
diff --git a/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue b/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue
index 591045c663..c919116a0d 100644
--- a/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue
+++ b/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue
@@ -63,7 +63,7 @@
:key="resource"
:can-remove="false"
>
- <SQLReviewAttachedResource :resource="resource" :show-prefix="true" />
+ <Resource :resource="resource" :show-prefix="true" />
</BBBadge>
</div>
</div>
@@ -165,10 +165,10 @@ import {
import { FeatureAttention } from "@/components/FeatureGuard";
import { SQLReviewCreation } from "@/components/SQLReview";
import SQLReviewAttachResourcesPanel from "@/components/SQLReview/components/SQLReviewAttachResourcesPanel.vue";
-import SQLReviewAttachedResource from "@/components/SQLReview/components/SQLReviewAttachedResource.vue";
import SQLReviewTabsByEngine from "@/components/SQLReview/components/SQLReviewTabsByEngine.vue";
import SQLRuleTableWithFilter from "@/components/SQLReview/components/SQLRuleTableWithFilter.vue";
import { rulesToTemplate } from "@/components/SQLReview/components/utils";
+import Resource from "@/components/v2/ResourceOccupiedModal/Resource.vue";
import { WORKSPACE_ROUTE_SQL_REVIEW } from "@/router/dashboard/workspaceRoutes";
import {
pushNotification,