Skip to content

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

feat(frontend): cancel plan check runs (#12837)

boojackf4e390ac8f50
diff --git a/backend/api/v1/acl_iam.go b/backend/api/v1/acl_iam.go
index eb9209c23f..d46596072b 100644
--- a/backend/api/v1/acl_iam.go
+++ b/backend/api/v1/acl_iam.go
@@ -122,7 +122,9 @@ func isSkippedMethod(fullMethod string) bool {
return true
// handled in the method because we need to consider plan.Creator.
case
- v1pb.PlanService_UpdatePlan_FullMethodName:
+ v1pb.PlanService_UpdatePlan_FullMethodName,
+ // TODO: maybe needs to add permission checks.
+ v1pb.PlanService_BatchCancelPlanCheckRuns_FullMethodName:
return true
// handled in the method because we need to consider issue.Creator and issue type.
// additional bb.plans.action and bb.rollouts.action permissions are required if the issue type is change database.
diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckBadge.vue b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckBadge.vue
index b20c806fc9..ad3e2f8a11 100644
--- a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckBadge.vue
+++ b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckBadge.vue
@@ -87,7 +87,7 @@ const buttonClasses = computed(() => {
case PlanCheckRun_Status.RUNNING:
bgColor = "bg-blue-100";
textColor = "text-blue-800";
- borderColor = "bg-blue-800";
+ borderColor = "border-blue-800";
break;
case PlanCheckRun_Status.FAILED:
bgColor = "bg-red-100";
diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue
index 8ff2d20c83..4876ee2c08 100644
--- a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue
+++ b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue
@@ -1,5 +1,14 @@
<template>
<div class="flex flex-col gap-y-0.5">
+ <div v-if="showCancelButton">
+ <NButton secondary size="small" @click="cancelPlanCheckRun">
+ <template #icon>
+ <XIcon class="w-4 h-auto" />
+ </template>
+ {{ $t("common.cancel") }}
+ </NButton>
+ </div>
+
<div
v-for="(row, i) in highlightTableRows"
:key="i"
@@ -231,13 +240,22 @@
</template>
<script setup lang="ts">
+import { XIcon } from "lucide-vue-next";
+import { NButton } from "naive-ui";
import { computed, reactive } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
+import { useIssueContext } from "@/components/IssueV1/logic";
import { SQLRuleEditDialog } from "@/components/SQLReview/components";
import HideInStandaloneMode from "@/components/misc/HideInStandaloneMode.vue";
+import { planServiceClient } from "@/grpcweb";
import { WORKSPACE_ROUTE_SQL_REVIEW } from "@/router/dashboard/workspaceRoutes";
import { useReviewPolicyForDatabase } from "@/store";
+import {
+ getProjectNamePlanIdPlanCheckRunId,
+ planNamePrefix,
+ projectNamePrefix,
+} from "@/store/modules/v1/common";
import type { RuleTemplateV2, ComposedDatabase } from "@/types";
import {
GeneralErrorCode,
@@ -279,6 +297,8 @@ const props = defineProps<{
database?: ComposedDatabase;
}>();
+const { events } = useIssueContext();
+
const { t } = useI18n();
const router = useRouter();
const state = reactive<LocalState>({
@@ -325,6 +345,11 @@ const checkResultList = computed((): PlanCheckRun_Result[] => {
return [];
});
+const showCancelButton = computed(
+ // Only allow canceling plan check run when it's running.
+ () => props.planCheckRun.status === PlanCheckRun_Status.RUNNING
+);
+
const getRuleTemplateByType = (type: string) => {
if (props.database) {
return ruleTemplateMapV2
@@ -467,4 +492,15 @@ const handleClickPlanCheckDetailLine = (line: number) => {
window.location.hash = `L${line}`;
emit("close");
};
+
+const cancelPlanCheckRun = async () => {
+ const planCheckRunName = props.planCheckRun.name;
+ const [projectName, planId] =
+ getProjectNamePlanIdPlanCheckRunId(planCheckRunName);
+ await planServiceClient.batchCancelPlanCheckRuns({
+ parent: `${projectNamePrefix}${projectName}/${planNamePrefix}${planId}`,
+ planCheckRuns: [planCheckRunName],
+ });
+ events.emit("status-changed", { eager: true });
+};
</script>
diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckRunButton.vue b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckRunButton.vue
index 6c2b651213..30973299ea 100644
--- a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckRunButton.vue
+++ b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckRunButton.vue
@@ -5,7 +5,7 @@
:disabled="hasRunningPlanCheck"
preference-key="issue.task.run-checks"
default-action-key="RUN-CHECKS"
- @click="$emit('run-checks')"
+ @click="handleRunChecks"
>
<template #icon>
<BBSpin v-if="hasRunningPlanCheck" :size="20" />
@@ -26,7 +26,7 @@
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import {
- planCheckRunListForSpec,
+ planCheckRunListForTask,
useIssueContext,
} from "@/components/IssueV1/logic";
import type { ContextMenuButtonAction } from "@/components/v2";
@@ -34,12 +34,12 @@ import { ContextMenuButton } from "@/components/v2";
import { IssueStatus } from "@/types/proto/v1/issue_service";
import { PlanCheckRun_Status } from "@/types/proto/v1/plan_service";
-defineEmits<{
+const emit = defineEmits<{
(event: "run-checks"): void;
}>();
const { t } = useI18n();
-const { isCreating, issue, selectedSpec } = useIssueContext();
+const { isCreating, issue, selectedTask } = useIssueContext();
const allowRunCheckForIssue = computed(() => {
if (isCreating.value) {
@@ -66,12 +66,18 @@ const actionList = computed(() => {
const hasRunningPlanCheck = computed((): boolean => {
if (isCreating.value) return false;
- const planCheckRunList = planCheckRunListForSpec(
+ const planCheckRunList = planCheckRunListForTask(
issue.value,
- selectedSpec.value
+ selectedTask.value
);
return planCheckRunList.some(
(checkRun) => checkRun.status === PlanCheckRun_Status.RUNNING
);
});
+
+const handleRunChecks = () => {
+ if (!allowRunCheckForIssue.value) return;
+ if (hasRunningPlanCheck.value) return;
+ emit("run-checks");
+};
</script>
diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckSection.vue b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckSection.vue
index e604aba444..1ea563fed4 100644
--- a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckSection.vue
+++ b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckSection.vue
@@ -21,9 +21,9 @@
import { NButton } from "naive-ui";
import { computed } from "vue";
import {
- planCheckRunListForSpec,
planCheckRunListForTask,
planSpecHasPlanChecks,
+ specForTask,
useIssueContext,
} from "@/components/IssueV1/logic";
import { planServiceClient } from "@/grpcweb";
@@ -33,16 +33,17 @@ import { extractUserResourceName, hasProjectPermissionV2 } from "@/utils";
import PlanCheckBar from "./PlanCheckBar";
const currentUser = useCurrentUserV1();
-const { isCreating, issue, selectedSpec, selectedTask } = useIssueContext();
+const { isCreating, issue, selectedTask } = useIssueContext();
const show = computed(() => {
if (isCreating.value) {
return false;
}
- if (selectedSpec.value.id === String(EMPTY_ID)) {
+ const spec = specForTask(issue.value.planEntity, selectedTask.value);
+ if (!spec) {
return false;
}
- return planSpecHasPlanChecks(selectedSpec.value);
+ return planSpecHasPlanChecks(spec);
});
const allowRunChecks = computed(() => {
@@ -70,10 +71,6 @@ const planCheckRunList = computed(() => {
if (selectedTask.value && selectedTask.value.uid !== String(EMPTY_ID)) {
return planCheckRunListForTask(issue.value, selectedTask.value);
}
- // If a spec is selected, show plan checks for the spec.
- if (selectedSpec.value && selectedSpec.value.id !== String(EMPTY_ID)) {
- return planCheckRunListForSpec(issue.value, selectedSpec.value);
- }
// Otherwise, show plan checks for the issue.
return issue.value.planCheckRunList;
});
diff --git a/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckBadge.vue b/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckBadge.vue
index 35ad0b4bc8..48c6e33274 100644
--- a/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckBadge.vue
+++ b/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckBadge.vue
@@ -45,7 +45,7 @@ import { computed, ref } from "vue";
import { SQLCheckPanel } from "@/components/SQLCheck";
import type { Advice } from "@/types/proto/v1/sql_service";
import { Advice_Status } from "@/types/proto/v1/sql_service";
-import { databaseForSpec, databaseForTask, useIssueContext } from "../../logic";
+import { databaseForTask, useIssueContext } from "../../logic";
import OnlineMigrationAdviceExtra from "./OnlineMigrationAdviceExtra.vue";
const props = defineProps<{
@@ -57,15 +57,11 @@ defineEmits<{
(event: "click"): void;
}>();
-const { issue, selectedTask, selectedSpec, events } = useIssueContext();
+const { issue, selectedTask, events } = useIssueContext();
const showDetailPanel = ref(false);
-const rolloutMode = computed(() => !!issue.value.rollout);
-
const database = computed(() => {
- return rolloutMode.value
- ? databaseForTask(issue.value, selectedTask.value)
- : databaseForSpec(issue.value, selectedSpec.value);
+ return databaseForTask(issue.value, selectedTask.value);
});
const status = computed(() => {
diff --git a/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckSection.vue b/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckSection.vue
index f83b5dcc88..2f2a8f8d56 100644
--- a/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckSection.vue
+++ b/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckSection.vue
@@ -44,7 +44,6 @@ import {
useIssueContext,
databaseForTask,
specForTask,
- databaseForSpec,
} from "@/components/IssueV1/logic";
import { SQLCheckButton } from "@/components/SQLCheck";
import { TaskTypeListWithStatement } from "@/types";
@@ -60,15 +59,11 @@ defineEmits<{
(event: "update:advices", advices: Advice[] | undefined): void;
}>();
-const { issue, selectedTask, selectedSpec, events } = useIssueContext();
+const { issue, selectedTask, events } = useIssueContext();
const { sheetStatement } = useTaskSheet();
-const rolloutMode = computed(() => !!issue.value.rollout);
-
const database = computed(() => {
- return rolloutMode.value
- ? databaseForTask(issue.value, selectedTask.value)
- : databaseForSpec(issue.value, selectedSpec.value);
+ return databaseForTask(issue.value, selectedTask.value);
});
const show = computed(() => {
diff --git a/frontend/src/components/IssueV1/components/StatementSection/EditorView/useTempEditState.ts b/frontend/src/components/IssueV1/components/StatementSection/EditorView/useTempEditState.ts
index 4f15d56a88..fb477e3563 100644
--- a/frontend/src/components/IssueV1/components/StatementSection/EditorView/useTempEditState.ts
+++ b/frontend/src/components/IssueV1/components/StatementSection/EditorView/useTempEditState.ts
@@ -9,20 +9,14 @@ export type EditState = {
};
export const useTempEditState = (state: EditState) => {
- const { isCreating, issue, selectedTask } = useIssueContext();
+ const { isCreating, selectedTask } = useIssueContext();
const { sheet, sheetName, sheetReady, sheetStatement } = useTaskSheet();
- const rolloutMode = computed(() => !!issue.value.rollout);
let stopWatching = () => {
// noop
};
const startWatching = () => {
- // In non-rollout mode, we don't have the task sheet.
- if (!rolloutMode.value) {
- return () => {};
- }
-
const tempEditStateMap = new Map<string, EditState>();
const isSwitchingTask = ref(false);
@@ -31,7 +25,6 @@ export const useTempEditState = (state: EditState) => {
// So we need to watch the id instead of the object ref.
const selectedTaskUID = computed((): string => {
if (isCreating.value) return String(UNKNOWN_ID);
- if (!rolloutMode.value) return String(UNKNOWN_ID);
return selectedTask.value.uid;
});
diff --git a/frontend/src/components/IssueV1/components/StatementSection/StatementSection.vue b/frontend/src/components/IssueV1/components/StatementSection/StatementSection.vue
index 9456547d83..c61ebd5b83 100644
--- a/frontend/src/components/IssueV1/components/StatementSection/StatementSection.vue
+++ b/frontend/src/components/IssueV1/components/StatementSection/StatementSection.vue
@@ -25,7 +25,7 @@ defineProps<{
advices?: Advice[];
}>();
-const { isCreating, selectedTask, selectedSpec } = useIssueContext();
+const { isCreating, selectedTask } = useIssueContext();
const editorViewRef = ref<InstanceType<typeof EditorView>>();
const router = useRouter();
@@ -46,10 +46,6 @@ const viewMode = computed((): ViewMode => {
return "EDITOR";
}
}
- if (selectedSpec.value.id !== String(EMPTY_ID)) {
- return "EDITOR";
- }
-
return "NONE";
});
diff --git a/frontend/src/store/modules/v1/common.ts b/frontend/src/store/modules/v1/common.ts
index 265d32b7b9..36d1794266 100644
--- a/frontend/src/store/modules/v1/common.ts
+++ b/frontend/src/store/modules/v1/common.ts
@@ -23,6 +23,8 @@ export const protectionRulesSuffix = "/protectionRules";
export const issueCommentNamePrefix = "issueComments/";
export const userGroupNamePrefix = "groups/";
export const reviewConfigNamePrefix = "reviewConfigs/";
+export const planNamePrefix = "plans/";
+export const planCheckRunPrefix = "planCheckRuns/";
export const getNameParentTokens = (
name: string,
@@ -71,6 +73,15 @@ export const getProjectName = (name: string): string => {
return projectId;
};
+export const getProjectNamePlanIdPlanCheckRunId = (name: string): string[] => {
+ const tokens = getNameParentTokens(name, [
+ projectNamePrefix,
+ planNamePrefix,
+ planCheckRunPrefix,
+ ]);
+ return [tokens[0], tokens[1], tokens[2]];
+};
+
export const getWorksheetId = (name: string): string => {
const tokens = getNameParentTokens(name, [worksheetNamePrefix]);
return tokens[0];