Skip to content

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

chore: make review config more flexible (#12697)

ecmadaoe6f031d1fb95
diff --git a/frontend/src/bbkit/BBAttention.vue b/frontend/src/bbkit/BBAttention.vue
index f18d2b5695..90d4350246 100644
--- a/frontend/src/bbkit/BBAttention.vue
+++ b/frontend/src/bbkit/BBAttention.vue
@@ -1,6 +1,8 @@
<template>
<NAlert :title="displayTitle" :type="type">
- <div class="flex items-center justify-between">
+ <div
+ class="flex flex-col justify-start items-start md:flex-row md:items-center md:justify-between"
+ >
<slot name="default">
<div v-if="description" class="mt-2 text-sm">
<p class="whitespace-pre-wrap">
@@ -13,7 +15,7 @@
<slot name="action">
<div
v-if="actionText != ''"
- class="flex items-center justify-end mt-2 md:mt-0 md:ml-2"
+ class="flex items-center justify-end mt-4 md:mt-0 md:ml-2"
>
<NButton :type="buttonType" @click.prevent="$emit('click')">
{{ $t(actionText) }}
diff --git a/frontend/src/components/SQLReview/SQLReviewCreation.vue b/frontend/src/components/SQLReview/SQLReviewCreation.vue
index 9d22245623..0bceff0b82 100644
--- a/frontend/src/components/SQLReview/SQLReviewCreation.vue
+++ b/frontend/src/components/SQLReview/SQLReviewCreation.vue
@@ -23,7 +23,7 @@
"
:is-edit="!!policy"
:is-create="!isUpdate"
- :allow-change-attached-resource="allowChangeAttachedResource"
+ :allow-change-attached-resource="false"
@select-template="tryApplyTemplate"
@name-change="(val: string) => (state.name = val)"
@resource-id-change="(val: string) => (state.resourceId = val)"
@@ -48,7 +48,10 @@ import { reactive, computed, withDefaults } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import { StepTab } from "@/components/v2";
-import { WORKSPACE_ROUTE_SQL_REVIEW } from "@/router/dashboard/workspaceRoutes";
+import {
+ WORKSPACE_ROUTE_SQL_REVIEW,
+ WORKSPACE_ROUTE_SQL_REVIEW_DETAIL,
+} from "@/router/dashboard/workspaceRoutes";
import {
useCurrentUserV1,
pushNotification,
@@ -71,7 +74,7 @@ import {
} from "@/types";
import { Engine } from "@/types/proto/v1/common";
import { SQLReviewRuleLevel } from "@/types/proto/v1/org_policy_service";
-import { hasWorkspacePermissionV2 } from "@/utils";
+import { hasWorkspacePermissionV2, sqlReviewPolicySlug } from "@/utils";
import SQLReviewConfig from "./SQLReviewConfig.vue";
import SQLReviewInfo from "./SQLReviewInfo.vue";
import { rulesToTemplate } from "./components";
@@ -91,12 +94,13 @@ const props = withDefaults(
defineProps<{
policy?: SQLReviewPolicy;
name?: string;
- selectedResources: string[];
+ selectedResources?: string[];
selectedRuleList?: RuleTemplateV2[];
}>(),
{
policy: undefined,
name: "",
+ selectedResources: () => [],
selectedRuleList: () => [],
}
);
@@ -134,13 +138,6 @@ const state = reactive<LocalState>({
const isUpdate = computed(() => !!props.policy);
-const allowChangeAttachedResource = computed(() => {
- if (isUpdate.value) {
- return (props.policy?.resources ?? []).length === 0;
- }
- return props.selectedResources.length === 0;
-});
-
const onTemplateApply = (template: SQLReviewPolicyTemplateV2 | undefined) => {
if (!template) {
return;
@@ -161,13 +158,25 @@ const onTemplateApply = (template: SQLReviewPolicyTemplateV2 | undefined) => {
);
};
-const onCancel = () => {
+const onCancel = (newPolicy: SQLReviewPolicy | undefined = undefined) => {
if (props.policy) {
emit("cancel");
} else {
- router.push({
- name: WORKSPACE_ROUTE_SQL_REVIEW,
- });
+ if (newPolicy) {
+ router.push({
+ name: WORKSPACE_ROUTE_SQL_REVIEW_DETAIL,
+ params: {
+ sqlReviewPolicySlug: sqlReviewPolicySlug(newPolicy),
+ },
+ query: {
+ attachResourcePanel: newPolicy.resources.length === 0 ? 1 : undefined,
+ },
+ });
+ } else {
+ router.push({
+ name: WORKSPACE_ROUTE_SQL_REVIEW,
+ });
+ }
}
};
@@ -177,7 +186,6 @@ const allowNext = computed((): boolean => {
return (
!!state.name &&
!!state.resourceId &&
- state.attachedResources.length > 0 &&
state.selectedRuleMapByEngine.size > 0
);
case CONFIGURE_RULE_STEP:
@@ -220,7 +228,6 @@ const tryFinishSetup = async () => {
const upsert = {
title: state.name,
ruleList: convertRuleMapToPolicyRuleList(state.selectedRuleMapByEngine),
- resources: state.attachedResources,
};
if (isUpdate.value) {
@@ -234,13 +241,12 @@ const tryFinishSetup = async () => {
style: "SUCCESS",
title: t("sql-review.policy-updated"),
});
+ onCancel();
} else {
- if (state.attachedResources.length === 0) {
- return;
- }
try {
- await store.createReviewPolicy({
+ const policy = await store.createReviewPolicy({
...upsert,
+ resources: state.attachedResources,
id: `${reviewConfigNamePrefix}${state.resourceId}`,
});
pushNotification({
@@ -248,6 +254,7 @@ const tryFinishSetup = async () => {
style: "SUCCESS",
title: t("sql-review.policy-created"),
});
+ onCancel(policy);
} catch {
pushNotification({
module: "bytebase",
@@ -256,8 +263,6 @@ const tryFinishSetup = async () => {
});
}
}
-
- onCancel();
};
const tryApplyTemplate = (template: SQLReviewPolicyTemplateV2) => {
diff --git a/frontend/src/components/SQLReview/SQLReviewInfo.vue b/frontend/src/components/SQLReview/SQLReviewInfo.vue
index b14a91cbfa..ba69483d53 100644
--- a/frontend/src/components/SQLReview/SQLReviewInfo.vue
+++ b/frontend/src/components/SQLReview/SQLReviewInfo.vue
@@ -1,12 +1,12 @@
<template>
<div class="space-y-6">
- <div>
+ <div v-if="attachedResources.length > 0">
<label class="textlabel">
- {{ $t("sql-review.create.basic-info.attach-resource") }}
+ {{ $t("sql-review.attach-resource.self") }}
<span style="color: red">*</span>
</label>
<p class="mt-1 textinfolabel">
- {{ $t("sql-review.create.basic-info.attach-resource-label") }}
+ {{ $t("sql-review.attach-resource.label") }}
</p>
<NRadioGroup
v-model:value="attachResourceType"
@@ -17,11 +17,7 @@
<NRadio value="project">{{ $t("common.project") }}</NRadio>
</NRadioGroup>
<BBAttention type="info" class="my-2">
- {{
- $t(
- `sql-review.create.basic-info.attach-resource-info-${attachResourceType}`
- )
- }}
+ {{ $t(`sql-review.attach-resource.label-${attachResourceType}`) }}
</BBAttention>
<EnvironmentSelect
v-if="attachResourceType === 'environment'"
diff --git a/frontend/src/components/SQLReview/components/SQLReviewAttachResourcesPanel.vue b/frontend/src/components/SQLReview/components/SQLReviewAttachResourcesPanel.vue
new file mode 100644
index 0000000000..b8ee3b88ae
--- /dev/null
+++ b/frontend/src/components/SQLReview/components/SQLReviewAttachResourcesPanel.vue
@@ -0,0 +1,124 @@
+<template>
+ <Drawer :show="show" @close="$emit('close')">
+ <DrawerContent
+ :title="$t('sql-review.attach-resource.self')"
+ class="w-[40rem] max-w-[100vw] relative"
+ >
+ <template #default>
+ <div class="space-y-6">
+ <p class="textinfolabel">
+ {{ $t("sql-review.attach-resource.label") }}
+ </p>
+ <div>
+ <div class="textlabel mb-1">
+ {{ $t("common.environment") }}
+ </div>
+ <p class="textinfolabel">
+ {{ $t("sql-review.attach-resource.label-environment") }}
+ </p>
+ <EnvironmentSelect
+ class="mt-3"
+ required
+ :environments="environments"
+ :use-resource-id="true"
+ :multiple="true"
+ @update:environments="onResourcesChange($event, projects)"
+ />
+ </div>
+ <NDivider />
+ <div>
+ <div class="textlabel mb-1">
+ {{ $t("common.project") }}
+ </div>
+ <p class="textinfolabel">
+ {{ $t("sql-review.attach-resource.label-project") }}
+ </p>
+ <ProjectSelect
+ class="mt-3"
+ style="width: 100%"
+ required
+ :projects="projects"
+ :use-resource-id="true"
+ :multiple="true"
+ @update:projects="onResourcesChange($event, environments)"
+ />
+ </div>
+ </div>
+ </template>
+ <template #footer>
+ <div class="flex items-center justify-end gap-x-3">
+ <NButton @click="$emit('close')">
+ {{ $t("common.cancel") }}
+ </NButton>
+ <NButton type="primary" @click="upsertReviewResource">
+ {{ $t("common.confirm") }}
+ </NButton>
+ </div>
+ </template>
+ </DrawerContent>
+ </Drawer>
+</template>
+
+<script setup lang="ts">
+import { NDivider } from "naive-ui";
+import { watch, ref, computed } from "vue";
+import { useI18n } from "vue-i18n";
+import { Drawer, DrawerContent, ProjectSelect } from "@/components/v2";
+import { useSQLReviewStore, pushNotification } from "@/store";
+import {
+ environmentNamePrefix,
+ projectNamePrefix,
+} from "@/store/modules/v1/common";
+import type { SQLReviewPolicy } from "@/types";
+
+const props = defineProps<{
+ show: boolean;
+ review: SQLReviewPolicy;
+}>();
+
+const emit = defineEmits<{
+ (event: "close"): void;
+}>();
+
+const resources = ref<string[]>([]);
+const sqlReviewStore = useSQLReviewStore();
+const { t } = useI18n();
+
+watch(
+ () => props.review.resources,
+ () => {
+ resources.value = [...props.review.resources];
+ },
+ { immediate: true, deep: true }
+);
+
+const environments = computed(() =>
+ resources.value.filter((resource) =>
+ resource.startsWith(environmentNamePrefix)
+ )
+);
+const projects = computed(() =>
+ resources.value.filter((resource) => resource.startsWith(projectNamePrefix))
+);
+
+const onResourcesChange = (
+ newResources: string[],
+ otherResources: string[]
+) => {
+ resources.value = [...newResources, ...otherResources];
+};
+
+const upsertReviewResource = async () => {
+ await sqlReviewStore.upsertReviewConfigTag({
+ oldResources: props.review.resources,
+ newResources: resources.value,
+ review: props.review.id,
+ });
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("sql-review.policy-updated"),
+ });
+ emit("close");
+};
+</script>
diff --git a/frontend/src/components/SQLReview/components/SQLReviewCategorySummaryFilter.vue b/frontend/src/components/SQLReview/components/SQLReviewCategorySummaryFilter.vue
deleted file mode 100644
index b91617edf4..0000000000
--- a/frontend/src/components/SQLReview/components/SQLReviewCategorySummaryFilter.vue
+++ /dev/null
@@ -1,62 +0,0 @@
-<template>
- <div
- class="flex flex-col items-start 2xl:flex-row 2xl:items-center gap-y-5 gap-x-5"
- >
- <div class="flex items-center gap-x-5">
- <label
- v-for="stats in errorLevelList"
- :key="stats.level"
- class="flex items-center gap-x-2 text-sm text-gray-600"
- >
- <NCheckbox
- :id="sQLReviewRuleLevelToJSON(stats.level)"
- :checked="isCheckedLevel(stats.level)"
- @update:checked="
- (checked) => $emit('toggle-checked-level', stats.level, checked)
- "
- >
- <SQLRuleLevelBadge
- :level="stats.level"
- :suffix="`(${stats.count})`"
- />
- </NCheckbox>
- </label>
- </div>
- </div>
-</template>
-
-<script lang="ts" setup>
-import { NCheckbox } from "naive-ui";
-import { computed } from "vue";
-import type { RuleTemplateV2 } from "@/types";
-import { LEVEL_LIST } from "@/types";
-import type { SQLReviewRuleLevel } from "@/types/proto/v1/org_policy_service";
-import { sQLReviewRuleLevelToJSON } from "@/types/proto/v1/org_policy_service";
-import SQLRuleLevelBadge from "./SQLRuleLevelBadge.vue";
-
-type RuleLevelStats = {
- level: SQLReviewRuleLevel;
- count: number;
-};
-
-const props = withDefaults(
- defineProps<{
- ruleList: RuleTemplateV2[];
- isCheckedLevel?: (level: SQLReviewRuleLevel) => boolean;
- }>(),
- {
- isCheckedLevel: () => false,
- }
-);
-
-defineEmits<{
- (event: "toggle-checked-level", level: SQLReviewRuleLevel, on: boolean): void;
-}>();
-
-const errorLevelList = computed((): RuleLevelStats[] => {
- return LEVEL_LIST.map((level) => ({
- level,
- count: props.ruleList.filter((rule) => rule.level === level).length,
- }));
-});
-</script>
diff --git a/frontend/src/components/SQLReview/components/SQLReviewCategoryTabFilter.vue b/frontend/src/components/SQLReview/components/SQLReviewCategoryTabFilter.vue
index 26558869ff..2751f4aedf 100644
--- a/frontend/src/components/SQLReview/components/SQLReviewCategoryTabFilter.vue
+++ b/frontend/src/components/SQLReview/components/SQLReviewCategoryTabFilter.vue
@@ -15,7 +15,9 @@
{{ data.label }}
</template>
<template #default>
- <slot :rule-list="data.ruleList" />
+ <slot
+ :rule-list="data.value === 'all' ? tabItemList.slice(1) : [data]"
+ />
</template>
</NTabPane>
</NTabs>
@@ -27,7 +29,13 @@ import { NTabs, NTabPane } from "naive-ui";
import { computed, reactive, watch } from "vue";
import { useI18n } from "vue-i18n";
import type { RuleTemplateV2 } from "@/types";
-import { convertToCategoryList } from "@/types";
+import { convertToCategoryMap } from "@/types";
+
+export interface RuleListWithCategory {
+ value: string;
+ label: string;
+ ruleList: RuleTemplateV2[];
+}
interface LocalState {
selectedTab: string;
@@ -70,22 +78,23 @@ watch(
);
const tabItemList = computed(() => {
- const list = [
+ const list: RuleListWithCategory[] = [
{
value: "all",
label: t("common.all"),
- ruleList: props.ruleList,
+ ruleList: [],
},
];
- list.push(
- ...convertToCategoryList(props.ruleList).map((category) => {
- return {
- value: category.id,
- label: t(`sql-review.category.${category.id.toLowerCase()}`),
- ruleList: category.ruleList,
- };
- })
- );
+
+ for (const [category, ruleList] of convertToCategoryMap(
+ props.ruleList
+ ).entries()) {
+ list.push({
+ value: category,
+ label: t(`sql-review.category.${category.toLowerCase()}`),
+ ruleList: ruleList,
+ });
+ }
return list;
});
</script>
diff --git a/frontend/src/components/SQLReview/components/SQLReviewForResource.vue b/frontend/src/components/SQLReview/components/SQLReviewForResource.vue
index d178f54d45..0c0ef34c61 100644
--- a/frontend/src/components/SQLReview/components/SQLReviewForResource.vue
+++ b/frontend/src/components/SQLReview/components/SQLReviewForResource.vue
@@ -19,8 +19,8 @@
</span>
</div>
<NButton
- v-else-if="allowCreateSQLReviewPolicy"
- @click.prevent="onSQLReviewPolicyClick"
+ v-else-if="allowEdit"
+ @click.prevent="showReviewSelectPanel = true"
>
{{ $t("sql-review.configure-policy") }}
</NButton>
@@ -29,16 +29,19 @@
</span>
</div>
</div>
+
+ <SQLReviewPolicySelectPanel
+ :resource="resource"
+ :show="showReviewSelectPanel"
+ @close="showReviewSelectPanel = false"
+ />
</template>
<script setup lang="ts">
-import { computed } from "vue";
+import { computed, ref } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
-import {
- WORKSPACE_ROUTE_SQL_REVIEW_CREATE,
- WORKSPACE_ROUTE_SQL_REVIEW_DETAIL,
-} from "@/router/dashboard/workspaceRoutes";
+import { WORKSPACE_ROUTE_SQL_REVIEW_DETAIL } from "@/router/dashboard/workspaceRoutes";
import {
useCurrentUserV1,
pushNotification,
@@ -56,6 +59,7 @@ const { t } = useI18n();
const router = useRouter();
const me = useCurrentUserV1();
const reviewStore = useSQLReviewStore();
+const showReviewSelectPanel = ref<boolean>(false);
const allowEditSQLReviewPolicy = computed(() => {
return (
@@ -63,12 +67,6 @@ const allowEditSQLReviewPolicy = computed(() => {
);
});
-const allowCreateSQLReviewPolicy = computed(() => {
- return (
- props.allowEdit && hasWorkspacePermissionV2(me.value, "bb.policies.create")
- );
-});
-
const toggleSQLReviewPolicy = async (on: boolean) => {
const policy = sqlReviewPolicy.value;
if (!policy) return;
@@ -93,13 +91,6 @@ const onSQLReviewPolicyClick = () => {
sqlReviewPolicySlug: sqlReviewPolicySlug(sqlReviewPolicy.value),
},
});
- } else {
- router.push({
- name: WORKSPACE_ROUTE_SQL_REVIEW_CREATE,
- query: {
- attachedResource: props.resource,
- },
- });
}
};
diff --git a/frontend/src/components/SQLReview/components/SQLReviewLevelFilter.vue b/frontend/src/components/SQLReview/components/SQLReviewLevelFilter.vue
new file mode 100644
index 0000000000..0c10707677
--- /dev/null
+++ b/frontend/src/components/SQLReview/components/SQLReviewLevelFilter.vue
@@ -0,0 +1,67 @@
+<template>
+ <div
+ class="flex flex-col items-start 2xl:flex-row 2xl:items-center gap-y-5 gap-x-5"
+ >
+ <div class="flex items-center gap-x-5">
+ <label
+ v-for="[level, count] in errorLevelList.entries()"
+ :key="level"
+ class="flex items-center gap-x-2 text-sm text-gray-600"
+ >
+ <NCheckbox
+ :id="sQLReviewRuleLevelToJSON(level)"
+ :checked="isCheckedLevel(level)"
+ @update:checked="
+ (checked) => $emit('toggle-checked-level', level, checked)
+ "
+ >
+ <SQLRuleLevelBadge :level="level" :suffix="`(${count})`" />
+ </NCheckbox>
+ </label>
+ </div>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { NCheckbox } from "naive-ui";
+import { computed } from "vue";
+import { SQLReviewRuleLevel } from "@/types/proto/v1/org_policy_service";
+import { sQLReviewRuleLevelToJSON } from "@/types/proto/v1/org_policy_service";
+import type { RuleListWithCategory } from "./SQLReviewCategoryTabFilter.vue";
+import SQLRuleLevelBadge from "./SQLRuleLevelBadge.vue";
+
+const LEVEL_LIST = [
+ SQLReviewRuleLevel.ERROR,
+ SQLReviewRuleLevel.WARNING,
+ SQLReviewRuleLevel.DISABLED,
+];
+
+const props = withDefaults(
+ defineProps<{
+ ruleList: RuleListWithCategory[];
+ isCheckedLevel?: (level: SQLReviewRuleLevel) => boolean;
+ }>(),
+ {
+ isCheckedLevel: () => false,
+ }
+);
+
+defineEmits<{
+ (event: "toggle-checked-level", level: SQLReviewRuleLevel, on: boolean): void;
+}>();
+
+const errorLevelList = computed(() => {
+ const map = LEVEL_LIST.reduce((m, level) => {
+ m.set(level, 0);
+ return m;
+ }, new Map<SQLReviewRuleLevel, number>());
+
+ for (const ruleWithCategory of props.ruleList) {
+ for (const rule of ruleWithCategory.ruleList) {
+ const count = map.get(rule.level) ?? 0;
+ map.set(rule.level, count + 1);
+ }
+ }
+ return map;
+});
+</script>
diff --git a/frontend/src/components/SQLReview/components/SQLReviewPolicyDataTable.vue b/frontend/src/components/SQLReview/components/SQLReviewPolicyDataTable.vue
new file mode 100644
index 0000000000..afda4e915c
--- /dev/null
+++ b/frontend/src/components/SQLReview/components/SQLReviewPolicyDataTable.vue
@@ -0,0 +1,187 @@
+<template>
+ <NDataTable
+ :size="size"
+ :striped="true"
+ :columns="columns"
+ :data="reviewList"
+ :row-props="rowProps"
+ :row-key="(review: SQLReviewPolicy) => review.id"
+ />
+</template>
+
+<script setup lang="tsx">
+import { NCheckbox, NDataTable, NButton } from "naive-ui";
+import type { DataTableColumn } from "naive-ui";
+import { computed } from "vue";
+import { useI18n } from "vue-i18n";
+import { BBButtonConfirm } from "@/bbkit";
+import { pushNotification, useCurrentUserV1, 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<{
+ size?: "small" | "medium";
+ reviewList: SQLReviewPolicy[];
+ filter?: string;
+ customClick?: boolean;
+ allowEdit: boolean;
+ }>(),
+ {
+ size: "medium",
+ filter: "",
+ customClick: false,
+ }
+);
+
+const emit = defineEmits<{
+ (event: "row-click", review: SQLReviewPolicy): void;
+ (event: "edit", review: SQLReviewPolicy): void;
+ (event: "delete", review: SQLReviewPolicy): void;
+}>();
+
+const { t } = useI18n();
+const currentUserV1 = useCurrentUserV1();
+const sqlReviewStore = useSQLReviewStore();
+
+const columns = computed(
+ (): (DataTableColumn<SQLReviewPolicy> & { hide?: boolean })[] => {
+ return [
+ {
+ title: t("common.name"),
+ key: "name",
+ resizable: true,
+ render: (review: SQLReviewPolicy) => {
+ return <div innerHTML={highlight(review.name)}></div>;
+ },
+ },
+ {
+ title: t("common.resource"),
+ key: "resource",
+ resizable: true,
+ render: (review: SQLReviewPolicy) => {
+ return (
+ <div>
+ {review.resources.length === 0 && <span>-</span>}
+ {review.resources.map((resource) => {
+ return (
+ <SQLReviewAttachedResource
+ key={resource}
+ resource={resource}
+ showPrefix={true}
+ link={true}
+ />
+ );
+ })}
+ </div>
+ );
+ },
+ },
+ {
+ title: t("sql-review.enabled-rules"),
+ key: "rules",
+ render: (review: SQLReviewPolicy) => {
+ return (
+ <span>
+ {
+ review.ruleList.filter(
+ (r) => r.level !== SQLReviewRuleLevel.DISABLED
+ ).length
+ }
+ </span>
+ );
+ },
+ },
+ {
+ title: () => {
+ return <div class="capitalize">{t("common.enabled")}</div>;
+ },
+ key: "enabled",
+ width: "7rem",
+ render: (review: SQLReviewPolicy) => {
+ return (
+ <NCheckbox
+ disabled={!hasUpdatePolicyPermission.value || !props.allowEdit}
+ checked={review.enforce}
+ onUpdate:checked={(on) => toggleReviewEnabled(review, on)}
+ />
+ );
+ },
+ },
+ {
+ title: t("common.operations"),
+ key: "operations",
+ width: "15rem",
+ hide: !props.allowEdit,
+ render: (review: SQLReviewPolicy) => {
+ return (
+ <div class="flex items-center gap-x-2">
+ <NButton onClick={() => emit("edit", review)}>
+ {hasUpdatePolicyPermission.value
+ ? t("common.edit")
+ : t("common.view")}
+ </NButton>
+ {hasDeletePolicyPermission.value && (
+ <BBButtonConfirm
+ type={"default"}
+ style={"DELETE"}
+ hideIcon={true}
+ buttonText={t("common.delete")}
+ okText={t("common.delete")}
+ confirmTitle={t("common.delete") + ` '${review.name}'?`}
+ requireConfirm={true}
+ onConfirm={() => emit("delete", review)}
+ />
+ )}
+ </div>
+ );
+ },
+ },
+ ].filter((item) => !item.hide);
+ }
+);
+
+const highlight = (content: string) => {
+ return getHighlightHTMLByRegExp(
+ content,
+ props.filter.toLowerCase().split(" "),
+ /* !caseSensitive */ false,
+ /* className */ "bg-yellow-100"
+ );
+};
+
+const rowProps = (review: SQLReviewPolicy) => {
+ return {
+ style: props.customClick ? "cursor: pointer;" : "",
+ onClick: (e: MouseEvent) => {
+ if (props.customClick) {
+ emit("row-click", review);
+ return;
+ }
+ },
+ };
+};
+
+const hasUpdatePolicyPermission = computed(() => {
+ return hasWorkspacePermissionV2(currentUserV1.value, "bb.policies.update");
+});
+
+const hasDeletePolicyPermission = computed(() => {
+ return hasWorkspacePermissionV2(currentUserV1.value, "bb.policies.delete");
+});
+
+const toggleReviewEnabled = async (review: SQLReviewPolicy, on: boolean) => {
+ await sqlReviewStore.updateReviewPolicy({
+ id: review.id,
+ enforce: on,
+ });
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("common.updated"),
+ });
+};
+</script>
diff --git a/frontend/src/components/SQLReview/components/SQLReviewPolicySelectPanel.vue b/frontend/src/components/SQLReview/components/SQLReviewPolicySelectPanel.vue
new file mode 100644
index 0000000000..98aad80bd5
--- /dev/null
+++ b/frontend/src/components/SQLReview/components/SQLReviewPolicySelectPanel.vue
@@ -0,0 +1,100 @@
+<template>
+ <Drawer :show="show" @close="$emit('close')">
+ <DrawerContent
+ :title="$t('sql-review.select-review')"
+ class="w-[60rem] max-w-[100vw] relative"
+ >
+ <template #default>
+ <div class="space-y-4">
+ <i18n-t
+ keypath="sql-review.select-review-label"
+ tag="p"
+ class="textinfo"
+ >
+ <template #create>
+ <NButton
+ text
+ type="primary"
+ class="normal-link lowercase"
+ @click="createPolicy"
+ @disabled="!allowCreateSQLReviewPolicy"
+ >
+ {{ $t("sql-review.create-policy") }}
+ </NButton>
+ </template>
+ </i18n-t>
+ <SQLReviewPolicyDataTable
+ :size="'small'"
+ :review-list="sqlReviewStore.reviewPolicyList"
+ :allow-edit="false"
+ :custom-click="true"
+ @row-click="onReviewSelect"
+ />
+ </div>
+ </template>
+ <template #footer>
+ <div class="flex items-center justify-end gap-x-3">
+ <NButton @click="$emit('close')">
+ {{ $t("common.cancel") }}
+ </NButton>
+ </div>
+ </template>
+ </DrawerContent>
+ </Drawer>
+</template>
+
+<script setup lang="ts">
+import { watchEffect, computed } from "vue";
+import { useI18n } from "vue-i18n";
+import { useRouter } from "vue-router";
+import { Drawer, DrawerContent } from "@/components/v2";
+import { WORKSPACE_ROUTE_SQL_REVIEW_CREATE } from "@/router/dashboard/workspaceRoutes";
+import { useSQLReviewStore, useCurrentUserV1, pushNotification } from "@/store";
+import type { SQLReviewPolicy } from "@/types";
+import { hasWorkspacePermissionV2 } from "@/utils";
+
+const props = defineProps<{
+ show: boolean;
+ resource: string;
+}>();
+
+const emit = defineEmits<{
+ (event: "close"): void;
+}>();
+
+const sqlReviewStore = useSQLReviewStore();
+const router = useRouter();
+const { t } = useI18n();
+const me = useCurrentUserV1();
+
+watchEffect(() => {
+ sqlReviewStore.fetchReviewPolicyList();
+});
+
+const allowCreateSQLReviewPolicy = computed(() => {
+ return hasWorkspacePermissionV2(me.value, "bb.policies.create");
+});
+
+const createPolicy = () => {
+ router.push({
+ name: WORKSPACE_ROUTE_SQL_REVIEW_CREATE,
+ query: {
+ attachedResource: props.resource,
+ },
+ });
+};
+
+const onReviewSelect = async (review: SQLReviewPolicy) => {
+ await sqlReviewStore.upsertReviewConfigTag({
+ oldResources: [...review.resources],
+ newResources: [...review.resources, props.resource],
+ review: review.id,
+ });
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("common.updated"),
+ });
+ emit("close");
+};
+</script>
diff --git a/frontend/src/components/SQLReview/components/SQLReviewPolicyTable.vue b/frontend/src/components/SQLReview/components/SQLReviewPolicyTable.vue
index beac13a95c..3f62c7010f 100644
--- a/frontend/src/components/SQLReview/components/SQLReviewPolicyTable.vue
+++ b/frontend/src/components/SQLReview/components/SQLReviewPolicyTable.vue
@@ -1,73 +1,14 @@
<template>
<div>
- <BBGrid
- :column-list="columnList"
- :data-source="reviewList"
- :row-clickable="false"
- class="border hidden md:grid"
- >
- <template #item="{ item: review }: { item: SQLReviewPolicy }">
- <div class="bb-grid-cell">
- <span v-if="review.resources.length === 0">-</span>
- <div v-else>
- <SQLReviewAttachedResource
- v-for="resource in review.resources"
- :key="resource"
- :resource="resource"
- :show-prefix="true"
- :link="true"
- />
- </div>
- </div>
- <div class="bb-grid-cell">
- <template v-if="review.id">
- <div :innerHTML="highlight(review.name)" />
- </template>
- <span v-else class="italic textinfo text-gray-400">
- {{ $t("sql-review.no-policy-set") }}
- </span>
- </div>
- <div class="bb-grid-cell justify-center">
- <NCheckbox
- :disabled="!review.id || !hasUpdatePolicyPermission"
- :checked="review.enforce ?? false"
- @update:checked="toggleReviewEnabled(review, $event)"
- />
- </div>
- <div class="bb-grid-cell gap-x-2 !pr-[3rem]">
- <template v-if="!review.id">
- <NButton
- :disabled="!hasUpdatePolicyPermission"
- @click.prevent="handleClickCreate(review.resources[0])"
- >
- {{ $t("sql-review.configure-policy") }}
- </NButton>
- </template>
- <template v-else>
- <NButton @click.prevent="handleClickEdit(review)">
- {{
- hasUpdatePolicyPermission
- ? $t("common.edit")
- : $t("common.view")
- }}
- </NButton>
-
- <BBButtonConfirm
- v-if="hasDeletePolicyPermission"
- type="default"
- :disabled="!hasUpdatePolicyPermission"
- :style="'DELETE'"
- :hide-icon="true"
- :button-text="$t('common.delete')"
- :ok-text="$t('common.delete')"
- :confirm-title="$t('common.delete') + ` '${review.name}'?`"
- :require-confirm="true"
- @confirm="handleClickDelete(review)"
- />
- </template>
- </div>
- </template>
- </BBGrid>
+ <div class="hidden md:grid">
+ <SQLReviewPolicyDataTable
+ :review-list="reviewList"
+ :filter="filter"
+ :allow-edit="true"
+ @edit="handleClickEdit"
+ @delete="handleClickDelete"
+ />
+ </div>
<div
class="flex flex-col md:hidden border px-2 pb-4 divide-y space-y-4 divide-block-border"
@@ -75,7 +16,7 @@
<div
v-for="(review, i) in reviewList"
:key="`${i}-${review.id}`"
- class="pt-4 space-y-3"
+ class="pt-4"
>
<div>
<span v-if="review.id" class="text-md">
@@ -85,13 +26,16 @@
{{ $t("sql-review.no-policy-set") }}
</span>
</div>
- <div class="flex items-center gap-x-2">
+ <div class="space-y-2 space-x-2">
<BBBadge
v-for="resource in review.resources"
:key="resource"
:can-remove="false"
>
- <SQLReviewAttachedResource :resource="resource" />
+ <SQLReviewAttachedResource
+ :show-prefix="true"
+ :resource="resource"
+ />
</BBBadge>
<BBBadge
v-if="review.id && !review.enforce"
@@ -100,60 +44,44 @@
:badge-style="'DISABLED'"
/>
</div>
- <div class="flex items-center gap-x-2">
- <template v-if="!review.id">
- <NButton
- :disabled="!hasUpdatePolicyPermission"
- @click.prevent="handleClickCreate(review.resources[0])"
- >
- {{ $t("sql-review.configure-policy") }}
- </NButton>
- </template>
- <template v-else>
- <NButton @click.prevent="handleClickEdit(review)">
- {{
- hasUpdatePolicyPermission
- ? $t("common.edit")
- : $t("common.view")
- }}
- </NButton>
+ <div class="flex items-center gap-x-2 mt-4">
+ <NButton @click.prevent="handleClickEdit(review)">
+ {{
+ hasUpdatePolicyPermission ? $t("common.edit") : $t("common.view")
+ }}
+ </NButton>
- <BBButtonConfirm
- v-if="hasDeletePolicyPermission"
- type="default"
- :disabled="!hasUpdatePolicyPermission"
- :style="'DELETE'"
- :hide-icon="true"
- :button-text="$t('common.delete')"
- :ok-text="$t('common.delete')"
- :confirm-title="$t('common.delete') + ` '${review.name}'?`"
- :require-confirm="true"
- @confirm="handleClickDelete(review)"
- />
- </template>
+ <BBButtonConfirm
+ v-if="hasDeletePolicyPermission"
+ type="default"
+ :disabled="!hasUpdatePolicyPermission"
+ :style="'DELETE'"
+ :hide-icon="true"
+ :button-text="$t('common.delete')"
+ :ok-text="$t('common.delete')"
+ :confirm-title="$t('common.delete') + ` '${review.name}'?`"
+ :require-confirm="true"
+ @confirm="handleClickDelete(review)"
+ />
</div>
</div>
</div>
</div>
</template>
-<script setup lang="ts">
-import { NCheckbox } from "naive-ui";
+<script setup lang="tsx">
+import { NButton } from "naive-ui";
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
-import type { BBGridColumn } from "@/bbkit";
-import { BBButtonConfirm, BBGrid } from "@/bbkit";
-import {
- WORKSPACE_ROUTE_SQL_REVIEW_CREATE,
- WORKSPACE_ROUTE_SQL_REVIEW_DETAIL,
-} from "@/router/dashboard/workspaceRoutes";
+import { BBButtonConfirm } from "@/bbkit";
+import { WORKSPACE_ROUTE_SQL_REVIEW_DETAIL } from "@/router/dashboard/workspaceRoutes";
import { pushNotification, useCurrentUserV1, useSQLReviewStore } from "@/store";
import type { SQLReviewPolicy } from "@/types";
import { hasWorkspacePermissionV2, sqlReviewPolicySlug } from "@/utils";
-import { getHighlightHTMLByRegExp } from "@/utils";
+import SQLReviewAttachedResource from "./SQLReviewAttachedResource.vue";
-const props = defineProps<{
+defineProps<{
reviewList: SQLReviewPolicy[];
filter: string;
}>();
@@ -163,44 +91,6 @@ const router = useRouter();
const currentUserV1 = useCurrentUserV1();
const sqlReviewStore = useSQLReviewStore();
-const columnList = computed((): BBGridColumn[] => {
- return [
- {
- title: t("common.resource"),
- width: "minmax(min-content, auto)",
- class: "capitalize",
- },
- {
- title: t("common.name"),
- width: "minmax(min-content, auto)",
- class: "capitalize",
- },
- {
- title: t("common.enabled"),
- width: "minmax(min-content, auto)",
- class: "capitalize justify-center",
- },
- {
- title: t("common.operations"),
- width: "minmax(min-content, auto)",
- class: "capitalize",
- },
- ];
-});
-
-const highlight = (content: string) => {
- return getHighlightHTMLByRegExp(
- content,
- props.filter.toLowerCase().split(" "),
- /* !caseSensitive */ false,
- /* className */ "bg-yellow-100"
- );
-};
-
-const hasCreatePolicyPermission = computed(() => {
- return hasWorkspacePermissionV2(currentUserV1.value, "bb.policies.create");
-});
-
const hasUpdatePolicyPermission = computed(() => {
return hasWorkspacePermissionV2(currentUserV1.value, "bb.policies.update");
});
@@ -209,23 +99,6 @@ const hasDeletePolicyPermission = computed(() => {
return hasWorkspacePermissionV2(currentUserV1.value, "bb.policies.delete");
});
-const handleClickCreate = (attachedResource: string | undefined) => {
- if (hasCreatePolicyPermission.value) {
- router.push({
- name: WORKSPACE_ROUTE_SQL_REVIEW_CREATE,
- query: {
- attachedResource,
- },
- });
- } else {
- pushNotification({
- module: "bytebase",
- style: "CRITICAL",
- title: t("sql-review.no-permission"),
- });
- }
-};
-
const handleClickEdit = (review: SQLReviewPolicy) => {
router.push({
name: WORKSPACE_ROUTE_SQL_REVIEW_DETAIL,
@@ -243,16 +116,4 @@ const handleClickDelete = async (review: SQLReviewPolicy) => {
title: t("sql-review.policy-removed"),
});
};
-
-const toggleReviewEnabled = async (review: SQLReviewPolicy, on: boolean) => {
- await sqlReviewStore.updateReviewPolicy({
- id: review.id,
- enforce: on,
- });
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("common.updated"),
- });
-};
</script>
diff --git a/frontend/src/components/SQLReview/components/SQLReviewTemplateSelector.vue b/frontend/src/components/SQLReview/components/SQLReviewTemplateSelector.vue
index 86414fde9a..9df0e34426 100644
--- a/frontend/src/components/SQLReview/components/SQLReviewTemplateSelector.vue
+++ b/frontend/src/components/SQLReview/components/SQLReviewTemplateSelector.vue
@@ -23,7 +23,7 @@
<span class="text-base mt-4 font-medium">
{{ template.review.name }}
</span>
- <div>
+ <div class="space-y-2">
<BBBadge
v-for="resource in template.review.resources"
:key="resource"
diff --git a/frontend/src/components/SQLReview/components/SQLRuleFilter.vue b/frontend/src/components/SQLReview/components/SQLRuleFilter.vue
index a5ef216aa1..25d99d34e8 100644
--- a/frontend/src/components/SQLReview/components/SQLRuleFilter.vue
+++ b/frontend/src/components/SQLReview/components/SQLRuleFilter.vue
@@ -9,23 +9,27 @@
#default="{
ruleList: ruleListFilteredByCategory,
}: {
- ruleList: RuleTemplateV2[];
+ ruleList: RuleListWithCategory[];
}"
>
- <div class="flex items-center justify-between">
- <SQLReviewCategorySummaryFilter
+ <div
+ class="flex flex-col justify-start items-start md:flex-row md:items-center md:justify-between"
+ >
+ <SQLReviewLevelFilter
:rule-list="ruleListFilteredByCategory"
:is-checked-level="(level) => params.checkedLevel.has(level)"
@toggle-checked-level="$emit('toggle-checked-level', $event)"
/>
<SearchBox
ref="searchField"
+ class="mt-2 md:mt-0 md:!max-w-72"
+ style="max-width: 100%"
:value="params.searchText"
:placeholder="$t('common.filter-by-name')"
@update:value="$emit('change-search-text', $event)"
/>
</div>
- <slot :rule-list="ruleListFilteredByCategory.filter(filterRule)" />
+ <slot :rule-list="filterRuleList(ruleListFilteredByCategory)" />
</template>
</SQLReviewCategoryTabFilter>
</div>
@@ -35,8 +39,9 @@
import type { RuleTemplateV2 } from "@/types";
import { getRuleLocalization } from "@/types";
import type { SQLReviewRuleLevel } from "@/types/proto/v1/org_policy_service";
-import SQLReviewCategorySummaryFilter from "./SQLReviewCategorySummaryFilter.vue";
import SQLReviewCategoryTabFilter from "./SQLReviewCategoryTabFilter.vue";
+import type { RuleListWithCategory } from "./SQLReviewCategoryTabFilter.vue";
+import SQLReviewLevelFilter from "./SQLReviewLevelFilter.vue";
import type { SQLRuleFilterParams } from "./useSQLRuleFilter";
const props = defineProps<{
@@ -50,6 +55,22 @@ defineEmits<{
(event: "change-search-text", keyword: string): void;
}>();
+const filterRuleList = (
+ list: RuleListWithCategory[]
+): RuleListWithCategory[] => {
+ if (props.params.checkedLevel.size === 0 && !props.params.searchText) {
+ return list;
+ }
+ return list
+ .map((item) => {
+ return {
+ ...item,
+ ruleList: item.ruleList.filter(filterRule),
+ };
+ })
+ .filter((item) => item.ruleList.length > 0);
+};
+
const filterRule = (rule: RuleTemplateV2) => {
if (props.params.checkedLevel.size > 0) {
if (!props.params.checkedLevel.has(rule.level)) {
diff --git a/frontend/src/components/SQLReview/components/SQLRuleTable.vue b/frontend/src/components/SQLReview/components/SQLRuleTable.vue
index f92ebcc694..816d869e43 100644
--- a/frontend/src/components/SQLReview/components/SQLRuleTable.vue
+++ b/frontend/src/components/SQLReview/components/SQLRuleTable.vue
@@ -1,9 +1,9 @@
<template>
<div>
- <template v-for="category in categoryList" :key="category.id">
+ <template v-for="category in ruleList" :key="category.value">
<div class="flex my-3 items-center">
<span class="text-xl text-main font-semibold">
- {{ $t(`sql-review.category.${category.id.toLowerCase()}`) }}
+ {{ category.label }}
</span>
<span class="text-control-light text-md ml-1">
({{ category.ruleList.length }})
@@ -177,22 +177,22 @@ import { BBGrid, type BBGridColumn } from "@/bbkit";
import { useCurrentPlan } from "@/store";
import type { RuleTemplateV2 } from "@/types";
import {
- convertToCategoryList,
getRuleLocalization,
ruleIsAvailableInSubscription,
planTypeToString,
} from "@/types";
import { SQLReviewRuleLevel } from "@/types/proto/v1/org_policy_service";
import RuleLevelSwitch from "./RuleLevelSwitch.vue";
+import type { RuleListWithCategory } from "./SQLReviewCategoryTabFilter.vue";
import SQLRuleEditDialog from "./SQLRuleEditDialog.vue";
type LocalState = {
activeRule: RuleTemplateV2 | undefined;
};
-const props = withDefaults(
+withDefaults(
defineProps<{
- ruleList?: RuleTemplateV2[];
+ ruleList?: RuleListWithCategory[];
editable: boolean;
}>(),
{
@@ -215,10 +215,6 @@ const state = reactive<LocalState>({
activeRule: undefined,
});
-const categoryList = computed(() => {
- return convertToCategoryList(props.ruleList);
-});
-
const columnList = computed((): BBGridColumn[] => {
const columns: BBGridColumn[] = [
{
diff --git a/frontend/src/components/SQLReview/components/SQLRuleTableWithFilter.vue b/frontend/src/components/SQLReview/components/SQLRuleTableWithFilter.vue
index 195ea70c9a..a09417c568 100644
--- a/frontend/src/components/SQLReview/components/SQLRuleTableWithFilter.vue
+++ b/frontend/src/components/SQLReview/components/SQLRuleTableWithFilter.vue
@@ -5,7 +5,11 @@
v-on="filterEvents"
>
<template
- #default="{ ruleList: filteredRuleList }: { ruleList: RuleTemplateV2[] }"
+ #default="{
+ ruleList: filteredRuleList,
+ }: {
+ ruleList: RuleListWithCategory[];
+ }"
>
<SQLRuleTable
v-if="filteredRuleList.length > 0"
@@ -27,6 +31,7 @@ import {
} from "@/components/SQLReview/components";
import type { RuleTemplateV2 } from "@/types";
import type { Engine } from "@/types/proto/v1/common";
+import type { RuleListWithCategory } from "./SQLReviewCategoryTabFilter.vue";
const props = defineProps<{
engine: Engine;
diff --git a/frontend/src/components/SQLReview/components/useSQLRuleFilter.ts b/frontend/src/components/SQLReview/components/useSQLRuleFilter.ts
index eff40f7f6e..bf87e79034 100644
--- a/frontend/src/components/SQLReview/components/useSQLRuleFilter.ts
+++ b/frontend/src/components/SQLReview/components/useSQLRuleFilter.ts
@@ -1,6 +1,6 @@
import { reactive } from "vue";
import { useRoute } from "vue-router";
-import type { SQLReviewRuleLevel } from "@/types/proto/v1/org_policy_service";
+import { SQLReviewRuleLevel } from "@/types/proto/v1/org_policy_service";
export type SQLRuleFilterParams = {
checkedLevel: Set<SQLReviewRuleLevel>;
@@ -11,7 +11,10 @@ export type SQLRuleFilterParams = {
export const useSQLRuleFilter = () => {
const route = useRoute();
const params = reactive<SQLRuleFilterParams>({
- checkedLevel: new Set(),
+ checkedLevel: new Set([
+ SQLReviewRuleLevel.ERROR,
+ SQLReviewRuleLevel.WARNING,
+ ]),
selectedCategory: route.query.category
? (route.query.category as string)
: undefined,
@@ -33,7 +36,10 @@ export const useSQLRuleFilter = () => {
},
reset() {
this.changeCategory(undefined);
- params.checkedLevel = new Set();
+ params.checkedLevel = new Set([
+ SQLReviewRuleLevel.ERROR,
+ SQLReviewRuleLevel.WARNING,
+ ]);
},
};
return { params, events };
diff --git a/frontend/src/components/v2/Select/EnvironmentSelect.vue b/frontend/src/components/v2/Select/EnvironmentSelect.vue
index 7e6fad5e6a..25aabfb0c1 100644
--- a/frontend/src/components/v2/Select/EnvironmentSelect.vue
+++ b/frontend/src/components/v2/Select/EnvironmentSelect.vue
@@ -1,14 +1,15 @@
<template>
<NSelect
v-bind="$attrs"
- :value="environment"
+ :value="value"
:options="options"
:placeholder="$t('environment.select')"
:filterable="true"
+ :multiple="multiple"
:filter="filterByName"
:render-label="renderLabel"
class="bb-environment-select"
- @update:value="$emit('update:environment', $event)"
+ @update:value="handleValueUpdated"
/>
</template>
@@ -30,24 +31,29 @@ interface EnvironmentSelectOption extends SelectOption {
const props = withDefaults(
defineProps<{
environment?: string | undefined;
+ environments?: string[] | undefined;
defaultEnvironmentName?: string | undefined;
includeArchived?: boolean;
showProductionIcon?: boolean;
useResourceId?: boolean;
+ multiple?: boolean;
filter?: (environment: Environment, index: number) => boolean;
}>(),
{
environment: undefined,
+ environments: undefined,
defaultEnvironmentName: undefined,
includeArchived: false,
showProductionIcon: true,
useResourceId: false,
+ multiple: false,
filter: () => true,
}
);
-defineEmits<{
+const emit = defineEmits<{
(event: "update:environment", id: string | undefined): void;
+ (event: "update:environments", id: string[]): void;
}>();
const { t } = useI18n();
@@ -58,6 +64,30 @@ const prepare = () => {
projectV1Store.fetchProjectList(true /* showDeleted */);
};
+const value = computed(() => {
+ if (props.multiple) {
+ return props.environments || [];
+ } else {
+ return props.environment;
+ }
+});
+
+const handleValueUpdated = (value: string | string[]) => {
+ if (props.multiple) {
+ if (!value) {
+ // normalize value
+ value = [];
+ }
+ emit("update:environments", value as string[]);
+ } else {
+ if (value === null) {
+ // normalize value
+ value = "";
+ }
+ emit("update:environment", value as string);
+ }
+};
+
const rawEnvironmentList = computed(() => {
const list = environmentV1Store.getEnvironmentList(true /* showDeleted */);
return list;
diff --git a/frontend/src/components/v2/Select/ProjectSelect.vue b/frontend/src/components/v2/Select/ProjectSelect.vue
index 534a2f82c9..5158996c90 100644
--- a/frontend/src/components/v2/Select/ProjectSelect.vue
+++ b/frontend/src/components/v2/Select/ProjectSelect.vue
@@ -1,16 +1,17 @@
<template>
<NSelect
v-bind="$attrs"
- :value="project"
+ :value="value"
:options="options"
:placeholder="$t('project.select')"
:filterable="true"
+ :multiple="multiple"
:filter="filterByName"
:disabled="disabled"
:render-label="renderLabel"
class="bb-project-select"
style="width: 12rem"
- @update:value="$emit('update:project', $event)"
+ @update:value="handleValueUpdated"
/>
</template>
@@ -43,29 +44,34 @@ const props = withDefaults(
defineProps<{
disabled?: boolean;
project?: string | undefined | null; // UNKNOWN_ID(-1) to "ALL"
+ projects?: string[] | undefined | null; // UNKNOWN_ID(-1) to "ALL"
allowedProjectRoleList?: string[]; // Empty array([]) to "ALL"
allowedProjectWorkflowTypeList?: Workflow[];
includeAll?: boolean;
includeDefaultProject?: boolean;
includeArchived?: boolean;
useResourceId?: boolean;
+ multiple?: boolean;
filter?: (project: ComposedProject, index: number) => boolean;
}>(),
{
disabled: false,
project: undefined,
+ projects: undefined,
allowedProjectRoleList: () => [],
allowedProjectWorkflowTypeList: () => [Workflow.UI, Workflow.VCS],
includeAll: false,
includeDefaultProject: false,
includeArchived: false,
useResourceId: false,
+ multiple: false,
filter: () => true,
}
);
-defineEmits<{
+const emit = defineEmits<{
(event: "update:project", id: string | undefined): void;
+ (event: "update:projects", id: string[]): void;
}>();
const { t } = useI18n();
@@ -76,6 +82,30 @@ const prepare = () => {
projectV1Store.fetchProjectList(true /* showDeleted */);
};
+const value = computed(() => {
+ if (props.multiple) {
+ return props.projects || [];
+ } else {
+ return props.project;
+ }
+});
+
+const handleValueUpdated = (value: string | string[]) => {
+ if (props.multiple) {
+ if (!value) {
+ // normalize value
+ value = [];
+ }
+ emit("update:projects", value as string[]);
+ } else {
+ if (value === null) {
+ // normalize value
+ value = "";
+ }
+ emit("update:project", value as string);
+ }
+};
+
const hasWorkspaceManageProjectPermission = computed(() =>
hasWorkspacePermissionV2(currentUserV1.value, "bb.projects.list")
);
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index ae833a7ce2..68056746d1 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -2796,6 +2796,8 @@
"disabled": "Disabled",
"no-policy-set": "No SQL review policy",
"create-policy": "Create policy",
+ "select-review": "Select SQL review",
+ "select-review-label": "You can attach an existed SQL review policy to the resource, or {create}.",
"duplicate-policy": "Duplicate SQL Review Policy",
"configure-policy": "Configure policy",
"policy-removed": "Successfully removed the review policy.",
@@ -2813,7 +2815,14 @@
"not-available-for-free": "Rule is not available for {plan}",
"unlock-full-feature": "Unlock 100+ SQL lint rules",
"search-by-name": "Search by name",
- "no-linked-resources": "No linked resources",
+ "attach-resource": {
+ "no-linked-resources": "No attached resources",
+ "change-resources": "Change attached resources",
+ "self": "Attach to resources",
+ "label": "Apply the review policy to the selected resource. One resource can only link one policy. The database will use the SQL review policy attached to the project, otherwise fallback to the environment policy.",
+ "label-environment": "The SQL review policy will effect all databases belongs to the selected environment.",
+ "label-project": "The SQL review policy will effect all databases belongs to the selected project. The SQL review policy for environment will be ignored."
+ },
"create": {
"breadcrumb": "Create SQL review policy",
"basic-info": {
@@ -2822,10 +2831,6 @@
"display-name-placeholder": "The review policy name",
"display-name-default": "SQL review policy",
"display-name-label": "A display name to help identifying among different review policies.",
- "attach-resource": "Attach to resource",
- "attach-resource-label": "Apply the review policy to the selected resource. One resource can only link one policy. The database will use the SQL review policy attached to the project, otherwise fallback to the environment policy.",
- "attach-resource-info-environment": "The SQL review policy will effect all databases belongs to the selected environment.",
- "attach-resource-info-project": "The SQL review policy will effect all databases belongs to the selected project. The SQL review policy for environment will be ignored.",
"choose-template": "Choose template"
},
"configure-rule": {
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index bed526840c..6060475d34 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -2796,6 +2796,8 @@
"disabled": "Deshabilitado",
"no-policy-set": "Sin política de revisión de SQL",
"create-policy": "Crear política",
+ "select-review": "Seleccione revisión SQL",
+ "select-review-label": "Puede adjuntar una política de revisión de SQL existente al recurso o {create}.",
"duplicate-policy": "Duplicar política de revisión de SQL",
"configure-policy": "Configurar política",
"policy-removed": "La política de revisión se eliminó correctamente.",
@@ -2813,7 +2815,14 @@
"not-available-for-free": "La regla no está disponible para {plan}",
"unlock-full-feature": "Desbloquear más de 100 reglas de validación de SQL",
"search-by-name": "Buscar por nombre",
- "no-linked-resources": "No hay recursos vinculados",
+ "attach-resource": {
+ "no-linked-resources": "Sin recursos adjuntos",
+ "change-resources": "Cambiar recursos adjuntos",
+ "self": "Adjuntar a recursos",
+ "label": "Aplicar la política de revisión al recurso seleccionado. Un recurso sólo puede vincular una política. La base de datos utilizará la política de revisión de SQL adjunta al proyecto; de lo contrario, recurrirá a la política de entorno.",
+ "label-environment": "La política de revisión de SQL afectará a todas las bases de datos que pertenecen al entorno seleccionado.",
+ "label-project": "La política de revisión de SQL afectará a todas las bases de datos que pertenecen al proyecto seleccionado. Se ignorará la política de revisión de SQL para el entorno."
+ },
"create": {
"breadcrumb": "Crear política de revisión SQL",
"basic-info": {
@@ -2822,10 +2831,6 @@
"display-name-placeholder": "El nombre de la política de revisión",
"display-name-default": "Política de revisión SQL",
"display-name-label": "Un nombre para mostrar que ayuda a identificar entre diferentes políticas de revisión.",
- "attach-resource": "Adjuntar al recurso",
- "attach-resource-label": "Aplicar la política de revisión al recurso seleccionado. Un recurso sólo puede vincular una política. La base de datos utilizará la política de revisión de SQL adjunta al proyecto; de lo contrario, recurrirá a la política de entorno.",
- "attach-resource-info-environment": "La política de revisión de SQL afectará a todas las bases de datos que pertenecen al entorno seleccionado.",
- "attach-resource-info-project": "La política de revisión de SQL afectará a todas las bases de datos que pertenecen al proyecto seleccionado. Se ignorará la política de revisión de SQL para el entorno.",
"choose-template": "Elegir plantilla"
},
"configure-rule": {
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index a3e133a425..c61d871144 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -2796,6 +2796,8 @@
"disabled": "無効",
"no-policy-set": "SQL監査ポリシーなし",
"create-policy": "監査ポリシーを作成する",
+ "select-review": "SQLレビューを選択",
+ "select-review-label": "既存の SQL レビュー ポリシーをリソースまたは {create} に添付できます。",
"duplicate-policy": "監査ポリシーをコピーする",
"configure-policy": "監査ポリシーを構成する",
"policy-removed": "監査ポリシーが削除されました",
@@ -2813,7 +2815,14 @@
"not-available-for-free": "{plan}定期購入ではこのルールを使用できません",
"unlock-full-feature": "100 を超える SQL レビュー ルールのロックを解除する",
"search-by-name": "名前で検索",
- "no-linked-resources": "リンクされたリソースはありません",
+ "attach-resource": {
+ "no-linked-resources": "リソースのバインドはありません",
+ "change-resources": "バインドされたリソースを変更する",
+ "self": "リソースにバインドする",
+ "label": "選択したリソースに監査ポリシーを適用します。リソースは 1 つのポリシーにのみ関連付けることができます。データベースはプロジェクトに添付された SQL 監査ポリシーを使用します。それ以外の場合は、環境ポリシーにフォールバックします。",
+ "label-environment": "SQL 監査ポリシーは、選択した環境に属するすべてのデータベースに影響します。",
+ "label-project": "SQL 監査ポリシーは、選択したプロジェクト内のすべてのデータベースに影響します。環境の SQL 監査ポリシーは無視されます。"
+ },
"create": {
"breadcrumb": "監査ポリシーを作成する",
"basic-info": {
@@ -2822,10 +2831,6 @@
"display-name-placeholder": "監査ポリシー名",
"display-name-default": "SQL監査ポリシー",
"display-name-label": "さまざまな監査ポリシーを区別するために使用される名前。",
- "attach-resource": "リソースにアタッチする",
- "attach-resource-label": "選択したリソースに監査ポリシーを適用します。リソースは 1 つのポリシーにのみ関連付けることができます。データベースはプロジェクトに添付された SQL 監査ポリシーを使用します。それ以外の場合は、環境ポリシーにフォールバックします。",
- "attach-resource-info-environment": "SQL 監査ポリシーは、選択した環境に属するすべてのデータベースに影響します。",
- "attach-resource-info-project": "SQL 監査ポリシーは、選択したプロジェクト内のすべてのデータベースに影響します。環境の SQL 監査ポリシーは無視されます。",
"choose-template": "テンプレートを選択"
},
"configure-rule": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index e653d9f1ef..752f16bec3 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -2796,6 +2796,8 @@
"disabled": "已禁用",
"no-policy-set": "没有 SQL 审核策略",
"create-policy": "创建审核策略",
+ "select-review": "选择 SQL 审核",
+ "select-review-label": "您可以将现有的 SQL 审核策略附加到资源,或者 {create}。",
"duplicate-policy": "复制审核策略",
"configure-policy": "配置审核策略",
"policy-removed": "审核策略已删除",
@@ -2813,7 +2815,14 @@
"not-available-for-free": "{plan}订阅不能使用该规则",
"unlock-full-feature": "解锁 100+ SQL Review 规则",
"search-by-name": "按名称搜索",
- "no-linked-resources": "没有绑定的资源",
+ "attach-resource": {
+ "no-linked-resources": "没有绑定的资源",
+ "change-resources": "更改绑定的资源",
+ "self": "绑定到资源",
+ "label": "将审核策略应用于所选资源。一个资源只能关联一个策略。数据库将使用附加到项目的 SQL 审核策略,否则将回退到环境策略。",
+ "label-environment": "SQL 审查策略将影响属于所选环境的所有数据库。",
+ "label-project": "SQL 审核策略将影响所选项目下的所有数据库。环境的 SQL 审核策略将被忽略。"
+ },
"create": {
"breadcrumb": "创建审核策略",
"basic-info": {
@@ -2822,10 +2831,6 @@
"display-name-placeholder": "审核策略名称",
"display-name-default": "SQL 审核策略",
"display-name-label": "用以区分不同审核策略的名称。",
- "attach-resource": "附加到资源",
- "attach-resource-label": "将审核策略应用于所选资源。一个资源只能关联一个策略。数据库将使用附加到项目的 SQL 审核策略,否则将回退到环境策略。",
- "attach-resource-info-environment": "SQL 审查策略将影响属于所选环境的所有数据库。",
- "attach-resource-info-project": "SQL 审核策略将影响所选项目下的所有数据库。环境的 SQL 审核策略将被忽略。",
"choose-template": "选择模板"
},
"configure-rule": {
diff --git a/frontend/src/store/modules/sqlReview.ts b/frontend/src/store/modules/sqlReview.ts
index 7652db2304..3819a7eb29 100644
--- a/frontend/src/store/modules/sqlReview.ts
+++ b/frontend/src/store/modules/sqlReview.ts
@@ -1,4 +1,4 @@
-import { pullAt, isEqual } from "lodash-es";
+import { pullAt, uniq } from "lodash-es";
import { defineStore } from "pinia";
import { computed, unref, watchEffect } from "vue";
import { reviewConfigServiceClient } from "@/grpcweb";
@@ -109,6 +109,23 @@ export const useSQLReviewStore = defineStore("sqlReview", {
];
}
},
+ async upsertReviewConfigTag({
+ oldResources,
+ newResources,
+ review,
+ }: {
+ oldResources: string[];
+ newResources: string[];
+ review: string;
+ }) {
+ await removeReviewConfigTag(uniq(oldResources));
+ await upsertReviewConfigTag(uniq(newResources), review);
+
+ const reviewPolicy = this.reviewPolicyList.find((r) => r.id === review);
+ if (reviewPolicy) {
+ reviewPolicy.resources = newResources;
+ }
+ },
async createReviewPolicy({
id,
title,
@@ -137,7 +154,11 @@ export const useSQLReviewStore = defineStore("sqlReview", {
},
});
- await upsertReviewConfigTag(resources, reviewConfig.name);
+ await this.upsertReviewConfigTag({
+ oldResources: [],
+ newResources: resources,
+ review: reviewConfig.name,
+ });
reviewConfig.resources = resources;
const reviewPolicy = convertToSQLReviewPolicy(reviewConfig);
@@ -148,6 +169,7 @@ export const useSQLReviewStore = defineStore("sqlReview", {
}
this.setReviewPolicy(reviewPolicy);
+ return reviewPolicy;
},
async removeReviewPolicy(id: string) {
const index = this.reviewPolicyList.findIndex((g) => g.id === id);
@@ -169,13 +191,11 @@ export const useSQLReviewStore = defineStore("sqlReview", {
title,
enforce,
ruleList,
- resources,
}: {
id: string;
title?: string;
enforce?: boolean;
ruleList?: SchemaPolicyRule[];
- resources?: string[];
}) {
const index = this.reviewPolicyList.findIndex((g) => g.id === id);
if (index < 0) {
@@ -214,12 +234,6 @@ export const useSQLReviewStore = defineStore("sqlReview", {
updateMask,
});
- if (resources && !isEqual(resources, targetPolicy.resources)) {
- await removeReviewConfigTag(targetPolicy.resources);
- await upsertReviewConfigTag(resources, targetPolicy.id);
- updated.resources = resources;
- }
-
const reviewPolicy = convertToSQLReviewPolicy(updated);
if (reviewPolicy) {
this.setReviewPolicy(reviewPolicy);
diff --git a/frontend/src/store/modules/v1/subscription.ts b/frontend/src/store/modules/v1/subscription.ts
index 580dc69ac6..f5483b20c2 100644
--- a/frontend/src/store/modules/v1/subscription.ts
+++ b/frontend/src/store/modules/v1/subscription.ts
@@ -2,10 +2,9 @@ import dayjs from "dayjs";
import { defineStore } from "pinia";
import type { Ref } from "vue";
import { computed } from "vue";
-import { useI18n } from "vue-i18n";
import { subscriptionServiceClient } from "@/grpcweb";
import type { FeatureType } from "@/types";
-import { PLANS, planTypeToString, instanceLimitFeature } from "@/types";
+import { PLANS, instanceLimitFeature } from "@/types";
import type { Instance } from "@/types/proto/v1/instance_service";
import type { Subscription } from "@/types/proto/v1/subscription_service";
import {
@@ -196,30 +195,6 @@ export const useSubscriptionV1Store = defineStore("subscription_v1", {
}
return PlanType.FREE;
},
- getRquiredPlanString(type: FeatureType): string {
- const { t } = useI18n();
- const plan = t(
- `subscription.plan.${planTypeToString(
- this.getMinimumRequiredPlan(type)
- )}.title`
- );
- return t("subscription.require-subscription", { requiredPlan: plan });
- },
- getFeatureRequiredPlanString(type: FeatureType): string {
- const { t } = useI18n();
- const minRequiredPlan = this.getMinimumRequiredPlan(type);
-
- const requiredPlan = t(
- `subscription.plan.${planTypeToString(minRequiredPlan)}.title`
- );
- const feature = t(
- `subscription.features.${type.replace(/\./g, "-")}.title`
- );
- return t("subscription.feature-require-subscription", {
- feature,
- requiredPlan,
- });
- },
async fetchSubscription() {
try {
const subscription = await subscriptionServiceClient.getSubscription(
diff --git a/frontend/src/types/sqlReview.ts b/frontend/src/types/sqlReview.ts
index 614c8f3c2e..35bb76159c 100644
--- a/frontend/src/types/sqlReview.ts
+++ b/frontend/src/types/sqlReview.ts
@@ -11,12 +11,6 @@ import sqlReviewDevTemplate from "./sql-review.dev.yaml";
import sqlReviewProdTemplate from "./sql-review.prod.yaml";
import sqlReviewSampleTemplate from "./sql-review.sample.yaml";
-export const LEVEL_LIST = [
- SQLReviewRuleLevel.ERROR,
- SQLReviewRuleLevel.WARNING,
- SQLReviewRuleLevel.DISABLED,
-];
-
// NumberPayload is the number type payload configuration options and default value.
// Used by the frontend.
export interface NumberPayload {
@@ -231,30 +225,17 @@ export const TEMPLATE_LIST_V2: SQLReviewPolicyTemplateV2[] = (function () {
});
})();
-interface RuleCategory {
- id: string;
- ruleList: RuleTemplateV2[];
-}
-
-// convertToCategoryList will reduce RuleTemplate list to RuleCategory list.
-export const convertToCategoryList = (
+// convertToCategoryMap will reduce RuleTemplate list to map by category.
+export const convertToCategoryMap = (
ruleList: RuleTemplateV2[]
-): RuleCategory[] => {
- const dict = ruleList.reduce(
- (dict, rule) => {
- if (!dict[rule.category]) {
- dict[rule.category] = {
- id: rule.category,
- ruleList: [],
- };
- }
- dict[rule.category].ruleList.push(rule);
- return dict;
- },
- {} as { [key: string]: RuleCategory }
- );
-
- return Object.values(dict);
+): Map<string, RuleTemplateV2[]> => {
+ return ruleList.reduce((map, rule) => {
+ if (!map.has(rule.category)) {
+ map.set(rule.category, []);
+ }
+ map.get(rule.category)?.push(rule);
+ return map;
+ }, new Map<string, RuleTemplateV2[]>());
};
// The convertPolicyRuleToRuleTemplate will convert the review policy rule to rule template for frontend useage.
diff --git a/frontend/src/views/SettingWorkspaceSQLReview.vue b/frontend/src/views/SettingWorkspaceSQLReview.vue
index fb63e55e41..38e7540224 100644
--- a/frontend/src/views/SettingWorkspaceSQLReview.vue
+++ b/frontend/src/views/SettingWorkspaceSQLReview.vue
@@ -27,19 +27,23 @@
</a>
</div>
- <div class="space-y-6">
- <SQLReviewPolicyTable
- :review-list="reviewConfigWithResourceList"
- :filter="searchText"
- />
- <div v-if="reviewConfigWithoutResourceList.length > 0">
- <h2 class="mb-3">{{ $t("sql-review.no-linked-resources") }}</h2>
- <SQLReviewPolicyTable
- :review-list="reviewConfigWithoutResourceList"
- :filter="searchText"
- />
- </div>
- </div>
+ <SQLReviewPolicyTable
+ v-if="sqlReviewStore.reviewPolicyList.length > 0"
+ :review-list="filteredReviewConfigList"
+ :filter="searchText"
+ />
+ <NoDataPlaceholder v-else>
+ <template #default>
+ <NButton
+ :size="'small'"
+ type="primary"
+ :disabled="!hasCreatePolicyPermission"
+ @click="createSQLReview"
+ >
+ {{ $t("sql-review.create-policy") }}
+ </NButton>
+ </template>
+ </NoDataPlaceholder>
</div>
</template>
@@ -47,20 +51,13 @@
import { watchEffect, ref, computed } from "vue";
import { useRouter } from "vue-router";
import { WORKSPACE_ROUTE_SQL_REVIEW_CREATE } from "@/router/dashboard/workspaceRoutes";
-import {
- useSQLReviewStore,
- useCurrentUserV1,
- useEnvironmentV1List,
-} from "@/store";
-import { environmentNamePrefix } from "@/store/modules/v1/common";
-import type { SQLReviewPolicy } from "@/types";
+import { useSQLReviewStore, useCurrentUserV1 } from "@/store";
import { hasWorkspacePermissionV2 } from "@/utils";
const router = useRouter();
const sqlReviewStore = useSQLReviewStore();
const searchText = ref("");
const currentUserV1 = useCurrentUserV1();
-const environmentList = useEnvironmentV1List();
watchEffect(() => {
sqlReviewStore.fetchReviewPolicyList();
@@ -84,45 +81,4 @@ const filteredReviewConfigList = computed(() => {
return config.name.toLowerCase().includes(searchText.value.toLowerCase());
});
});
-
-const reviewConfigWithResourceList = computed(() => {
- const reviewConfigWithEnvironmentList = environmentList.value
- .map<SQLReviewPolicy>((environment) => {
- const review = sqlReviewStore.getReviewPolicyByResouce(environment.name);
-
- return (
- review ?? {
- id: "",
- enforce: false,
- name: "",
- ruleList: [],
- resources: [environment.name],
- }
- );
- })
- .filter((review) => {
- if (!searchText.value) {
- return true;
- }
- return review.name.toLowerCase().includes(searchText.value.toLowerCase());
- });
-
- return [
- ...reviewConfigWithEnvironmentList,
- ...filteredReviewConfigList.value.filter((review) => {
- return (
- review.resources.length > 0 &&
- !review.resources.some((resource) =>
- resource.startsWith(environmentNamePrefix)
- )
- );
- }),
- ];
-});
-
-const reviewConfigWithoutResourceList = computed(() => {
- return filteredReviewConfigList.value.filter((review) => {
- return review.resources.length === 0;
- });
-});
</script>
diff --git a/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue b/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue
index f9d9f92a95..e340181d0f 100644
--- a/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue
+++ b/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue
@@ -6,7 +6,6 @@
class="mt-1"
:policy="reviewPolicy"
:name="reviewPolicy.name"
- :selected-resources="reviewPolicy.resources"
:selected-rule-list="ruleListOfPolicy"
@cancel="state.editMode = false"
/>
@@ -45,16 +44,27 @@
<NButton v-else @click.prevent="state.showEnableModal = true">
{{ $t("common.enable") }}
</NButton>
+ <NButton
+ v-if="reviewPolicy.resources.length > 0"
+ @click.prevent="state.showResourcePanel = true"
+ >
+ {{ $t("sql-review.attach-resource.change-resources") }}
+ </NButton>
<NButton type="primary" @click="onEdit">
{{ $t("sql-review.create.configure-rule.change-template") }}
</NButton>
</div>
</div>
<div class="mt-4 space-y-4">
- <BBAttention v-if="reviewPolicy.resources.length === 0" type="warning">
- {{ $t("sql-review.no-linked-resources") }}
- </BBAttention>
- <div class="flex space-x-2 items-center">
+ <BBAttention
+ v-if="reviewPolicy.resources.length === 0"
+ type="warning"
+ :title="$t('sql-review.attach-resource.no-linked-resources')"
+ :description="$t('sql-review.attach-resource.label')"
+ :action-text="$t('sql-review.attach-resource.self')"
+ @click="state.showResourcePanel = true"
+ />
+ <div class="space-y-2 space-x-2">
<BBBadge
v-for="resource in reviewPolicy.resources"
:key="resource"
@@ -131,13 +141,19 @@
"
@cancel="state.showEnableModal = false"
/>
+
+ <SQLReviewAttachResourcesPanel
+ :show="state.showResourcePanel"
+ :review="reviewPolicy"
+ @close="state.showResourcePanel = false"
+ />
</template>
<script lang="tsx" setup>
import { useTitle } from "@vueuse/core";
import { computed, reactive, watch, watchEffect } from "vue";
import { useI18n } from "vue-i18n";
-import { useRouter } from "vue-router";
+import { useRouter, useRoute } from "vue-router";
import { BBTextField } from "@/bbkit";
import { rulesToTemplate } from "@/components/SQLReview/components/utils";
import { WORKSPACE_ROUTE_SQL_REVIEW } from "@/router/dashboard/workspaceRoutes";
@@ -171,11 +187,13 @@ interface LocalState {
rulesUpdated: boolean;
updating: boolean;
editingTitle: boolean;
+ showResourcePanel: boolean;
}
const { t } = useI18n();
const store = useSQLReviewStore();
const router = useRouter();
+const route = useRoute();
const currentUserV1 = useCurrentUserV1();
const subscriptionStore = useSubscriptionV1Store();
@@ -187,6 +205,7 @@ const state = reactive<LocalState>({
rulesUpdated: false,
updating: false,
editingTitle: false,
+ showResourcePanel: false,
});
const hasPermission = computed(() => {
@@ -195,6 +214,9 @@ const hasPermission = computed(() => {
watchEffect(async () => {
await store.getOrFetchReviewPolicyByName(props.sqlReviewPolicySlug);
+ if (route.query.attachResourcePanel) {
+ state.showResourcePanel = true;
+ }
});
const reviewPolicy = computed(() => {