Skip to content

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

refactor(frontend): plan check run components (#12860)

boojackf5e830d786bc
diff --git a/frontend/src/components/AlterSchemaPrepForm/SchemaEditorSQLCheckButton/OnlineMigrationAdviceExtra.vue b/frontend/src/components/AlterSchemaPrepForm/SchemaEditorSQLCheckButton/OnlineMigrationAdviceExtra.vue
index 06be7ce0e7..9ae53fda31 100644
--- a/frontend/src/components/AlterSchemaPrepForm/SchemaEditorSQLCheckButton/OnlineMigrationAdviceExtra.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/SchemaEditorSQLCheckButton/OnlineMigrationAdviceExtra.vue
@@ -12,7 +12,7 @@
<script setup lang="ts">
import { computed } from "vue";
import { useI18n } from "vue-i18n";
-import type { PlanCheckDetailTableRow } from "@/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue";
+import type { PlanCheckDetailTableRow } from "@/components/PlanCheckRun/PlanCheckRunDetail.vue";
const props = defineProps<{
row: PlanCheckDetailTableRow;
diff --git a/frontend/src/components/IssueV1/components/Panel/IssueReviewActionPanel.vue b/frontend/src/components/IssueV1/components/Panel/IssueReviewActionPanel.vue
index 976598034b..77fef7bf50 100644
--- a/frontend/src/components/IssueV1/components/Panel/IssueReviewActionPanel.vue
+++ b/frontend/src/components/IssueV1/components/Panel/IssueReviewActionPanel.vue
@@ -17,12 +17,14 @@
</div>
</div>
- <PlanCheckBar
+ <PlanCheckRunBar
v-if="issue.planCheckRunList.length > 0"
class="shrink-0 flex-col gap-y-1"
label-class="!text-base"
:allow-run-checks="false"
+ :plan-name="issue.plan"
:plan-check-run-list="issue.planCheckRunList"
+ :database="database"
/>
<div v-if="planCheckErrors.length > 0" class="flex flex-col">
@@ -97,11 +99,12 @@ import {
issueReviewActionButtonProps,
issueReviewActionDisplayName,
planCheckRunSummaryForIssue,
+ databaseForTask,
} from "@/components/IssueV1/logic";
+import PlanCheckRunBar from "@/components/PlanCheckRun/PlanCheckRunBar.vue";
import RequiredStar from "@/components/RequiredStar.vue";
import { issueServiceClient } from "@/grpcweb";
import { Issue_Approver_Status } from "@/types/proto/v1/issue_service";
-import { PlanCheckBar } from "../PlanCheckSection";
import { ErrorList } from "../common";
import CommonDrawer from "./CommonDrawer.vue";
@@ -120,7 +123,7 @@ const { t } = useI18n();
const state = reactive<LocalState>({
loading: false,
});
-const { events, issue } = useIssueContext();
+const { events, issue, activeTask } = useIssueContext();
const comment = ref("");
const performActionAnyway = ref(false);
@@ -136,6 +139,10 @@ const title = computed(() => {
return ""; // Make linter happy
});
+const database = computed(() =>
+ databaseForTask(issue.value, activeTask.value)
+);
+
const planCheckErrors = computed(() => {
const errors: string[] = [];
if (props.action === "APPROVE") {
diff --git a/frontend/src/components/IssueV1/components/Panel/TaskRolloutActionPanel.vue b/frontend/src/components/IssueV1/components/Panel/TaskRolloutActionPanel.vue
index d2a3d4b275..fc3641eed5 100644
--- a/frontend/src/components/IssueV1/components/Panel/TaskRolloutActionPanel.vue
+++ b/frontend/src/components/IssueV1/components/Panel/TaskRolloutActionPanel.vue
@@ -55,7 +55,7 @@
</div>
</div>
- <PlanCheckBar
+ <PlanCheckRunBar
v-if="
(action === 'ROLLOUT' || action === 'RETRY') &&
planCheckRunList.length > 0
@@ -63,7 +63,9 @@
class="shrink-0 flex-col gap-y-1"
label-class="!text-base"
:allow-run-checks="false"
+ :plan-name="issue.plan"
:plan-check-run-list="planCheckRunList"
+ :database="database"
/>
<div v-if="planCheckErrors.length > 0" class="flex flex-col">
@@ -131,11 +133,10 @@ import { head, uniqBy } from "lodash-es";
import { NButton, NCheckbox, NInput, NScrollbar, NTooltip } from "naive-ui";
import { computed, reactive, ref } from "vue";
import { useI18n } from "vue-i18n";
-import { PlanCheckBar } from "@/components/IssueV1/components/PlanCheckSection";
import type { TaskRolloutAction } from "@/components/IssueV1/logic";
import {
+ databaseForTask,
planCheckRunListForTask,
- planCheckRunSummaryForCheckRunList,
semanticTaskType,
stageForTask,
taskRolloutActionButtonProps,
@@ -144,6 +145,8 @@ import {
taskRunListForTask,
useIssueContext,
} from "@/components/IssueV1/logic";
+import PlanCheckRunBar from "@/components/PlanCheckRun/PlanCheckRunBar.vue";
+import { planCheckRunSummaryForCheckRunList } from "@/components/PlanCheckRun/common";
import { rolloutServiceClient } from "@/grpcweb";
import { pushNotification } from "@/store";
import type { Task, TaskRun } from "@/types/proto/v1/rollout_service";
@@ -182,6 +185,8 @@ const title = computed(() => {
return action;
});
+const database = computed(() => databaseForTask(issue.value, activeTask.value));
+
const stage = computed(() => {
const firstTask = head(props.taskList);
if (!firstTask) return undefined;
diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckBadge.vue b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckBadge.vue
deleted file mode 100644
index ad3e2f8a11..0000000000
--- a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckBadge.vue
+++ /dev/null
@@ -1,163 +0,0 @@
-<template>
- <div class="issue-debug">
- <div>type: {{ type }}</div>
- <div>count in type: {{ planCheckRunList.length }}</div>
- <div>latest: {{ latestPlanCheckRun.name }}</div>
- </div>
-
- <button
- class="inline-flex items-center px-3 leading-6 rounded-full text-sm border"
- :class="buttonClasses"
- @click="clickable && $emit('click')"
- >
- <template v-if="status === PlanCheckRun_Status.RUNNING">
- <TaskSpinner class="-ml-1 mr-1.5 h-4 w-4 text-info" />
- </template>
- <template v-else-if="status === PlanCheckRun_Status.DONE">
- <template v-if="resultStatus === PlanCheckRun_Result_Status.SUCCESS">
- <heroicons-outline:check
- class="-ml-1 mr-1.5 mt-0.5 h-4 w-4 text-success"
- />
- </template>
- <template v-else-if="resultStatus === PlanCheckRun_Result_Status.WARNING">
- <heroicons-outline:exclamation
- class="-ml-1 mr-1.5 mt-0.5 h-4 w-4 text-warning"
- />
- </template>
- <template v-else-if="resultStatus === PlanCheckRun_Result_Status.ERROR">
- <span class="mr-1.5 font-medium text-error" aria-hidden="true">
- !
- </span>
- </template>
- </template>
- <template v-else-if="status === PlanCheckRun_Status.FAILED">
- <span class="mr-1.5 font-medium text-error" aria-hidden="true"> ! </span>
- </template>
- <template v-else-if="status === PlanCheckRun_Status.CANCELED">
- <heroicons-outline:ban class="-ml-1 mr-1.5 mt-0.5 h-4 w-4 text-control" />
- </template>
-
- <span>{{ name }}</span>
- </button>
-</template>
-
-<script setup lang="ts">
-import { maxBy } from "lodash-es";
-import { computed } from "vue";
-import { useI18n } from "vue-i18n";
-import { planCheckRunResultStatus } from "@/components/IssueV1/logic";
-import type { PlanCheckRun } from "@/types/proto/v1/plan_service";
-import {
- PlanCheckRun_Result_Status,
- PlanCheckRun_Status,
- PlanCheckRun_Type,
-} from "@/types/proto/v1/plan_service";
-import { TaskSpinner } from "../../common";
-
-const props = defineProps<{
- planCheckRunList: PlanCheckRun[];
- type: PlanCheckRun_Type;
- clickable?: boolean;
- selected?: boolean;
-}>();
-
-defineEmits<{
- (event: "click"): void;
-}>();
-
-const { t } = useI18n();
-
-const latestPlanCheckRun = computed(() => {
- return maxBy(props.planCheckRunList, (check) => Number(check.uid))!;
-});
-
-const status = computed(() => {
- return latestPlanCheckRun.value.status;
-});
-
-const resultStatus = computed(() => {
- return planCheckRunResultStatus(latestPlanCheckRun.value);
-});
-
-const buttonClasses = computed(() => {
- let bgColor = "";
- let textColor = "";
- let borderColor = "";
- switch (status.value) {
- case PlanCheckRun_Status.RUNNING:
- bgColor = "bg-blue-100";
- textColor = "text-blue-800";
- borderColor = "border-blue-800";
- break;
- case PlanCheckRun_Status.FAILED:
- bgColor = "bg-red-100";
- textColor = "text-red-800";
- borderColor = "border-red-800";
- break;
- case PlanCheckRun_Status.CANCELED:
- bgColor = "bg-yellow-100";
- textColor = "text-yellow-800";
- borderColor = "border-yellow-800";
- break;
- case PlanCheckRun_Status.DONE:
- switch (resultStatus.value) {
- case PlanCheckRun_Result_Status.SUCCESS:
- bgColor = "bg-gray-100";
- textColor = "text-gray-800";
- borderColor = "border-gray-800";
- break;
- case PlanCheckRun_Result_Status.WARNING:
- bgColor = "bg-yellow-100";
- textColor = "text-yellow-800";
- borderColor = "border-yellow-800";
- break;
- case PlanCheckRun_Result_Status.ERROR:
- bgColor = "bg-red-100";
- textColor = "text-red-800";
- borderColor = "border-red-800";
- break;
- }
- break;
- }
-
- const styleList: string[] = [textColor];
- if (props.clickable) {
- styleList.push("cursor-pointer");
- if (props.selected) {
- styleList.push("font-medium", borderColor);
- } else {
- styleList.push(bgColor, "hover:opacity-80", "border-transparent");
- }
- } else {
- styleList.push(bgColor);
- styleList.push("cursor-default");
- }
- styleList.push("cursor-pointer");
- styleList.push(bgColor);
-
- return styleList.join(" ");
-});
-
-// Defines the mapping from PlanCheckRun_Type to an i18n resource keypath
-const PlanCheckRunTypeNameDict = new Map<PlanCheckRun_Type, string>([
- [PlanCheckRun_Type.DATABASE_STATEMENT_FAKE_ADVISE, "task.check-type.fake"],
- [PlanCheckRun_Type.DATABASE_STATEMENT_ADVISE, "task.check-type.sql-review"],
- [PlanCheckRun_Type.DATABASE_CONNECT, "task.check-type.connection"],
- [PlanCheckRun_Type.DATABASE_GHOST_SYNC, "task.check-type.ghost-sync"],
- [
- PlanCheckRun_Type.DATABASE_STATEMENT_SUMMARY_REPORT,
- "task.check-type.summary-report",
- ],
-]);
-
-const name = computed(() => {
- const { type } = latestPlanCheckRun.value;
- const has = PlanCheckRunTypeNameDict.has(type);
- console.assert(has, `Missing PlanCheckType name of "${type}"`);
- if (has) {
- const key = PlanCheckRunTypeNameDict.get(type)!;
- return t(key);
- }
- return type;
-});
-</script>
diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckModal.vue b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckModal.vue
deleted file mode 100644
index 2be2c4a21b..0000000000
--- a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckModal.vue
+++ /dev/null
@@ -1,49 +0,0 @@
-<template>
- <BBModal
- :title="$t('task.check-result.title-general')"
- class="!w-[56rem]"
- header-class="whitespace-pre-wrap break-all gap-x-1"
- @close="$emit('close')"
- >
- <PlanCheckPanel
- :plan-check-run-list="planCheckRunList"
- :selected-type="selectedType"
- @close="$emit('close')"
- />
- </BBModal>
-</template>
-
-<script setup lang="ts">
-import { first, orderBy } from "lodash-es";
-import { computed, ref, watch } from "vue";
-import type {
- PlanCheckRun,
- PlanCheckRun_Type,
-} from "@/types/proto/v1/plan_service";
-import PlanCheckPanel from "./PlanCheckPanel.vue";
-
-const props = defineProps<{
- planCheckRunList: PlanCheckRun[];
- selectedType: PlanCheckRun_Type;
-}>();
-
-defineEmits<{
- (event: "close"): void;
-}>();
-
-const selectedPlanCheckRunList = computed(() => {
- return orderBy(
- props.planCheckRunList.filter(
- (checkRun) => checkRun.type === props.selectedType
- ),
- (checkRun) => parseInt(checkRun.uid, 10),
- "desc"
- );
-});
-
-const selectedPlanCheckRunUID = ref(first(selectedPlanCheckRunList.value)?.uid);
-
-watch(selectedPlanCheckRunList, (list) => {
- selectedPlanCheckRunUID.value = first(list)?.uid;
-});
-</script>
diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/index.ts b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/index.ts
deleted file mode 100644
index 86b498a89c..0000000000
--- a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-import PlanCheckBar from "./PlanCheckBar.vue";
-
-export default PlanCheckBar;
diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckSection.vue b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckSection.vue
index 1ea563fed4..6016ec6064 100644
--- a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckSection.vue
+++ b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckSection.vue
@@ -1,44 +1,32 @@
<template>
- <div class="issue-debug">
- <h3>plan check section</h3>
- <div v-if="!isCreating">
- <NButton type="primary" @click="runPlanChecks">Run plan checks</NButton>
- </div>
- <div>
- issue.planCheckRunList.length: {{ issue.planCheckRunList.length }}
- </div>
- </div>
-
- <PlanCheckBar
+ <PlanCheckRunBar
v-if="show"
+ class="px-4 py-2"
:allow-run-checks="allowRunChecks"
+ :database="database"
+ :plan-name="issue.plan"
:plan-check-run-list="planCheckRunList"
- class="px-4 py-2"
/>
</template>
<script lang="ts" setup>
-import { NButton } from "naive-ui";
import { computed } from "vue";
import {
+ databaseForTask,
planCheckRunListForTask,
planSpecHasPlanChecks,
specForTask,
useIssueContext,
} from "@/components/IssueV1/logic";
-import { planServiceClient } from "@/grpcweb";
+import PlanCheckRunBar from "@/components/PlanCheckRun/PlanCheckRunBar.vue";
import { useCurrentUserV1 } from "@/store";
import { EMPTY_ID } from "@/types";
import { extractUserResourceName, hasProjectPermissionV2 } from "@/utils";
-import PlanCheckBar from "./PlanCheckBar";
const currentUser = useCurrentUserV1();
-const { isCreating, issue, selectedTask } = useIssueContext();
+const { issue, selectedTask } = useIssueContext();
const show = computed(() => {
- if (isCreating.value) {
- return false;
- }
const spec = specForTask(issue.value.planEntity, selectedTask.value);
if (!spec) {
return false;
@@ -46,8 +34,12 @@ const show = computed(() => {
return planSpecHasPlanChecks(spec);
});
+const database = computed(() =>
+ databaseForTask(issue.value, selectedTask.value)
+);
+
const allowRunChecks = computed(() => {
- // Allowing below users to run plan checks
+ // Allowing below users to run plan checks:
// - the creator of the issue
// - ones who have bb.planCheckRuns.run permission in the project
const me = currentUser.value;
@@ -74,17 +66,4 @@ const planCheckRunList = computed(() => {
// Otherwise, show plan checks for the issue.
return issue.value.planCheckRunList;
});
-
-const runPlanChecks = async () => {
- const plan = issue.value.planEntity;
- if (!plan) return;
-
- try {
- await planServiceClient.runPlanChecks({
- name: plan.name,
- });
- } catch (ex) {
- // debugger;
- }
-};
</script>
diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/index.ts b/frontend/src/components/IssueV1/components/PlanCheckSection/index.ts
index bf5c827d15..b84a918147 100644
--- a/frontend/src/components/IssueV1/components/PlanCheckSection/index.ts
+++ b/frontend/src/components/IssueV1/components/PlanCheckSection/index.ts
@@ -1,6 +1,3 @@
-import PlanCheckBar from "./PlanCheckBar";
import PlanCheckSection from "./PlanCheckSection.vue";
export default PlanCheckSection;
-
-export { PlanCheckBar };
diff --git a/frontend/src/components/IssueV1/components/SQLCheckSection/OnlineMigrationAdviceExtra.vue b/frontend/src/components/IssueV1/components/SQLCheckSection/OnlineMigrationAdviceExtra.vue
index 28fbb62124..58ea9a193a 100644
--- a/frontend/src/components/IssueV1/components/SQLCheckSection/OnlineMigrationAdviceExtra.vue
+++ b/frontend/src/components/IssueV1/components/SQLCheckSection/OnlineMigrationAdviceExtra.vue
@@ -13,8 +13,8 @@
import { NButton } from "naive-ui";
import { computed } from "vue";
import { useI18n } from "vue-i18n";
+import { type PlanCheckDetailTableRow } from "@/components/PlanCheckRun/PlanCheckRunDetail.vue";
import { isGroupingChangeTaskV1, useIssueContext } from "../../logic";
-import { type PlanCheckDetailTableRow } from "../PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue";
import { allowGhostForTask } from "../Sidebar/GhostSection/common";
const emit = defineEmits<{
diff --git a/frontend/src/components/IssueV1/components/StageSection/StageCard.vue b/frontend/src/components/IssueV1/components/StageSection/StageCard.vue
index d21543b6e7..3f33299400 100644
--- a/frontend/src/components/IssueV1/components/StageSection/StageCard.vue
+++ b/frontend/src/components/IssueV1/components/StageSection/StageCard.vue
@@ -72,9 +72,9 @@ import {
isTaskFinished,
isValidStage,
planCheckRunListForTask,
- planCheckRunSummaryForCheckRunList,
useIssueContext,
} from "@/components/IssueV1/logic";
+import { planCheckRunSummaryForCheckRunList } from "@/components/PlanCheckRun/common";
import { EMPTY_TASK_NAME } from "@/types";
import { PlanCheckRun_Result_Status } from "@/types/proto/v1/plan_service";
import type { Stage } from "@/types/proto/v1/rollout_service";
diff --git a/frontend/src/components/IssueV1/logic/plan-check.ts b/frontend/src/components/IssueV1/logic/plan-check.ts
index 42dbf1fa58..8d0a75d46b 100644
--- a/frontend/src/components/IssueV1/logic/plan-check.ts
+++ b/frontend/src/components/IssueV1/logic/plan-check.ts
@@ -1,10 +1,7 @@
-import { maxBy } from "lodash-es";
+import { planCheckRunSummaryForCheckRunList } from "@/components/PlanCheckRun/common";
import type { ComposedIssue } from "@/types";
import {
- PlanCheckRun,
PlanCheckRun_Result_Status,
- PlanCheckRun_Status,
- PlanCheckRun_Type,
type Plan_Spec,
} from "@/types/proto/v1/plan_service";
import type { Task } from "@/types/proto/v1/rollout_service";
@@ -61,24 +58,6 @@ export const planCheckRunListForSpec = (
});
};
-export const HiddenPlanCheckTypes = new Set<PlanCheckRun_Type>([
- PlanCheckRun_Type.DATABASE_STATEMENT_SUMMARY_REPORT,
-]);
-
-export const planCheckRunResultStatus = (checkRun: PlanCheckRun) => {
- let status = PlanCheckRun_Result_Status.SUCCESS;
-
- for (const result of checkRun.results) {
- if (result.status === PlanCheckRun_Result_Status.ERROR) {
- return PlanCheckRun_Result_Status.ERROR;
- }
- if (result.status === PlanCheckRun_Result_Status.WARNING) {
- status = PlanCheckRun_Result_Status.WARNING;
- }
- }
- return status;
-};
-
export const planCheckStatusForTask = (issue: ComposedIssue, task: Task) => {
if (
task.status === Task_Status.PENDING ||
@@ -91,77 +70,6 @@ export const planCheckStatusForTask = (issue: ComposedIssue, task: Task) => {
return undefined;
};
-export type PlanCheckRunSummary = {
- runningCount: number;
- successCount: number;
- warnCount: number;
- errorCount: number;
-};
-
-export const planCheckRunSummaryForCheckRunList = (
- planCheckRunList: PlanCheckRun[]
-) => {
- const summary: PlanCheckRunSummary = {
- runningCount: 0,
- successCount: 0,
- warnCount: 0,
- errorCount: 0,
- };
-
- planCheckRunList = planCheckRunList.filter(
- (check) => !HiddenPlanCheckTypes.has(check.type)
- );
-
- const listGroupByTypeTargetSheet = planCheckRunList.reduce(
- (acc, checkRun) => {
- const key = `${checkRun.type}-${checkRun.target}-${checkRun.sheet}`;
- if (!acc[key]) {
- acc[key] = [];
- }
- acc[key].push(checkRun);
- return acc;
- },
- {} as { [key: string]: PlanCheckRun[] }
- );
-
- const latestCheckRunOfEachTypeTargetSheet = Object.keys(
- listGroupByTypeTargetSheet
- ).map((k) => {
- const listOfTypeTargetSheet = listGroupByTypeTargetSheet[k];
- const latest = maxBy(listOfTypeTargetSheet, (checkRun) =>
- Number(checkRun.uid)
- )!;
- return latest;
- });
-
- for (const checkRun of latestCheckRunOfEachTypeTargetSheet) {
- switch (checkRun.status) {
- case PlanCheckRun_Status.CANCELED:
- // nothing todo
- break;
- case PlanCheckRun_Status.FAILED:
- summary.errorCount++;
- break;
- case PlanCheckRun_Status.RUNNING:
- summary.runningCount++;
- break;
- case PlanCheckRun_Status.DONE:
- switch (planCheckRunResultStatus(checkRun)) {
- case PlanCheckRun_Result_Status.SUCCESS:
- summary.successCount++;
- break;
- case PlanCheckRun_Result_Status.WARNING:
- summary.warnCount++;
- break;
- case PlanCheckRun_Result_Status.ERROR:
- summary.errorCount++;
- }
- }
- }
-
- return summary;
-};
-
export const planCheckRunSummaryForIssue = (issue: ComposedIssue) => {
const sheets = issue.planEntity?.steps.reduce((acc, step) => {
step.specs.forEach((spec) => {
diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateIssueButton.vue b/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateIssueButton.vue
index 7261394b71..8bcbddf9d9 100644
--- a/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateIssueButton.vue
+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/create/CreateIssueButton.vue
@@ -37,9 +37,9 @@ import { useRouter } from "vue-router";
import { ErrorList } from "@/components/Plan/components/common";
import {
planCheckRunListForSpec,
- planCheckRunSummaryForCheckRunList,
usePlanContext,
} from "@/components/Plan/logic";
+import { planCheckRunSummaryForCheckRunList } from "@/components/PlanCheckRun/common";
import { useSQLCheckContext } from "@/components/SQLCheck";
import { issueServiceClient, rolloutServiceClient } from "@/grpcweb";
import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";
diff --git a/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckBar/PlanCheckBadgeBar.vue b/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckBar/PlanCheckBadgeBar.vue
deleted file mode 100644
index 2b99fc0e4a..0000000000
--- a/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckBar/PlanCheckBadgeBar.vue
+++ /dev/null
@@ -1,56 +0,0 @@
-<template>
- <div class="flex items-center flex-wrap gap-2 flex-1">
- <PlanCheckBadge
- v-for="group in planCheckRunsGroupByType"
- :key="group.type"
- :type="group.type"
- :clickable="true"
- :selected="group.type === selectedType"
- :plan-check-run-list="group.list"
- @click="$emit('select-type', group.type)"
- />
- <!-- Default slot for other actions -->
- <slot></slot>
- </div>
-</template>
-
-<script lang="ts" setup>
-import { orderBy } from "lodash-es";
-import { computed } from "vue";
-import type { PlanCheckRun } from "@/types/proto/v1/plan_service";
-import { PlanCheckRun_Type } from "@/types/proto/v1/plan_service";
-import { groupBy } from "@/utils/collections";
-import PlanCheckBadge from "./PlanCheckBadge.vue";
-
-const props = defineProps<{
- planCheckRunList: PlanCheckRun[];
- selectedType?: PlanCheckRun_Type;
-}>();
-
-defineEmits<{
- (event: "select-type", type: PlanCheckRun_Type): void;
-}>();
-
-const planCheckRunsGroupByType = computed(() => {
- const groups = groupBy(props.planCheckRunList, (checkRun) => checkRun.type);
- const list = Array.from(groups.entries()).map(([type, list]) => ({
- type,
- list,
- }));
- // Sort by pre-defined orders
- // If an item's order is not defined, put it behind
- return orderBy(
- list,
- [(group) => PlanCheckTypeOrderDict.get(group.type) ?? 99999],
- "asc"
- );
-});
-
-const PlanCheckTypeOrderList: PlanCheckRun_Type[] = [
- PlanCheckRun_Type.DATABASE_CONNECT,
- PlanCheckRun_Type.DATABASE_STATEMENT_ADVISE,
-];
-const PlanCheckTypeOrderDict = new Map<PlanCheckRun_Type, number>(
- PlanCheckTypeOrderList.map((type, order) => [type, order])
-);
-</script>
diff --git a/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckBar/PlanCheckBar.vue b/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckBar/PlanCheckBar.vue
deleted file mode 100644
index 4526cc9851..0000000000
--- a/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckBar/PlanCheckBar.vue
+++ /dev/null
@@ -1,42 +0,0 @@
-<template>
- <div class="w-full flex flex-col items-start gap-4">
- <div class="w-full flex flex-row justify-between items-center">
- <div class="textlabel h-[26px] inline-flex items-center">
- {{ $t("task.task-checks") }}
- </div>
-
- <div class="flex justify-end items-center shrink-0">
- <PlanCheckRunButton v-if="allowRunChecks" @run-checks="runChecks" />
- </div>
- </div>
-
- <PlanCheckPanel :plan-check-run-list="planCheckRunList" />
- </div>
-</template>
-
-<script lang="ts" setup>
-import { usePlanContext } from "@/components/Plan/logic";
-import { planServiceClient } from "@/grpcweb";
-import type { PlanCheckRun } from "@/types/proto/v1/plan_service";
-import PlanCheckPanel from "./PlanCheckPanel.vue";
-import PlanCheckRunButton from "./PlanCheckRunButton.vue";
-
-withDefaults(
- defineProps<{
- allowRunChecks?: boolean;
- planCheckRunList?: PlanCheckRun[];
- }>(),
- {
- allowRunChecks: true,
- planCheckRunList: () => [],
- }
-);
-
-const { plan } = usePlanContext();
-
-const runChecks = () => {
- planServiceClient.runPlanChecks({
- name: plan.value.name,
- });
-};
-</script>
diff --git a/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue b/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue
deleted file mode 100644
index 39939170b3..0000000000
--- a/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue
+++ /dev/null
@@ -1,333 +0,0 @@
-<template>
- <div class="space-y-3 divide-y pb-4 px-2">
- <div
- v-for="(row, i) in tableRows"
- :key="i"
- class="pt-3 first:pt-2 space-y-2"
- >
- <div class="flex items-center space-x-3">
- <div
- class="relative w-5 h-5 flex flex-shrink-0 items-center justify-center rounded-full select-none"
- :class="statusIconClass(row.checkResult.status)"
- >
- <template
- v-if="row.checkResult.status === PlanCheckRun_Result_Status.SUCCESS"
- >
- <heroicons-solid:check class="w-4 h-4" />
- </template>
- <template
- v-if="row.checkResult.status === PlanCheckRun_Result_Status.WARNING"
- >
- <heroicons-outline:exclamation class="h-4 w-4" />
- </template>
- <template
- v-else-if="
- row.checkResult.status === PlanCheckRun_Result_Status.ERROR
- "
- >
- <span class="text-white font-medium text-base" aria-hidden="true">
- !
- </span>
- </template>
- </div>
- <div v-if="showCategoryColumn" class="shrink-0">
- {{ row.category }}
- </div>
- <div class="font-semibold">{{ row.title }}</div>
- </div>
- <div class="textinfolabel">
- <span>{{ row.checkResult.content }}</span>
- <template v-if="row.checkResult.sqlReviewReport?.detail">
- <span
- class="ml-1 normal-link"
- @click="
- state.activeResultDefinition =
- row.checkResult.sqlReviewReport!.detail
- "
- >{{ $t("sql-review.view-definition") }}</span
- >
- <span class="border-r border-control-border ml-1"></span>
- </template>
- <template
- v-if="
- row.checkResult.sqlReviewReport &&
- getActiveRule(row.checkResult.title)
- "
- >
- <span
- class="ml-1 normal-link"
- @click="setActiveRule(row.checkResult.title)"
- >{{ $t("sql-review.rule-detail") }}</span
- >
- <span class="border-r border-control-border ml-1"></span>
- </template>
- <template v-if="row.checkResult.sqlSummaryReport">
- {{ row.checkResult.sqlSummaryReport.affectedRows }}
- </template>
-
- <HideInStandaloneMode>
- <a
- v-if="row.link"
- class="ml-1 normal-link"
- :href="row.link.url"
- :target="row.link.target"
- >
- {{ row.link.title }}
- </a>
- </HideInStandaloneMode>
-
- <!-- Only show the error line for latest plan check run -->
- <template v-if="showCodeLocation && 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
- )
- "
- >
- Line {{ row.checkResult.sqlReviewReport.line }}
- </span>
- </template>
- </div>
- </div>
- </div>
-
- <SQLRuleEditDialog
- v-if="state.activeRule"
- :rule="state.activeRule"
- :disabled="true"
- @cancel="state.activeRule = undefined"
- />
-
- <ResultDefinitionModal
- v-if="state.activeResultDefinition"
- :definition="state.activeResultDefinition"
- @cancel="state.activeResultDefinition = undefined"
- />
-</template>
-
-<script setup lang="ts">
-import { computed, reactive } from "vue";
-import { useI18n } from "vue-i18n";
-import { useRouter } from "vue-router";
-import { SQLRuleEditDialog } from "@/components/SQLReview/components";
-import { WORKSPACE_ROUTE_SQL_REVIEW } from "@/router/dashboard/workspaceRoutes";
-import { useReviewPolicyForDatabase } from "@/store";
-import type { RuleTemplateV2, ComposedDatabase } from "@/types";
-import {
- GeneralErrorCode,
- SQLReviewPolicyErrorCode,
- getRuleLocalization,
- ruleTemplateMapV2,
-} from "@/types";
-import { convertPolicyRuleToRuleTemplate } from "@/types";
-import type { PlanCheckRun } from "@/types/proto/v1/plan_service";
-import {
- PlanCheckRun_Result,
- PlanCheckRun_Result_Status,
- PlanCheckRun_Status,
-} from "@/types/proto/v1/plan_service";
-import ResultDefinitionModal from "./ResultDefinitionModal.vue";
-
-interface ErrorCodeLink {
- title: string;
- target: string;
- url: string;
-}
-
-export type PlanCheckDetailTableRow = {
- checkResult: PlanCheckRun_Result;
- category: string;
- title: string;
- link: ErrorCodeLink | undefined;
-};
-
-type LocalState = {
- activeRule?: RuleTemplateV2;
- activeResultDefinition?: string;
-};
-
-const props = defineProps<{
- planCheckRun: PlanCheckRun;
- database?: ComposedDatabase;
- showCodeLocation?: boolean;
-}>();
-
-const { t } = useI18n();
-const router = useRouter();
-const state = reactive<LocalState>({
- activeRule: undefined,
- activeResultDefinition: undefined,
-});
-
-const emit = defineEmits<{
- (event: "close"): void;
-}>();
-
-const statusIconClass = (status: PlanCheckRun_Result_Status) => {
- switch (status) {
- case PlanCheckRun_Result_Status.SUCCESS:
- return "bg-success text-white";
- case PlanCheckRun_Result_Status.WARNING:
- return "bg-warning text-white";
- case PlanCheckRun_Result_Status.ERROR:
- return "bg-error text-white";
- }
-};
-
-const checkResultList = computed((): PlanCheckRun_Result[] => {
- if (props.planCheckRun.status === PlanCheckRun_Status.DONE) {
- return props.planCheckRun.results;
- } else if (props.planCheckRun.status === PlanCheckRun_Status.FAILED) {
- return [
- PlanCheckRun_Result.fromPartial({
- status: PlanCheckRun_Result_Status.ERROR,
- title: t("common.error"),
- content: props.planCheckRun.error,
- }),
- ];
- } else if (props.planCheckRun.status === PlanCheckRun_Status.CANCELED) {
- return [
- PlanCheckRun_Result.fromPartial({
- status: PlanCheckRun_Result_Status.WARNING,
- title: t("common.canceled"),
- content: props.planCheckRun.error,
- }),
- ];
- }
-
- return [];
-});
-
-const getRuleTemplateByType = (type: string) => {
- if (props.database) {
- return ruleTemplateMapV2
- .get(props.database.instanceResource.engine)
- ?.get(type);
- }
-
- // fallback
- for (const mapByType of ruleTemplateMapV2.values()) {
- if (mapByType.has(type)) {
- return mapByType.get(type);
- }
- }
- return;
-};
-
-const categoryAndTitle = (
- checkResult: PlanCheckRun_Result
-): [string, string] => {
- if (checkResult.sqlReviewReport) {
- const code = checkResult.sqlReviewReport?.code ?? checkResult.code;
- if (!code) {
- return ["", checkResult.title];
- }
- if (code === SQLReviewPolicyErrorCode.EMPTY_POLICY) {
- const title = messageWithCode(checkResult.title, code);
- return ["", title];
- }
- const rule = getRuleTemplateByType(checkResult.title);
- if (rule) {
- const ruleLocalization = getRuleLocalization(rule.type);
- const key = `sql-review.category.${rule.category.toLowerCase()}`;
- const category = t(key);
- const title = messageWithCode(ruleLocalization.title, code);
- return [category, title];
- }
- return ["", messageWithCode(checkResult.title, code)];
- }
- if (checkResult.sqlSummaryReport) {
- if (typeof checkResult.sqlSummaryReport.affectedRows === "number") {
- return ["", t("task.check-type.affected-rows")];
- }
- return ["", checkResult.title];
- }
-
- return ["", checkResult.title];
-};
-
-const messageWithCode = (message: string, code: number) => {
- return `${message} #${code}`;
-};
-
-const errorCodeLink = (
- checkResult: PlanCheckRun_Result
-): ErrorCodeLink | undefined => {
- const code = checkResult.sqlReviewReport?.code ?? checkResult.code;
- switch (code) {
- case undefined:
- return;
- case GeneralErrorCode.OK:
- return;
- case SQLReviewPolicyErrorCode.EMPTY_POLICY:
- return {
- title: t("sql-review.configure-policy"),
- target: "__blank",
- url: router.resolve({
- name: WORKSPACE_ROUTE_SQL_REVIEW,
- }).fullPath,
- };
- default: {
- const errorCodeNamespace =
- checkResult.sqlReviewReport !== undefined ? "advisor" : "core";
- const domain = "https://www.bytebase.com";
- const path = `/docs/reference/error-code/${errorCodeNamespace}/`;
- const query = `source=console#${code}`;
- const url = `${domain}${path}?${query}`;
- return {
- title: t("common.view-doc"),
- target: "__blank",
- url: url,
- };
- }
- }
-};
-
-const tableRows = computed(() => {
- return checkResultList.value.map<PlanCheckDetailTableRow>((checkResult) => {
- const [category, title] = categoryAndTitle(checkResult);
- const link = errorCodeLink(checkResult);
- return {
- checkResult,
- category,
- title,
- link,
- };
- });
-});
-
-const showCategoryColumn = computed((): boolean =>
- tableRows.value.some((row) => row.category !== "")
-);
-
-const reviewPolicy = useReviewPolicyForDatabase(
- computed(() => {
- return props.database;
- })
-);
-
-const getActiveRule = (type: string): RuleTemplateV2 | undefined => {
- const rule = reviewPolicy.value?.ruleList.find((rule) => rule.type === type);
- if (!rule) {
- return undefined;
- }
-
- const ruleTemplate = getRuleTemplateByType(type);
- if (!ruleTemplate) {
- return undefined;
- }
-
- return convertPolicyRuleToRuleTemplate(rule, ruleTemplate);
-};
-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/Plan/components/PlanCheckSection/PlanCheckBar/PlanCheckPanel.vue b/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckBar/PlanCheckPanel.vue
deleted file mode 100644
index 264a71905c..0000000000
--- a/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckBar/PlanCheckPanel.vue
+++ /dev/null
@@ -1,130 +0,0 @@
-<template>
- <div class="space-y-2">
- <TabFilter
- v-if="selectedPlanCheckRunUID && tabItemList.length > 1"
- v-model:value="selectedPlanCheckRunUID"
- :items="tabItemList"
- />
-
- <PlanCheckBadgeBar
- :plan-check-run-list="planCheckRunList"
- :selected-type="selectedTypeRef"
- @select-type="(type) => (selectedTypeRef = type)"
- />
-
- <PlanCheckDetail
- v-if="selectedPlanCheckRun"
- :plan-check-run="selectedPlanCheckRun"
- :database="database"
- :show-code-location="isLatestPlanCheckRun"
- @close="$emit('close')"
- />
- </div>
-</template>
-
-<script setup lang="ts">
-import { first, orderBy } from "lodash-es";
-import { computed, ref, watch } from "vue";
-import { useI18n } from "vue-i18n";
-import { databaseForSpec } from "@/components/Plan/logic";
-import { usePlanContext } from "@/components/Plan/logic";
-import type { TabFilterItem } from "@/components/v2";
-import { TabFilter } from "@/components/v2";
-import { EMPTY_ID } from "@/types";
-import {
- PlanCheckRun_Result_Status,
- PlanCheckRun_Type,
- type PlanCheckRun,
-} from "@/types/proto/v1/plan_service";
-import { humanizeDate } from "@/utils";
-import PlanCheckBadgeBar from "./PlanCheckBadgeBar.vue";
-import PlanCheckDetail from "./PlanCheckDetail.vue";
-
-const props = defineProps<{
- planCheckRunList: PlanCheckRun[];
- selectedType?: PlanCheckRun_Type;
-}>();
-
-defineEmits<{
- (event: "close"): void;
-}>();
-
-const getInitialSelectedType = () => {
- if (props.selectedType) {
- return props.selectedType;
- }
-
- // Find the first plan check run with error or warning.
- const planCheck = props.planCheckRunList.find((checkRun) =>
- [PlanCheckRun_Result_Status.ERROR, PlanCheckRun_Result_Status.WARNING].some(
- (status) =>
- checkRun.results.map((result) => result.status).includes(status)
- )
- );
- if (planCheck) {
- return planCheck.type;
- }
- return (
- first(props.planCheckRunList)?.type ?? PlanCheckRun_Type.TYPE_UNSPECIFIED
- );
-};
-
-const { t } = useI18n();
-const { plan, selectedSpec } = usePlanContext();
-const selectedTypeRef = ref<PlanCheckRun_Type>(getInitialSelectedType());
-
-const selectedPlanCheckRunList = computed(() => {
- return orderBy(
- props.planCheckRunList.filter(
- (checkRun) => checkRun.type === selectedTypeRef.value
- ),
- (checkRun) => parseInt(checkRun.uid, 10),
- "desc"
- );
-});
-
-const selectedPlanCheckRunUID = ref(first(selectedPlanCheckRunList.value)?.uid);
-
-const selectedPlanCheckRun = computed(() => {
- const uid = selectedPlanCheckRunUID.value;
- if (!uid) return undefined;
- return selectedPlanCheckRunList.value.find(
- (checkRun) => checkRun.uid === uid
- );
-});
-
-const isLatestPlanCheckRun = computed(() => {
- return (
- selectedPlanCheckRunUID.value === first(selectedPlanCheckRunList.value)?.uid
- );
-});
-
-const tabItemList = computed(() => {
- return selectedPlanCheckRunList.value.map<TabFilterItem<string>>(
- (checkRun, i) => {
- const label =
- i === 0
- ? t("common.latest")
- : checkRun.createTime
- ? humanizeDate(checkRun.createTime)
- : `UID(${checkRun.uid})`;
- return {
- label,
- value: checkRun.uid,
- };
- }
- );
-});
-
-watch(selectedPlanCheckRunList, (list) => {
- selectedPlanCheckRunUID.value = first(list)?.uid;
-});
-
-const database = computed(() => {
- const spec = selectedSpec.value;
- if (!spec || spec.id === String(EMPTY_ID)) {
- return;
- }
- return databaseForSpec(plan.value, spec);
-});
-</script>
diff --git a/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckBar/PlanCheckRunButton.vue b/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckBar/PlanCheckRunButton.vue
deleted file mode 100644
index 29dacf0a99..0000000000
--- a/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckBar/PlanCheckRunButton.vue
+++ /dev/null
@@ -1,71 +0,0 @@
-<template>
- <ContextMenuButton
- v-if="actionList.length > 0"
- :action-list="actionList"
- :disabled="hasRunningPlanCheck"
- preference-key="plan.task.run-checks"
- default-action-key="RUN-CHECKS"
- @click="$emit('run-checks')"
- >
- <template #icon>
- <BBSpin v-if="hasRunningPlanCheck" :size="20" />
- <heroicons-outline:play v-else class="w-4 h-4" />
- </template>
- <template #default="{ action }">
- <template v-if="hasRunningPlanCheck">
- {{ $t("task.checking") }}
- </template>
- <template v-else>
- {{ action.text }}
- </template>
- </template>
- </ContextMenuButton>
-</template>
-
-<script setup lang="ts">
-import { computed } from "vue";
-import { useI18n } from "vue-i18n";
-import { planCheckRunListForSpec } from "@/components/Plan/logic";
-import { usePlanContext } from "@/components/Plan/logic";
-import type { ContextMenuButtonAction } from "@/components/v2";
-import { ContextMenuButton } from "@/components/v2";
-import { PlanCheckRun_Status } from "@/types/proto/v1/plan_service";
-
-defineEmits<{
- (event: "run-checks"): void;
-}>();
-
-const { t } = useI18n();
-const { isCreating, plan, selectedSpec } = usePlanContext();
-
-const allowRunCheckForPlan = computed(() => {
- if (isCreating.value) {
- return false;
- }
- return true;
-});
-
-const actionList = computed(() => {
- if (!allowRunCheckForPlan.value) return [];
-
- const actionList: ContextMenuButtonAction[] = [];
- actionList.push({
- key: "RUN-CHECKS",
- text: t("task.run-checks"),
- params: {},
- });
- return actionList;
-});
-
-const hasRunningPlanCheck = computed((): boolean => {
- if (isCreating.value) return false;
-
- const planCheckRunList = planCheckRunListForSpec(
- plan.value,
- selectedSpec.value
- );
- return planCheckRunList.some(
- (checkRun) => checkRun.status === PlanCheckRun_Status.RUNNING
- );
-});
-</script>
diff --git a/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckBar/ResultDefinitionModal.vue b/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckBar/ResultDefinitionModal.vue
deleted file mode 100644
index 9dd9277c4b..0000000000
--- a/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckBar/ResultDefinitionModal.vue
+++ /dev/null
@@ -1,29 +0,0 @@
-<template>
- <BBModal :title="$t('sql-review.view-definition')" @close="emit('cancel')">
- <div class="space-y-4 w-[calc(100vw-5rem)] sm:w-[40rem] pb-1">
- <div class="space-y-1">
- <div class="flex flex-col gap-x-2 whitespace-pre-wrap">
- {{ definition }}
- </div>
- </div>
- <div class="mt-4 pt-2 border-t flex justify-end">
- <NButton @click.prevent="emit('cancel')">
- {{ $t("common.cancel") }}
- </NButton>
- </div>
- </div>
- </BBModal>
-</template>
-
-<script lang="ts" setup>
-defineProps({
- definition: {
- required: true,
- type: String,
- },
-});
-
-const emit = defineEmits<{
- (event: "cancel"): void;
-}>();
-</script>
diff --git a/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckBar/index.ts b/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckBar/index.ts
deleted file mode 100644
index 86b498a89c..0000000000
--- a/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckBar/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-import PlanCheckBar from "./PlanCheckBar.vue";
-
-export default PlanCheckBar;
diff --git a/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckSection.vue b/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckSection.vue
index fff150c68f..75f5ad611b 100644
--- a/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckSection.vue
+++ b/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckSection.vue
@@ -1,9 +1,11 @@
<template>
- <PlanCheckBar
+ <PlanCheckRunBar
v-if="show"
+ class="px-4 py-2"
:allow-run-checks="allowRunChecks"
+ :database="database"
+ :plan-name="plan.name"
:plan-check-run-list="planCheckRunList"
- class="px-4 py-2"
/>
</template>
@@ -14,25 +16,27 @@ import {
planCheckRunListForSpec,
planSpecHasPlanChecks,
usePlanContext,
+ databaseForSpec,
} from "@/components/Plan/logic";
+import PlanCheckRunBar from "@/components/PlanCheckRun/PlanCheckRunBar.vue";
import { useCurrentUserV1 } from "@/store";
import { EMPTY_ID } from "@/types";
import { extractUserResourceName, hasProjectPermissionV2 } from "@/utils";
-import PlanCheckBar from "./PlanCheckBar";
const currentUser = useCurrentUserV1();
-const { isCreating, plan, selectedSpec } = usePlanContext();
+const { plan, selectedSpec } = usePlanContext();
const show = computed(() => {
- if (isCreating.value) {
- return false;
- }
if (selectedSpec.value.id === String(EMPTY_ID)) {
return false;
}
return planSpecHasPlanChecks(selectedSpec.value);
});
+const database = computed(() =>
+ databaseForSpec(plan.value, selectedSpec.value)
+);
+
const allowRunChecks = computed(() => {
// Allowing below users to run plan checks
// - the creator of the plan
diff --git a/frontend/src/components/Plan/components/PlanCheckSection/index.ts b/frontend/src/components/Plan/components/PlanCheckSection/index.ts
index bf5c827d15..b84a918147 100644
--- a/frontend/src/components/Plan/components/PlanCheckSection/index.ts
+++ b/frontend/src/components/Plan/components/PlanCheckSection/index.ts
@@ -1,6 +1,3 @@
-import PlanCheckBar from "./PlanCheckBar";
import PlanCheckSection from "./PlanCheckSection.vue";
export default PlanCheckSection;
-
-export { PlanCheckBar };
diff --git a/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue b/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue
index c667bf342a..668d9ec713 100644
--- a/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue
+++ b/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue
@@ -60,6 +60,7 @@ import { isEqual } from "lodash-es";
import { NTooltip } from "naive-ui";
import { computed, onMounted } from "vue";
import DatabaseGroupIcon from "@/components/DatabaseGroupIcon.vue";
+import { planCheckRunSummaryForCheckRunList } from "@/components/PlanCheckRun/common";
import { useDBGroupStore } from "@/store";
import {
PlanCheckRun_Result_Status,
@@ -72,7 +73,6 @@ import {
usePlanContext,
isGroupingChangeSpec,
planCheckRunListForSpec,
- planCheckRunSummaryForCheckRunList,
} from "../../logic";
const props = defineProps<{
diff --git a/frontend/src/components/Plan/components/StepSection/StepCard.vue b/frontend/src/components/Plan/components/StepSection/StepCard.vue
index cd93ab21fc..91c2311dc1 100644
--- a/frontend/src/components/Plan/components/StepSection/StepCard.vue
+++ b/frontend/src/components/Plan/components/StepSection/StepCard.vue
@@ -54,9 +54,9 @@ import { computed } from "vue";
import {
isValidSpec,
planCheckRunListForSpec,
- planCheckRunSummaryForCheckRunList,
usePlanContext,
} from "@/components/Plan/logic";
+import { planCheckRunSummaryForCheckRunList } from "@/components/PlanCheckRun/common";
import type { Plan_Step } from "@/types/proto/v1/plan_service";
import { PlanCheckRun_Result_Status } from "@/types/proto/v1/plan_service";
diff --git a/frontend/src/components/Plan/logic/plan-check.ts b/frontend/src/components/Plan/logic/plan-check.ts
index 30b97d3d46..9d87ad5f24 100644
--- a/frontend/src/components/Plan/logic/plan-check.ts
+++ b/frontend/src/components/Plan/logic/plan-check.ts
@@ -1,10 +1,4 @@
-import { maxBy } from "lodash-es";
-import type { PlanCheckRun, Plan_Spec } from "@/types/proto/v1/plan_service";
-import {
- PlanCheckRun_Result_Status,
- PlanCheckRun_Status,
- PlanCheckRun_Type,
-} from "@/types/proto/v1/plan_service";
+import type { Plan_Spec } from "@/types/proto/v1/plan_service";
import type { ComposedPlan } from "@/types/v1/issue/plan";
import { sheetNameForSpec, databaseForSpec } from ".";
@@ -29,92 +23,3 @@ export const planCheckRunListForSpec = (
return check.target === target;
});
};
-
-export const HiddenPlanCheckTypes = new Set<PlanCheckRun_Type>([
- PlanCheckRun_Type.DATABASE_STATEMENT_SUMMARY_REPORT,
-]);
-
-export const planCheckRunResultStatus = (checkRun: PlanCheckRun) => {
- let status = PlanCheckRun_Result_Status.SUCCESS;
-
- for (const result of checkRun.results) {
- if (result.status === PlanCheckRun_Result_Status.ERROR) {
- return PlanCheckRun_Result_Status.ERROR;
- }
- if (result.status === PlanCheckRun_Result_Status.WARNING) {
- status = PlanCheckRun_Result_Status.WARNING;
- }
- }
- return status;
-};
-
-export type PlanCheckRunSummary = {
- runningCount: number;
- successCount: number;
- warnCount: number;
- errorCount: number;
-};
-
-export const planCheckRunSummaryForCheckRunList = (
- planCheckRunList: PlanCheckRun[]
-) => {
- const summary: PlanCheckRunSummary = {
- runningCount: 0,
- successCount: 0,
- warnCount: 0,
- errorCount: 0,
- };
-
- planCheckRunList = planCheckRunList.filter(
- (check) => !HiddenPlanCheckTypes.has(check.type)
- );
-
- const listGroupByTypeTargetSheet = planCheckRunList.reduce(
- (acc, checkRun) => {
- const key = `${checkRun.type}-${checkRun.target}-${checkRun.sheet}`;
- if (!acc[key]) {
- acc[key] = [];
- }
- acc[key].push(checkRun);
- return acc;
- },
- {} as { [key: string]: PlanCheckRun[] }
- );
-
- const latestCheckRunOfEachTypeTargetSheet = Object.keys(
- listGroupByTypeTargetSheet
- ).map((k) => {
- const listOfTypeTargetSheet = listGroupByTypeTargetSheet[k];
- const latest = maxBy(listOfTypeTargetSheet, (checkRun) =>
- Number(checkRun.uid)
- )!;
- return latest;
- });
-
- for (const checkRun of latestCheckRunOfEachTypeTargetSheet) {
- switch (checkRun.status) {
- case PlanCheckRun_Status.CANCELED:
- // nothing todo
- break;
- case PlanCheckRun_Status.FAILED:
- summary.errorCount++;
- break;
- case PlanCheckRun_Status.RUNNING:
- summary.runningCount++;
- break;
- case PlanCheckRun_Status.DONE:
- switch (planCheckRunResultStatus(checkRun)) {
- case PlanCheckRun_Result_Status.SUCCESS:
- summary.successCount++;
- break;
- case PlanCheckRun_Result_Status.WARNING:
- summary.warnCount++;
- break;
- case PlanCheckRun_Result_Status.ERROR:
- summary.errorCount++;
- }
- }
- }
-
- return summary;
-};
diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckResultDefinitionModal.vue b/frontend/src/components/PlanCheckRun/PlanCheckResultDefinitionModal.vue
similarity index 70%
rename from frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckResultDefinitionModal.vue
rename to frontend/src/components/PlanCheckRun/PlanCheckResultDefinitionModal.vue
index 9dd9277c4b..c3f62140f5 100644
--- a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckResultDefinitionModal.vue
+++ b/frontend/src/components/PlanCheckRun/PlanCheckResultDefinitionModal.vue
@@ -1,5 +1,5 @@
<template>
- <BBModal :title="$t('sql-review.view-definition')" @close="emit('cancel')">
+ <BBModal :title="$t('sql-review.view-definition')" @close="emit('close')">
<div class="space-y-4 w-[calc(100vw-5rem)] sm:w-[40rem] pb-1">
<div class="space-y-1">
<div class="flex flex-col gap-x-2 whitespace-pre-wrap">
@@ -7,8 +7,8 @@
</div>
</div>
<div class="mt-4 pt-2 border-t flex justify-end">
- <NButton @click.prevent="emit('cancel')">
- {{ $t("common.cancel") }}
+ <NButton @click.prevent="emit('close')">
+ {{ $t("common.close") }}
</NButton>
</div>
</div>
@@ -16,14 +16,9 @@
</template>
<script lang="ts" setup>
-defineProps({
- definition: {
- required: true,
- type: String,
- },
-});
+defineProps<{ definition: string }>();
const emit = defineEmits<{
- (event: "cancel"): void;
+ (event: "close"): void;
}>();
</script>
diff --git a/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckBar/PlanCheckBadge.vue b/frontend/src/components/PlanCheckRun/PlanCheckRunBadge.vue
similarity index 96%
rename from frontend/src/components/Plan/components/PlanCheckSection/PlanCheckBar/PlanCheckBadge.vue
rename to frontend/src/components/PlanCheckRun/PlanCheckRunBadge.vue
index 5b250531a8..387c1bef49 100644
--- a/frontend/src/components/Plan/components/PlanCheckSection/PlanCheckBar/PlanCheckBadge.vue
+++ b/frontend/src/components/PlanCheckRun/PlanCheckRunBadge.vue
@@ -39,14 +39,14 @@
import { maxBy } from "lodash-es";
import { computed } from "vue";
import { useI18n } from "vue-i18n";
-import { planCheckRunResultStatus } from "@/components/Plan/logic";
+import { TaskSpinner } from "@/components/IssueV1/components/common";
import type { PlanCheckRun } from "@/types/proto/v1/plan_service";
import {
PlanCheckRun_Result_Status,
PlanCheckRun_Status,
PlanCheckRun_Type,
} from "@/types/proto/v1/plan_service";
-import { TaskSpinner } from "../../common";
+import { planCheckRunResultStatus } from "./common";
const props = defineProps<{
planCheckRunList: PlanCheckRun[];
@@ -81,7 +81,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/PlanCheckBadgeBar.vue b/frontend/src/components/PlanCheckRun/PlanCheckRunBadgeBar.vue
similarity index 92%
rename from frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckBadgeBar.vue
rename to frontend/src/components/PlanCheckRun/PlanCheckRunBadgeBar.vue
index 0abeac97d2..d0789aa01e 100644
--- a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckBadgeBar.vue
+++ b/frontend/src/components/PlanCheckRun/PlanCheckRunBadgeBar.vue
@@ -1,6 +1,6 @@
<template>
<div class="flex items-center flex-wrap gap-2 flex-1">
- <PlanCheckBadge
+ <PlanCheckRunBadge
v-for="group in planCheckRunsGroupByType"
:key="group.type"
:type="group.type"
@@ -9,8 +9,6 @@
:plan-check-run-list="group.list"
@click="$emit('select-type', group.type)"
/>
- <!-- Default slot for other actions -->
- <slot></slot>
</div>
</template>
@@ -20,7 +18,7 @@ import { computed } from "vue";
import type { PlanCheckRun } from "@/types/proto/v1/plan_service";
import { PlanCheckRun_Type } from "@/types/proto/v1/plan_service";
import { groupBy } from "@/utils/collections";
-import PlanCheckBadge from "./PlanCheckBadge.vue";
+import PlanCheckRunBadge from "./PlanCheckRunBadge.vue";
const props = defineProps<{
planCheckRunList: PlanCheckRun[];
diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckBar.vue b/frontend/src/components/PlanCheckRun/PlanCheckRunBar.vue
similarity index 58%
rename from frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckBar.vue
rename to frontend/src/components/PlanCheckRun/PlanCheckRunBar.vue
index 8d57ad35ea..b5ad72f543 100644
--- a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckBar.vue
+++ b/frontend/src/components/PlanCheckRun/PlanCheckRunBar.vue
@@ -8,20 +8,25 @@
</div>
<div class="flex-1">
- <PlanCheckBadgeBar
+ <PlanCheckRunBadgeBar
:plan-check-run-list="planCheckRunList"
@select-type="selectedType = $event"
/>
</div>
<div class="flex justify-end items-center shrink-0">
- <PlanCheckRunButton v-if="allowRunChecks" @run-checks="runChecks" />
+ <PlanCheckRunButton
+ v-if="allowRunChecks"
+ :plan-check-run-list="planCheckRunList"
+ @run-checks="runChecks"
+ />
</div>
- <PlanCheckModal
+ <PlanCheckRunModal
v-if="planCheckRunList.length > 0 && selectedType"
:selected-type="selectedType"
:plan-check-run-list="planCheckRunList"
+ :database="database"
@close="selectedType = undefined"
/>
</div>
@@ -29,25 +34,25 @@
<script lang="ts" setup>
import { ref } from "vue";
-import {
- notifyNotEditableLegacyIssue,
- useIssueContext,
-} from "@/components/IssueV1/logic";
import { planServiceClient } from "@/grpcweb";
+import type { ComposedDatabase } from "@/types";
import type {
PlanCheckRun,
PlanCheckRun_Type,
} from "@/types/proto/v1/plan_service";
import type { VueClass } from "@/utils";
-import PlanCheckBadgeBar from "./PlanCheckBadgeBar.vue";
-import PlanCheckModal from "./PlanCheckModal.vue";
+import PlanCheckRunBadgeBar from "./PlanCheckRunBadgeBar.vue";
import PlanCheckRunButton from "./PlanCheckRunButton.vue";
+import PlanCheckRunModal from "./PlanCheckRunModal.vue";
+import { usePlanCheckRunContext } from "./context";
-withDefaults(
+const props = withDefaults(
defineProps<{
- allowRunChecks?: boolean;
- labelClass?: VueClass;
- planCheckRunList?: PlanCheckRun[];
+ allowRunChecks: boolean;
+ labelClass: VueClass;
+ planName: string;
+ planCheckRunList: PlanCheckRun[];
+ database: ComposedDatabase;
}>(),
{
allowRunChecks: true,
@@ -56,19 +61,14 @@ withDefaults(
}
);
-const { issue, events } = useIssueContext();
-const selectedType = ref<PlanCheckRun_Type>();
+const { events } = usePlanCheckRunContext();
-const runChecks = () => {
- const { plan } = issue.value;
- if (!plan) {
- notifyNotEditableLegacyIssue();
- return;
- }
+const selectedType = ref<PlanCheckRun_Type>();
- planServiceClient.runPlanChecks({
- name: plan,
+const runChecks = async () => {
+ await planServiceClient.runPlanChecks({
+ name: props.planName,
});
- events.emit("status-changed", { eager: true });
+ events.emit("status-changed");
};
</script>
diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckRunButton.vue b/frontend/src/components/PlanCheckRun/PlanCheckRunButton.vue
similarity index 63%
rename from frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckRunButton.vue
rename to frontend/src/components/PlanCheckRun/PlanCheckRunButton.vue
index 30973299ea..80fcf08011 100644
--- a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckRunButton.vue
+++ b/frontend/src/components/PlanCheckRun/PlanCheckRunButton.vue
@@ -8,7 +8,7 @@
@click="handleRunChecks"
>
<template #icon>
- <BBSpin v-if="hasRunningPlanCheck" :size="20" />
+ <BBSpin v-if="hasRunningPlanCheck" :size="16" />
<heroicons-outline:play v-else class="w-4 h-4" />
</template>
<template #default="{ action }">
@@ -25,35 +25,24 @@
<script setup lang="ts">
import { computed } from "vue";
import { useI18n } from "vue-i18n";
-import {
- planCheckRunListForTask,
- useIssueContext,
-} from "@/components/IssueV1/logic";
import type { ContextMenuButtonAction } from "@/components/v2";
import { ContextMenuButton } from "@/components/v2";
-import { IssueStatus } from "@/types/proto/v1/issue_service";
-import { PlanCheckRun_Status } from "@/types/proto/v1/plan_service";
+import {
+ PlanCheckRun,
+ PlanCheckRun_Status,
+} from "@/types/proto/v1/plan_service";
+
+const props = defineProps<{
+ planCheckRunList: PlanCheckRun[];
+}>();
const emit = defineEmits<{
(event: "run-checks"): void;
}>();
const { t } = useI18n();
-const { isCreating, issue, selectedTask } = useIssueContext();
-
-const allowRunCheckForIssue = computed(() => {
- if (isCreating.value) {
- return false;
- }
- if (issue.value.status !== IssueStatus.OPEN) {
- return false;
- }
- return true;
-});
const actionList = computed(() => {
- if (!allowRunCheckForIssue.value) return [];
-
const actionList: ContextMenuButtonAction[] = [];
actionList.push({
key: "RUN-CHECKS",
@@ -64,19 +53,12 @@ const actionList = computed(() => {
});
const hasRunningPlanCheck = computed((): boolean => {
- if (isCreating.value) return false;
-
- const planCheckRunList = planCheckRunListForTask(
- issue.value,
- selectedTask.value
- );
- return planCheckRunList.some(
+ return props.planCheckRunList.some(
(checkRun) => checkRun.status === PlanCheckRun_Status.RUNNING
);
});
const handleRunChecks = () => {
- if (!allowRunCheckForIssue.value) return;
if (hasRunningPlanCheck.value) return;
emit("run-checks");
};
diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue b/frontend/src/components/PlanCheckRun/PlanCheckRunDetail.vue
similarity index 97%
rename from frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue
rename to frontend/src/components/PlanCheckRun/PlanCheckRunDetail.vue
index 4876ee2c08..55bf975105 100644
--- a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue
+++ b/frontend/src/components/PlanCheckRun/PlanCheckRunDetail.vue
@@ -12,8 +12,8 @@
<div
v-for="(row, i) in highlightTableRows"
:key="i"
- class="py-2 px-2 space-y-2"
:class="[
+ 'py-2 px-2 space-y-2',
row.checkResult.status === PlanCheckRun_Result_Status.ERROR &&
'border-error border rounded',
row.checkResult.status === PlanCheckRun_Result_Status.WARNING &&
@@ -235,7 +235,7 @@
<PlanCheckResultDefinitionModal
v-if="state.activeResultDefinition"
:definition="state.activeResultDefinition"
- @cancel="state.activeResultDefinition = undefined"
+ @close="state.activeResultDefinition = undefined"
/>
</template>
@@ -245,7 +245,6 @@ 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";
@@ -262,8 +261,8 @@ import {
SQLReviewPolicyErrorCode,
getRuleLocalization,
ruleTemplateMapV2,
+ convertPolicyRuleToRuleTemplate,
} from "@/types";
-import { convertPolicyRuleToRuleTemplate } from "@/types";
import {
PlanCheckRun,
PlanCheckRun_Result,
@@ -271,6 +270,7 @@ import {
PlanCheckRun_Status,
} from "@/types/proto/v1/plan_service";
import PlanCheckResultDefinitionModal from "./PlanCheckResultDefinitionModal.vue";
+import { usePlanCheckRunContext } from "./context";
import { OnlineMigrationDetail } from "./detail";
interface ErrorCodeLink {
@@ -297,19 +297,14 @@ const props = defineProps<{
database?: ComposedDatabase;
}>();
-const { events } = useIssueContext();
-
const { t } = useI18n();
const router = useRouter();
+const { events } = usePlanCheckRunContext();
const state = reactive<LocalState>({
activeRule: undefined,
activeResultDefinition: undefined,
});
-const emit = defineEmits<{
- (event: "close"): void;
-}>();
-
const statusIconClass = (status: PlanCheckRun_Result_Status) => {
switch (status) {
case PlanCheckRun_Result_Status.SUCCESS:
@@ -490,7 +485,6 @@ const setActiveRule = (type: string) => {
const handleClickPlanCheckDetailLine = (line: number) => {
window.location.hash = `L${line}`;
- emit("close");
};
const cancelPlanCheckRun = async () => {
@@ -501,6 +495,6 @@ const cancelPlanCheckRun = async () => {
parent: `${projectNamePrefix}${projectName}/${planNamePrefix}${planId}`,
planCheckRuns: [planCheckRunName],
});
- events.emit("status-changed", { eager: true });
+ events.emit("status-changed");
};
</script>
diff --git a/frontend/src/components/PlanCheckRun/PlanCheckRunModal.vue b/frontend/src/components/PlanCheckRun/PlanCheckRunModal.vue
new file mode 100644
index 0000000000..a81cf20a37
--- /dev/null
+++ b/frontend/src/components/PlanCheckRun/PlanCheckRunModal.vue
@@ -0,0 +1,34 @@
+<template>
+ <BBModal
+ :title="$t('task.check-result.title-general')"
+ class="!w-[56rem]"
+ header-class="whitespace-pre-wrap break-all gap-x-1"
+ @close="$emit('close')"
+ >
+ <PlanCheckRunPanel
+ :plan-check-run-list="planCheckRunList"
+ :selected-type="selectedType"
+ :database="database"
+ @close="$emit('close')"
+ />
+ </BBModal>
+</template>
+
+<script setup lang="ts">
+import type { ComposedDatabase } from "@/types";
+import type {
+ PlanCheckRun,
+ PlanCheckRun_Type,
+} from "@/types/proto/v1/plan_service";
+import PlanCheckRunPanel from "./PlanCheckRunPanel.vue";
+
+defineProps<{
+ planCheckRunList: PlanCheckRun[];
+ selectedType: PlanCheckRun_Type;
+ database: ComposedDatabase;
+}>();
+
+defineEmits<{
+ (event: "close"): void;
+}>();
+</script>
diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckPanel.vue b/frontend/src/components/PlanCheckRun/PlanCheckRunPanel.vue
similarity index 83%
rename from frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckPanel.vue
rename to frontend/src/components/PlanCheckRun/PlanCheckRunPanel.vue
index 5d91cb4bf7..9ab4ca7975 100644
--- a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckPanel.vue
+++ b/frontend/src/components/PlanCheckRun/PlanCheckRunPanel.vue
@@ -6,18 +6,17 @@
:items="tabItemList"
/>
- <PlanCheckBadgeBar
+ <PlanCheckRunBadgeBar
:plan-check-run-list="planCheckRunList"
:selected-type="selectedTypeRef"
@select-type="handlePlanCheckRunTypeChange"
/>
- <PlanCheckDetail
+ <PlanCheckRunDetail
v-if="selectedPlanCheckRun"
:plan-check-run="selectedPlanCheckRun"
:database="database"
:show-code-location="isLatestPlanCheckRun"
- @close="$emit('close')"
/>
</div>
</template>
@@ -26,28 +25,24 @@
import { first, orderBy } from "lodash-es";
import { computed, ref } from "vue";
import { useI18n } from "vue-i18n";
-import { databaseForSpec, useIssueContext } from "@/components/IssueV1/logic";
import type { TabFilterItem } from "@/components/v2";
import { TabFilter } from "@/components/v2";
-import { EMPTY_ID } from "@/types";
+import { type ComposedDatabase } from "@/types";
import {
PlanCheckRun_Result_Status,
PlanCheckRun_Type,
type PlanCheckRun,
} from "@/types/proto/v1/plan_service";
import { humanizeDate } from "@/utils";
-import PlanCheckBadgeBar from "./PlanCheckBadgeBar.vue";
-import PlanCheckDetail from "./PlanCheckDetail.vue";
+import PlanCheckRunBadgeBar from "./PlanCheckRunBadgeBar.vue";
+import PlanCheckRunDetail from "./PlanCheckRunDetail.vue";
const props = defineProps<{
planCheckRunList: PlanCheckRun[];
+ database: ComposedDatabase;
selectedType?: PlanCheckRun_Type;
}>();
-defineEmits<{
- (event: "close"): void;
-}>();
-
const getInitialSelectedType = () => {
if (props.selectedType) {
return props.selectedType;
@@ -69,7 +64,6 @@ const getInitialSelectedType = () => {
};
const { t } = useI18n();
-const { issue, selectedSpec } = useIssueContext();
const selectedTypeRef = ref<PlanCheckRun_Type>(getInitialSelectedType());
const selectedPlanCheckRunList = computed(() => {
@@ -115,14 +109,6 @@ const tabItemList = computed(() => {
);
});
-const database = computed(() => {
- const spec = selectedSpec.value;
- if (!spec || spec.id === String(EMPTY_ID)) {
- return;
- }
- return databaseForSpec(issue.value, spec);
-});
-
const handlePlanCheckRunTypeChange = (type: PlanCheckRun_Type) => {
selectedTypeRef.value = type;
selectedPlanCheckRunUID.value = first(selectedPlanCheckRunList.value)?.uid;
diff --git a/frontend/src/components/PlanCheckRun/common.ts b/frontend/src/components/PlanCheckRun/common.ts
new file mode 100644
index 0000000000..2765c2a5d4
--- /dev/null
+++ b/frontend/src/components/PlanCheckRun/common.ts
@@ -0,0 +1,96 @@
+import { maxBy } from "lodash-es";
+import {
+ PlanCheckRun_Result_Status,
+ PlanCheckRun_Status,
+ PlanCheckRun_Type,
+ type PlanCheckRun,
+} from "@/types/proto/v1/plan_service";
+
+export const planCheckRunResultStatus = (checkRun: PlanCheckRun) => {
+ let status = PlanCheckRun_Result_Status.SUCCESS;
+
+ for (const result of checkRun.results) {
+ if (result.status === PlanCheckRun_Result_Status.ERROR) {
+ return PlanCheckRun_Result_Status.ERROR;
+ }
+ if (result.status === PlanCheckRun_Result_Status.WARNING) {
+ status = PlanCheckRun_Result_Status.WARNING;
+ }
+ }
+ return status;
+};
+
+export const HiddenPlanCheckTypes = new Set<PlanCheckRun_Type>([
+ PlanCheckRun_Type.DATABASE_STATEMENT_SUMMARY_REPORT,
+]);
+
+export type PlanCheckRunSummary = {
+ runningCount: number;
+ successCount: number;
+ warnCount: number;
+ errorCount: number;
+};
+
+export const planCheckRunSummaryForCheckRunList = (
+ planCheckRunList: PlanCheckRun[]
+) => {
+ const summary: PlanCheckRunSummary = {
+ runningCount: 0,
+ successCount: 0,
+ warnCount: 0,
+ errorCount: 0,
+ };
+
+ planCheckRunList = planCheckRunList.filter(
+ (check) => !HiddenPlanCheckTypes.has(check.type)
+ );
+
+ const listGroupByTypeTargetSheet = planCheckRunList.reduce(
+ (acc, checkRun) => {
+ const key = `${checkRun.type}-${checkRun.target}-${checkRun.sheet}`;
+ if (!acc[key]) {
+ acc[key] = [];
+ }
+ acc[key].push(checkRun);
+ return acc;
+ },
+ {} as { [key: string]: PlanCheckRun[] }
+ );
+
+ const latestCheckRunOfEachTypeTargetSheet = Object.keys(
+ listGroupByTypeTargetSheet
+ ).map((k) => {
+ const listOfTypeTargetSheet = listGroupByTypeTargetSheet[k];
+ const latest = maxBy(listOfTypeTargetSheet, (checkRun) =>
+ Number(checkRun.uid)
+ )!;
+ return latest;
+ });
+
+ for (const checkRun of latestCheckRunOfEachTypeTargetSheet) {
+ switch (checkRun.status) {
+ case PlanCheckRun_Status.CANCELED:
+ // nothing todo
+ break;
+ case PlanCheckRun_Status.FAILED:
+ summary.errorCount++;
+ break;
+ case PlanCheckRun_Status.RUNNING:
+ summary.runningCount++;
+ break;
+ case PlanCheckRun_Status.DONE:
+ switch (planCheckRunResultStatus(checkRun)) {
+ case PlanCheckRun_Result_Status.SUCCESS:
+ summary.successCount++;
+ break;
+ case PlanCheckRun_Result_Status.WARNING:
+ summary.warnCount++;
+ break;
+ case PlanCheckRun_Result_Status.ERROR:
+ summary.errorCount++;
+ }
+ }
+ }
+
+ return summary;
+};
diff --git a/frontend/src/components/PlanCheckRun/context.ts b/frontend/src/components/PlanCheckRun/context.ts
new file mode 100644
index 0000000000..011d8d950c
--- /dev/null
+++ b/frontend/src/components/PlanCheckRun/context.ts
@@ -0,0 +1,34 @@
+import type Emittery from "emittery";
+import { v4 as uuidv4 } from "uuid";
+import type { InjectionKey } from "vue";
+import { inject, provide } from "vue";
+
+export type PlanCheckRunEvents = Emittery<{
+ "status-changed": undefined;
+}>;
+
+export type PlanCheckRunContext = {
+ events: PlanCheckRunEvents;
+};
+
+const KEY = Symbol(
+ `bb.plan-check-run.context.${uuidv4()}`
+) as InjectionKey<PlanCheckRunContext>;
+
+export const usePlanCheckRunContext = () => {
+ return inject(KEY)!;
+};
+
+export const providePlanCheckRunContext = (
+ context: Partial<PlanCheckRunContext>,
+ root = false
+) => {
+ if (!root) {
+ const parent = usePlanCheckRunContext();
+ context = {
+ ...parent,
+ ...context,
+ };
+ }
+ provide(KEY, context as PlanCheckRunContext);
+};
diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/detail/OnlineMigrationDetail.vue b/frontend/src/components/PlanCheckRun/detail/OnlineMigrationDetail.vue
similarity index 85%
rename from frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/detail/OnlineMigrationDetail.vue
rename to frontend/src/components/PlanCheckRun/detail/OnlineMigrationDetail.vue
index d7a209e2e4..da1603101b 100644
--- a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/detail/OnlineMigrationDetail.vue
+++ b/frontend/src/components/PlanCheckRun/detail/OnlineMigrationDetail.vue
@@ -10,7 +10,7 @@
<script setup lang="ts">
import { computed } from "vue";
-import type { PlanCheckDetailTableRow } from "../PlanCheckDetail.vue";
+import type { PlanCheckDetailTableRow } from "../PlanCheckRunDetail.vue";
const props = defineProps<{
row: PlanCheckDetailTableRow;
diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/detail/index.ts b/frontend/src/components/PlanCheckRun/detail/index.ts
similarity index 100%
rename from frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/detail/index.ts
rename to frontend/src/components/PlanCheckRun/detail/index.ts
diff --git a/frontend/src/components/SQLCheck/SQLCheckButton.vue b/frontend/src/components/SQLCheck/SQLCheckButton.vue
index 32df7c677a..8230422a65 100644
--- a/frontend/src/components/SQLCheck/SQLCheckButton.vue
+++ b/frontend/src/components/SQLCheck/SQLCheckButton.vue
@@ -86,6 +86,7 @@ import type { CheckRequest_ChangeType } from "@/types/proto/v1/sql_service";
import { Advice, Advice_Status } from "@/types/proto/v1/sql_service";
import type { Defer, VueStyle } from "@/utils";
import { defer, hasWorkspacePermissionV2 } from "@/utils";
+import { providePlanCheckRunContext } from "../PlanCheckRun/context";
import ErrorList from "../misc/ErrorList.vue";
import SQLCheckPanel from "./SQLCheckPanel.vue";
import SQLCheckSummary from "./SQLCheckSummary.vue";
@@ -166,6 +167,8 @@ const policyErrors = computed(() => {
return [];
});
+providePlanCheckRunContext({});
+
const runCheckInternal = async (
statement: string,
databaseMetadata: DatabaseMetadata | undefined
diff --git a/frontend/src/components/SQLCheck/SQLCheckPanel.vue b/frontend/src/components/SQLCheck/SQLCheckPanel.vue
index d5ee3d8664..1a53fb6687 100644
--- a/frontend/src/components/SQLCheck/SQLCheckPanel.vue
+++ b/frontend/src/components/SQLCheck/SQLCheckPanel.vue
@@ -8,16 +8,15 @@
container-class="!pt-0 -mt-px"
@close="$emit('close')"
>
- <PlanCheckDetail
+ <PlanCheckRunDetail
:plan-check-run="planCheckRun"
:database="database"
:show-code-location="showCodeLocation"
- @close="$emit('close')"
>
<template #row-title-extra="{ row }">
<slot name="row-title-extra" :row="row" />
</template>
- </PlanCheckDetail>
+ </PlanCheckRunDetail>
<div
v-if="confirm"
@@ -40,6 +39,7 @@
<script setup lang="ts">
import { NButton } from "naive-ui";
import { computed, watchEffect, ref } from "vue";
+import PlanCheckRunDetail from "@/components/PlanCheckRun/PlanCheckRunDetail.vue";
import { usePolicyV1Store } from "@/store";
import type { ComposedDatabase } from "@/types";
import { PolicyType } from "@/types/proto/v1/org_policy_service";
@@ -53,7 +53,6 @@ import {
import type { Advice } from "@/types/proto/v1/sql_service";
import { Advice_Status } from "@/types/proto/v1/sql_service";
import type { Defer } from "@/utils";
-import PlanCheckDetail from "../IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue";
const props = defineProps<{
database: ComposedDatabase;
diff --git a/frontend/src/views/project/ProjectIssueDetail.vue b/frontend/src/views/project/ProjectIssueDetail.vue
index 93b44d9ff2..6593faf5e8 100644
--- a/frontend/src/views/project/ProjectIssueDetail.vue
+++ b/frontend/src/views/project/ProjectIssueDetail.vue
@@ -18,6 +18,7 @@
<script lang="ts" setup>
import { useTitle } from "@vueuse/core";
+import Emittery from "emittery";
import { NSpin } from "naive-ui";
import { computed, onMounted, reactive, toRef } from "vue";
import { useI18n } from "vue-i18n";
@@ -29,6 +30,10 @@ import {
useBaseIssueContext,
useInitializeIssue,
} from "@/components/IssueV1";
+import {
+ providePlanCheckRunContext,
+ type PlanCheckRunEvents,
+} from "@/components/PlanCheckRun/context";
import { useBodyLayoutContext } from "@/layouts/common";
import { useUIStateStore } from "@/store";
import { UNKNOWN_ID } from "@/types";
@@ -62,17 +67,33 @@ const ready = computed(() => {
});
const uiStateStore = useUIStateStore();
+const issueBaseContext = useBaseIssueContext({
+ isCreating,
+ ready,
+ issue,
+});
+
provideIssueContext(
{
isCreating,
issue,
ready,
reInitialize,
- ...useBaseIssueContext({
- isCreating,
- ready,
- issue,
- }),
+ ...issueBaseContext,
+ },
+ true /* root */
+);
+
+providePlanCheckRunContext(
+ {
+ events: (() => {
+ const emittery: PlanCheckRunEvents = new Emittery();
+ emittery.on("status-changed", () => {
+ // If the status of plan checks changes, trigger a refresh.
+ issueBaseContext.events?.emit("status-changed", { eager: true });
+ });
+ return emittery;
+ })(),
},
true /* root */
);
diff --git a/frontend/src/views/project/ProjectPlanDetail.vue b/frontend/src/views/project/ProjectPlanDetail.vue
index 08559be015..5b0a1c5aff 100644
--- a/frontend/src/views/project/ProjectPlanDetail.vue
+++ b/frontend/src/views/project/ProjectPlanDetail.vue
@@ -16,6 +16,7 @@
<script lang="ts" setup>
import { useTitle } from "@vueuse/core";
+import Emittery from "emittery";
import { NSpin } from "naive-ui";
import { computed, reactive, toRef } from "vue";
import { useI18n } from "vue-i18n";
@@ -25,6 +26,10 @@ import {
useInitializePlan,
} from "@/components/Plan";
import PlanDetailPage from "@/components/Plan/PlanDetailPage.vue";
+import {
+ providePlanCheckRunContext,
+ type PlanCheckRunEvents,
+} from "@/components/PlanCheckRun/context";
import { useBodyLayoutContext } from "@/layouts/common";
import { UNKNOWN_ID } from "@/types";
@@ -54,6 +59,11 @@ const { isCreating, plan, isInitializing, reInitialize } = useInitializePlan(
const ready = computed(() => {
return !isInitializing.value && !!plan.value;
});
+const planBaseContext = useBasePlanContext({
+ isCreating,
+ ready,
+ plan,
+});
providePlanContext(
{
@@ -61,11 +71,21 @@ providePlanContext(
plan,
ready,
reInitialize,
- ...useBasePlanContext({
- isCreating,
- ready,
- plan,
- }),
+ ...planBaseContext,
+ },
+ true /* root */
+);
+
+providePlanCheckRunContext(
+ {
+ events: (() => {
+ const emittery: PlanCheckRunEvents = new Emittery();
+ emittery.on("status-changed", () => {
+ // If the status of plan checks changes, trigger a refresh.
+ planBaseContext.events?.emit("status-changed", { eager: true });
+ });
+ return emittery;
+ })(),
},
true /* root */
);