Skip to content

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

feat: click plan check detail line anchor element will navigate to line (#11914)

h3n4lbbb89cbde965
diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue
index 0c0adc914f..a7daded755 100644
--- a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue
+++ b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue
@@ -74,6 +74,20 @@
{{ row.link.title }}
</a>
+ <template v-if="row.checkResult.sqlReviewReport?.line">
+ <span class="border-r border-control-border ml-1"></span>
+ <span
+ class="ml-1 normal-link"
+ @click="
+ handleClickPlanCheckDetailLine(
+ row.checkResult.sqlReviewReport.line
+ )
+ "
+ >
+ L{{ row.checkResult.sqlReviewReport.line }}
+ </span>
+ </template>
+
<slot name="row-extra" :row="row" />
</div>
</div>
@@ -125,7 +139,6 @@ interface ErrorCodeLink {
target: string;
url: string;
}
-
type PreviewSQLReviewRule = {
rule: RuleTemplate;
payload: PayloadValueType[];
@@ -155,6 +168,10 @@ const state = reactive<LocalState>({
activeResultDefinition: undefined,
});
+const emit = defineEmits<{
+ (event: "close"): void;
+}>();
+
const statusIconClass = (status: PlanCheckRun_Result_Status) => {
switch (status) {
case PlanCheckRun_Result_Status.SUCCESS:
@@ -309,4 +326,9 @@ const getActiveRule = (type: string): PreviewSQLReviewRule | undefined => {
const setActiveRule = (type: string) => {
state.activeRule = getActiveRule(type);
};
+
+const handleClickPlanCheckDetailLine = (line: number) => {
+ window.location.hash = `L${line}`;
+ emit("close");
+};
</script>
diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckPanel.vue b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckPanel.vue
index 9c2ee8df98..f4c513de4c 100644
--- a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckPanel.vue
+++ b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckPanel.vue
@@ -25,6 +25,7 @@
v-if="selectedPlanCheckRun"
:plan-check-run="selectedPlanCheckRun"
:environment="environment"
+ @close="$emit('close')"
/>
</div>
</BBModal>
diff --git a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
index 962e084d96..1529490147 100644
--- a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
+++ b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
@@ -128,6 +128,7 @@
:data-height="editorContainerHeight"
>
<MonacoEditor
+ ref="monacoEditorRef"
class="w-full h-auto max-h-[240px] min-h-[120px] border rounded-[3px]"
:filename="filename"
:content="state.statement"
@@ -283,6 +284,7 @@ const { events, isCreating, issue, selectedTask, formatOnSave } =
const project = computed(() => issue.value.projectEntity);
const dialog = useDialog();
const editorContainerElRef = ref<HTMLElement>();
+const monacoEditorRef = ref<InstanceType<typeof MonacoEditor>>();
const { height: editorContainerHeight } = useElementSize(editorContainerElRef);
const state = reactive<LocalState>({
@@ -744,4 +746,10 @@ watch(isCreating, (curr, prev) => {
state.isEditing = false;
}
});
+
+defineExpose({
+ get editor() {
+ return monacoEditorRef.value;
+ },
+});
</script>
diff --git a/frontend/src/components/IssueV1/components/StatementSection/StatementSection.vue b/frontend/src/components/IssueV1/components/StatementSection/StatementSection.vue
index a10dd0e249..16b9288010 100644
--- a/frontend/src/components/IssueV1/components/StatementSection/StatementSection.vue
+++ b/frontend/src/components/IssueV1/components/StatementSection/StatementSection.vue
@@ -1,12 +1,15 @@
<template>
<div v-if="viewMode !== 'NONE'" class="px-4 py-2 flex flex-col gap-y-2">
- <EditorView v-if="viewMode === 'EDITOR'" />
+ <EditorView v-if="viewMode === 'EDITOR'" ref="editorViewRef" />
<SDLView v-if="viewMode === 'SDL'" />
</div>
</template>
<script setup lang="ts">
import { computed } from "vue";
+import { ref } from "vue";
+import { nextTick } from "vue";
+import { useRouter } from "vue-router";
import { TaskTypeListWithStatement } from "@/types";
import { Task_Type } from "@/types/proto/v1/rollout_service";
import { useIssueContext } from "../../logic";
@@ -15,6 +18,9 @@ import SDLView from "./SDLView";
const { isCreating, selectedTask } = useIssueContext();
+const editorViewRef = ref<InstanceType<typeof EditorView>>();
+const router = useRouter();
+
type ViewMode = "NONE" | "EDITOR" | "SDL";
const viewMode = computed((): ViewMode => {
@@ -32,4 +38,21 @@ const viewMode = computed((): ViewMode => {
return "NONE";
});
+
+router.afterEach((to) => {
+ if (to.hash) {
+ scrollToLineByHash(to.hash);
+ }
+});
+
+const scrollToLineByHash = (hash: string) => {
+ const match = hash.match(/^#L(\d+)$/);
+ if (!match) return;
+ const lineNumber = parseInt(match[1], 10);
+ nextTick(() => {
+ editorViewRef.value?.editor?.monacoEditor?.editor?.codeEditor?.revealLineNearTop(
+ lineNumber
+ );
+ });
+};
</script>
diff --git a/frontend/src/components/MonacoEditor/MonacoEditor.vue b/frontend/src/components/MonacoEditor/MonacoEditor.vue
index 1b3f3b2e63..c49523acdb 100644
--- a/frontend/src/components/MonacoEditor/MonacoEditor.vue
+++ b/frontend/src/components/MonacoEditor/MonacoEditor.vue
@@ -1,19 +1,23 @@
<template>
<MonacoTextModelEditor
+ ref="textModelEditorRef"
class="bb-monaco-editor"
:model="model"
- @update:content="(...args) => $emit('update:content', ...args)"
+ @update:content="handleChange"
/>
</template>
<script setup lang="ts">
import { v4 as uuidv4 } from "uuid";
import { computed, toRef } from "vue";
+import { ref } from "vue";
import type { Language } from "@/types";
-import MonacoTextModelEditor from "./MonacoTextModelEditor.vue";
+import type MonacoTextModelEditor from "./MonacoTextModelEditor.vue";
import { useMonacoTextModel } from "./text-model";
import { extensionNameOfLanguage } from "./utils";
+const textModelEditorRef = ref<InstanceType<typeof MonacoTextModelEditor>>();
+
const props = withDefaults(
defineProps<{
filename?: string;
@@ -44,6 +48,16 @@ const filename = computed(() => {
return `${uuidv4()}.${extensionNameOfLanguage(props.language)}`;
});
const model = useMonacoTextModel(filename, content, toRef(props, "language"));
+
+const handleChange = (value: string) => {
+ emit('update:content', value)
+};
+
+defineExpose({
+ get editor() {
+ return textModelEditorRef.value;
+ },
+});
</script>
<style lang="postcss" scoped>
diff --git a/frontend/src/components/MonacoEditor/MonacoTextModelEditor.vue b/frontend/src/components/MonacoEditor/MonacoTextModelEditor.vue
index 60603bbbdd..840e4ea60f 100644
--- a/frontend/src/components/MonacoEditor/MonacoTextModelEditor.vue
+++ b/frontend/src/components/MonacoEditor/MonacoTextModelEditor.vue
@@ -169,7 +169,9 @@ onBeforeUnmount(() => {
});
defineExpose({
- editorRef,
+ get codeEditor() {
+ return editorRef.value;
+ },
});
</script>
diff --git a/frontend/src/components/MonacoEditor/WrappedMonacoEditor.vue b/frontend/src/components/MonacoEditor/WrappedMonacoEditor.vue
index c8cb65abeb..828e7cee5a 100644
--- a/frontend/src/components/MonacoEditor/WrappedMonacoEditor.vue
+++ b/frontend/src/components/MonacoEditor/WrappedMonacoEditor.vue
@@ -1,6 +1,6 @@
<template>
<Suspense>
- <MonacoEditor v-bind="$attrs as any" />
+ <MonacoEditor ref="monacoEditorRef" v-bind="$attrs as any" />
<template #fallback>
<div ref="spinnerWrapperElRef" :class="classes">
<BBSpin />
@@ -19,6 +19,7 @@ const MonacoEditor = defineAsyncComponent(() => import("./MonacoEditor.vue"));
const spinnerWrapperElRef = ref<HTMLElement>();
const parentElRef = useParentElement(spinnerWrapperElRef);
+const monacoEditorRef = ref<InstanceType<typeof MonacoEditor>>();
const classes = computed(() => {
const classes: string[] = [
@@ -43,4 +44,10 @@ const classes = computed(() => {
classes.push("w-full", "h-full");
return classes;
});
+
+defineExpose({
+ get monacoEditor() {
+ return monacoEditorRef.value;
+ },
+});
</script>