Skip to content

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

refactor(frontend): extract shared SpecLink component for plan spec updates (#18496)

boojack0db78abd4f1c
diff --git a/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionSentence.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionSentence.vue
index e7460c897c..331b409d4c 100644
--- a/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionSentence.vue
+++ b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionSentence.vue
@@ -5,20 +5,28 @@
<script lang="tsx" setup>
import { defineComponent } from "vue";
import { Translation, useI18n } from "vue-i18n";
+import { SpecLink } from "@/components/v2";
import {
extractUserId,
getIssueCommentType,
IssueCommentType,
useUserStore,
} from "@/store";
+import type { ComposedIssue } from "@/types";
import type { IssueComment } from "@/types/proto-es/v1/issue_service_pb";
import {
IssueComment_Approval_Status,
IssueStatus,
} from "@/types/proto-es/v1/issue_service_pb";
+import {
+ extractPlanUID,
+ extractProjectResourceName,
+ getSpecDisplayInfo,
+} from "@/utils";
import StatementUpdate from "./StatementUpdate.vue";
const props = defineProps<{
+ issue: ComposedIssue;
issueComment: IssueComment;
}>();
@@ -94,12 +102,25 @@ const renderActionSentence = () => {
commentType === IssueCommentType.PLAN_SPEC_UPDATE &&
issueComment.event?.case === "planSpecUpdate"
) {
- const { fromSheet, toSheet } = issueComment.event.value;
+ const { spec, fromSheet, toSheet } = issueComment.event.value;
if (fromSheet !== undefined && toSheet !== undefined) {
+ const specs = props.issue.planEntity?.specs ?? [];
+ const specInfo = getSpecDisplayInfo(specs, spec);
+ const planName = props.issue.planEntity?.name ?? props.issue.plan;
+ const projectName = extractProjectResourceName(props.issue.project);
+ const planUID = extractPlanUID(planName);
+
return (
- <Translation keypath="dynamic.activity.sentence.changed-x-link">
+ <Translation keypath="dynamic.activity.sentence.modified-sql-of-spec-link">
{{
- name: () => "SQL",
+ spec: () => (
+ <SpecLink
+ projectName={projectName}
+ planUID={planUID}
+ specId={specInfo?.specId ?? ""}
+ displayIndex={specInfo?.displayIndex ?? 0}
+ />
+ ),
link: () => (
<StatementUpdate oldSheet={fromSheet} newSheet={toSheet} />
),
diff --git a/frontend/src/components/Plan/components/IssueReviewView/ActivitySection/IssueCommentView/ActionSentence.vue b/frontend/src/components/Plan/components/IssueReviewView/ActivitySection/IssueCommentView/ActionSentence.vue
index d25b272296..1e307cf3f8 100644
--- a/frontend/src/components/Plan/components/IssueReviewView/ActivitySection/IssueCommentView/ActionSentence.vue
+++ b/frontend/src/components/Plan/components/IssueReviewView/ActivitySection/IssueCommentView/ActionSentence.vue
@@ -5,6 +5,8 @@
<script lang="tsx" setup>
import { defineComponent } from "vue";
import { Translation, useI18n } from "vue-i18n";
+import { usePlanContext } from "@/components/Plan/logic";
+import { SpecLink } from "@/components/v2";
import {
extractUserId,
getIssueCommentType,
@@ -16,6 +18,11 @@ import {
IssueComment_Approval_Status,
IssueStatus,
} from "@/types/proto-es/v1/issue_service_pb";
+import {
+ extractPlanUID,
+ extractProjectResourceName,
+ getSpecDisplayInfo,
+} from "@/utils";
import StatementUpdate from "./StatementUpdate.vue";
const props = defineProps<{
@@ -24,6 +31,7 @@ const props = defineProps<{
const { t } = useI18n();
const userStore = useUserStore();
+const { plan } = usePlanContext();
const maybeAutomaticallyVerb = (
issueComment: IssueComment,
@@ -93,12 +101,25 @@ const renderActionSentence = () => {
commentType === IssueCommentType.PLAN_SPEC_UPDATE &&
issueComment.event?.case === "planSpecUpdate"
) {
- const { fromSheet, toSheet } = issueComment.event.value;
+ const { spec, fromSheet, toSheet } = issueComment.event.value;
if (fromSheet !== undefined && toSheet !== undefined) {
+ const specs = plan.value.specs ?? [];
+ const specInfo = getSpecDisplayInfo(specs, spec);
+ const planName = plan.value.name;
+ const projectName = extractProjectResourceName(planName);
+ const planUID = extractPlanUID(planName);
+
return (
- <Translation keypath="dynamic.activity.sentence.changed-x-link">
+ <Translation keypath="dynamic.activity.sentence.modified-sql-of-spec-link">
{{
- name: () => "SQL",
+ spec: () => (
+ <SpecLink
+ projectName={projectName}
+ planUID={planUID}
+ specId={specInfo?.specId ?? ""}
+ displayIndex={specInfo?.displayIndex ?? 0}
+ />
+ ),
link: () => (
<StatementUpdate oldSheet={fromSheet} newSheet={toSheet} />
),
diff --git a/frontend/src/components/v2/Model/Plan/SpecLink.vue b/frontend/src/components/v2/Model/Plan/SpecLink.vue
new file mode 100644
index 0000000000..1ed0ffa18b
--- /dev/null
+++ b/frontend/src/components/v2/Model/Plan/SpecLink.vue
@@ -0,0 +1,36 @@
+<template>
+ <RouterLink
+ v-if="canLink"
+ :to="{
+ name: PROJECT_V1_ROUTE_PLAN_DETAIL_SPEC_DETAIL,
+ params: {
+ projectId: projectName,
+ planId: planUID,
+ specId: specId,
+ },
+ }"
+ class="inline-flex items-center gap-1 hover:underline"
+ >
+ {{ $t("plan.spec.change") }}
+ <NTag size="tiny" round> #{{ displayIndex }} </NTag>
+ </RouterLink>
+ <span v-else>{{ $t("plan.spec.change") }}</span>
+</template>
+
+<script lang="ts" setup>
+import { NTag } from "naive-ui";
+import { computed } from "vue";
+import { RouterLink } from "vue-router";
+import { PROJECT_V1_ROUTE_PLAN_DETAIL_SPEC_DETAIL } from "@/router/dashboard/projectV1";
+
+const props = defineProps<{
+ projectName: string;
+ planUID: string;
+ specId: string;
+ displayIndex: number;
+}>();
+
+const canLink = computed(() => {
+ return props.projectName && props.planUID && props.specId;
+});
+</script>
diff --git a/frontend/src/components/v2/Model/Plan/index.ts b/frontend/src/components/v2/Model/Plan/index.ts
new file mode 100644
index 0000000000..9136e32723
--- /dev/null
+++ b/frontend/src/components/v2/Model/Plan/index.ts
@@ -0,0 +1 @@
+export { default as SpecLink } from "./SpecLink.vue";
diff --git a/frontend/src/components/v2/Model/index.ts b/frontend/src/components/v2/Model/index.ts
index 720d41de6f..8a4c234b86 100644
--- a/frontend/src/components/v2/Model/index.ts
+++ b/frontend/src/components/v2/Model/index.ts
@@ -11,6 +11,7 @@ import ProjectV1Table from "./ProjectV1Table.vue";
import RichDatabaseName from "./RichDatabaseName.vue";
export * from "./Instance";
+export * from "./Plan";
export * from "./User";
export * from "./DatabaseV1Table";
export * from "./Project";
diff --git a/frontend/src/locales/dynamic/en-US.json b/frontend/src/locales/dynamic/en-US.json
index 636e0ff6a3..6e70a4de18 100644
--- a/frontend/src/locales/dynamic/en-US.json
+++ b/frontend/src/locales/dynamic/en-US.json
@@ -23,7 +23,8 @@
"sentence": {
"verb-type-target-by-people": "{verb} {type} {target}",
"verb-type-target-by-system-bot": "{type} {target} {verb}",
- "changed-x-link": "changed {name}. {link}"
+ "changed-x-link": "changed {name}. {link}",
+ "modified-sql-of-spec-link": "Modified SQL of {spec}. {link}"
}
},
"settings": {
diff --git a/frontend/src/locales/dynamic/es-ES.json b/frontend/src/locales/dynamic/es-ES.json
index eaeaefc51c..2d07ecc0cc 100644
--- a/frontend/src/locales/dynamic/es-ES.json
+++ b/frontend/src/locales/dynamic/es-ES.json
@@ -23,7 +23,8 @@
"sentence": {
"verb-type-target-by-people": "{verb} {type} {target}",
"verb-type-target-by-system-bot": "{type} {target} {verb}",
- "changed-x-link": "cambiado {name}. \n{link}"
+ "changed-x-link": "cambiado {name}. \n{link}",
+ "modified-sql-of-spec-link": "SQL modificado de {spec}. {link}"
}
},
"settings": {
diff --git a/frontend/src/locales/dynamic/ja-JP.json b/frontend/src/locales/dynamic/ja-JP.json
index c07790173f..28ef3581c4 100644
--- a/frontend/src/locales/dynamic/ja-JP.json
+++ b/frontend/src/locales/dynamic/ja-JP.json
@@ -23,7 +23,8 @@
"sentence": {
"verb-type-target-by-people": "{verb} {type} {target}",
"verb-type-target-by-system-bot": "{type} {target} {verb}",
- "changed-x-link": "{name} が変更されました。 {link}"
+ "changed-x-link": "{name} が変更されました。 {link}",
+ "modified-sql-of-spec-link": "{spec} の SQL が変更されました。{link}"
}
},
"settings": {
diff --git a/frontend/src/locales/dynamic/vi-VN.json b/frontend/src/locales/dynamic/vi-VN.json
index 8503e5a0ba..e7cc5b256b 100644
--- a/frontend/src/locales/dynamic/vi-VN.json
+++ b/frontend/src/locales/dynamic/vi-VN.json
@@ -23,7 +23,8 @@
"sentence": {
"verb-type-target-by-people": "{verb} {type} {target}",
"verb-type-target-by-system-bot": "{type} {target} {verb}",
- "changed-x-link": "đã thay đổi {name}. {link}"
+ "changed-x-link": "đã thay đổi {name}. {link}",
+ "modified-sql-of-spec-link": "Đã sửa đổi SQL của {spec}. {link}"
}
},
"settings": {
diff --git a/frontend/src/locales/dynamic/zh-CN.json b/frontend/src/locales/dynamic/zh-CN.json
index c72cafc9a2..1711449f58 100644
--- a/frontend/src/locales/dynamic/zh-CN.json
+++ b/frontend/src/locales/dynamic/zh-CN.json
@@ -23,7 +23,8 @@
"sentence": {
"verb-type-target-by-people": "{verb} {type} {target}",
"verb-type-target-by-system-bot": "{type} {target} {verb}",
- "changed-x-link": "修改了 {name}。{link}"
+ "changed-x-link": "修改了 {name}。{link}",
+ "modified-sql-of-spec-link": "修改了 {spec} 的 SQL。{link}"
}
},
"settings": {
diff --git a/frontend/src/utils/v1/issue/plan.ts b/frontend/src/utils/v1/issue/plan.ts
index c407d7cbdb..49cda7e995 100644
--- a/frontend/src/utils/v1/issue/plan.ts
+++ b/frontend/src/utils/v1/issue/plan.ts
@@ -32,3 +32,27 @@ export const extractPlanCheckRunUID = (name: string) => {
const matches = name.match(pattern);
return matches?.[1] ?? "";
};
+
+export const extractSpecId = (name: string) => {
+ const pattern = /(?:^|\/)specs\/([^/]+)(?:$|\/)/;
+ const matches = name.match(pattern);
+ return matches?.[1] ?? "";
+};
+
+/**
+ * Get spec display info from spec resource name.
+ * Returns specId and 1-based display index, or null if not found.
+ */
+export const getSpecDisplayInfo = (
+ specs: Plan_Spec[],
+ specResourceName: string
+): { specId: string; displayIndex: number } | null => {
+ const specId = extractSpecId(specResourceName);
+ if (!specId) return null;
+
+ const index = specs.findIndex((spec) => spec.id === specId);
+ if (index >= 0) {
+ return { specId, displayIndex: index + 1 };
+ }
+ return null;
+};