Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: update spec list section (#16090)
boojack6d5729e158b9
diff --git a/frontend/src/components/IssueV1/components/TaskListSection/TaskFilter.vue b/frontend/src/components/IssueV1/components/TaskListSection/TaskFilter.vueindex 41ca11d241..74132fc51d 100644--- a/frontend/src/components/IssueV1/components/TaskListSection/TaskFilter.vue+++ b/frontend/src/components/IssueV1/components/TaskListSection/TaskFilter.vue@@ -11,7 +11,7 @@class="bg-gray-50 pl-2 p-1 flex flex-row items-center rounded-full gap-1"><span class="text-sm mr-1 text-gray-600">{{- $t("issue.sql-check.sql-checks")+ isCreating ? $t("issue.sql-check.sql-checks") : $t("task.task-checks")}}</span><template v-for="status in ADVICE_STATUS_FILTERS" :key="status"><NTagdiff --git a/frontend/src/components/IssueV1/components/TaskListSection/filter.ts b/frontend/src/components/IssueV1/components/TaskListSection/filter.tsindex 1ce5df2119..2f7bfd94c7 100644--- a/frontend/src/components/IssueV1/components/TaskListSection/filter.ts+++ b/frontend/src/components/IssueV1/components/TaskListSection/filter.ts@@ -1,14 +1,9 @@+import { planCheckRunSummaryForCheckRunList } from "@/components/PlanCheckRun/common";import type { Task, Task_Status } from "@/types/proto/v1/rollout_service";import { Advice_Status } from "@/types/proto/v1/sql_service";import { type IssueContext } from "../../logic";import { type SQLCheckContext } from "../SQLCheckSection/context";-export interface TaskFilter {- // Only for created tasks.- status: Task_Status[];- adviceStatus: Advice_Status[];-}-export const filterTask = (issueContext: IssueContext,sqlCheckContext: SQLCheckContext,@@ -42,12 +37,16 @@ export const filterTask = ();}} else {- const planCheckRuns = getPlanCheckRunsForTask(task);- return planCheckRuns.some((run) =>- run.results.some(- (result) => result.status.toString() === adviceStatus.toString()- )+ const summary = planCheckRunSummaryForCheckRunList(+ getPlanCheckRunsForTask(task));+ if (summary.errorCount > 0) {+ return adviceStatus === Advice_Status.ERROR;+ } else if (summary.warnCount > 0) {+ return adviceStatus === Advice_Status.WARNING;+ } else {+ return adviceStatus === Advice_Status.SUCCESS;+ }}}diff --git a/frontend/src/components/Plan/components/SpecListSection/CurrentSpecSection.vue b/frontend/src/components/Plan/components/SpecListSection/CurrentSpecSection.vuenew file mode 100644index 0000000000..5e7c1a494d--- /dev/null+++ b/frontend/src/components/Plan/components/SpecListSection/CurrentSpecSection.vue@@ -0,0 +1,122 @@+<template>+ <div class="px-4 py-2 flex flex-row items-center gap-x-4">+ <span class="textlabel">{{ $t("task.current-task") }}</span>+ <div class="flex items-center flex-wrap gap-1">+ <InstanceV1Name+ v-if="!isCreatingDatabaseSpec"+ :instance="coreDatabaseInfo.instanceResource"+ :plain="true"+ :link="link"+ >+ <template+ v-if="+ database &&+ formatEnvironmentName(instanceEnvironment.id) !==+ database.effectiveEnvironment+ "+ #prefix+ >+ <EnvironmentV1Name+ :environment="instanceEnvironment"+ :plain="true"+ :show-icon="false"+ :link="link"+ text-class="text-control-light"+ />+ </template>+ </InstanceV1Name>+ <span v-else>+ <!-- For creating database issues, we will only show the resource id of target instance. -->+ {{ extractInstanceResourceName(targetOfSpec(selectedSpec) || "") }}+ </span>++ <ChevronRightIcon class="text-control-light" :size="16" />++ <div class="flex items-center gap-x-1">+ <DatabaseIcon class="text-control-light" :size="16" />++ <template v-if="!isCreatingDatabaseSpec">+ <EnvironmentV1Name+ :environment="coreDatabaseInfo.effectiveEnvironmentEntity"+ :plain="true"+ :show-icon="false"+ :link="link"+ text-class="text-control-light"+ />++ <DatabaseV1Name+ :database="coreDatabaseInfo"+ :plain="true"+ :link="link"+ />+ </template>+ <span v-else>+ {{ coreDatabaseInfo.databaseName }}+ </span>+ </div>+ </div>+ </div>+</template>++<script lang="ts" setup>+import { computedAsync } from "@vueuse/core";+import { ChevronRightIcon, DatabaseIcon } from "lucide-vue-next";+import { computed } from "vue";+import {+ DatabaseV1Name,+ EnvironmentV1Name,+ InstanceV1Name,+} from "@/components/v2";+import { useDatabaseV1Store, useEnvironmentV1Store } from "@/store";+import {+ formatEnvironmentName,+ isValidDatabaseName,+ unknownEnvironment,+} from "@/types";+import { extractInstanceResourceName, isNullOrUndefined } from "@/utils";+import { databaseForSpec, targetOfSpec, usePlanContext } from "../../logic";++withDefaults(+ defineProps<{+ link?: boolean;+ }>(),+ {+ link: true,+ }+);++const { plan, selectedSpec } = usePlanContext();++const coreDatabaseInfo = computed(() => {+ return databaseForSpec(plan.value, selectedSpec.value);+});++const isCreatingDatabaseSpec = computed(+ () => !isNullOrUndefined(selectedSpec.value.createDatabaseConfig)+);++const database = computedAsync(async () => {+ const maybeExistedDatabase = coreDatabaseInfo.value;+ if (isValidDatabaseName(maybeExistedDatabase.name)) {+ return maybeExistedDatabase;+ }+ if (isCreatingDatabaseSpec.value) {+ const name = coreDatabaseInfo.value.name;+ const maybeCreatedDatabase =+ await useDatabaseV1Store().getOrFetchDatabaseByName(name);+ if (isValidDatabaseName(maybeCreatedDatabase.name)) {+ return maybeCreatedDatabase;+ }+ }+ return undefined;+}, undefined);++const instanceEnvironment = computed(() => {+ if (!database.value) return unknownEnvironment();+ return (+ useEnvironmentV1Store().getEnvironmentByName(+ database.value.instanceResource.environment+ ) ?? unknownEnvironment()+ );+});+</script>diff --git a/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue b/frontend/src/components/Plan/components/SpecListSection/SpecCard.vueindex 71a93c2dcf..75b96fc1ce 100644--- a/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue+++ b/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue@@ -15,8 +15,8 @@placement="top"><template #trigger>- <heroicons:exclamation-circle-solid- class="w-5 h-5 shrink-0"+ <AlertCircleIcon+ class="w-4 h-4 shrink-0":class="[planCheckStatus === PlanCheckRun_Result_Status.ERROR? 'text-error hover:text-error-hover'@@ -64,13 +64,13 @@<script setup lang="ts">import { isEqual } from "lodash-es";+import { AlertCircleIcon } from "lucide-vue-next";import { NTooltip } from "naive-ui";-import { computed, onMounted } from "vue";+import { computed } from "vue";import DatabaseGroupIcon from "@/components/DatabaseGroupIcon.vue";import { planCheckRunSummaryForCheckRunList } from "@/components/PlanCheckRun/common";import { InstanceV1Name } from "@/components/v2";-import { useDatabaseV1Store, useDBGroupStore } from "@/store";-import { DatabaseGroupView } from "@/types/proto/v1/database_group_service";+import { useDBGroupStore } from "@/store";import {PlanCheckRun_Result_Status,type Plan_Spec,@@ -88,7 +88,6 @@ const props = defineProps<{}>();const { isCreating, plan, selectedSpec, events } = usePlanContext();-const databaseStore = useDatabaseV1Store();const dbGroupStore = useDBGroupStore();const specClass = computed(() => {@@ -132,23 +131,6 @@ const planCheckStatus = computed((): PlanCheckRun_Result_Status => {return PlanCheckRun_Result_Status.SUCCESS;});-// Prepare target.-onMounted(async () => {- if (isDatabaseChangeSpec(props.spec)) {- await databaseStore.getOrFetchDatabaseByName(- props.spec.changeDatabaseConfig!.target- );- } else if (isGroupingChangeSpec(props.spec)) {- await dbGroupStore.getOrFetchDBGroupByName(- props.spec.changeDatabaseConfig!.target,- {- skipCache: true,- view: DatabaseGroupView.DATABASE_GROUP_VIEW_FULL,- }- );- }-});-const onClickSpec = (spec: Plan_Spec) => {events.emit("select-spec", { spec });};diff --git a/frontend/src/components/Plan/components/SpecListSection/SpecFilter.vue b/frontend/src/components/Plan/components/SpecListSection/SpecFilter.vuenew file mode 100644index 0000000000..94772f97b2--- /dev/null+++ b/frontend/src/components/Plan/components/SpecListSection/SpecFilter.vue@@ -0,0 +1,83 @@+<template>+ <div class="w-full flex flex-row gap-4">+ <div class="flex items-center justify-between">+ <h3 class="textlabel">+ {{ $t("common.tasks") }}+ <span>({{ specList.length }})</span>+ </h3>+ </div>+ <div class="flex flex-row gap-2 items-center">+ <div+ class="bg-gray-50 pl-2 p-1 flex flex-row items-center rounded-full gap-1"+ >+ <span class="text-sm mr-1 text-gray-600">{{+ $t("issue.sql-check.sql-checks")+ }}</span>+ <template v-for="status in ADVICE_STATUS_FILTERS" :key="status">+ <NTag+ v-if="getSpecCount(status) > 0"+ :disabled="disabled"+ :size="'small'"+ round+ checkable+ :checked="adviceStatusList.includes(status)"+ @update:checked="+ (checked) => {+ emit(+ 'update:adviceStatusList',+ checked+ ? [...adviceStatusList, status]+ : adviceStatusList.filter((s) => s !== status)+ );+ }+ "+ >+ <template #avatar>+ <AdviceStatusIcon :status="status" />+ </template>+ <span class="select-none">{{ getSpecCount(status) }}</span>+ </NTag>+ </template>+ </div>+ </div>+ </div>+</template>++<script lang="ts" setup>+import { NTag } from "naive-ui";+import { computed } from "vue";+import { Advice_Status } from "@/types/proto/v1/sql_service";+import { usePlanContext } from "../../logic";+import AdviceStatusIcon from "../SQLCheckSectionV1/AdviceStatusIcon.vue";+import { usePlanSQLCheckContext } from "../SQLCheckSectionV1/context";+import { filterSpec } from "./filter";++defineProps<{+ disabled: boolean;+ adviceStatusList: Advice_Status[];+}>();++const emit = defineEmits<{+ (event: "update:adviceStatusList", adviceStatusList: Advice_Status[]): void;+}>();++const ADVICE_STATUS_FILTERS: Advice_Status[] = [+ Advice_Status.UNRECOGNIZED,+ Advice_Status.SUCCESS,+ Advice_Status.WARNING,+ Advice_Status.ERROR,+];++const planContext = usePlanContext();+const sqlCheckContext = usePlanSQLCheckContext();++const { plan } = planContext;++const specList = computed(() => plan.value.steps.flatMap((step) => step.specs));++const getSpecCount = (adviceStatus?: Advice_Status) => {+ return specList.value.filter((spec) =>+ filterSpec(planContext, sqlCheckContext, spec, { adviceStatus })+ ).length;+};+</script>diff --git a/frontend/src/components/Plan/components/SpecListSection/SpecListSection.vue b/frontend/src/components/Plan/components/SpecListSection/SpecListSection.vueindex ac5af3c8be..5e21118b10 100644--- a/frontend/src/components/Plan/components/SpecListSection/SpecListSection.vue+++ b/frontend/src/components/Plan/components/SpecListSection/SpecListSection.vue@@ -1,34 +1,181 @@<template>- <div class="w-full relative">+ <div class="w-relative"><div- ref="specBar"- class="spec-list gap-2 px-4 py-2 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 3xl:grid-cols-5 4xl:grid-cols-6 overflow-y-auto"- :class="{- 'more-bottom': specBarScrollState.bottom,- 'more-top': specBarScrollState.top,- }"- :style="{- 'max-height': `${MAX_LIST_HEIGHT}px`,- }"+ v-if="shouldShowSpecFilter"+ class="w-full sticky top-0 z-10 bg-white px-4 pt-2 pb-1">- <SpecCard v-for="(spec, i) in specList" :key="i" :spec="spec" />+ <SpecFilter+ :disabled="state.isRequesting"+ v-model:advice-status-list="state.adviceStatusFilters"+ />+ </div>+ <div class="w-full relative">+ <div+ ref="specBar"+ class="spec-list gap-2 px-4 py-2 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 3xl:grid-cols-5 4xl:grid-cols-6 overflow-y-auto"+ :class="{+ 'more-bottom': specBarScrollState.bottom,+ 'more-top': specBarScrollState.top,+ }"+ :style="{+ 'max-height': `${MAX_LIST_HEIGHT}px`,+ }"+ >+ <SpecCard+ v-for="(spec, i) in filteredSpecList.slice(0, state.index)"+ :key="i"+ :spec="spec"+ />+ <div+ v-show="state.isRequesting"+ class="col-span-full flex items-center justify-center py-4"+ >+ <BBSpin />+ </div>+ <div+ v-if="filteredSpecList.length > state.index"+ class="col-span-full flex flex-row items-center justify-end"+ >+ <NButton+ size="small"+ quaternary+ :loading="state.isRequesting"+ @click="loadMore"+ >+ {{ $t("common.load-more") }}+ </NButton>+ </div>+ </div></div></div>++ <CurrentSpecSection v-if="shouldShowCurrentSpecView" /></template><script lang="ts" setup>-import { computed, ref } from "vue";+import { useDebounceFn } from "@vueuse/core";+import { head } from "lodash-es";+import { NButton } from "naive-ui";+import { computed, reactive, ref, watch } from "vue";+import { BBSpin } from "@/bbkit";import { useVerticalScrollState } from "@/composables/useScrollState";-import { usePlanContext } from "../../logic";+import { batchGetOrFetchDatabases, useDBGroupStore } from "@/store";+import type { Advice_Status } from "@/types/proto/v1/sql_service";+import { isDev } from "@/utils";+import {+ databaseForSpec,+ isDatabaseChangeSpec,+ isGroupingChangeSpec,+ targetOfSpec,+ usePlanContext,+} from "../../logic";+import { usePlanSQLCheckContext } from "../SQLCheckSectionV1/context";+import CurrentSpecSection from "./CurrentSpecSection.vue";import SpecCard from "./SpecCard.vue";+import SpecFilter from "./SpecFilter.vue";+import { filterSpec } from "./filter";++interface LocalState {+ // Index is the current number of specs to show.+ index: number;+ adviceStatusFilters: Advice_Status[];+ isRequesting: boolean;+}const MAX_LIST_HEIGHT = 256;-const { plan } = usePlanContext();+// The default number of specs to show per page.+// This is set to 4 in development mode for easier testing.+const SPEC_PER_PAGE = isDev() ? 4 : 20;++const planContext = usePlanContext();+const sqlCheckContext = usePlanSQLCheckContext();+const { plan, selectedSpec } = planContext;+const dbGroupStore = useDBGroupStore();+const state = reactive<LocalState>({+ index: 0,+ adviceStatusFilters: [],+ isRequesting: false,+});const specBar = ref<HTMLDivElement>();const specBarScrollState = useVerticalScrollState(specBar, MAX_LIST_HEIGHT);const specList = computed(() => plan.value.steps.flatMap((step) => step.specs));++const filteredSpecList = computed(() => {+ return specList.value.filter((spec) => {+ if (state.adviceStatusFilters.length > 0) {+ if (+ !state.adviceStatusFilters.some((status) =>+ filterSpec(planContext, sqlCheckContext, spec, {+ adviceStatus: status,+ })+ )+ ) {+ return false;+ }+ }+ return true;+ });+});++const shouldShowSpecFilter = computed(() => {+ return (+ specList.value.length > 2 &&+ // Only show the filter when every spec is a database change spec.+ // Excluding database group spec.+ specList.value.every((spec) => isDatabaseChangeSpec(spec))+ );+});++const shouldShowCurrentSpecView = computed(() => {+ // Only show the current spec view when the selected spec is not in the filtered list.+ return !filteredSpecList.value+ .slice(0, state.index)+ .some((spec) => spec.id === selectedSpec.value.id);+});++const loadMore = useDebounceFn(async () => {+ if (state.isRequesting) return;++ const isGroupChangingPlan = specList.value.every((spec) =>+ isGroupingChangeSpec(spec)+ );+ if (isGroupChangingPlan) {+ // Should be only one database group in the plan.+ const spec = head(specList.value);+ if (!spec) {+ throw new Error("No spec found in the plan");+ }+ const databaseGroupName = targetOfSpec(spec);+ if (!databaseGroupName) {+ throw new Error("No database group name found in the spec");+ }+ await dbGroupStore.getOrFetchDBGroupByName(databaseGroupName);+ } else {+ const fromIndex = state.index;+ const toIndex = fromIndex + SPEC_PER_PAGE;+ const databaseNames = filteredSpecList.value+ .slice(fromIndex, toIndex)+ .map((spec) => databaseForSpec(plan.value, spec).name);++ state.isRequesting = true;+ try {+ await batchGetOrFetchDatabases(databaseNames);+ } finally {+ state.index = toIndex;+ state.isRequesting = false;+ }+ }+}, 500);++watch(+ () => plan.value.name,+ async () => {+ await loadMore();+ },+ { immediate: true }+);</script><style scoped lang="postcss">diff --git a/frontend/src/components/Plan/components/SpecListSection/filter.ts b/frontend/src/components/Plan/components/SpecListSection/filter.tsnew file mode 100644index 0000000000..8f7f95149d--- /dev/null+++ b/frontend/src/components/Plan/components/SpecListSection/filter.ts@@ -0,0 +1,51 @@+import { planCheckRunSummaryForCheckRunList } from "@/components/PlanCheckRun/common";+import type { Plan_Spec } from "@/types/proto/v1/plan_service";+import { Advice_Status } from "@/types/proto/v1/sql_service";+import { sheetNameOfSpec } from "@/utils";+import { targetOfSpec, type PlanContext } from "../../logic";+import type { SQLCheckContext } from "../SQLCheckSectionV1/context";++export const filterSpec = (+ planContext: PlanContext,+ sqlCheckContext: SQLCheckContext,+ spec: Plan_Spec,+ {+ adviceStatus,+ }: {+ adviceStatus?: Advice_Status;+ }+): boolean => {+ const { isCreating } = planContext;+ if (adviceStatus) {+ if (isCreating.value) {+ const { resultMap } = sqlCheckContext;+ const result = resultMap.value[targetOfSpec(spec) || ""];+ if (adviceStatus === Advice_Status.UNRECOGNIZED) {+ return !Boolean(result);+ }+ if (adviceStatus === Advice_Status.SUCCESS) {+ return result && result.advices.length === 0;+ }+ return (+ result &&+ result.advices.some((advice) => advice.status === adviceStatus)+ );+ } else {+ const planCheckRuns = planContext.plan.value.planCheckRunList.filter(+ (run) =>+ run.sheet === sheetNameOfSpec(spec) &&+ run.target === targetOfSpec(spec)+ );+ const summary = planCheckRunSummaryForCheckRunList(planCheckRuns);+ if (summary.errorCount > 0) {+ return adviceStatus === Advice_Status.ERROR;+ } else if (summary.warnCount > 0) {+ return adviceStatus === Advice_Status.WARNING;+ } else {+ return adviceStatus === Advice_Status.SUCCESS;+ }+ }+ }++ return false;+};diff --git a/frontend/src/components/Plan/logic/initialize/create.ts b/frontend/src/components/Plan/logic/initialize/create.tsindex cfd89e8d8b..5eaa1325ad 100644--- a/frontend/src/components/Plan/logic/initialize/create.ts+++ b/frontend/src/components/Plan/logic/initialize/create.ts@@ -58,15 +58,12 @@ export const createPlanSkeleton = async (`${projectNamePrefix}${projectName}`);const databaseNameList = (query.databaseList ?? "").split(",");- await batchGetOrFetchDatabases(databaseNameList);-const params: CreatePlanParams = {databaseNameList,project,query,initialSQL: await extractInitialSQLFromQuery(query),};-const plan = await buildPlan(params);return plan;};diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex e11d3cc9be..a6dac4d9c3 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -916,7 +916,7 @@},"you-are-not-allowed-to-change-this-value": "You are not allowed to change this value","sql-check": {- "sql-checks": "SQL Checks",+ "sql-checks": "SQL checks","not-executed-yet": "Not executed yet","statement-is-required": "SQL statement is required","statement-is-too-large": "As the current statement size exceeds 2MB, the SQL check will be skipped.",diff --git a/frontend/src/store/modules/v1/plan.ts b/frontend/src/store/modules/v1/plan.tsindex 119171ee4c..7b1b735677 100644--- a/frontend/src/store/modules/v1/plan.ts+++ b/frontend/src/store/modules/v1/plan.ts@@ -18,7 +18,6 @@ import {hasProjectPermissionV2,type SearchParams,} from "@/utils";-import { batchGetOrFetchDatabases } from "./database";import { useProjectV1Store } from "./project";export interface PlanFind {@@ -90,13 +89,6 @@ export const composePlan = async (rawPlan: Plan): Promise<ComposedPlan> => {projectEntity,creatorEntity,};-- await batchGetOrFetchDatabases(- plan.steps- .flatMap((step) => step.specs)- .flatMap((spec) => spec.changeDatabaseConfig?.target ?? "")- );-if (hasProjectPermissionV2(projectEntity, "bb.planCheckRuns.list")) {// Only show the latest plan check runs.// TODO(steven): maybe we need to show all plan check runs on a separate page later.@@ -106,7 +98,6 @@ export const composePlan = async (rawPlan: Plan): Promise<ComposedPlan> => {});plan.planCheckRunList = orderBy(planCheckRuns, "name", "desc");}-return plan;};