Skip to content

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

feat(frontend): add presets to approval rule edit modal (#18232)

p0ny1198d54b21da
diff --git a/frontend/src/components/CustomApproval/Settings/components/CustomApproval/RulesPanel/RuleEditModal.vue b/frontend/src/components/CustomApproval/Settings/components/CustomApproval/RulesPanel/RuleEditModal.vue
index 1b18a32dde..94db9c30db 100644
--- a/frontend/src/components/CustomApproval/Settings/components/CustomApproval/RulesPanel/RuleEditModal.vue
+++ b/frontend/src/components/CustomApproval/Settings/components/CustomApproval/RulesPanel/RuleEditModal.vue
@@ -19,6 +19,31 @@
</div>
<div class="flex-1 flex flex-col px-6 py-4 overflow-hidden gap-y-4">
+ <div v-if="mode === 'create'" class="flex flex-col gap-y-2">
+ <h3 class="font-medium text-sm text-control">
+ {{ $t("custom-approval.approval-flow.template.presets-title") }}
+ </h3>
+ <div class="flex flex-wrap gap-2">
+ <NTooltip
+ v-for="(template, index) in templates"
+ :key="index"
+ to="body"
+ :disabled="!template.description()"
+ >
+ <template #trigger>
+ <NButton
+ size="small"
+ :disabled="!allowAdmin"
+ @click="applyTemplate(template)"
+ >
+ {{ template.title() }}
+ </NButton>
+ </template>
+ {{ template.description() }}
+ </NTooltip>
+ </div>
+ </div>
+
<div class="flex flex-col gap-y-2">
<h3 class="font-medium text-sm text-control">
{{ $t("common.title") }} <RequiredStar />
@@ -96,7 +121,7 @@
<script lang="ts" setup>
import { create as createProto } from "@bufbuild/protobuf";
import { cloneDeep, head } from "lodash-es";
-import { NButton, NInput, NModal } from "naive-ui";
+import { NButton, NInput, NModal, NTooltip } from "naive-ui";
import { computed, reactive, watch } from "vue";
import ExprEditor from "@/components/ExprEditor";
import RequiredStar from "@/components/RequiredStar.vue";
@@ -122,6 +147,11 @@ import {
} from "../../common/utils";
import { StepsTable } from "../common";
import { useCustomApprovalContext } from "../context";
+import {
+ type ApprovalRuleTemplate,
+ applyTemplateToState,
+ useApprovalRuleTemplates,
+} from "./template";
type LocalState = {
title: string;
@@ -144,6 +174,7 @@ const emit = defineEmits<{
const context = useCustomApprovalContext();
const { allowAdmin } = context;
+const templates = useApprovalRuleTemplates();
const state = reactive<LocalState>({
title: "",
@@ -194,6 +225,13 @@ const handleUpdate = () => {
// Trigger reactivity
};
+const applyTemplate = (template: ApprovalRuleTemplate) => {
+ const applied = applyTemplateToState(template);
+ state.title = applied.title;
+ state.conditionExpr = applied.conditionExpr;
+ state.flow = applied.flow;
+};
+
const handleSave = async () => {
if (!context.hasFeature.value) {
context.showFeatureModal.value = true;
diff --git a/frontend/src/components/CustomApproval/Settings/components/CustomApproval/RulesPanel/template.ts b/frontend/src/components/CustomApproval/Settings/components/CustomApproval/RulesPanel/template.ts
new file mode 100644
index 0000000000..eedf629227
--- /dev/null
+++ b/frontend/src/components/CustomApproval/Settings/components/CustomApproval/RulesPanel/template.ts
@@ -0,0 +1,51 @@
+import { create } from "@bufbuild/protobuf";
+import { computed } from "vue";
+import type { ConditionGroupExpr } from "@/plugins/cel";
+import { ExprType, wrapAsGroup } from "@/plugins/cel";
+import { t } from "@/plugins/i18n";
+import { PresetRoleType } from "@/types";
+import { ApprovalFlowSchema } from "@/types/proto-es/v1/issue_service_pb";
+
+export type ApprovalRuleTemplate = {
+ title: () => string;
+ description: () => string;
+ expr: ConditionGroupExpr;
+ roles: string[];
+};
+
+export const useApprovalRuleTemplates = () => {
+ const templates = computed((): ApprovalRuleTemplate[] => {
+ return [
+ {
+ title: () =>
+ t("custom-approval.approval-flow.template.presets.fallback"),
+ description: () =>
+ t(
+ "custom-approval.approval-flow.template.preset-descriptions.fallback"
+ ),
+ // The condition "true" matches all requests not matched by other rules.
+ expr: wrapAsGroup({
+ type: ExprType.RawString,
+ content: "true",
+ }),
+ roles: [PresetRoleType.PROJECT_OWNER],
+ },
+ ];
+ });
+
+ return templates;
+};
+
+export const applyTemplateToState = (
+ template: ApprovalRuleTemplate
+): {
+ title: string;
+ conditionExpr: ConditionGroupExpr;
+ flow: ReturnType<typeof create<typeof ApprovalFlowSchema>>;
+} => {
+ return {
+ title: template.title(),
+ conditionExpr: template.expr,
+ flow: create(ApprovalFlowSchema, { roles: [...template.roles] }),
+ };
+};
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index a6fa773846..5ac40c9185 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -2688,7 +2688,16 @@
"review-sent-back-by": "Review sent back by {user}"
},
"add-rule": "Add rule",
- "edit-rule": "Edit rule"
+ "edit-rule": "Edit rule",
+ "template": {
+ "presets-title": "Presets",
+ "presets": {
+ "fallback": "Fallback Rule"
+ },
+ "preset-descriptions": {
+ "fallback": "A catch-all rule that matches all requests. Place at the end of your rules list."
+ }
+ }
},
"risk": {
"risks": "Risks",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 482528cd63..89770f03d6 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -2688,7 +2688,16 @@
"review-sent-back-by": "Reseña enviada por {user}"
},
"add-rule": "Agregar regla",
- "edit-rule": "Editar regla"
+ "edit-rule": "Editar regla",
+ "template": {
+ "presets-title": "Plantillas",
+ "presets": {
+ "fallback": "Regla de respaldo"
+ },
+ "preset-descriptions": {
+ "fallback": "Una regla general que coincide con todas las solicitudes. Colóquela al final de su lista de reglas."
+ }
+ }
},
"risk": {
"risks": "Riesgo",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 2764a5c757..114347a43c 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -2688,7 +2688,16 @@
"review-sent-back-by": "{user} から承認が返されました"
},
"add-rule": "ルールを追加",
- "edit-rule": "ルールを編集"
+ "edit-rule": "ルールを編集",
+ "template": {
+ "presets-title": "プリセット",
+ "presets": {
+ "fallback": "フォールバックルール"
+ },
+ "preset-descriptions": {
+ "fallback": "すべてのリクエストに一致するキャッチオールルール。ルールリストの最後に配置してください。"
+ }
+ }
},
"risk": {
"risks": "リスク",
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 611c7d12eb..50935eacb7 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -2688,7 +2688,16 @@
"review-sent-back-by": "Đánh giá đã gửi lại bởi {user}"
},
"add-rule": "Thêm quy tắc",
- "edit-rule": "Chỉnh sửa quy tắc"
+ "edit-rule": "Chỉnh sửa quy tắc",
+ "template": {
+ "presets-title": "Mẫu có sẵn",
+ "presets": {
+ "fallback": "Quy tắc dự phòng"
+ },
+ "preset-descriptions": {
+ "fallback": "Quy tắc bắt tất cả khớp với mọi yêu cầu. Đặt ở cuối danh sách quy tắc của bạn."
+ }
+ }
},
"risk": {
"risks": "Rủi ro",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 65998c18e1..6837897c31 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -2688,7 +2688,16 @@
"review-sent-back-by": "审批被 {user} 退回"
},
"add-rule": "添加规则",
- "edit-rule": "编辑规则"
+ "edit-rule": "编辑规则",
+ "template": {
+ "presets-title": "预设模板",
+ "presets": {
+ "fallback": "兜底规则"
+ },
+ "preset-descriptions": {
+ "fallback": "匹配所有请求的兜底规则,请将其放在规则列表的末尾。"
+ }
+ }
},
"risk": {
"risks": "风险",