Skip to content

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

chore: add create issue button to plan detail page (#12129)

boojack4f027ec4fb8f
diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/Actions.vue b/frontend/src/components/Plan/components/HeaderSection/Actions/Actions.vue
index d2228d9e56..5631169a04 100644
--- a/frontend/src/components/Plan/components/HeaderSection/Actions/Actions.vue
+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/Actions.vue
@@ -1,21 +1,46 @@
<template>
- <div class="flex flex-col items-end">
- <CreateButton v-if="actionType === 'CREATE'" />
+ <div class="h-full flex flex-row justify-end items-center">
+ <CreateButton v-if="isCreating" />
+ <template v-else>
+ <CreateIssueButton v-if="!relatedIssueUID" />
+ <div
+ v-else
+ :to="plan.issue"
+ class="flex flex-row justify-center items-center text-accent gap-1 cursor-pointer hover:opacity-80"
+ @click="gotoIssueDetailPage"
+ >
+ <span>{{ `${$t("common.issue")}#${relatedIssueUID}` }}</span>
+ <ExternalLinkIcon class="w-4 h-auto" />
+ </div>
+ </template>
</div>
</template>
<script setup lang="ts">
-import { asyncComputed } from "@vueuse/core";
+import { ExternalLinkIcon } from "lucide-vue-next";
+import { computed } from "vue";
+import { useRouter } from "vue-router";
import { usePlanContext } from "@/components/Plan/logic";
-import { CreateButton } from "./create";
+import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";
+import {
+ extractIssueUID,
+ extractProjectResourceName,
+ issueSlug,
+} from "@/utils";
+import { CreateButton, CreateIssueButton } from "./create";
-type ActionType = "CREATE";
+const router = useRouter();
+const { isCreating, plan } = usePlanContext();
-const { isCreating } = usePlanContext();
+const relatedIssueUID = computed(() => extractIssueUID(plan.value.issue));
-const actionType = asyncComputed(async (): Promise<ActionType | undefined> => {
- if (isCreating.value) {
- return "CREATE";
- }
-}, undefined);
+const gotoIssueDetailPage = () => {
+ router.push({
+ name: PROJECT_V1_ROUTE_ISSUE_DETAIL,
+ params: {
+ projectId: extractProjectResourceName(plan.value.project),
+ issueSlug: issueSlug(plan.value.title, relatedIssueUID.value),
+ },
+ });
+};
</script>
diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateButton.vue b/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateButton.vue
index 0fcae27d2b..8d5cae9468 100644
--- a/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateButton.vue
+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateButton.vue
@@ -53,6 +53,7 @@ import {
extractDeploymentConfigName,
extractProjectResourceName,
extractSheetUID,
+ flattenSpecList,
getSheetStatement,
hasProjectPermissionV2,
planSlug,
@@ -83,12 +84,8 @@ const planCreateErrorList = computed(() => {
if (!plan.value.title.trim()) {
errorList.push("Missing plan title");
}
- if (
- !plan.value.steps.every((step) =>
- step.specs.every((spec) => isValidSpec(spec))
- )
- ) {
- errorList.push("Missing SQL statement in some specs");
+ if (!flattenSpecList(plan.value).every((spec) => isValidSpec(spec))) {
+ errorList.push("Missing SQL statement in some tasks");
}
return errorList;
diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateIssueButton.vue b/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateIssueButton.vue
new file mode 100644
index 0000000000..7dc3d6bfe7
--- /dev/null
+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateIssueButton.vue
@@ -0,0 +1,135 @@
+<template>
+ <NTooltip :disabled="issueCreateErrorList.length === 0" placement="top">
+ <template #trigger>
+ <NButton
+ type="primary"
+ size="medium"
+ tag="div"
+ :disabled="issueCreateErrorList.length > 0 || loading"
+ :loading="loading"
+ @click="doCreateIssue"
+ >
+ {{ loading ? $t("common.creating") : $t("issue.create-issue") }}
+ </NButton>
+ </template>
+
+ <template #default>
+ <ErrorList :errors="issueCreateErrorList" />
+ </template>
+ </NTooltip>
+
+ <!-- prevent clicking the page when creating in progress -->
+ <div
+ v-if="loading"
+ v-zindexable="{ enabled: true }"
+ class="fixed inset-0 pointer-events-auto flex flex-col items-center justify-center"
+ @click.stop.prevent
+ />
+</template>
+
+<script setup lang="ts">
+import { NTooltip, NButton } from "naive-ui";
+import { zindexable as vZindexable } from "vdirs";
+import { computed, nextTick, ref } from "vue";
+import { useI18n } from "vue-i18n";
+import { useRouter } from "vue-router";
+import { ErrorList } from "@/components/Plan/components/common";
+import { usePlanContext } from "@/components/Plan/logic";
+import { useSQLCheckContext } from "@/components/SQLCheck";
+import { issueServiceClient, rolloutServiceClient } from "@/grpcweb";
+import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";
+import { useCurrentUserV1 } from "@/store";
+import { emptyIssue, type ComposedIssue } from "@/types";
+import { Issue, IssueStatus, Issue_Type } from "@/types/proto/v1/issue_service";
+import {
+ extractProjectResourceName,
+ hasProjectPermissionV2,
+ issueSlug,
+} from "@/utils";
+
+const { t } = useI18n();
+const router = useRouter();
+const { plan } = usePlanContext();
+const { runSQLCheck } = useSQLCheckContext();
+const me = useCurrentUserV1();
+const loading = ref(false);
+
+const issueCreateErrorList = computed(() => {
+ const errorList: string[] = [];
+ if (
+ !hasProjectPermissionV2(
+ plan.value.projectEntity,
+ me.value,
+ "bb.plans.create"
+ )
+ ) {
+ errorList.push(t("common.missing-permission"));
+ }
+ if (!plan.value.title.trim()) {
+ errorList.push("Missing issue title");
+ }
+
+ return errorList;
+});
+
+const doCreateIssue = async () => {
+ loading.value = true;
+ const check = runSQLCheck.value;
+ if (check && !(await check())) {
+ loading.value = false;
+ return;
+ }
+
+ try {
+ const createdIssue = await issueServiceClient.createIssue({
+ parent: plan.value.project,
+ issue: {
+ ...Issue.fromPartial(buildIssue()),
+ rollout: "",
+ plan: plan.value.name,
+ },
+ });
+ const composedIssue: ComposedIssue = {
+ ...emptyIssue(),
+ ...createdIssue,
+ planEntity: plan.value,
+ };
+ const createdRollout = await rolloutServiceClient.createRollout({
+ parent: plan.value.project,
+ rollout: {
+ plan: plan.value.name,
+ },
+ });
+
+ composedIssue.rollout = createdRollout.name;
+ composedIssue.rolloutEntity = createdRollout;
+
+ nextTick(() => {
+ router.push({
+ name: PROJECT_V1_ROUTE_ISSUE_DETAIL,
+ params: {
+ projectId: extractProjectResourceName(plan.value.project),
+ issueSlug: issueSlug(composedIssue.title, composedIssue.uid),
+ },
+ });
+ });
+
+ return composedIssue;
+ } catch {
+ loading.value = false;
+ }
+};
+
+const buildIssue = () => {
+ const issue = emptyIssue();
+ const me = useCurrentUserV1();
+ issue.creator = `users/${me.value.email}`;
+ issue.creatorEntity = me.value;
+ issue.project = plan.value.projectEntity.name;
+ issue.projectEntity = plan.value.projectEntity;
+ issue.title = plan.value.title;
+ issue.status = IssueStatus.OPEN;
+ issue.type = Issue_Type.DATABASE_CHANGE;
+ return issue;
+};
+</script>
diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/create/index.ts b/frontend/src/components/Plan/components/HeaderSection/Actions/create/index.ts
index b30ba24e7e..14255371a7 100644
--- a/frontend/src/components/Plan/components/HeaderSection/Actions/create/index.ts
+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/create/index.ts
@@ -1,3 +1,4 @@
import CreateButton from "./CreateButton.vue";
+import CreateIssueButton from "./CreateIssueButton.vue";
-export { CreateButton };
+export { CreateButton, CreateIssueButton };
diff --git a/frontend/src/components/Plan/components/HeaderSection/HeaderSection.vue b/frontend/src/components/Plan/components/HeaderSection/HeaderSection.vue
index c241ae62bc..a5702f3c7d 100644
--- a/frontend/src/components/Plan/components/HeaderSection/HeaderSection.vue
+++ b/frontend/src/components/Plan/components/HeaderSection/HeaderSection.vue
@@ -1,6 +1,6 @@
<template>
<div
- class="flex flex-col sm:flex-row sm:items-start sm:justify-between gap-2 py-2 px-4"
+ class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 py-2 px-4"
>
<div class="flex-1 flex items-center gap-x-2">
<Title />
diff --git a/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue b/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue
index 6f04b5c9fc..b4073d00f5 100644
--- a/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue
+++ b/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue
@@ -329,6 +329,9 @@ const shouldShowEditButton = computed(() => {
if (state.isEditing) {
return false;
}
+ if (plan.value.issue) {
+ return false;
+ }
return true;
});
@@ -548,9 +551,12 @@ const handleUpdateStatement = async (statement: string, filename: string) => {
};
const applySpecStateToOthers = async () => {
- const specList = flattenSpecList(plan.value);
- for (let i = 0; i < specList.length; i++) {
- const spec = specList[i];
+ if (!selectedStep.value) {
+ return;
+ }
+
+ // Apply current statement to all other specs in the same step.
+ for (const spec of selectedStep.value.specs) {
const sheetName = sheetNameForSpec(spec);
if (!sheetName) continue;
const sheet = getLocalSheetByName(sheetName);
@@ -622,16 +628,16 @@ const updateStatement = async (statement: string) => {
});
};
-const handleStatementChange = (value: string) => {
+const handleStatementChange = (statement: string) => {
if (isEditorReadonly.value) {
return;
}
- state.statement = value;
+ state.statement = statement;
if (isCreating.value) {
// When creating an plan, update the local sheet directly.
if (!sheet.value) return;
- setSheetStatement(sheet.value, value);
+ setSheetStatement(sheet.value, statement);
}
};
diff --git a/frontend/src/components/Plan/components/StepSection/StepCard.vue b/frontend/src/components/Plan/components/StepSection/StepCard.vue
index e23e310521..0ba0f0dda1 100644
--- a/frontend/src/components/Plan/components/StepSection/StepCard.vue
+++ b/frontend/src/components/Plan/components/StepSection/StepCard.vue
@@ -11,7 +11,7 @@
</div>
<NTooltip
- v-if="isCreating && stepMissingStatement"
+ v-if="isCreating && !validateSpecs()"
trigger="hover"
placement="top"
>
@@ -54,17 +54,14 @@
import { head, isEqual, uniqBy } from "lodash-es";
import { NTooltip } from "naive-ui";
import { computed } from "vue";
-import { sheetNameForSpec } from "@/components/Plan";
import {
- getLocalSheetByName,
+ isValidSpec,
planCheckRunListForSpec,
planCheckRunSummaryForCheckRunList,
usePlanContext,
} from "@/components/Plan/logic";
-import { useSheetV1Store } from "@/store";
import type { Plan_Step } from "@/types/proto/v1/plan_service";
import { PlanCheckRun_Result_Status } from "@/types/proto/v1/plan_service";
-import { extractSheetUID, getSheetStatement } from "@/utils";
const props = defineProps<{
step: Plan_Step;
@@ -82,27 +79,9 @@ const stepClass = computed(() => {
return classList;
});
-const stepMissingStatement = computed(() => {
- for (const spec of props.step.specs) {
- const sheetName = sheetNameForSpec(spec);
- const uid = extractSheetUID(sheetName);
- if (uid.startsWith("-")) {
- const sheet = getLocalSheetByName(sheetName);
- if (getSheetStatement(sheet).length === 0) {
- return true;
- }
- } else {
- const sheet = useSheetV1Store().getSheetByName(sheetName);
- if (!sheet) {
- return true;
- }
- if (getSheetStatement(sheet).length === 0) {
- return true;
- }
- }
- }
- return false;
-});
+const validateSpecs = () => {
+ return props.step.specs.every((spec) => isValidSpec(spec));
+};
const planCheckStatus = computed((): PlanCheckRun_Result_Status => {
if (isCreating.value) return PlanCheckRun_Result_Status.UNRECOGNIZED;
diff --git a/frontend/src/components/Plan/components/StepSection/StepSection.vue b/frontend/src/components/Plan/components/StepSection/StepSection.vue
index 1602812197..55ea9e9d3a 100644
--- a/frontend/src/components/Plan/components/StepSection/StepSection.vue
+++ b/frontend/src/components/Plan/components/StepSection/StepSection.vue
@@ -8,7 +8,7 @@
>
<template
v-for="(step, index) in stepList"
- :key="`${index}-${step - title}`"
+ :key="`${index}-${step.title}`"
>
<StepCard
:step="step"
diff --git a/frontend/src/components/Plan/logic/sheet.ts b/frontend/src/components/Plan/logic/sheet.ts
index ad6a875b7b..7438429497 100644
--- a/frontend/src/components/Plan/logic/sheet.ts
+++ b/frontend/src/components/Plan/logic/sheet.ts
@@ -7,7 +7,7 @@ export const createEmptyLocalSheet = () => {
return reactive(Sheet.fromJSON({}));
};
-export const getLocalSheetByName = (name: string) => {
+export const getLocalSheetByName = (name: string): Sheet => {
const existed = sheetsByName.get(name);
if (existed) {
return existed;
diff --git a/frontend/src/components/v2/Model/Instance/InstanceName.vue b/frontend/src/components/v2/Model/Instance/InstanceName.vue
deleted file mode 100644
index 52c01450e7..0000000000
--- a/frontend/src/components/v2/Model/Instance/InstanceName.vue
+++ /dev/null
@@ -1,58 +0,0 @@
-<template>
- <component
- :is="link ? 'router-link' : tag"
- v-bind="bindings"
- :to="link && `/${instance.name}`"
- class="inline-flex items-center gap-x-1"
- :class="link && 'normal-link'"
- >
- <InstanceEngineIcon
- v-if="icon && iconPosition === 'prefix'"
- :instance="instance"
- />
-
- <span>{{ instanceName(instance) }}</span>
-
- <InstanceEngineIcon
- v-if="icon && iconPosition === 'suffix'"
- :instance="instance"
- />
- </component>
-</template>
-
-<script lang="ts" setup>
-import { computed } from "vue";
-import InstanceEngineIcon from "@/components/InstanceEngineIcon.vue";
-import type { Instance } from "@/types";
-import { instanceName } from "@/utils";
-
-const props = withDefaults(
- defineProps<{
- instance: Instance;
- tag?: string;
- link?: boolean;
- icon?: boolean;
- iconPosition?: "prefix" | "suffix";
- }>(),
- {
- tag: "span",
- link: true,
- icon: true,
- iconPosition: "prefix",
- }
-);
-
-const bindings = computed(() => {
- if (props.link) {
- return {
- to: `/${props.instance.name}`,
- activeClass: "",
- exactActiveClass: "",
- onClick: (e: MouseEvent) => {
- e.stopPropagation();
- },
- };
- }
- return {};
-});
-</script>
diff --git a/frontend/src/components/v2/Model/Instance/index.ts b/frontend/src/components/v2/Model/Instance/index.ts
index d2f49219de..aca1487586 100644
--- a/frontend/src/components/v2/Model/Instance/index.ts
+++ b/frontend/src/components/v2/Model/Instance/index.ts
@@ -1,5 +1,4 @@
import InstanceEngineRadioGrid from "./InstanceEngineRadioGrid.vue";
-import InstanceName from "./InstanceName.vue";
import InstanceRoleTable from "./InstanceRoleTable";
import InstanceV1EngineIcon from "./InstanceV1EngineIcon.vue";
import InstanceV1Name from "./InstanceV1Name.vue";
@@ -7,7 +6,6 @@ import InstanceV1Table from "./InstanceV1Table";
import RichEngineName from "./RichEngineName.vue";
export {
- InstanceName,
InstanceEngineRadioGrid,
InstanceV1Name,
InstanceV1EngineIcon,
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 7a5963da60..6e342e5ebf 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1223,7 +1223,8 @@
"sql-review": {
"statement-type": "Statement type"
},
- "sql-review-only": "SQL Review Only"
+ "sql-review-only": "SQL Review Only",
+ "create-issue": "Create issue"
},
"alter-schema": {
"vcs-enabled": "This project has enabled VCS based version control and selecting database below will navigate you to the corresponding Git repository to initiate the change process.",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 701a2e0375..1978174216 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -1223,7 +1223,8 @@
"sql-review": {
"statement-type": "Tipo de declaración"
},
- "sql-review-only": "Sólo revisión de SQL"
+ "sql-review-only": "Sólo revisión de SQL",
+ "create-issue": "Crear problema"
},
"alter-schema": {
"vcs-enabled": "Este proyecto ha habilitado el control de versiones basado en VCS y seleccionar la base de datos a continuación lo llevará al repositorio Git correspondiente para iniciar el proceso de cambio.",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 233654c756..95ed35dfcc 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -1223,7 +1223,8 @@
"sql-review": {
"statement-type": "ステートメントタイプ"
},
- "sql-review-only": "SQLレビューのみ"
+ "sql-review-only": "SQLレビューのみ",
+ "create-issue": "問題を作成"
},
"alter-schema": {
"vcs-enabled": "このプロジェクトでは、VCS ベースのバージョン管理が有効になっています。以下のデータベースを選択すると、対応する Git リポジトリに移動して、変更プロセスを開始します。",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index eb7e92fb92..5e1589b470 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1223,7 +1223,8 @@
"sql-review": {
"statement-type": "语句类型"
},
- "sql-review-only": "仅 SQL 审核"
+ "sql-review-only": "仅 SQL 审核",
+ "create-issue": "创建变更工单"
},
"alter-schema": {
"vcs-enabled": "该项目开启了基于 VCS 的版本管理,选择下面的数据库会将您导航到相应的 Git 仓库以发起变更流程。",