Skip to content

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

fix: instance role section api calls and ui improvements (#17421)

boojack0d5177d94d89
diff --git a/frontend/src/components/Plan/components/Configuration/Configuration.vue b/frontend/src/components/Plan/components/Configuration/Configuration.vue
index 94f031d66e..fdf7b6ae71 100644
--- a/frontend/src/components/Plan/components/Configuration/Configuration.vue
+++ b/frontend/src/components/Plan/components/Configuration/Configuration.vue
@@ -4,10 +4,10 @@
{{ $t("plan.options.self") }}
</p>
<div class="w-auto flex flex-col gap-2">
+ <InstanceRoleSection v-if="shouldShowInstanceRoleSection" />
<TransactionModeSection v-if="shouldShowTransactionModeSection" />
<GhostSection v-if="shouldShowGhostSection" />
<PreBackupSection v-if="shouldShowPreBackupSection" />
- <InstanceRoleSection v-if="shouldShowInstanceRoleSection" />
</div>
</div>
</template>
diff --git a/frontend/src/components/Plan/components/Configuration/InstanceRoleSection/InstanceRoleSection.vue b/frontend/src/components/Plan/components/Configuration/InstanceRoleSection/InstanceRoleSection.vue
index db3181c8f9..2ecd1cab95 100644
--- a/frontend/src/components/Plan/components/Configuration/InstanceRoleSection/InstanceRoleSection.vue
+++ b/frontend/src/components/Plan/components/Configuration/InstanceRoleSection/InstanceRoleSection.vue
@@ -1,20 +1,25 @@
<template>
- <div
- class="w-full flex items-center justify-start gap-x-2 flex-wrap whitespace-nowrap"
- >
- <InstanceRoleSelect />
+ <div class="w-full flex items-center gap-3">
<NTooltip>
<template #trigger>
- <div class="textlabel flex items-center">
- <span>{{ $t("common.role.self") }}</span>
- </div>
+ <span class="text-sm font-medium cursor-help flex items-center gap-1">
+ {{ $t("common.role.self") }}
+ <heroicons:question-mark-circle class="w-4 h-4 text-gray-400" />
+ </span>
</template>
<template #default>
- <div class="max-w-[20rem]">
- {{ $t("instance.select-database-user") }}
+ <div class="max-w-xs space-y-1">
+ <p class="font-medium">{{ $t("plan.spec.role-selection.title") }}</p>
+ <p class="text-sm">
+ {{ $t("plan.spec.role-selection.description") }}
+ </p>
+ <p class="text-xs text-gray-400">
+ {{ $t("plan.spec.role-selection.technical-note") }}
+ </p>
</div>
</template>
</NTooltip>
+ <InstanceRoleSelect />
</div>
</template>
diff --git a/frontend/src/components/Plan/components/Configuration/InstanceRoleSection/InstanceRoleSelect.vue b/frontend/src/components/Plan/components/Configuration/InstanceRoleSection/InstanceRoleSelect.vue
index df9775936f..66a1d032de 100644
--- a/frontend/src/components/Plan/components/Configuration/InstanceRoleSection/InstanceRoleSelect.vue
+++ b/frontend/src/components/Plan/components/Configuration/InstanceRoleSection/InstanceRoleSelect.vue
@@ -9,6 +9,7 @@
:filterable="true"
:virtual-scroll="true"
:fallback-option="false"
+ :clearable="true"
:disabled="!allowChange"
:loading="loading"
/>
@@ -17,11 +18,16 @@
<script setup lang="tsx">
import { create } from "@bufbuild/protobuf";
import { NSelect, type SelectOption } from "naive-ui";
-import { computed, ref, watch } from "vue";
+import { computed, nextTick, ref, watch } from "vue";
+import {
+ usePlanContext,
+ updateSpecSheetWithStatement,
+} from "@/components/Plan/logic";
import { instanceRoleServiceClientConnect } from "@/grpcweb";
import { DEFAULT_PAGE_SIZE } from "@/store/modules/common";
import type { InstanceRole } from "@/types/proto-es/v1/instance_role_service_pb";
import { ListInstanceRolesRequestSchema } from "@/types/proto-es/v1/instance_role_service_pb";
+import { setSheetStatement } from "@/utils";
import { useSelectedSpec } from "../../SpecDetailView/context";
import {
parseStatement,
@@ -37,7 +43,11 @@ const {
events,
} = useInstanceRoleSettingContext();
const selectedSpec = useSelectedSpec();
-const { sheetStatement, updateSheetStatement } = useSpecSheet(selectedSpec);
+const { sheetStatement, sheet, sheetReady } = useSpecSheet(selectedSpec);
+const { plan, isCreating } = usePlanContext();
+
+// Flag to prevent circular updates
+const isUpdatingFromUI = ref(false);
const instanceRoles = ref<InstanceRole[]>([]);
const loading = ref(false);
@@ -45,10 +55,13 @@ const loading = ref(false);
const selectedRole = computed({
get: () => contextSelectedRole.value,
set: (value: string | undefined) => {
+ isUpdatingFromUI.value = true;
contextSelectedRole.value = value;
- if (value) {
- setRoleInStatement(value);
- }
+ setRoleInStatement(value);
+ // Reset the flag after Vue's next tick to allow statement updates to propagate
+ nextTick(() => {
+ isUpdatingFromUI.value = false;
+ });
},
});
@@ -92,6 +105,12 @@ const options = computed(() => {
// Initialize selected role from statement
const initializeFromStatement = () => {
+ if (!sheetReady.value || !sheetStatement.value) {
+ // If sheet is not ready or statement is empty, reset to undefined
+ contextSelectedRole.value = undefined;
+ return;
+ }
+
const parsed = parseStatement(sheetStatement.value);
if (parsed.roleSetterBlock) {
// Extract role name from the role setter block
@@ -118,9 +137,33 @@ watch(
}
);
-const setRoleInStatement = (roleName: string) => {
+// Watch for sheet statement changes to update role
+// Only update when statement changes externally, not when we change it ourselves
+watch(
+ [sheetStatement, sheetReady],
+ () => {
+ if (!isUpdatingFromUI.value) {
+ initializeFromStatement();
+ }
+ },
+ { immediate: true }
+);
+
+const setRoleInStatement = async (roleName: string | undefined) => {
const updatedStatement = updateRoleSetter(sheetStatement.value, roleName);
- updateSheetStatement(updatedStatement);
+
+ if (isCreating.value) {
+ // When creating a plan, update the local sheet directly.
+ if (!sheet.value) return;
+ setSheetStatement(sheet.value, updatedStatement);
+ } else {
+ // For created plans, create new sheet and update plan/spec
+ await updateSpecSheetWithStatement(
+ plan.value,
+ selectedSpec.value,
+ updatedStatement
+ );
+ }
events.emit("update");
};
</script>
diff --git a/frontend/src/components/Plan/components/StatementSection/directiveUtils.ts b/frontend/src/components/Plan/components/StatementSection/directiveUtils.ts
index e7d521d8ba..d7245a0b7a 100644
--- a/frontend/src/components/Plan/components/StatementSection/directiveUtils.ts
+++ b/frontend/src/components/Plan/components/StatementSection/directiveUtils.ts
@@ -101,7 +101,7 @@ export function updateTransactionMode(
*/
export function updateRoleSetter(
statement: string,
- roleName: string | null
+ roleName: string | undefined
): string {
const parsed = parseStatement(statement);
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index d1ddd87421..6d038ac9cf 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1131,6 +1131,11 @@
"delete-change": {
"title": "Delete Change",
"content": "Are you sure you want to delete this change?"
+ },
+ "role-selection": {
+ "title": "Database Role Selection",
+ "description": "Choose which PostgreSQL role to execute this statement as.",
+ "technical-note": "Adds \"SET ROLE {role};\" to your SQL statement."
}
},
"targets": {
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 0dd2a0c45f..354ac0a890 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -1131,6 +1131,11 @@
"delete-change": {
"title": "Eliminar cambio",
"content": "¿Está seguro de que desea eliminar este cambio?"
+ },
+ "role-selection": {
+ "title": "Selección de roles de base de datos",
+ "description": "Elija qué rol de PostgreSQL desea ejecutar como esta declaración.",
+ "technical-note": "Agrega \"SET ROLE {role};\" a su declaración SQL."
}
},
"targets": {
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index a60c42a7f9..19f54095ac 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -1131,6 +1131,11 @@
"delete-change": {
"title": "削除変更",
"content": "この変更を削除してもよろしいですか?"
+ },
+ "role-selection": {
+ "title": "データベースロールの選択",
+ "description": "このステートメントを実行する PostgreSQL ロールを選択します。",
+ "technical-note": "SQL ステートメントに「SET ROLE {role};」を追加します。"
}
},
"targets": {
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 73d0184c67..a356b43061 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -1131,6 +1131,11 @@
"delete-change": {
"title": "Xóa thay đổi",
"content": "Bạn có chắc chắn muốn xóa thay đổi này không?"
+ },
+ "role-selection": {
+ "title": "Lựa chọn vai trò cơ sở dữ liệu",
+ "description": "Chọn vai trò PostgreSQL để thực thi câu lệnh này.",
+ "technical-note": "Thêm \"SET ROLE {role};\" vào câu lệnh SQL của bạn."
}
},
"targets": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 719798192c..8148d9b173 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1131,6 +1131,11 @@
"delete-change": {
"title": "删除变更项",
"content": "您确定要删除该变更项吗?"
+ },
+ "role-selection": {
+ "title": "数据库角色选择",
+ "description": "选择以哪个 PostgreSQL 角色来执行此语句。",
+ "technical-note": "将“SET ROLE {role};”添加到您的 SQL 语句中。"
}
},
"targets": {