Skip to content

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

feat(frontend): issue status action for new issue UI (#7519)

Liu Jic6f42d3ada4f
diff --git a/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue b/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue
index 9298b65661..275dd56847 100644
--- a/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue
+++ b/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue
@@ -5,10 +5,11 @@
type="primary"
size="large"
tag="div"
- :disabled="issueCreateErrorList.length > 0"
+ :disabled="issueCreateErrorList.length > 0 || loading"
+ :loading="loading"
@click="doCreateIssue"
>
- {{ $t("common.create") }}
+ {{ loading ? $t("common.creating") : $t("common.create") }}
</NButton>
</template>
@@ -16,11 +17,21 @@
<ErrorList :errors="issueCreateErrorList" />
</template>
</NTooltip>
+
+ <Teleport v-if="loading" to="body">
+ <!-- prevent clicking the page -->
+ <div
+ v-zindexable="{ enabled: true }"
+ class="fixed inset-0 pointer-events-auto flex flex-col items-center justify-center"
+ @click.stop.prevent
+ />
+ </Teleport>
</template>
<script setup lang="ts">
import { NTooltip, NButton } from "naive-ui";
-import { computed } from "vue";
+import { zindexable as vZindexable } from "vdirs";
+import { computed, ref } from "vue";
import { useRouter } from "vue-router";
import { ErrorList } from "@/components/IssueV1/components/common";
import {
@@ -40,6 +51,7 @@ const MAX_FORMATTABLE_STATEMENT_SIZE = 10000; // 10K characters
const router = useRouter();
const { issue, formatOnSave } = useIssueContext();
+const loading = ref(false);
const issueCreateErrorList = computed(() => {
const errorList: string[] = [];
@@ -56,35 +68,40 @@ const issueCreateErrorList = computed(() => {
});
const doCreateIssue = async () => {
- await createSheets();
- const createdPlan = await createPlan();
- if (!createdPlan) return;
-
- issue.value.plan = createdPlan.name;
- issue.value.planEntity = createdPlan;
-
- const createdIssue = await issueServiceClient.createIssue({
- parent: issue.value.project,
- issue: issue.value,
- });
-
- const createdRollout = await rolloutServiceClient.createRollout({
- parent: issue.value.project,
- plan: createdPlan.name,
- });
-
- createdIssue.rollout = createdRollout.name;
-
- const composedIssue: ComposedIssue = {
- ...issue.value,
- ...createdIssue,
- planEntity: createdPlan,
- rolloutEntity: createdRollout,
- };
-
- router.push(`/issue/${composedIssue.uid}`);
-
- return composedIssue;
+ loading.value = true;
+ try {
+ await createSheets();
+ const createdPlan = await createPlan();
+ if (!createdPlan) return;
+
+ issue.value.plan = createdPlan.name;
+ issue.value.planEntity = createdPlan;
+
+ const createdIssue = await issueServiceClient.createIssue({
+ parent: issue.value.project,
+ issue: issue.value,
+ });
+
+ const createdRollout = await rolloutServiceClient.createRollout({
+ parent: issue.value.project,
+ plan: createdPlan.name,
+ });
+
+ createdIssue.rollout = createdRollout.name;
+
+ const composedIssue: ComposedIssue = {
+ ...issue.value,
+ ...createdIssue,
+ planEntity: createdPlan,
+ rolloutEntity: createdRollout,
+ };
+
+ router.push(`/issue/${composedIssue.uid}`);
+
+ return composedIssue;
+ } catch {
+ loading.value = false;
+ }
};
// Create sheets for spec configs and update their resource names.
diff --git a/frontend/src/components/IssueV1/components/Panel/IssueStatusActionPanel.vue b/frontend/src/components/IssueV1/components/Panel/IssueStatusActionPanel.vue
index d0393d8ff6..6a65126f00 100644
--- a/frontend/src/components/IssueV1/components/Panel/IssueStatusActionPanel.vue
+++ b/frontend/src/components/IssueV1/components/Panel/IssueStatusActionPanel.vue
@@ -38,7 +38,7 @@
{{ $t("common.cancel") }}
</NButton>
<NButton
- v-bind="issueStatusActionButtonProps(action) !== undefined"
+ v-bind="issueStatusActionButtonProps(action)"
@click="handleConfirm(action, comment)"
>
{{ issueStatusActionDisplayName(action) }}
@@ -56,8 +56,11 @@ import {
useIssueContext,
issueStatusActionButtonProps,
issueStatusActionDisplayName,
+ IssueStatusActionToIssueStatusMap,
} from "@/components/IssueV1/logic";
+import { issueServiceClient } from "@/grpcweb";
import { pushNotification } from "@/store";
+import { Issue } from "@/types/proto/v1/issue_service";
import CommonDrawer from "./CommonDrawer.vue";
type LocalState = {
@@ -97,9 +100,17 @@ const handleConfirm = async (
comment: string | undefined
) => {
state.loading = true;
- // TODO
try {
- await new Promise((r) => setTimeout(r, 1000));
+ const issuePatch = Issue.fromJSON({
+ ...issue.value,
+ status: IssueStatusActionToIssueStatusMap[action],
+ });
+ const response = await issueServiceClient.batchUpdateIssues({
+ parent: issue.value.project,
+ requests: [{ issue: issuePatch, updateMask: ["status"] }],
+ });
+ const updatedIssue = response.issues[0];
+ Object.assign(issue.value, updatedIssue);
// notify the issue logic to update issue status
events.emit("status-changed", { eager: true });
@@ -109,24 +120,9 @@ const handleConfirm = async (
style: "SUCCESS",
title: t("common.updated"),
});
+ emit("close");
} finally {
state.loading = false;
- emit("close");
}
-
- // Trying to avoid some kind of concurrency and race condition, we fetch the
- // latest snapshot of issue from the server-side and check whether this
- // transition is applicable again.
- // const latestIssue = await useIssueStore().fetchIssueById(issue.value.id);
-
- // const { action: transition } = props;
- // const applicableList = getApplicableIssueStatusTransitionList(latestIssue);
- // if (!isApplicableTransition(transition, applicableList)) {
- // return cleanup();
- // }
-
- // changeIssueStatus(transition.to, comment);
- // isTransiting.value = false;
- // emit("updated");
};
</script>
diff --git a/frontend/src/components/IssueV1/logic/action/issue.ts b/frontend/src/components/IssueV1/logic/action/issue.ts
index 3d0cfca9f1..1c4ddf5d1a 100644
--- a/frontend/src/components/IssueV1/logic/action/issue.ts
+++ b/frontend/src/components/IssueV1/logic/action/issue.ts
@@ -15,7 +15,19 @@ import { isTaskFinished } from "..";
export type IssueStatusAction = "RESOLVE" | "CANCEL" | "REOPEN";
-export const IssueStatusActionMap: Record<IssueStatus, IssueStatusAction[]> = {
+export const IssueStatusActionToIssueStatusMap: Record<
+ IssueStatusAction,
+ IssueStatus
+> = {
+ CANCEL: IssueStatus.CANCELED,
+ REOPEN: IssueStatus.OPEN,
+ RESOLVE: IssueStatus.DONE,
+};
+
+export const PossibleIssueStatusActionMap: Record<
+ IssueStatus,
+ IssueStatusAction[]
+> = {
[IssueStatus.OPEN]: ["RESOLVE", "CANCEL"],
[IssueStatus.DONE]: ["REOPEN"],
[IssueStatus.CANCELED]: ["REOPEN"],
@@ -28,7 +40,7 @@ export const IssueStatusActionMap: Record<IssueStatus, IssueStatusAction[]> = {
export const getApplicableIssueStatusActionList = (
issue: ComposedIssue
): IssueStatusAction[] => {
- const list = IssueStatusActionMap[issue.status];
+ const list = PossibleIssueStatusActionMap[issue.status];
return list.filter((action) => {
if (isGrantRequestIssue(issue)) {
// Don't show RESOLVE or REOPEN for request granting issues.