Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor: migrate issue list batch status ops to v1 api (#8173)
Liu Ji9ffa53974709
diff --git a/frontend/src/components/IssueV1/components/BatchIssueActionsV1.vue b/frontend/src/components/IssueV1/components/BatchIssueActionsV1.vueindex 6227e97192..4d6615fcf0 100644--- a/frontend/src/components/IssueV1/components/BatchIssueActionsV1.vue+++ b/frontend/src/components/IssueV1/components/BatchIssueActionsV1.vue@@ -1,9 +1,9 @@<template><BBTooltipButtontype="primary"- :disabled="!isTransitionApplicableForAllIssues('RESOLVE')"+ :disabled="!isActionApplicableForAllIssues('RESOLVE')"tooltip-mode="DISABLED-ONLY"- @click="startBatchIssueTransition('RESOLVE')"+ @click="startBatchIssueStatusAction('RESOLVE')">{{ $t("issue.batch-transition.resolve") }}<template #tooltip>@@ -19,9 +19,9 @@<BBTooltipButtontype="normal"- :disabled="!isTransitionApplicableForAllIssues('CANCEL')"+ :disabled="!isActionApplicableForAllIssues('CANCEL')"tooltip-mode="DISABLED-ONLY"- @click="startBatchIssueTransition('CANCEL')"+ @click="startBatchIssueStatusAction('CANCEL')">{{ $t("issue.batch-transition.cancel") }}<template #tooltip>@@ -37,9 +37,9 @@<BBTooltipButtontype="normal"- :disabled="!isTransitionApplicableForAllIssues('REOPEN')"+ :disabled="!isActionApplicableForAllIssues('REOPEN')"tooltip-mode="DISABLED-ONLY"- @click="startBatchIssueTransition('REOPEN')"+ @click="startBatchIssueStatusAction('REOPEN')">{{ $t("issue.batch-transition.reopen") }}<template #tooltip>@@ -53,106 +53,29 @@</template></BBTooltipButton>- <BBModal- v-if="state.modal.show"- :title="state.modal.title"- class="relative overflow-hidden"- @close="state.modal.show = false"- >- <div- v-if="state.isRequesting"- class="absolute inset-0 flex flex-col items-center justify-center bg-white/70"- >- <BBSpin />- <div class="flex items-center textlabel">- <span>{{ $t("common.updating") }}</span>- <span v-if="state.stats"- >({{ state.stats.success }} / {{ state.stats.total }})</span- >- </div>- </div>-- <div>- <div class="sm:col-span-4 w-112 min-w-full">- <label for="about" class="textlabel">- {{ $t("issue.status-transition.form.note") }}- </label>- <div class="mt-1">- <textarea- ref="commentTextArea"- v-model="state.modal.comment"- rows="3"- class="textarea block w-full resize-none mt-1 text-sm text-control rounded-md whitespace-pre-wrap"- :placeholder="$t('issue.status-transition.form.placeholder')"- @input="- (e) => {- sizeToFit(e.target as HTMLTextAreaElement);- }- "- @focus="- (e) => {- sizeToFit(e.target as HTMLTextAreaElement);- }- "- ></textarea>- </div>- </div>- </div>-- <!-- Update button group -->- <div class="flex justify-end items-center pt-5">- <button- type="button"- class="btn-normal mt-3 px-4 py-2 sm:mt-0 sm:w-auto"- @click.prevent="state.modal.show = false"- >- {{ $t("common.cancel") }}- </button>- <button- type="button"- class="ml-3 px-4 py-2"- :class="state.modal.okButtonClass"- @click="doBatchIssueTransition(state.modal.transition!)"- >- {{ state.modal.okButtonText }}- </button>- </div>- </BBModal>+ <BatchIssueStatusActionPanel+ :issue-list="issueList"+ :action="ongoingIssueStatusAction?.action"+ @updating="state.isRequesting = true"+ @updated="handleUpdated"+ @close="ongoingIssueStatusAction = undefined"+ /></template><script lang="ts" setup>-import { computed, PropType, reactive } from "vue";+import { computed, PropType, reactive, ref } from "vue";import { useI18n } from "vue-i18n";-import { pushNotification, refreshIssueList, useIssueStore } from "@/store";-import type {- ComposedIssue,- IssueStatusPatch,- IssueStatusTransition,- IssueStatusTransitionType,-} from "@/types";-import { ISSUE_STATUS_TRANSITION_LIST } from "@/types";-import { extractIssueUID } from "@/utils";-import { calcApplicableIssueStatusTransitionList } from "../logic/transition";--type RequestStats = {- total: number;- success: number;- failed: number;-};--type ModalProps = {- show: boolean;- title: string;- comment: string;- transition?: IssueStatusTransition;- okButtonText: string;- okButtonClass?: string;-};+import { refreshIssueList } from "@/store";+import type { ComposedIssue } from "@/types";+import {+ getApplicableIssueStatusActionList,+ IssueStatusAction,+ issueStatusActionDisplayName,+} from "../logic";+import { BatchIssueStatusActionPanel } from "./Panel";type LocalState = {isRequesting: boolean;- modal: ModalProps;- stats?: RequestStats;};const props = defineProps({@@ -164,91 +87,41 @@ const props = defineProps({const state = reactive<LocalState>({isRequesting: false,- modal: {- show: false,- title: "",- comment: "",- okButtonText: "",- },});-const issueStore = useIssueStore();const { t } = useI18n();-const issueTransitionList = computed(() => {+const ongoingIssueStatusAction = ref<{+ action: IssueStatusAction;+ title: string;+}>();++const issueStatusActionList = computed(() => {return props.issueList.map((issue) => {- const transitions = calcApplicableIssueStatusTransitionList(issue);- return { issue, transitions };+ const actions = getApplicableIssueStatusActionList(issue);+ return { issue, actions };});});-const isTransitionApplicableForAllIssues = (- type: IssueStatusTransitionType-): boolean => {- return issueTransitionList.value.every((item) => {- return (- item.transitions.findIndex((transition) => transition.type === type) >= 0- );+const isActionApplicableForAllIssues = (action: IssueStatusAction): boolean => {+ return issueStatusActionList.value.every(({ actions }) => {+ return actions.includes(action);});};-const startBatchIssueTransition = (type: IssueStatusTransitionType) => {- const { modal } = state;- modal.show = true;- const transition = ISSUE_STATUS_TRANSITION_LIST.get(type)!;- modal.transition = transition;- modal.comment = "";- modal.okButtonClass = transition.buttonClass;- modal.okButtonText = t(transition.buttonName);- modal.title = t("issue.batch-transition.action-n-issues", {- action: t(`issue.batch-transition.${type.toLowerCase()}`),- n: props.issueList.length,- });+const handleUpdated = () => {+ state.isRequesting = false;+ ongoingIssueStatusAction.value = undefined;+ refreshIssueList();};-const doBatchIssueTransition = async (transition: IssueStatusTransition) => {- const issueStatusPatch: IssueStatusPatch = {- status: transition.to,- comment: state.modal.comment,- };-- const stats = reactive<RequestStats>({- total: props.issueList.length,- success: 0,- failed: 0,- });-- const doSingleIssueTransition = async (- issue: ComposedIssue,- index: number- ) => {- const request = issueStore.updateIssueStatus({- issueId: extractIssueUID(issue.name),- issueStatusPatch,- });- request.then(- () => stats.success++,- () => stats.failed++- );-- return request;+const startBatchIssueStatusAction = (action: IssueStatusAction) => {+ ongoingIssueStatusAction.value = {+ action,+ title: t("issue.batch-transition.action-n-issues", {+ action: issueStatusActionDisplayName(action),+ n: props.issueList.length,+ }),};-- state.isRequesting = true;- state.stats = stats;- try {- const requestList = props.issueList.map(doSingleIssueTransition);- await Promise.allSettled(requestList);- pushNotification({- module: "bytebase",- style: "SUCCESS",- title: t("issue.batch-transition.successfully-updated-n-issues", {- n: stats.success,- }),- });- } finally {- state.isRequesting = false;- refreshIssueList();- }};</script>diff --git a/frontend/src/components/IssueV1/components/IssueTableV1.vue b/frontend/src/components/IssueV1/components/IssueTableV1.vueindex 9bf0af956c..531722ed70 100644--- a/frontend/src/components/IssueV1/components/IssueTableV1.vue+++ b/frontend/src/components/IssueV1/components/IssueTableV1.vue@@ -4,142 +4,148 @@>{{ title }}</div>- <BBGrid- :column-list="columnList"- :data-source="issueList"- :row-clickable="true"- :show-placeholder="showPlaceholder"- :is-row-expanded="isIssueExpanded"- :is-row-clickable="(_: ComposedIssue) => true"- :custom-header="true"- class="border w-auto overflow-x-auto"- header-class="capitalize"- @click-row="clickIssue"- >- <template #header>- <div role="table-row" class="bb-grid-row bb-grid-header-row group">+ <div ref="tableRef">+ <BBGrid+ :column-list="columnList"+ :data-source="issueList"+ :row-clickable="true"+ :show-placeholder="showPlaceholder"+ :is-row-expanded="isIssueExpanded"+ :is-row-clickable="(_: ComposedIssue) => true"+ :custom-header="true"+ class="border w-auto overflow-x-auto"+ header-class="capitalize"+ v-bind="$attrs"+ @click-row="clickIssue"+ >+ <template #header>+ <div role="table-row" class="bb-grid-row bb-grid-header-row group">+ <div+ v-for="(column, index) in columnList"+ :key="index"+ role="table-cell"+ class="bb-grid-header-cell"+ >+ <template v-if="index === 0">+ <input+ v-if="issueList.length > 0"+ type="checkbox"+ class="h-4 w-4 text-accent rounded disabled:cursor-not-allowed border-control-border focus:ring-accent"+ :checked="allSelectionState.checked"+ :indeterminate="allSelectionState.indeterminate"+ @input="+ setAllIssuesSelection(+ ($event.target as HTMLInputElement).checked+ )+ "+ />+ </template>+ <template v-else>{{ column.title }}</template>+ </div>+ </div>+ </template>+ <template #item="{ item: issue }: { item: ComposedIssue }"><div- v-for="(column, index) in columnList"- :key="index"- role="table-cell"- class="bb-grid-header-cell"+ class="bb-grid-cell"+ @click.stop="setIssueSelection(issue, !isIssueSelected(issue))">- <template v-if="index === 0">- <input- v-if="issueList.length > 0"- type="checkbox"- class="h-4 w-4 text-accent rounded disabled:cursor-not-allowed border-control-border focus:ring-accent"- :checked="allSelectionState.checked"- :indeterminate="allSelectionState.indeterminate"- @input="- setAllIssuesSelection(- ($event.target as HTMLInputElement).checked- )- "- />- </template>- <template v-else>{{ column.title }}</template>+ <!-- width: 1% means as narrow as possible -->+ <input+ type="checkbox"+ class="h-4 w-4 text-accent rounded disabled:cursor-not-allowed border-control-border focus:ring-accent"+ :checked="isIssueSelected(issue)"+ /></div>- </div>- </template>- <template #item="{ item: issue }: { item: ComposedIssue }">- <div- class="bb-grid-cell"- @click.stop="setIssueSelection(issue, !isIssueSelected(issue))"- >- <!-- width: 1% means as narrow as possible -->- <input- type="checkbox"- class="h-4 w-4 text-accent rounded disabled:cursor-not-allowed border-control-border focus:ring-accent"- :checked="isIssueSelected(issue)"- />- </div>- <div class="bb-grid-cell w-12">- <IssueStatusIcon- :issue-status="issue.status"- :task-status="issueTaskStatus(issue)"- />- </div>- <div class="bb-grid-cell">- <div class="flex items-center">- <div class="whitespace-nowrap mr-2 text-control">- <template v-if="mode == 'ALL'">- {{ issue.projectEntity.key }}-{{ issue.uid }}- </template>- <template v-else> #{{ issue.uid }} </template>- </div>- <div- class="flex truncate"- :class="{- 'font-semibold': isAssigneeAttentionOn(issue),- }"- >- <span- v-for="(item, index) in issueHighlightSections(- issue.title,- highlights- )"- :key="index"- :class="['whitespace-pre', item.highlight ? 'bg-yellow-100' : '']"+ <div class="bb-grid-cell w-12">+ <IssueStatusIcon+ :issue-status="issue.status"+ :task-status="issueTaskStatus(issue)"+ />+ </div>+ <div class="bb-grid-cell">+ <div class="flex items-center">+ <div class="whitespace-nowrap mr-2 text-control">+ <template v-if="mode == 'ALL'">+ {{ issue.projectEntity.key }}-{{ issue.uid }}+ </template>+ <template v-else> #{{ issue.uid }} </template>+ </div>+ <div+ class="flex truncate"+ :class="{+ 'font-semibold': isAssigneeAttentionOn(issue),+ }">- {{ item.text }}- </span>- </div>- <NTooltip v-if="isAssigneeAttentionOn(issue)">- <template #trigger>- <span>- <heroicons-outline:bell-alert- class="w-4 h-4 text-accent ml-1"- />+ <span+ v-for="(item, index) in issueHighlightSections(+ issue.title,+ highlights+ )"+ :key="index"+ :class="[+ 'whitespace-pre',+ item.highlight ? 'bg-yellow-100' : '',+ ]"+ >+ {{ item.text }}</span>- </template>- <span class="whitespace-nowrap">- {{ $t("issue.assignee-attention.needs-attention") }}+ </div>+ <NTooltip v-if="isAssigneeAttentionOn(issue)">+ <template #trigger>+ <span>+ <heroicons-outline:bell-alert+ class="w-4 h-4 text-accent ml-1"+ />+ </span>+ </template>+ <span class="whitespace-nowrap">+ {{ $t("issue.assignee-attention.needs-attention") }}+ </span>+ </NTooltip>+ </div>+ </div>+ <div class="hidden md:bb-grid-cell w-36">+ {{ humanizeTs((issue.updateTime?.getTime() ?? 0) / 1000) }}+ </div>+ <div class="hidden sm:bb-grid-cell w-36">+ <CurrentApproverV1 :issue="issue" />+ </div>+ <div class="hidden sm:bb-grid-cell w-36">+ <div class="flex flex-row items-center">+ <BBAvatar+ :size="'SMALL'"+ :username="issue.assigneeEntity?.title ?? $t('common.unassigned')"+ />+ <span class="ml-2">+ {{ issue.assigneeEntity?.title ?? $t("common.unassigned") }}</span>- </NTooltip>+ </div></div>- </div>- <div class="hidden md:bb-grid-cell w-36">- {{ humanizeTs((issue.updateTime?.getTime() ?? 0) / 1000) }}- </div>- <div class="hidden sm:bb-grid-cell w-36">- <CurrentApproverV1 :issue="issue" />- </div>- <div class="hidden sm:bb-grid-cell w-36">- <div class="flex flex-row items-center">- <BBAvatar- :size="'SMALL'"- :username="issue.assigneeEntity?.title ?? $t('common.unassigned')"- />- <span class="ml-2">- {{ issue.assigneeEntity?.title ?? $t("common.unassigned") }}- </span>+ <div class="hidden sm:bb-grid-cell w-36">+ <div class="flex flex-row items-center">+ <BBAvatar :size="'SMALL'" :username="issue.creatorEntity.title" />+ <span class="ml-2">+ {{ issue.creatorEntity.title }}+ </span>+ </div></div>- </div>- <div class="hidden sm:bb-grid-cell w-36">- <div class="flex flex-row items-center">- <BBAvatar :size="'SMALL'" :username="issue.creatorEntity.title" />- <span class="ml-2">- {{ issue.creatorEntity.title }}+ </template>+ <template #expanded-item="{ item: issue }: { item: ComposedIssue }">+ <div class="w-full max-h-[20rem] overflow-auto pl-2">+ <span+ v-for="(item, index) in issueHighlightSections(+ issue.description,+ highlights+ )"+ :key="index"+ :class="['whitespace-pre', item.highlight ? 'bg-yellow-100' : '']"+ >+ {{ item.text }}</span></div>- </div>- </template>- <template #expanded-item="{ item: issue }: { item: ComposedIssue }">- <div class="w-full max-h-[20rem] overflow-auto pl-2">- <span- v-for="(item, index) in issueHighlightSections(- issue.description,- highlights- )"- :key="index"- :class="['whitespace-pre', item.highlight ? 'bg-yellow-100' : '']"- >- {{ item.text }}- </span>- </div>- </template>- </BBGrid>+ </template>+ </BBGrid>+ </div><divv-if="isTableInViewport && selectedIssueList.length > 0"@@ -174,7 +180,7 @@ const columnList = computed((): BBGridColumn[] => {const resp = [{title: "",- width: "2rem",+ width: "auto",},{title: "",@@ -222,19 +228,11 @@ const props = withDefaults(title: string;issueList: ComposedIssue[];mode?: Mode;- leftBordered?: boolean;- rightBordered?: boolean;- topBordered?: boolean;- bottomBordered?: boolean;highlightText?: string;showPlaceholder?: boolean;}>(),{mode: "ALL",- leftBordered: false,- rightBordered: false,- topBordered: false,- bottomBordered: false,highlightText: "",showPlaceholder: false,}@@ -248,7 +246,7 @@ const state = reactive<LocalState>({});const currentUserV1 = useCurrentUserV1();-const tableRef = ref<HTMLTableElement>();+const tableRef = ref<HTMLDivElement>();const isTableInViewport = useElementVisibilityInScrollParent(tableRef);const selectedIssueList = computed(() => {diff --git a/frontend/src/components/IssueV1/components/Panel/BatchIssueStatusActionPanel.vue b/frontend/src/components/IssueV1/components/Panel/BatchIssueStatusActionPanel.vuenew file mode 100644index 0000000000..7eeb3e7aff--- /dev/null+++ b/frontend/src/components/IssueV1/components/Panel/BatchIssueStatusActionPanel.vue@@ -0,0 +1,132 @@+<template>+ <CommonDrawer+ :show="action !== undefined"+ :title="title"+ :loading="state.loading"+ @show="comment = ''"+ @close="$emit('close')"+ >+ <template #default>+ <div v-if="action" class="flex flex-col gap-y-4 px-1">+ <div class="flex flex-col gap-y-1">+ <div class="font-medium text-control">+ {{+ issueList.length === 1 ? $t("common.issue") : $t("common.issues")+ }}+ </div>+ <div class="textinfolabel">+ <ul+ class="flex flex-col"+ :class="[issueList.length > 1 && 'list-disc pl-4']"+ >+ <li v-for="issue in issueList" :key="issue.uid">+ {{ issue.title }}+ </li>+ </ul>+ </div>+ </div>++ <div class="flex flex-col gap-y-1">+ <p class="font-medium text-control">+ {{ $t("common.comment") }}+ </p>+ <NInput+ v-model:value="comment"+ type="textarea"+ :placeholder="$t('issue.leave-a-comment')"+ :autosize="{+ minRows: 3,+ maxRows: 10,+ }"+ />+ </div>+ </div>+ </template>+ <template #footer>+ <div v-if="action" class="flex justify-end gap-x-3">+ <NButton @click="$emit('close')">+ {{ $t("common.cancel") }}+ </NButton>+ <NButton+ v-bind="issueStatusActionButtonProps(action)"+ @click="handleConfirm(action, comment)"+ >+ {{ issueStatusActionDisplayName(action) }}+ </NButton>+ </div>+ </template>+ </CommonDrawer>+</template>++<script setup lang="ts">+import { computed, reactive, ref } from "vue";+import { useI18n } from "vue-i18n";+import {+ IssueStatusAction,+ issueStatusActionButtonProps,+ issueStatusActionDisplayName,+ IssueStatusActionToIssueStatusMap,+} from "@/components/IssueV1/logic";+import { issueServiceClient } from "@/grpcweb";+import { pushNotification } from "@/store";+import { ComposedIssue } from "@/types";+import CommonDrawer from "./CommonDrawer.vue";++type LocalState = {+ loading: boolean;+};++const props = defineProps<{+ issueList: ComposedIssue[];+ action?: IssueStatusAction;+}>();++const emit = defineEmits<{+ (event: "updating"): void;+ (event: "updated"): void;+ (event: "close"): void;+}>();++const { t } = useI18n();+const state = reactive<LocalState>({+ loading: false,+});+const comment = ref("");++const title = computed(() => {+ const { action } = props;+ if (!action) return "";++ return t("issue.batch-transition.action-n-issues", {+ action: issueStatusActionDisplayName(action),+ n: props.issueList.length,+ });+});++const handleConfirm = async (+ action: IssueStatusAction,+ comment: string | undefined+) => {+ state.loading = true;++ try {+ emit("updating");+ await issueServiceClient.batchUpdateIssuesStatus({+ parent: "projects/-",+ issues: props.issueList.map((issue) => issue.name),+ status: IssueStatusActionToIssueStatusMap[action],+ reason: comment ?? "",+ });++ // notify the parent component that issues updated+ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: t("common.updated"),+ });+ emit("updated");+ } finally {+ state.loading = false;+ }+};+</script>diff --git a/frontend/src/components/IssueV1/components/Panel/index.ts b/frontend/src/components/IssueV1/components/Panel/index.tsindex 32b6821416..278a6b667c 100644--- a/frontend/src/components/IssueV1/components/Panel/index.ts+++ b/frontend/src/components/IssueV1/components/Panel/index.ts@@ -1,3 +1,4 @@+import BatchIssueStatusActionPanel from "./BatchIssueStatusActionPanel.vue";import IssueReviewActionPanel from "./IssueReviewActionPanel.vue";import IssueStatusActionPanel from "./IssueStatusActionPanel.vue";import TaskRolloutActionPanel from "./TaskRolloutActionPanel.vue";@@ -6,4 +7,5 @@ export {IssueStatusActionPanel,IssueReviewActionPanel,TaskRolloutActionPanel,+ BatchIssueStatusActionPanel,};diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vueindex a261bb5b13..ed0e351eb0 100644--- a/frontend/src/views/Home.vue+++ b/frontend/src/views/Home.vue@@ -16,6 +16,7 @@><template #table="{ issueList, loading }"><IssueTableV1+ class="border-x-0":show-placeholder="!loading":title="$t('issue.waiting-approval')":issue-list="issueList.filter(keywordFilter)"@@ -37,7 +38,7 @@><template #table="{ issueList, loading }"><IssueTableV1- class="-mt-px"+ class="-mt-px border-x-0":show-placeholder="!loading":title="$t('issue.waiting-rollout')":issue-list="issueList.filter(keywordFilter)"@@ -59,7 +60,7 @@><template #table="{ issueList, loading }"><IssueTableV1- class="-mt-px"+ class="-mt-px border-x-0":show-placeholder="!loading":title="$t('common.created')":issue-list="issueList.filter(keywordFilter)"@@ -81,7 +82,7 @@><template #table="{ issueList, loading }"><IssueTableV1- class="-mt-px"+ class="-mt-px border-x-0":show-placeholder="!loading":title="$t('common.subscribed')":issue-list="issueList.filter(keywordFilter)"@@ -105,7 +106,7 @@><template #table="{ issueList, loading }"><IssueTableV1- class="-mt-px"+ class="-mt-px border-x-0":show-placeholder="!loading":title="$t('project.overview.recently-closed')":issue-list="issueList.filter(keywordFilter)"diff --git a/frontend/src/views/IssueDashboard.vue b/frontend/src/views/IssueDashboard.vueindex 6fc8f5494c..8a495b9f22 100644--- a/frontend/src/views/IssueDashboard.vue+++ b/frontend/src/views/IssueDashboard.vue@@ -51,8 +51,7 @@><template #table="{ issueList, loading }"><IssueTableV1- :top-bordered="true"- :bottom-bordered="true"+ class="border-x-0":show-placeholder="!loading":title="$t('issue.table.open')":issue-list="issueList.filter(filter)"@@ -74,9 +73,7 @@><template #table="{ issueList, loading }"><IssueTableV1- class="-mt-px"- :top-bordered="true"- :bottom-bordered="true"+ class="-mt-px border-x-0":show-placeholder="!loading":title="$t('issue.table.closed')":issue-list="issueList.filter(filter)"