Skip to content

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

feat(frontend): Issue review 🛴 (#5213)

Liu Ji938b9fafdb0f
diff --git a/frontend/src/bbkit/BBModal.vue b/frontend/src/bbkit/BBModal.vue
index 9feb290b75..28dceee171 100644
--- a/frontend/src/bbkit/BBModal.vue
+++ b/frontend/src/bbkit/BBModal.vue
@@ -10,7 +10,7 @@
:data-bb-modal-active="active"
>
<div class="modal-header" :class="headerClass">
- <div class="text-xl text-main mr-2">
+ <div class="text-xl text-main mr-2 flex-1 overflow-hidden">
<slot name="title"><component :is="renderTitle" /></slot>
<component :is="renderSubtitle" />
</div>
diff --git a/frontend/src/components/EnvironmentForm.vue b/frontend/src/components/EnvironmentForm.vue
index b10e64ab96..c90846db40 100644
--- a/frontend/src/components/EnvironmentForm.vue
+++ b/frontend/src/components/EnvironmentForm.vue
@@ -65,12 +65,14 @@
</div>
</div>
<div class="col-span-1 mt-6">
- <label class="textlabel"> {{ $t("policy.approval.name") }} </label>
+ <label class="textlabel">
+ {{ $t("policy.roll-out.name") }}
+ </label>
<span v-show="valueChanged('approvalPolicy')" class="textlabeltip">{{
- $t("policy.approval.tip")
+ $t("policy.roll-out.tip")
}}</span>
<div class="mt-1 textinfolabel">
- {{ $t("policy.approval.info") }}
+ {{ $t("policy.roll-out.info") }}
</div>
<div class="mt-4 flex flex-col space-y-4">
<div class="flex space-x-4">
@@ -84,9 +86,11 @@
:disabled="!allowEdit"
/>
<div class="-mt-0.5">
- <div class="textlabel">{{ $t("policy.approval.manual") }}</div>
+ <div class="textlabel">
+ {{ $t("policy.roll-out.manual") }}
+ </div>
<div class="mt-1 textinfolabel">
- {{ $t("policy.approval.manual-info") }}
+ {{ $t("policy.roll-out.manual-info") }}
</div>
</div>
</div>
@@ -112,14 +116,14 @@
/>
<div class="-mt-0.5">
<div class="textlabel flex">
- {{ $t("policy.approval.auto") }}
+ {{ $t("policy.roll-out.auto") }}
<FeatureBadge
feature="bb.feature.approval-policy"
class="text-accent"
/>
</div>
<div class="mt-1 textinfolabel">
- {{ $t("policy.approval.auto-info") }}
+ {{ $t("policy.roll-out.auto-info") }}
</div>
</div>
</div>
diff --git a/frontend/src/components/EnvironmentForm/AssigneeGroupEditor.vue b/frontend/src/components/EnvironmentForm/AssigneeGroupEditor.vue
index 769aac3ed2..8f9c059127 100644
--- a/frontend/src/components/EnvironmentForm/AssigneeGroupEditor.vue
+++ b/frontend/src/components/EnvironmentForm/AssigneeGroupEditor.vue
@@ -12,7 +12,7 @@
/>
<div class="-mt-0.5">
<div class="textlabel">
- {{ $t("policy.approval.assignee-group.workspace-owner-or-dba") }}
+ {{ $t("policy.roll-out.assignee-group.workspace-owner-or-dba") }}
</div>
</div>
</div>
@@ -28,7 +28,7 @@
/>
<div class="-mt-0.5">
<div class="textlabel">
- {{ $t("policy.approval.assignee-group.project-owner") }}
+ {{ $t("policy.roll-out.assignee-group.project-owner") }}
</div>
</div>
</div>
diff --git a/frontend/src/components/Issue/IssueActivityPanel.vue b/frontend/src/components/Issue/IssueActivityPanel.vue
index 6b9930a36e..425045134d 100644
--- a/frontend/src/components/Issue/IssueActivityPanel.vue
+++ b/frontend/src/components/Issue/IssueActivityPanel.vue
@@ -62,7 +62,12 @@
</div>
</div>
</template>
- <template v-else-if="actionIcon(item.activity) == 'run'">
+ <template
+ v-else-if="
+ actionIcon(item.activity) == 'run' ||
+ actionIcon(item.activity) == 'rollout'
+ "
+ >
<div class="relative pl-0.5">
<div
class="w-7 h-7 bg-control-bg rounded-full ring-4 ring-white flex items-center justify-center"
@@ -301,18 +306,6 @@
"
></textarea>
<div class="mt-4 flex items-center justify-between space-x-4">
- <div>
- <button
- type="button"
- class="group btn-normal !text-accent hover:!bg-gray-50"
- @click="lgtm"
- >
- <heroicons-outline:thumb-up
- class="w-5 h-5 group-hover:thumb-up"
- />
- <span class="ml-1">LGTM</span>
- </button>
- </div>
<div>
<button
type="button"
@@ -391,6 +384,7 @@ type ActionIconType =
| "update"
| "run"
| "approve"
+ | "rollout"
| "cancel"
| "fail"
| "complete"
@@ -526,26 +520,6 @@ const doCreateComment = (comment: string, clear = true) => {
});
};
-const lgtm = (e: Event) => {
- doCreateComment("LGTM", false);
-
- // import the effect lib asynchronously
- import("canvas-confetti").then(({ default: confetti }) => {
- const button = e.target as HTMLElement;
- const { left, top, width, height } = button.getBoundingClientRect();
- const { innerWidth: winWidth, innerHeight: winHeight } = window;
- // Create a confetti effect from the position of the LGTM button
- confetti({
- particleCount: 100,
- spread: 70,
- origin: {
- x: (left + width / 2) / winWidth,
- y: (top + height / 2) / winHeight,
- },
- });
- });
-};
-
const allowEditActivity = (activity: Activity) => {
if (activity.type !== "bb.issue.comment.create") {
return false;
@@ -596,7 +570,7 @@ const actionIcon = (activity: Activity): ActionIconType => {
if (payload.oldStatus == "RUNNING") {
return "cancel";
} else if (payload.oldStatus == "PENDING_APPROVAL") {
- return "approve";
+ return "rollout";
}
break;
}
@@ -638,6 +612,11 @@ const actionIcon = (activity: Activity): ActionIconType => {
activity.type == "bb.pipeline.task.general.earliest-allowed-time.update"
) {
return "update";
+ } else if (activity.type === "bb.issue.comment.create") {
+ const payload = activity.payload as ActivityIssueCommentCreatePayload;
+ if (payload.approvalEvent?.status === "APPROVED") {
+ return "approve";
+ }
}
return activity.creator.id == SYSTEM_BOT_ID ? "system" : "avatar";
diff --git a/frontend/src/components/Issue/IssueBanner.vue b/frontend/src/components/Issue/IssueBanner.vue
index 90175e08fa..adeebf4556 100644
--- a/frontend/src/components/Issue/IssueBanner.vue
+++ b/frontend/src/components/Issue/IssueBanner.vue
@@ -1,30 +1,39 @@
<template>
- <div
- v-if="showCancelBanner"
- class="h-8 w-full text-base font-medium bg-gray-400 text-white flex justify-center items-center"
- >
- {{ $t("common.canceled") }}
- </div>
- <div
- v-else-if="showSuccessBanner"
- class="h-8 w-full text-base font-medium bg-success text-white flex justify-center items-center"
- >
- {{ $t("common.done") }}
- </div>
- <div
- v-else-if="showPendingApproval"
- class="h-8 w-full text-base font-medium bg-accent text-white flex justify-center items-center"
- >
- {{ $t("issue.waiting-approval") }}
- </div>
- <div
- v-else-if="showEarliestAllowedTimeBanner"
- class="h-8 w-full text-base font-medium bg-accent text-white flex justify-center items-center"
- >
- {{
- $t("issue.waiting-earliest-allowed-time", { time: earliestAllowedTime })
- }}
- </div>
+ <template v-if="showPendingReview">
+ <div
+ class="h-8 w-full text-base font-medium bg-accent text-white flex justify-center items-center"
+ >
+ {{ $t("issue.waiting-for-review") }}
+ </div>
+ </template>
+ <template v-else>
+ <div
+ v-if="showCancelBanner"
+ class="h-8 w-full text-base font-medium bg-gray-400 text-white flex justify-center items-center"
+ >
+ {{ $t("common.canceled") }}
+ </div>
+ <div
+ v-else-if="showSuccessBanner"
+ class="h-8 w-full text-base font-medium bg-success text-white flex justify-center items-center"
+ >
+ {{ $t("common.done") }}
+ </div>
+ <div
+ v-else-if="showPendingRollout"
+ class="h-8 w-full text-base font-medium bg-accent text-white flex justify-center items-center"
+ >
+ {{ $t("issue.waiting-to-roll-out") }}
+ </div>
+ <div
+ v-else-if="showEarliestAllowedTimeBanner"
+ class="h-8 w-full text-base font-medium bg-accent text-white flex justify-center items-center"
+ >
+ {{
+ $t("issue.waiting-earliest-allowed-time", { time: earliestAllowedTime })
+ }}
+ </div>
+ </template>
</template>
<script lang="ts" setup>
@@ -34,8 +43,16 @@ import dayjs from "dayjs";
import { Issue } from "@/types";
import { activeTask } from "@/utils";
import { useIssueLogic } from "./logic";
+import { useIssueReviewContext } from "@/plugins/issue/logic/review/context";
-const issue = useIssueLogic().issue as Ref<Issue>;
+const issueContext = useIssueLogic();
+const issue = issueContext.issue as Ref<Issue>;
+const reviewContext = useIssueReviewContext();
+
+const showPendingReview = computed(() => {
+ if (issueContext.create.value) return false;
+ return !reviewContext.done.value;
+});
const showCancelBanner = computed(() => {
if (issue.value.status == "CANCELED") {
@@ -50,7 +67,7 @@ const showSuccessBanner = computed(() => {
return issue.value.status == "DONE";
});
-const showPendingApproval = computed(() => {
+const showPendingRollout = computed(() => {
const task = activeTask(issue.value.pipeline);
return task.status == "PENDING_APPROVAL";
});
diff --git a/frontend/src/components/Issue/IssueDetailLayout.vue b/frontend/src/components/Issue/IssueDetailLayout.vue
index 512d1b04da..6d4cf7b6d0 100644
--- a/frontend/src/components/Issue/IssueDetailLayout.vue
+++ b/frontend/src/components/Issue/IssueDetailLayout.vue
@@ -9,9 +9,7 @@
<!-- Highlight Panel -->
<div class="bg-white px-4 pb-4">
- <IssueHighlightPanel>
- <IssueStatusTransitionButtonGroup />
- </IssueHighlightPanel>
+ <IssueHighlightPanel />
</div>
<!-- Stage Flow Bar -->
@@ -109,7 +107,6 @@ import {
import IssueBanner from "./IssueBanner.vue";
import IssueHighlightPanel from "./IssueHighlightPanel.vue";
import IssueStagePanel from "./IssueStagePanel.vue";
-import IssueStatusTransitionButtonGroup from "./IssueStatusTransitionButtonGroup.vue";
import IssueOutputPanel from "./IssueOutputPanel.vue";
import IssueSidebar from "./IssueSidebar.vue";
import IssueTaskSDLPanel from "./IssueTaskSDLPanel.vue";
diff --git a/frontend/src/components/Issue/IssueHighlightPanel.vue b/frontend/src/components/Issue/IssueHighlightPanel.vue
index 22b4d42e0c..3f3e3729a4 100644
--- a/frontend/src/components/Issue/IssueHighlightPanel.vue
+++ b/frontend/src/components/Issue/IssueHighlightPanel.vue
@@ -22,7 +22,8 @@
/>
<div class="mt-4 flex space-x-3 md:mt-0 md:ml-4">
- <slot />
+ <IssueReviewButtonGroup v-if="showReviewButton" />
+ <IssueStatusTransitionButtonGroup v-else />
</div>
</div>
<div v-if="!create">
@@ -87,6 +88,8 @@
<script lang="ts" setup>
import { reactive, watch, computed, Ref } from "vue";
+import { head } from "lodash-es";
+
import IssueStatusIcon from "./IssueStatusIcon.vue";
import IssueRollbackFromTips from "./IssueRollbackFromTips.vue";
import { activeTask } from "@/utils";
@@ -97,7 +100,9 @@ import {
VCSPushEvent,
} from "@/types";
import { useExtraIssueLogic, useIssueLogic } from "./logic";
-import { head } from "lodash-es";
+import IssueStatusTransitionButtonGroup from "./IssueStatusTransitionButtonGroup.vue";
+import { IssueReviewButtonGroup } from "./review";
+import { useIssueReviewContext } from "@/plugins/issue/logic/review/context";
interface LocalState {
editing: boolean;
@@ -108,12 +113,19 @@ const logic = useIssueLogic();
const create = logic.create;
const issue = logic.issue as Ref<Issue>;
const { allowEditNameAndDescription, updateName } = useExtraIssueLogic();
+const issueReview = useIssueReviewContext();
+const { done: reviewDone } = issueReview;
const state = reactive<LocalState>({
editing: false,
name: issue.value.name,
});
+const showReviewButton = computed(() => {
+ if (create.value) return false;
+ return !reviewDone.value;
+});
+
watch(
() => issue.value,
(curIssue) => {
diff --git a/frontend/src/components/Issue/IssueSidebar.vue b/frontend/src/components/Issue/IssueSidebar.vue
index a1b08c5f3c..454df76222 100644
--- a/frontend/src/components/Issue/IssueSidebar.vue
+++ b/frontend/src/components/Issue/IssueSidebar.vue
@@ -19,8 +19,20 @@
</div>
</template>
+ <template v-if="!create">
+ <IssueReviewSidebarSection />
+ </template>
+
<h2 class="textlabel flex items-center col-span-1 col-start-1 gap-x-1">
<span>{{ $t("common.assignee") }}</span>
+ <span>
+ <NTooltip>
+ <template #trigger>
+ <heroicons-outline:question-mark-circle />
+ </template>
+ <div>{{ $t("issue.assignee-tooltip") }}</div>
+ </NTooltip>
+ </span>
<span v-if="create" class="text-red-600">*</span>
<AssigneeAttentionButton />
</h2>
@@ -289,6 +301,7 @@ import isSameOrAfter from "dayjs/plugin/isSameOrAfter";
import StageSelect from "./StageSelect.vue";
import TaskSelect from "./TaskSelect.vue";
import IssueStatusIcon from "./IssueStatusIcon.vue";
+import { IssueReviewSidebarSection } from "./review";
import IssueSubscriberPanel from "./IssueSubscriberPanel.vue";
import TaskRollbackView from "./rollback/TaskRollbackView.vue";
import InstanceEngineIcon from "../InstanceEngineIcon.vue";
diff --git a/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue b/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue
index 06b2d15f79..b321182288 100644
--- a/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue
+++ b/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue
@@ -127,7 +127,9 @@ import {
useExtraIssueLogic,
useIssueLogic,
} from "./logic";
-import type { ButtonAction } from "@/bbkit/BBContextMenuButton.vue";
+import BBContextMenuButton, {
+ type ButtonAction,
+} from "@/bbkit/BBContextMenuButton.vue";
export type IssueContext = {
currentUser: Principal;
@@ -228,8 +230,8 @@ const tryStartStageOrTaskStatusTransition = (
case "RUN":
actionText = t("common.run");
break;
- case "APPROVE":
- actionText = t("common.approve");
+ case "ROLLOUT":
+ actionText = t("common.rollout");
break;
case "RETRY":
actionText = t("common.retry");
diff --git a/frontend/src/components/Issue/StatusTransitionForm.vue b/frontend/src/components/Issue/StatusTransitionForm.vue
index 9ab7fc3f85..345c26168a 100644
--- a/frontend/src/components/Issue/StatusTransitionForm.vue
+++ b/frontend/src/components/Issue/StatusTransitionForm.vue
@@ -244,7 +244,7 @@ export default defineComponent({
switch ((props.transition as TaskStatusTransition).type) {
case "RUN":
return "btn-primary";
- case "APPROVE":
+ case "ROLLOUT":
return "btn-primary";
case "RETRY":
return "btn-primary";
diff --git a/frontend/src/components/Issue/TaskCheckBadgeBar.vue b/frontend/src/components/Issue/TaskCheckBadgeBar.vue
index dba7ee5cb6..ec34f650f4 100644
--- a/frontend/src/components/Issue/TaskCheckBadgeBar.vue
+++ b/frontend/src/components/Issue/TaskCheckBadgeBar.vue
@@ -190,7 +190,7 @@ export default defineComponent({
// Returns the most severe status
const taskCheckStatus = (taskCheckRun: TaskCheckRun): TaskCheckStatus => {
let value: TaskCheckStatus = "SUCCESS";
- for (const result of taskCheckRun.result.resultList) {
+ for (const result of taskCheckRun.result.resultList ?? []) {
if (result.status == "ERROR") {
return "ERROR";
}
diff --git a/frontend/src/components/Issue/activity/ActionSentence.vue b/frontend/src/components/Issue/activity/ActionSentence.vue
index f964b3153f..63be93fe62 100644
--- a/frontend/src/components/Issue/activity/ActionSentence.vue
+++ b/frontend/src/components/Issue/activity/ActionSentence.vue
@@ -52,6 +52,9 @@ const renderActionSentence = () => {
});
}
}
+ if (payload.approvalEvent?.status === "APPROVED") {
+ return t("custom-approval.issue-review.approved-issue");
+ }
}
const [tid, params] = issueActivityActionSentence(activity);
return t(tid, params);
@@ -77,7 +80,7 @@ const renderActionSentence = () => {
if (payload.oldStatus == "RUNNING") {
str = t("activity.sentence.canceled");
} else if (payload.oldStatus == "PENDING_APPROVAL") {
- str = t("activity.sentence.approved");
+ str = t("activity.sentence.rolled-out");
}
break;
}
diff --git a/frontend/src/components/Issue/logic/transition.ts b/frontend/src/components/Issue/logic/transition.ts
index 51f1b60d22..6626cf40cf 100644
--- a/frontend/src/components/Issue/logic/transition.ts
+++ b/frontend/src/components/Issue/logic/transition.ts
@@ -128,14 +128,14 @@ export const useIssueTransitionLogic = (issue: Ref<Issue>) => {
case "OPEN": {
if (isAllowedToApplyTaskTransition.value) {
// Only "Approve" can be applied to current stage by now.
- const APPROVE = TASK_STATUS_TRANSITION_LIST.get("APPROVE")!;
+ const ROLLOUT = TASK_STATUS_TRANSITION_LIST.get("ROLLOUT")!;
const currentStage = activeStage(issue.pipeline);
const pendingApprovalTaskList = currentStage.taskList.filter(
(task) => {
return (
task.status === "PENDING_APPROVAL" &&
- allowApplyTaskStatusTransition(task, APPROVE.to)
+ allowApplyTaskStatusTransition(task, ROLLOUT.to)
);
}
);
@@ -143,7 +143,7 @@ export const useIssueTransitionLogic = (issue: Ref<Issue>) => {
// Allowing "Approve" a stage when it has TWO OR MORE tasks
// are "PENDING_APPROVAL" (including the "activeTask" itself)
if (pendingApprovalTaskList.length >= 2) {
- return [APPROVE];
+ return [ROLLOUT];
}
}
diff --git a/frontend/src/components/Issue/review/ApprovalTimeline.vue b/frontend/src/components/Issue/review/ApprovalTimeline.vue
new file mode 100644
index 0000000000..e1f4f15641
--- /dev/null
+++ b/frontend/src/components/Issue/review/ApprovalTimeline.vue
@@ -0,0 +1,89 @@
+<template>
+ <NTimeline :icon-size="20" size="medium" class="bb-approval-timeline">
+ <NTimelineItem v-for="step in steps" :key="step.index">
+ <template #icon>
+ <div
+ class="w-5 h-5 rounded-full flex items-center justify-center text-xs shrink-0"
+ :class="iconClass(step)"
+ >
+ <heroicons-outline:thumb-up
+ v-if="step.status === 'DONE'"
+ class="w-3.5 h-3.5 text-white"
+ />
+ <heroicons-outline:user
+ v-else-if="step.status === 'CURRENT'"
+ class="w-3.5 h-3.5"
+ />
+ <template v-else>
+ {{ step.index + 1 }}
+ </template>
+ </div>
+ </template>
+
+ <div class="flex-1 flex text-sm overflow-hidden" :class="itemClass(step)">
+ <div class="whitespace-nowrap shrink-0">
+ {{ approvalNodeGroupValueText(step.step.nodes[0].groupValue!) }}
+ </div>
+ <div class="mr-1.5 shrink-0">:</div>
+ <div class="flex-1 overflow-hidden">
+ <NEllipsis
+ v-if="step.status === 'DONE'"
+ class="inline-block"
+ :class="step.approver?.name === currentUser.name && 'font-bold'"
+ >
+ <span>{{ step.approver?.title }}</span>
+ <span v-if="step.approver?.name === currentUser.name">
+ ({{ $t("custom-approval.issue-review.you") }})
+ </span>
+ </NEllipsis>
+ <Candidates v-else :step="step" />
+ </div>
+ </div>
+ </NTimelineItem>
+ </NTimeline>
+</template>
+
+<script lang="ts" setup>
+import { NTimeline, NTimelineItem, NEllipsis } from "naive-ui";
+
+import { WrappedReviewStep } from "@/types";
+import { approvalNodeGroupValueText } from "@/utils";
+import { storeToRefs } from "pinia";
+import { useAuthStore } from "@/store";
+import Candidates from "./Candidates.vue";
+
+defineProps<{
+ steps: WrappedReviewStep[];
+}>();
+
+const { currentUser } = storeToRefs(useAuthStore());
+
+const iconClass = (step: WrappedReviewStep) => {
+ const { status } = step;
+ return [
+ status === "DONE" && "bg-success",
+ status === "CURRENT" && "bg-white border-[2px] border-info text-accent",
+ status === "PENDING" && "bg-white border-[3px] border-gray-300",
+ ];
+};
+
+const itemClass = (step: WrappedReviewStep) => {
+ const { status } = step;
+ return [
+ status === "DONE" && "text-control-light",
+ status === "CURRENT" && "text-accent",
+ status === "PENDING" && "text-control-placeholder",
+ ];
+};
+</script>
+
+<style>
+.bb-approval-timeline
+ .n-timeline-item
+ .n-timeline-item-timeline
+ .n-timeline-item-timeline__line {
+ --line-padding: 4px;
+ top: calc(var(--n-icon-size) + var(--line-padding)) !important;
+ bottom: calc(var(--line-padding)) !important;
+}
+</style>
diff --git a/frontend/src/components/Issue/review/Candidates.vue b/frontend/src/components/Issue/review/Candidates.vue
new file mode 100644
index 0000000000..1b23236104
--- /dev/null
+++ b/frontend/src/components/Issue/review/Candidates.vue
@@ -0,0 +1,80 @@
+<template>
+ <NEllipsis
+ class="flex-1 truncate"
+ :tooltip="{
+ raw: true,
+ showArrow: false,
+ }"
+ :theme-overrides="{
+ peers: {
+ Tooltip: {
+ boxShadow: 'none',
+ },
+ },
+ }"
+ >
+ <div
+ v-for="(user, i) in candidates"
+ :key="user.name"
+ class="inline-flex flex-nowrap truncate"
+ >
+ <span
+ :class="user.name === currentUser.name && 'font-bold'"
+ class="truncate"
+ >
+ {{ user.title }}
+ </span>
+ <span v-if="user.name === currentUser.name" class="font-bold ml-1">
+ ({{ $t("custom-approval.issue-review.you") }})
+ </span>
+ <span v-if="i < candidates.length - 1" class="mr-1">,</span>
+ </div>
+
+ <template #tooltip>
+ <div
+ class="w-[12rem] max-h-[18rem] flex flex-col border rounded bg-white shadow-md text-control-light overflow-y-hidden"
+ >
+ <div class="whitespace-nowrap pt-3 pb-2 px-2 border-b textlabel">
+ {{ approvalNodeGroupValueText(step.step.nodes[0].groupValue!) }}
+ </div>
+ <div class="flex-1 overflow-auto text-xs">
+ <div
+ v-for="user in candidates"
+ :key="user.name"
+ class="flex items-center py-1.5 px-2"
+ :class="[user.name === currentUser.name && 'font-bold']"
+ >
+ <PrincipalAvatar
+ :principal="convertUserToPrincipal(user)"
+ size="SMALL"
+ class="mr-2"
+ />
+ <span class="whitespace-nowrap">{{ user.title }}</span>
+ <span v-if="user.name === currentUser.name" class="ml-1">
+ ({{ $t("custom-approval.issue-review.you") }})
+ </span>
+ </div>
+ </div>
+ </div>
+ </template>
+ </NEllipsis>
+</template>
+
+<script lang="ts" setup>
+import { computed } from "vue";
+import { storeToRefs } from "pinia";
+import { NEllipsis } from "naive-ui";
+
+import { convertUserToPrincipal, useAuthStore } from "@/store";
+import { WrappedReviewStep } from "@/types";
+import { approvalNodeGroupValueText } from "@/utils";
+import PrincipalAvatar from "@/components/PrincipalAvatar.vue";
+
+const { currentUser } = storeToRefs(useAuthStore());
+
+const props = defineProps<{
+ step: WrappedReviewStep;
+}>();
+
+const candidates = computed(() => props.step.candidates);
+</script>
diff --git a/frontend/src/components/Issue/review/IssueReviewButtonGroup.vue b/frontend/src/components/Issue/review/IssueReviewButtonGroup.vue
new file mode 100644
index 0000000000..0f1307fdc6
--- /dev/null
+++ b/frontend/src/components/Issue/review/IssueReviewButtonGroup.vue
@@ -0,0 +1,89 @@
+<template>
+ <button
+ v-if="showApproveButton"
+ class="btn-primary"
+ @click="state.modal = true"
+ >
+ {{ $t("common.approve") }}
+ </button>
+
+ <BBModal
+ v-if="state.modal"
+ :title="$t('custom-approval.issue-review.approve-issue')"
+ class="relative overflow-hidden !w-[30rem] !max-w-[30rem]"
+ header-class="overflow-hidden"
+ @close="state.modal = false"
+ >
+ <div
+ v-if="state.loading"
+ class="absolute inset-0 flex items-center justify-center bg-white/50"
+ >
+ <BBSpin />
+ </div>
+ <IssueReviewForm
+ @cancel="state.modal = false"
+ @confirm="handleConfirmApprove"
+ />
+ </BBModal>
+</template>
+
+<script lang="ts" setup>
+import { computed, reactive, Ref } from "vue";
+import { storeToRefs } from "pinia";
+
+import { useIssueReviewContext } from "@/plugins/issue/logic/review/context";
+import {
+ candidatesOfApprovalStep,
+ useAuthStore,
+ useReviewStore,
+} from "@/store";
+import { Issue } from "@/types";
+import { useIssueLogic } from "../logic";
+import IssueReviewForm from "./IssueReviewForm.vue";
+
+type LocalState = {
+ modal: boolean;
+ loading: boolean;
+};
+
+const state = reactive<LocalState>({
+ modal: false,
+ loading: false,
+});
+
+const store = useReviewStore();
+const { currentUser } = storeToRefs(useAuthStore());
+const issueContext = useIssueLogic();
+const issue = issueContext.issue as Ref<Issue>;
+const { flow, ready, done } = useIssueReviewContext();
+
+const showApproveButton = computed(() => {
+ if (issue.value.status === "CANCELED" || issue.value.status === "DONE") {
+ return false;
+ }
+
+ if (!ready.value) return false;
+ if (done.value) return false;
+
+ const index = flow.value.currentStepIndex;
+ const steps = flow.value.template.flow?.steps ?? [];
+ const step = steps[index];
+ if (!step) return [];
+ const candidates = candidatesOfApprovalStep(issue.value, step);
+ return candidates.includes(currentUser.value.name);
+});
+
+const handleConfirmApprove = async (onSuccess: () => void) => {
+ state.loading = true;
+ try {
+ await store.approveReview(issue.value);
+ onSuccess();
+ state.modal = false;
+
+ // notify the issue logic to update issue status
+ issueContext.onStatusChanged(true);
+ } finally {
+ state.loading = false;
+ }
+};
+</script>
diff --git a/frontend/src/components/Issue/review/IssueReviewForm.vue b/frontend/src/components/Issue/review/IssueReviewForm.vue
new file mode 100644
index 0000000000..5fb6985233
--- /dev/null
+++ b/frontend/src/components/Issue/review/IssueReviewForm.vue
@@ -0,0 +1,60 @@
+<template>
+ <div space-y-3>
+ <div class="pt-4 pb-1 flex justify-end gap-x-3">
+ <button class="btn-normal" @click="$emit('cancel')">
+ {{ $t("common.cancel") }}
+ </button>
+ <button class="btn-primary" @click="handleConfirm">
+ {{ $t("common.approve") }}
+ </button>
+ </div>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { h, Ref } from "vue";
+
+import { useOverrideSubtitle } from "@/bbkit/BBModal.vue";
+import { useIssueLogic } from "../logic";
+import { Issue } from "@/types";
+
+const emit = defineEmits<{
+ (event: "cancel"): void;
+ (event: "confirm", onSuccess: () => void): void;
+}>();
+
+const issueContext = useIssueLogic();
+const issue = issueContext.issue as Ref<Issue>;
+
+useOverrideSubtitle(() => {
+ return h(
+ "div",
+ {
+ class: "mt-1 textinfolabel whitespace-pre-wrap",
+ },
+ issue.value.name
+ );
+});
+
+const handleConfirm = (e: MouseEvent) => {
+ const button = e.target as HTMLElement;
+ const { left, top, width, height } = button.getBoundingClientRect();
+ const { innerWidth: winWidth, innerHeight: winHeight } = window;
+ const onSuccess = () => {
+ // import the effect lib asynchronously
+ import("canvas-confetti").then(({ default: confetti }) => {
+ // Create a confetti effect from the position of the LGTM button
+ confetti({
+ particleCount: 100,
+ spread: 70,
+ origin: {
+ x: (left + width / 2) / winWidth,
+ y: (top + height / 2) / winHeight,
+ },
+ });
+ });
+ };
+
+ emit("confirm", onSuccess);
+};
+</script>
diff --git a/frontend/src/components/Issue/review/IssueReviewPanel.vue b/frontend/src/components/Issue/review/IssueReviewPanel.vue
new file mode 100644
index 0000000000..98d5ec754c
--- /dev/null
+++ b/frontend/src/components/Issue/review/IssueReviewPanel.vue
@@ -0,0 +1,64 @@
+<template>
+ <div v-if="ready && wrappedSteps" class="mt-1">
+ <ApprovalTimeline :steps="wrappedSteps" />
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { computed } from "vue";
+
+import {
+ candidatesOfApprovalStep,
+ extractUserEmail,
+ useAuthStore,
+ useUserStore,
+} from "@/store";
+import { useIssueReviewContext } from "@/plugins/issue/logic/review/context";
+import { useIssueLogic } from "../logic";
+import { Issue, WrappedReviewStep } from "@/types";
+import ApprovalTimeline from "./ApprovalTimeline.vue";
+
+const userStore = useUserStore();
+const issueLogic = useIssueLogic();
+const currentUserName = computed(() => useAuthStore().currentUser.name);
+const issue = computed(() => issueLogic.issue.value as Issue);
+const context = useIssueReviewContext();
+const { ready, flow, done } = context;
+
+const wrappedSteps = computed(() => {
+ const steps = flow.value.template.flow?.steps;
+ const currentStepIndex = flow.value.currentStepIndex ?? -1;
+
+ const statusOfStep = (index: number) => {
+ if (done.value) return "DONE";
+ if (index < currentStepIndex) return "DONE";
+ if (index === currentStepIndex) return "CURRENT";
+ return "PENDING";
+ };
+ const approverOfStep = (index: number) => {
+ const principal = flow.value.approvers[index]?.principal;
+ if (!principal) return undefined;
+ const email = extractUserEmail(principal);
+ return userStore.getUserByEmail(email);
+ };
+ const candidatesOfStep = (index: number) => {
+ const step = steps?.[index];
+ if (!step) return [];
+ const users = candidatesOfApprovalStep(issue.value, step);
+ const idx = users.indexOf(currentUserName.value);
+ if (idx > 0) {
+ users.splice(idx, 1);
+ users.unshift(currentUserName.value);
+ }
+ return users.map((user) => userStore.getUserByName(user)!);
+ };
+
+ return steps?.map<WrappedReviewStep>((step, index) => ({
+ index,
+ step,
+ status: statusOfStep(index),
+ approver: approverOfStep(index),
+ candidates: candidatesOfStep(index),
+ }));
+});
+</script>
diff --git a/frontend/src/components/Issue/review/IssueReviewSidebarSection.vue b/frontend/src/components/Issue/review/IssueReviewSidebarSection.vue
new file mode 100644
index 0000000000..91f6fb9e3f
--- /dev/null
+++ b/frontend/src/components/Issue/review/IssueReviewSidebarSection.vue
@@ -0,0 +1,61 @@
+<template>
+ <template v-if="showApprovalFlowSection">
+ <h2 class="textlabel flex items-start col-span-1 col-start-1 pt-1">
+ <div class="flex items-center gap-x-1">
+ <span>{{ $t("issue.approval-flow.self") }}</span>
+ <NTooltip v-if="false">
+ <div>{{ $t("issue.approval-flow.tooltip") }}</div>
+ <template #trigger>
+ <heroicons-outline:question-mark-circle />
+ </template>
+ </NTooltip>
+ </div>
+ </h2>
+ <div class="col-span-2">
+ <div
+ v-if="!ready"
+ class="flex items-center gap-x-2 mt-1 text-sm text-control-placeholder"
+ >
+ <BBSpin class="w-4 h-4" />
+ <span>
+ {{ $t("custom-approval.issue-review.generating-approval-flow") }}
+ </span>
+ </div>
+ <IssueReviewPanel v-else-if="steps.length > 0" />
+ </div>
+ </template>
+ <template v-else-if="steps.length > 0">
+ <h2 class="textlabel flex items-start col-span-1 col-start-1 pt-1">
+ <div class="flex items-center gap-x-1">
+ <span>{{ $t("issue.approval-flow.self") }}</span>
+ <NTooltip>
+ <template #trigger>
+ <heroicons-outline:question-mark-circle />
+ </template>
+ <div>{{ $t("issue.approval-flow.tooltip") }}</div>
+ </NTooltip>
+ </div>
+ </h2>
+ </template>
+</template>
+
+<script lang="ts" setup>
+import { computed } from "vue";
+
+import { useIssueReviewContext } from "@/plugins/issue/logic/review/context";
+import IssueReviewPanel from "./IssueReviewPanel.vue";
+
+const context = useIssueReviewContext();
+const { ready, flow } = context;
+
+const steps = computed(() => flow.value.template.flow?.steps ?? []);
+
+const showApprovalFlowSection = computed(() => {
+ if (!ready.value) {
+ // Show a 'generating' indicator
+ return true;
+ }
+ // Show if not skip manual review
+ return steps.value.length > 0;
+});
+</script>
diff --git a/frontend/src/components/Issue/review/index.ts b/frontend/src/components/Issue/review/index.ts
new file mode 100644
index 0000000000..e3d5defd9a
--- /dev/null
+++ b/frontend/src/components/Issue/review/index.ts
@@ -0,0 +1,5 @@
+import IssueReviewPanel from "./IssueReviewPanel.vue";
+import IssueReviewButtonGroup from "./IssueReviewButtonGroup.vue";
+import IssueReviewSidebarSection from "./IssueReviewSidebarSection.vue";
+
+export { IssueReviewPanel, IssueReviewButtonGroup, IssueReviewSidebarSection };
diff --git a/frontend/src/components/Project/ProjectSetting/ProjectAdvancedSettingPanel.vue b/frontend/src/components/Project/ProjectSetting/ProjectAdvancedSettingPanel.vue
deleted file mode 100644
index fd5825814f..0000000000
--- a/frontend/src/components/Project/ProjectSetting/ProjectAdvancedSettingPanel.vue
+++ /dev/null
@@ -1,150 +0,0 @@
-<template>
- <div class="max-w-md space-y-4">
- <p class="text-lg font-medium leading-7 text-main">
- {{ $t("common.advanced") }}
- </p>
- <div class="space-y-4">
- <div class="flex items-center space-x-1">
- <label class="textlabel !font-bold">
- {{ $t("project.lgtm-check.self") }}
- </label>
- <FeatureBadge feature="bb.feature.lgtm" class="text-accent" />
- </div>
-
- <label class="flex items-center space-x-4">
- <input
- v-model="state.lgtmCheckValue"
- tabindex="-1"
- type="radio"
- class="text-accent disabled:text-accent-disabled focus:ring-accent"
- value="DISABLED"
- :disabled="!allowEdit"
- />
- <div class="-mt-0.5">
- <div class="textlabel">
- {{ $t("project.lgtm-check.disabled") }}
- </div>
- </div>
- </label>
-
- <label class="flex items-center space-x-4">
- <input
- v-model="state.lgtmCheckValue"
- tabindex="-1"
- type="radio"
- class="text-accent disabled:text-accent-disabled focus:ring-accent"
- value="PROJECT_MEMBER"
- :disabled="!allowEdit"
- />
- <div class="-mt-0.5">
- <div class="textlabel">
- {{ $t("project.lgtm-check.project-member") }}
- </div>
- </div>
- </label>
-
- <label class="flex items-center space-x-4">
- <input
- v-model="state.lgtmCheckValue"
- tabindex="-1"
- type="radio"
- class="text-accent disabled:text-accent-disabled focus:ring-accent"
- value="PROJECT_OWNER"
- :disabled="!allowEdit"
- />
- <div class="-mt-0.5">
- <div class="textlabel">
- {{ $t("project.lgtm-check.project-owner") }}
- </div>
- </div>
- </label>
- </div>
-
- <div v-if="allowEdit" class="flex justify-end">
- <button
- type="button"
- class="btn-primary"
- :disabled="!allowSave"
- @click.prevent="save"
- >
- {{ $t("common.save") }}
- </button>
- </div>
-
- <FeatureModal
- v-if="state.missingFeature !== undefined"
- :feature="state.missingFeature"
- @cancel="state.missingFeature = undefined"
- />
- </div>
-</template>
-
-<script lang="ts" setup>
-import { computed, PropType, reactive, watch } from "vue";
-import { useI18n } from "vue-i18n";
-import { FeatureType, LGTMCheckValue, Project, ProjectPatch } from "@/types";
-import { featureToRef, pushNotification, useProjectStore } from "@/store";
-import FeatureBadge from "@/components/FeatureBadge.vue";
-
-interface LocalState {
- lgtmCheckValue: LGTMCheckValue;
- missingFeature: FeatureType | undefined;
-}
-
-const props = defineProps({
- project: {
- required: true,
- type: Object as PropType<Project>,
- },
- allowEdit: {
- default: true,
- type: Boolean,
- },
-});
-const { t } = useI18n();
-const projectStore = useProjectStore();
-const hasLGTMFeature = featureToRef("bb.feature.lgtm");
-
-const state = reactive<LocalState>({
- lgtmCheckValue: props.project.lgtmCheckSetting.value,
- missingFeature: undefined,
-});
-
-const allowSave = computed((): boolean => {
- return state.lgtmCheckValue !== props.project.lgtmCheckSetting.value;
-});
-
-const save = () => {
- if (!hasLGTMFeature.value) {
- state.missingFeature = "bb.feature.lgtm";
- return;
- }
-
- const projectPatch: ProjectPatch = {
- lgtmCheckSetting: {
- value: state.lgtmCheckValue,
- },
- };
-
- projectStore
- .patchProject({
- projectId: props.project.id,
- projectPatch,
- })
- .then((updatedProject: Project) => {
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("project.settings.success-updated"),
- });
- });
-};
-
-// Sync the local state if props changed
-watch(
- () => props.project.lgtmCheckSetting.value,
- (value) => {
- state.lgtmCheckValue = value;
- }
-);
-</script>
diff --git a/frontend/src/components/ProjectGeneralSettingPanel.vue b/frontend/src/components/Project/ProjectSetting/ProjectGeneralSettingPanel.vue
similarity index 98%
rename from frontend/src/components/ProjectGeneralSettingPanel.vue
rename to frontend/src/components/Project/ProjectSetting/ProjectGeneralSettingPanel.vue
index 1b7cc11007..89b43c34c3 100644
--- a/frontend/src/components/ProjectGeneralSettingPanel.vue
+++ b/frontend/src/components/Project/ProjectSetting/ProjectGeneralSettingPanel.vue
@@ -109,10 +109,10 @@ import {
ProjectPatch,
ProjectTenantMode,
FeatureType,
-} from "../types";
+} from "../../../types";
import FeatureModal from "@/components/FeatureModal.vue";
import { hasFeature, pushNotification, useProjectStore } from "@/store";
-import ResourceIdField from "./ResourceIdField.vue";
+import ResourceIdField from "../../ResourceIdField.vue";
interface LocalState {
name: string;
diff --git a/frontend/src/components/Project/ProjectSetting/index.ts b/frontend/src/components/Project/ProjectSetting/index.ts
index ea82e8b3b6..354603b5e7 100644
--- a/frontend/src/components/Project/ProjectSetting/index.ts
+++ b/frontend/src/components/Project/ProjectSetting/index.ts
@@ -1,3 +1,3 @@
-import ProjectAdvancedSettingPanel from "./ProjectAdvancedSettingPanel.vue";
+import ProjectGeneralSettingPanel from "./ProjectGeneralSettingPanel.vue";
-export { ProjectAdvancedSettingPanel };
+export { ProjectGeneralSettingPanel };
diff --git a/frontend/src/components/ProjectSettingPanel.vue b/frontend/src/components/ProjectSettingPanel.vue
index 0ebb433f1a..24fea7b36c 100644
--- a/frontend/src/components/ProjectSettingPanel.vue
+++ b/frontend/src/components/ProjectSettingPanel.vue
@@ -2,11 +2,6 @@
<div class="max-w-3xl mx-auto space-y-4">
<div class="divide-y divide-block-border space-y-6">
<ProjectGeneralSettingPanel :project="project" :allow-edit="allowEdit" />
- <ProjectAdvancedSettingPanel
- :project="project"
- :allow-edit="allowEdit"
- class="pt-4"
- />
<div class="pt-4">
<ProjectMemberPanel :project="project" />
</div>
@@ -45,8 +40,7 @@
<script lang="ts">
import { computed, defineComponent, PropType } from "vue";
import { hasProjectPermission, hasWorkspacePermission } from "../utils";
-import ProjectGeneralSettingPanel from "../components/ProjectGeneralSettingPanel.vue";
-import { ProjectAdvancedSettingPanel } from "../components/Project/ProjectSetting";
+import { ProjectGeneralSettingPanel } from "../components/Project/ProjectSetting";
import ProjectMemberPanel from "../components/ProjectMemberPanel.vue";
import { ProjectPatch, Project } from "../types";
import { useCurrentUser, useProjectStore } from "@/store";
@@ -55,7 +49,6 @@ export default defineComponent({
name: "ProjectSettingPanel",
components: {
ProjectGeneralSettingPanel,
- ProjectAdvancedSettingPanel,
ProjectMemberPanel,
},
props: {
diff --git a/frontend/src/components/ProvideDashboardContext.vue b/frontend/src/components/ProvideDashboardContext.vue
index 2b34ba6757..ef762b2cb7 100644
--- a/frontend/src/components/ProvideDashboardContext.vue
+++ b/frontend/src/components/ProvideDashboardContext.vue
@@ -11,6 +11,7 @@ import {
useUIStateStore,
useProjectStore,
useDebugStore,
+ useUserStore,
} from "@/store";
import { defineComponent } from "vue";
import { DEFAULT_PROJECT_ID } from "../types";
@@ -22,6 +23,7 @@ export default defineComponent({
useSettingStore().fetchSetting(),
// Fetch so MemberSelect can have the data.
useMemberStore().fetchMemberList(),
+ useUserStore().fetchUserList(),
// Though fetchMemberList also return the principal info, it's possible that a principal is no longer a member.
// since all record types have creator, updater which are associated with principal, so we need to fetch
// the principal list as well.
diff --git a/frontend/src/composables/useProgressivePoll.ts b/frontend/src/composables/useProgressivePoll.ts
new file mode 100644
index 0000000000..2f9a3fc1e2
--- /dev/null
+++ b/frontend/src/composables/useProgressivePoll.ts
@@ -0,0 +1,56 @@
+import { MaybeRef } from "@/types";
+import { minmax } from "@/utils";
+import { random } from "lodash-es";
+import { onBeforeUnmount, reactive, unref } from "vue";
+
+type ProgressivePollOptions = {
+ interval: {
+ min: number;
+ max: number;
+ growth: number;
+ jitter: number;
+ };
+};
+
+type ProgressivePollState = {
+ timer: ReturnType<typeof setTimeout> | undefined;
+};
+
+// Poll with time interval increasing progressively
+// e.g., 1s, 2s, 4s, 8s, 16s, 30s, 30s, 30s, 30s...
+export const useProgressivePoll = (
+ tick: () => void,
+ options: MaybeRef<ProgressivePollOptions>
+) => {
+ const state = reactive<ProgressivePollState>({
+ timer: undefined,
+ });
+
+ const stop = () => {
+ if (!state.timer) return;
+ clearTimeout(state.timer);
+ state.timer = undefined;
+ };
+
+ const poll = (interval: number) => {
+ stop();
+
+ const { min, max, growth, jitter } = unref(options).interval;
+ const int = minmax(interval + random(-jitter, jitter), min, max);
+
+ state.timer = setTimeout(() => {
+ tick();
+
+ const next = Math.min(int * growth, max);
+ poll(next);
+ }, int);
+ };
+
+ const start = () => {
+ poll(unref(options).interval.min);
+ };
+
+ onBeforeUnmount(stop);
+
+ return { stop, start, restart: start };
+};
diff --git a/frontend/src/grpcweb/index.ts b/frontend/src/grpcweb/index.ts
index 4fc981c4d9..7ba4d8ec67 100644
--- a/frontend/src/grpcweb/index.ts
+++ b/frontend/src/grpcweb/index.ts
@@ -11,6 +11,7 @@ import { ProjectServiceDefinition } from "@/types/proto/v1/project_service";
import { SQLServiceDefinition } from "@/types/proto/v1/sql_service";
import { RiskServiceDefinition } from "@/types/proto/v1/risk_service";
import { SettingServiceDefinition } from "@/types/proto/v1/setting_service";
+import { ReviewServiceDefinition } from "@/types/proto/v1/review_service";
// Create each grpc service client.
// Reference: https://github.com/deeplay-io/nice-grpc/blob/master/packages/nice-grpc-web/README.md
@@ -63,6 +64,11 @@ export const settingServiceClient = clientFactory.create(
channel
);
+export const reviewServiceClient = clientFactory.create(
+ ReviewServiceDefinition,
+ channel
+);
+
export const sqlClient = clientFactory.create(SQLServiceDefinition, channel);
// e.g. How to use `authServiceClient`?
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 2112db0b97..cdb5f319df 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -231,7 +231,8 @@
"download": "Download",
"will-lose-unsaved-data": "Will lose any unsaved data.",
"deleted": "Deleted",
- "will-override-current-data": "Will override current data."
+ "will-override-current-data": "Will override current data.",
+ "rollout": "Roll out"
},
"error-page": {
"go-back-home": "Go back home"
@@ -576,7 +577,8 @@
"committed-to-at": "committed {file} to {branch}{'@'}{repo}",
"dismissed-stale-approval": "dismissed stale approvals of {task}",
"external-approval-rejected": "rejected external approval from {imName} of stage \"{stageName}\"",
- "skipped": "skipped"
+ "skipped": "skipped",
+ "rolled-out": "rolled out"
},
"subject-prefix": {
"task": "Task",
@@ -686,7 +688,13 @@
"generated-ddl-statements": "Generated DDL statements",
"full-schema": "Full schema",
"left-schema-may-change": "The schema on the left side may change before the issue is applied."
- }
+ },
+ "assignee-tooltip": "The one who's responsible for the rolling out.",
+ "approval-flow": {
+ "self": "Approval flow"
+ },
+ "waiting-to-roll-out": "Waiting to roll out",
+ "waiting-for-review": "Waiting for review"
},
"alter-schema": {
"vcs-enabled": "This project has enabled VCS based version control and selecting database below will navigate you to the corresponding Git repository to initiate the change process.",
@@ -920,17 +928,17 @@
}
},
"policy": {
- "approval": {
- "name": "Approval Policy",
+ "roll-out": {
+ "name": "Roll out policy",
"tip": "The policy is applied to issues retroactively.",
"info": "For updating schema on the existing database, this setting controls whether the task requires manual approval.",
- "manual": "Require manual approval",
- "manual-info": "Tasks will only be executed after being manually approved.",
- "auto": "Skip manual approval",
- "auto-info": "Tasks will be approved and executed automatically if all task checks pass.",
+ "manual": "Require manual rolling out",
+ "manual-info": "Tasks will only be executed after being manually rolled out.",
+ "auto": "Skip manual rolling out",
+ "auto-info": "Tasks will be rolled out and executed automatically if all task checks pass.",
"assignee-group": {
- "workspace-owner-or-dba": "Require approval from DBA or workspace owner.",
- "project-owner": "Require approval from project owner."
+ "workspace-owner-or-dba": "Require rolling out from DBA or workspace owner.",
+ "project-owner": "Require rolling out from project owner."
}
},
"backup": {
@@ -1710,8 +1718,8 @@
"desc": "Intelligent database management for tenants using identical schemas."
},
"bb-feature-approval-policy": {
- "title": "Approval policy",
- "desc": "Approval policy controls whether the schema change task requires manual approval."
+ "title": "Roll out policy",
+ "desc": "Roll out policy controls whether the schema change task requires manual rolling out."
},
"bb-feature-backup-policy": {
"title": "Backup policy",
@@ -2194,6 +2202,16 @@
},
"rule": {
"rules": "Rules"
+ },
+ "issue-review": {
+ "approve-issue": "Approve issue?",
+ "form": {
+ "placeholder": "(Optional) Add a note...",
+ "note": "Note"
+ },
+ "you": "You",
+ "generating-approval-flow": "Generating approval flow",
+ "approved-issue": "approved issue"
}
}
}
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index c6f5a5d262..38bd9a59be 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -81,7 +81,7 @@
"developer": "开发者",
"member": "成员"
},
- "assignee": "审核人",
+ "assignee": "责任人",
"revert": "恢复",
"apply": "应用",
"reorder": "排序",
@@ -229,7 +229,8 @@
"download": "下载",
"will-lose-unsaved-data": "这会丢失当前所有未保存的数据。",
"deleted": "已删除",
- "will-override-current-data": "将会覆盖当前数据。"
+ "will-override-current-data": "将会覆盖当前数据。",
+ "rollout": "发布"
},
"error-page": {
"go-back-home": "回到主页"
@@ -574,7 +575,8 @@
"committed-to-at": "提交 {file} 到 {branch}{'@'}{repo}",
"dismissed-stale-approval": "更新了{task},此前的批准已被撤销",
"external-approval-rejected": "拒绝阶段 \"{stageName}\" 的{imName}外部审批",
- "skipped": "跳过"
+ "skipped": "跳过",
+ "rolled-out": "发布"
},
"subject-prefix": {
"task": "任务",
@@ -684,7 +686,13 @@
"generated-ddl-statements": "生成的 DDL 语句",
"full-schema": "完整 schema",
"left-schema-may-change": "左边的 schema 在工单执行前可能会发生变化。"
- }
+ },
+ "assignee-tooltip": "该工单的发布负责人",
+ "approval-flow": {
+ "self": "审批流"
+ },
+ "waiting-to-roll-out": "等待发布",
+ "waiting-for-review": "等待审核"
},
"alter-schema": {
"vcs-enabled": "该项目开启了基于 VCS 的版本管理,选择下面的数据库会将您导航到相应的 Git 仓库以发起变更流程。",
@@ -918,17 +926,17 @@
}
},
"policy": {
- "approval": {
- "name": "审批策略",
+ "roll-out": {
+ "name": "发布策略",
"tip": "新策略对旧工单也生效",
- "info": "要更改数据库 schema,该选项控制了是否需要手动审批。",
- "manual": "需要人工审批",
- "manual-info": "任务只有被人工审批后才会执行。",
- "auto": "无需审批",
- "auto-info": "如果任务检查都通过的话,任务无需审批并且会被自动执行。",
+ "info": "要更改数据库 schema,该选项控制了是否需要手动发布。",
+ "manual": "需要人工发布",
+ "manual-info": "任务只有被人工发布后才会执行。",
+ "auto": "无需发布",
+ "auto-info": "如果任务检查都通过的话,任务无需发布并且会被自动执行。",
"assignee-group": {
- "workspace-owner-or-dba": "需要 DBA 或者 Bytebase 实例所有者审批。",
- "project-owner": "需要项目所有者审批。"
+ "workspace-owner-or-dba": "需要 DBA 或者 Bytebase 实例所有者发布。",
+ "project-owner": "需要项目所有者发布。"
}
},
"backup": {
@@ -1709,8 +1717,8 @@
"desc": "「多租户功能」可以同时管理多个属于不同租户的同构数据库,帮您更统一和方便地对多个数据库进行管理和表结构变更。"
},
"bb-feature-approval-policy": {
- "title": "审批策略",
- "desc": "「审批策略」可以控制数据库 schema 的变更是否需要手动审批"
+ "title": "发布策略",
+ "desc": "「发布策略」可以控制数据库 schema 的变更是否需要手动发布"
},
"bb-feature-backup-policy": {
"title": "备份策略",
@@ -2191,6 +2199,16 @@
},
"rule": {
"rules": "规则"
+ },
+ "issue-review": {
+ "approve-issue": "批准工单?",
+ "form": {
+ "placeholder": "(可选)添加一段笔记…",
+ "note": "笔记"
+ },
+ "you": "你",
+ "generating-approval-flow": "正在生成审批流",
+ "approved-issue": "批准工单"
}
}
}
diff --git a/frontend/src/plugins/issue/logic/index.ts b/frontend/src/plugins/issue/logic/index.ts
index 489d21258c..1e924110f3 100644
--- a/frontend/src/plugins/issue/logic/index.ts
+++ b/frontend/src/plugins/issue/logic/index.ts
@@ -1,2 +1,3 @@
export * from "./initialize";
export * from "./poll";
+export * from "./review";
diff --git a/frontend/src/plugins/issue/logic/review/context.ts b/frontend/src/plugins/issue/logic/review/context.ts
new file mode 100644
index 0000000000..3bd2d15c7e
--- /dev/null
+++ b/frontend/src/plugins/issue/logic/review/context.ts
@@ -0,0 +1,28 @@
+import { ReviewFlow } from "@/types";
+import { Review } from "@/types/proto/v1/review_service";
+import { inject, provide, type InjectionKey, type Ref } from "vue";
+
+export type IssueReviewContext = {
+ review: Ref<Review>;
+
+ /// derived states
+ // true if the approval flow is generated
+ ready: Ref<boolean>;
+ // The review flow.
+ // Now we have only one flow in an issue
+ flow: Ref<ReviewFlow>;
+ // Whether the review flow is finished successfully.
+ done: Ref<boolean>;
+};
+
+export const KEY = Symbol(
+ "bb.issue.review"
+) as InjectionKey<IssueReviewContext>;
+
+export const useIssueReviewContext = () => {
+ return inject(KEY)!;
+};
+
+export const provideIssueReviewContext = (context: IssueReviewContext) => {
+ provide(KEY, context);
+};
diff --git a/frontend/src/plugins/issue/logic/review/index.ts b/frontend/src/plugins/issue/logic/review/index.ts
new file mode 100644
index 0000000000..ae3e315c56
--- /dev/null
+++ b/frontend/src/plugins/issue/logic/review/index.ts
@@ -0,0 +1,78 @@
+import { computed, watch, type Ref } from "vue";
+
+import type { Issue, ReviewFlow } from "@/types";
+import { Review } from "@/types/proto/v1/review_service";
+import { useReviewStore } from "@/store";
+import { provideIssueReviewContext } from "./context";
+import { ApprovalTemplate } from "@/types/proto/store/approval";
+import { useProgressivePoll } from "@/composables/useProgressivePoll";
+
+export const provideIssueReview = (issue: Ref<Issue | undefined>) => {
+ const store = useReviewStore();
+ const review = computed(() => {
+ return issue.value
+ ? store.getReviewByIssue(issue.value)
+ : Review.fromJSON({});
+ });
+ const ready = computed(() => {
+ return review.value.approvalFindingDone ?? false;
+ });
+ const flow = computed((): ReviewFlow => {
+ if (!ready.value) return emptyFlow();
+ const { approvalTemplates, approvers } = review.value;
+ if (approvalTemplates.length === 0) return emptyFlow();
+ return {
+ template: approvalTemplates[0],
+ approvers,
+ currentStepIndex: approvers.length,
+ };
+ });
+ const done = computed(() => {
+ if (!ready.value) return false;
+ const { template, approvers } = flow.value;
+ const steps = template.flow?.steps ?? [];
+ if (steps.length === 0) return true;
+ return approvers.length === steps.length;
+ });
+
+ const update = () => {
+ if (issue.value) {
+ store.fetchReviewByIssue(issue.value);
+ }
+ };
+
+ const poller = useProgressivePoll(update, {
+ interval: {
+ min: 500,
+ max: 10000,
+ growth: 2,
+ jitter: 500,
+ },
+ });
+
+ watch(
+ () => issue.value?.id,
+ () => {
+ if (issue.value) poller.start();
+ else poller.stop();
+ },
+ {
+ immediate: true,
+ }
+ );
+
+ provideIssueReviewContext({
+ review,
+ ready,
+ flow,
+ done,
+ });
+};
+
+const emptyFlow = (): ReviewFlow => {
+ return {
+ template: ApprovalTemplate.fromJSON({}),
+ approvers: [],
+ currentStepIndex: -1,
+ };
+};
diff --git a/frontend/src/store/modules/index.ts b/frontend/src/store/modules/index.ts
index a62aa1e98a..4bfa2408ba 100644
--- a/frontend/src/store/modules/index.ts
+++ b/frontend/src/store/modules/index.ts
@@ -48,3 +48,4 @@ export * from "./idp";
export * from "./user";
export * from "./risk";
export * from "./workspaceApprovalSetting";
+export * from "./review";
diff --git a/frontend/src/store/modules/review.ts b/frontend/src/store/modules/review.ts
new file mode 100644
index 0000000000..472b855e27
--- /dev/null
+++ b/frontend/src/store/modules/review.ts
@@ -0,0 +1,118 @@
+import { defineStore } from "pinia";
+
+import { Issue } from "@/types";
+import {
+ Review,
+ ApprovalStep,
+ ApprovalNode_Type,
+ ApprovalNode_GroupValue,
+} from "@/types/proto/v1/review_service";
+import { ref } from "vue";
+import { extractUserEmail, useUserStore } from "./user";
+import { useMemberStore } from "./member";
+import { uniq, uniqBy } from "lodash-es";
+import { reviewServiceClient } from "@/grpcweb";
+import { User } from "@/types/proto/v1/auth_service";
+
+const reviewName = (issue: Issue) => {
+ return `projects/${issue.project.id}/reviews/${issue.id}`;
+};
+
+const emptyReview = (issue: Issue) => {
+ return Review.fromJSON({
+ name: reviewName(issue),
+ approvalFindingDone: false,
+ });
+};
+
+export const useReviewStore = defineStore("review", () => {
+ const reviewsByName = ref(new Map<string, Review>());
+
+ const getReviewByIssue = (issue: Issue) => {
+ return reviewsByName.value.get(reviewName(issue)) ?? emptyReview(issue);
+ };
+
+ const setReviewByIssue = async (issue: Issue, review: Review) => {
+ await fetchReviewApproversAndCandidates(issue, review);
+ reviewsByName.value.set(reviewName(issue), review);
+ };
+
+ const fetchReviewByIssue = async (issue: Issue, ignoreCache = false) => {
+ const name = reviewName(issue);
+
+ try {
+ const review = await reviewServiceClient.getReview({
+ name,
+ });
+ await setReviewByIssue(issue, review);
+ return review;
+ } catch (error) {
+ return Review.fromJSON({});
+ }
+ };
+
+ const approveReview = async (issue: Issue) => {
+ const review = await reviewServiceClient.approveReview({
+ name: reviewName(issue),
+ });
+ await setReviewByIssue(issue, review);
+ };
+
+ return {
+ getReviewByIssue,
+ fetchReviewByIssue,
+ approveReview,
+ };
+});
+
+const fetchReviewApproversAndCandidates = async (
+ issue: Issue,
+ review: Review
+) => {
+ const userStore = useUserStore();
+ const approvers = review.approvers.map((approver) => {
+ return userStore.getUserByEmail(extractUserEmail(approver.principal));
+ });
+ const candidates = review.approvalTemplates
+ .flatMap((template) => {
+ const steps = template.flow?.steps ?? [];
+ return steps.flatMap((step) => candidatesOfApprovalStep(issue, step));
+ })
+ .map((user) => userStore.getUserByName(user));
+ const users = [...approvers, ...candidates].filter(
+ (user) => user !== undefined
+ ) as User[];
+ return uniqBy(users, "name");
+};
+
+export const candidatesOfApprovalStep = (issue: Issue, step: ApprovalStep) => {
+ const memberStore = useMemberStore();
+
+ const candidates = step.nodes.flatMap((node) => {
+ const { type, groupValue } = node;
+ if (type !== ApprovalNode_Type.ANY_IN_GROUP) return [];
+ if (groupValue === ApprovalNode_GroupValue.PROJECT_MEMBER) {
+ return issue.project.memberList
+ .filter((member) => member.role === "DEVELOPER")
+ .map((member) => member.principal);
+ }
+ if (groupValue === ApprovalNode_GroupValue.PROJECT_OWNER) {
+ return issue.project.memberList
+ .filter((member) => member.role === "OWNER")
+ .map((member) => member.principal);
+ }
+ if (groupValue === ApprovalNode_GroupValue.WORKSPACE_DBA) {
+ return memberStore.memberList
+ .filter((member) => member.role === "DBA")
+ .map((member) => member.principal);
+ }
+ if (groupValue === ApprovalNode_GroupValue.WORKSPACE_OWNER) {
+ return memberStore.memberList
+ .filter((member) => member.role === "OWNER")
+ .map((member) => member.principal);
+ }
+ return [];
+ });
+
+ return uniq(candidates.map((principal) => `users/${principal.id}`));
+};
diff --git a/frontend/src/store/modules/user.ts b/frontend/src/store/modules/user.ts
index 64d9e15ac2..7933ab061a 100644
--- a/frontend/src/store/modules/user.ts
+++ b/frontend/src/store/modules/user.ts
@@ -76,9 +76,19 @@ export const useUserStore = defineStore("user", {
getUserById(id: number) {
return this.userMapByName.get(getUserNameWithUserId(id));
},
+ getUserByEmail(email: string) {
+ return [...this.userMapByName.values()].find(
+ (user) => user.email === email
+ );
+ },
},
});
+export const extractUserEmail = (emailResource: string) => {
+ const matches = emailResource.match(/^user:(.+)$/);
+ return matches?.[1] ?? "";
+};
+
export const getUserNameWithUserId = (userId: number) => {
return `${userNamePrefix}${userId}`;
};
diff --git a/frontend/src/types/activity.ts b/frontend/src/types/activity.ts
index 372d8f4fea..a7878dd63e 100644
--- a/frontend/src/types/activity.ts
+++ b/frontend/src/types/activity.ts
@@ -17,6 +17,7 @@ import { Principal } from "./principal";
import { VCSPushEvent } from "./vcs";
import { Advice } from "./sqlAdvice";
import { t } from "../plugins/i18n";
+import { ApprovalEvent } from "./review";
export type IssueActivityType =
| "bb.issue.create"
@@ -117,6 +118,7 @@ export type ActivityIssueCommentCreatePayload = {
externalApprovalEvent?: ExternalApprovalEvent;
issueName: string;
taskRollbackBy?: TaskRollbackBy;
+ approvalEvent?: ApprovalEvent;
};
export type ActivityIssueFieldUpdatePayload = {
diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.ts
index 1a5c7f4a78..e9c7b9902b 100644
--- a/frontend/src/types/index.ts
+++ b/frontend/src/types/index.ts
@@ -51,3 +51,4 @@ export * from "./externalApproval";
export * from "./mfa";
export * from "./risk";
export * from "./workspaceApprovalSetting";
+export * from "./review";
diff --git a/frontend/src/types/review.ts b/frontend/src/types/review.ts
new file mode 100644
index 0000000000..4fa9300bab
--- /dev/null
+++ b/frontend/src/types/review.ts
@@ -0,0 +1,24 @@
+import type { User } from "./proto/v1/auth_service";
+import type {
+ ApprovalStep,
+ ApprovalTemplate,
+ Review_Approver,
+} from "./proto/v1/review_service";
+
+export type ApprovalEvent = {
+ status: "APPROVED";
+};
+
+export type ReviewFlow = {
+ template: ApprovalTemplate;
+ approvers: Review_Approver[];
+ currentStepIndex: number; // -1 if finished
+};
+
+export type WrappedReviewStep = {
+ index: number;
+ step: ApprovalStep;
+ status: "DONE" | "CURRENT" | "PENDING";
+ approver: User | undefined;
+ candidates: User[];
+};
diff --git a/frontend/src/utils/pipeline.ts b/frontend/src/utils/pipeline.ts
index 6ecd907b12..14a305f501 100644
--- a/frontend/src/utils/pipeline.ts
+++ b/frontend/src/utils/pipeline.ts
@@ -159,7 +159,7 @@ export function activeDatabase(pipeline: Pipeline): Database | undefined {
export type TaskStatusTransitionType =
| "RUN"
- | "APPROVE"
+ | "ROLLOUT"
| "RETRY"
| "CANCEL"
| "SKIP"
@@ -186,11 +186,11 @@ export const TASK_STATUS_TRANSITION_LIST: Map<
},
],
[
- "APPROVE",
+ "ROLLOUT",
{
- type: "APPROVE",
+ type: "ROLLOUT",
to: "PENDING",
- buttonName: "common.approve",
+ buttonName: "common.rollout",
buttonType: "PRIMARY",
},
],
@@ -229,7 +229,7 @@ export const APPLICABLE_TASK_TRANSITION_LIST: Map<
TaskStatusTransitionType[]
> = new Map([
["PENDING", ["CANCEL"]],
- ["PENDING_APPROVAL", ["APPROVE"]],
+ ["PENDING_APPROVAL", ["ROLLOUT"]],
["RUNNING", ["CANCEL"]],
["DONE", []],
["FAILED", ["RETRY"]],
diff --git a/frontend/src/views/IssueDetail.vue b/frontend/src/views/IssueDetail.vue
index 80034321bf..577fc61578 100644
--- a/frontend/src/views/IssueDetail.vue
+++ b/frontend/src/views/IssueDetail.vue
@@ -24,6 +24,8 @@
import { onMounted, computed, reactive, watch } from "vue";
import { useRoute, _RouteLocationBase } from "vue-router";
import { NSpin } from "naive-ui";
+import { useI18n } from "vue-i18n";
+
import { IssueDetailLayout } from "@/components/Issue";
import {
IssueType,
@@ -40,9 +42,12 @@ import {
useProjectStore,
useUIStateStore,
} from "@/store";
-import { useInitializeIssue, usePollIssue } from "@/plugins/issue/logic";
+import {
+ useInitializeIssue,
+ provideIssueReview,
+ usePollIssue,
+} from "@/plugins/issue/logic";
import { useTitle } from "@vueuse/core";
-import { useI18n } from "vue-i18n";
interface LocalState {
showFeatureModal: boolean;
@@ -75,6 +80,12 @@ const showLoading = computed(() => {
const pollIssue = usePollIssue(issueSlug, issue);
+provideIssueReview(
+ computed(() => {
+ return create.value ? undefined : (issue.value as Issue);
+ })
+);
+
onMounted(() => {
if (!uiStateStore.getIntroStateByKey("issue.visit")) {
uiStateStore.saveIntroStateByKey({