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: IssueDetailLayout with better typing support (#1209)
Liu Ji605a879e7ea5
diff --git a/frontend/src/components/Issue/IssueDescriptionPanel.vue b/frontend/src/components/Issue/IssueDescriptionPanel.vueindex d0a9043ab4..57a0898136 100644--- a/frontend/src/components/Issue/IssueDescriptionPanel.vue+++ b/frontend/src/components/Issue/IssueDescriptionPanel.vue@@ -80,8 +80,8 @@ import {watch,defineComponent,} from "vue";-import { Issue } from "../../types";-import { sizeToFit } from "../../utils";+import type { Issue, IssueCreate } from "@/types";+import { sizeToFit } from "@/utils";interface LocalState {editing: boolean;@@ -93,7 +93,7 @@ export default defineComponent({props: {issue: {required: true,- type: Object as PropType<Issue>,+ type: Object as PropType<Issue | IssueCreate>,},create: {required: true,diff --git a/frontend/src/components/Issue/IssueDetailLayout.vue b/frontend/src/components/Issue/IssueDetailLayout.vueindex ec18a9ac8b..e8aa255d85 100644--- a/frontend/src/components/Issue/IssueDetailLayout.vue+++ b/frontend/src/components/Issue/IssueDetailLayout.vue@@ -4,12 +4,12 @@class="flex-1 overflow-auto focus:outline-none"tabindex="0">- <IssueBanner v-if="!create" :issue="issue" />+ <IssueBanner v-if="!create" :issue="(issue as Issue)" /><!-- Highlight Panel --><div class="bg-white px-4 pb-4"><IssueHighlightPanel- :issue="issue"+ :issue="(issue as Issue)":create="create":allow-edit="allowEditNameAndDescription"@update-name="updateName"@@ -44,7 +44,7 @@v-if="project":create="create":project="project"- :pipeline="issue.pipeline"+ :pipeline="(issue as Issue).pipeline":selected-stage="selectedStage":selected-task="selectedTask"class="border-t border-b"@@ -68,7 +68,7 @@<template v-else><PipelineSimpleFlow:create="create"- :pipeline="issue.pipeline"+ :pipeline="(issue as Issue).pipeline":selected-stage="selectedStage"@select-stage-id="selectStageId"/>@@ -76,8 +76,8 @@<div v-if="!create" class="px-4 py-4 md:flex md:flex-col border-b"><IssueStagePanel- :stage="selectedStage"- :selected-task="selectedTask"+ :stage="(selectedStage as Stage)"+ :selected-task="(selectedTask as Task)":is-tenant-mode="isTenantDeployMode":is-ghost-mode="isGhostMode"/>@@ -92,7 +92,7 @@:class="showPipelineFlowBar ? '' : 'lg:border-t'"><IssueOutputPanel- :issue="issue"+ :issue="(issue as Issue)":output-field-list="issueTemplate.outputFieldList":allow-edit="allowEditOutput"@update-custom-field="updateCustomField"@@ -138,7 +138,7 @@<section v-if="showIssueTaskStatementPanel" class="border-b mb-4"><div v-if="!create" class="mb-4"><TaskCheckBar- :task="selectedTask"+ :task="(selectedTask as Task)"@run-checks="runTaskChecks"/></div>@@ -198,11 +198,11 @@/></template><template- v-for="(stage, index) in issue.pipeline.stageList"+ v-for="(stage, index) in (issue as Issue).pipeline.stageList"v-else:key="index">- <template v-if="selectedStage.id == stage.id">+ <template v-if="(selectedStage as Stage).id == stage.id"><IssueTaskStatementPanel:sql-hint="sqlHint()":statement="statement(stage)"@@ -228,7 +228,7 @@class="mt-4"><IssueActivityPanel- :issue="issue"+ :issue="(issue as Issue)":issue-template="issueTemplate"@add-subscriber-id="addSubscriberId"/>@@ -240,17 +240,10 @@</div></template>-<script lang="ts">+<script lang="ts" setup>/* eslint-disable vue/no-mutating-props */-import {- computed,- defineComponent,- nextTick,- onMounted,- PropType,- watchEffect,-} from "vue";+import { computed, nextTick, onMounted, PropType, watchEffect } from "vue";import { useRoute, useRouter } from "vue-router";import { cloneDeep, isEqual } from "lodash-es";import {@@ -261,10 +254,9 @@ import {indexFromSlug,activeStage,stageSlug,- activeTask,taskSlug,isDev,-} from "../../utils";+} from "@/utils";import IssueBanner from "./IssueBanner.vue";import IssueHighlightPanel from "./IssueHighlightPanel.vue";import IssueStagePanel from "./IssueStagePanel.vue";@@ -278,7 +270,7 @@ import PipelineSimpleFlow from "./PipelineSimpleFlow.vue";import PipelineTenantFlow from "./PipelineTenantFlow.vue";import PipelineGhostFlow from "./PipelineGhostFlow.vue";import TaskCheckBar from "./TaskCheckBar.vue";-import {+import type {Issue,IssueCreate,IssuePatch,@@ -306,13 +298,13 @@ import {UpdateSchemaDetail,TaskDatabaseSchemaUpdateGhostSyncPayload,UpdateSchemaGhostContext,-} from "../../types";+} from "@/types";import {- defaulTemplate as defaultTemplate,+ defaultTemplate,templateForType,InputField,OutputField,-} from "../../plugins";+} from "@/plugins";import {featureToRef,useCurrentUser,@@ -324,785 +316,697 @@ import {useTaskStore,} from "@/store";-export default defineComponent({- name: "IssueDetailLayout",- components: {- IssueBanner,- IssueHighlightPanel,- IssueStagePanel,- IssueOutputPanel,- IssueTaskStatementPanel,- IssueDescriptionPanel,- IssueActivityPanel,- IssueSidebar,- IssueStatusTransitionButtonGroup,- PipelineSimpleFlow,- PipelineTenantFlow,- PipelineGhostFlow,- TaskCheckBar,+const props = defineProps({+ create: {+ type: Boolean,+ required: true,},- props: {- create: {- type: Boolean,- required: true,- },- issue: {- type: Object as PropType<Issue | IssueCreate>,- required: true,- },- },- emits: {- "status-changed": (eager: boolean) => true,+ issue: {+ type: Object as PropType<Issue | IssueCreate>,+ required: true,},- setup(props, { emit }) {- const router = useRouter();- const route = useRoute();-- const currentUser = useCurrentUser();- const issueStore = useIssueStore();- const issueSubscriberStore = useIssueSubscriberStore();- const taskStore = useTaskStore();- const projectStore = useProjectStore();-- watchEffect(function prepare() {- if (props.create) {- projectStore.fetchProjectById((props.issue as IssueCreate).projectId);- }- });+});- const issueTemplate = computed(- () => templateForType(props.issue.type) || defaultTemplate()- );+const emit = defineEmits<{+ (e: "status-changed", eager: boolean): void;+}>();- const project = computed((): Project => {- if (props.create) {- return projectStore.getProjectById(- (props.issue as IssueCreate).projectId- );- }- return (props.issue as Issue).project;- });+const router = useRouter();+const route = useRoute();- const updateName = (- newName: string,- postUpdated: (updatedIssue: Issue) => void- ) => {- if (props.create) {- props.issue.name = newName;- } else {- patchIssue(- {- name: newName,- },- postUpdated- );- }- };+const currentUser = useCurrentUser();+const issueStore = useIssueStore();+const issueSubscriberStore = useIssueSubscriberStore();+const taskStore = useTaskStore();+const projectStore = useProjectStore();- const updateStatement = (- newStatement: string,- postUpdated?: (updatedTask: Task) => void- ) => {- if (props.create) {- if (isTenantDeployMode.value) {- // For tenant deploy mode, we apply the statement to all stages and all tasks- const issueCreate = props.issue as IssueCreate;- const context = issueCreate.createContext as UpdateSchemaContext;- issueCreate.pipeline?.stageList.forEach((stage: StageCreate) => {- stage.taskList.forEach((task) => {- task.statement = newStatement;- });- });- // We also apply it to the CreateContext- context.updateSchemaDetailList.forEach(- (detail) => (detail.statement = newStatement)- );- } else {- // otherwise apply it to the only one task in stage- // i.e. selectedStage.taskList[0]- const stage = selectedStage.value as StageCreate;- stage.taskList[0].statement = newStatement;- }- } else {- if (isTenantDeployMode.value) {- // <del>For tenant deploy mode, we patch the issue's create context</del>- // nope, we are not allowed to update statement in tenant deploy mode anyway- } else {- // otherwise, patch the task- patchTask(- (selectedTask.value as Task).id,- {- statement: newStatement,- },- postUpdated- );- }- }- };+watchEffect(function prepare() {+ if (props.create) {+ projectStore.fetchProjectById((props.issue as IssueCreate).projectId);+ }+});- const applyStatementToOtherStages = (newStatement: string) => {- for (const stage of (props.issue as IssueCreate).pipeline!.stageList) {- for (const task of stage.taskList) {- if (- task.type == "bb.task.general" ||- task.type == "bb.task.database.create" ||- task.type == "bb.task.database.schema.update" ||- task.type == "bb.task.database.schema.update.ghost.sync" ||- task.type == "bb.task.database.data.update"- ) {- task.statement = newStatement;- }- }- }- };+const issueTemplate = computed(+ () => templateForType(props.issue.type) || defaultTemplate()+);- const updateDescription = (- newDescription: string,- postUpdated: (updatedIssue: Issue) => void- ) => {- if (props.create) {- props.issue.description = newDescription;- } else {- patchIssue(- {- description: newDescription,- },- postUpdated- );- }- };+const project = computed((): Project => {+ if (props.create) {+ return projectStore.getProjectById((props.issue as IssueCreate).projectId);+ }+ return (props.issue as Issue).project;+});- const updateAssigneeId = (newAssigneeId: PrincipalId) => {- if (props.create) {- (props.issue as IssueCreate).assigneeId = newAssigneeId;- } else {- patchIssue({- assigneeId: newAssigneeId,+const updateName = (+ newName: string,+ postUpdated: (updatedIssue: Issue) => void+) => {+ if (props.create) {+ props.issue.name = newName;+ } else {+ patchIssue(+ {+ name: newName,+ },+ postUpdated+ );+ }+};++const updateStatement = (+ newStatement: string,+ postUpdated?: (updatedTask: Task) => void+) => {+ if (props.create) {+ if (isTenantDeployMode.value) {+ // For tenant deploy mode, we apply the statement to all stages and all tasks+ const issueCreate = props.issue as IssueCreate;+ const context = issueCreate.createContext as UpdateSchemaContext;+ issueCreate.pipeline?.stageList.forEach((stage: StageCreate) => {+ stage.taskList.forEach((task) => {+ task.statement = newStatement;});- }- };-- const updateEarliestAllowedTime = (newEarliestAllowedTsMs: number) => {- if (props.create) {- if (isGhostMode.value) {- // In gh-ost mode, when creating an issue, all sub-tasks in a stage- // share the same earliestAllowedTs.- // So updates on any one of them will be applied to others.- // (They can be updated independently after creation)- const taskList = selectedStage.value.taskList as TaskCreate[];- taskList.forEach((task) => {- task.earliestAllowedTs = newEarliestAllowedTsMs;- });- } else {- selectedTask.value.earliestAllowedTs = newEarliestAllowedTsMs;- }- } else {- const taskPatch: TaskPatch = {- earliestAllowedTs: newEarliestAllowedTsMs,- };- patchTask((selectedTask.value as Task).id, taskPatch);- }- };-- const addSubscriberId = (subscriberId: PrincipalId) => {- issueSubscriberStore.createSubscriber({- issueId: (props.issue as Issue).id,- subscriberId,- });- };-- const removeSubscriberId = (subscriberId: PrincipalId) => {- issueSubscriberStore.deleteSubscriber({- issueId: (props.issue as Issue).id,- subscriberId,});- };-- const updateCustomField = (field: InputField | OutputField, value: any) => {- if (!isEqual(props.issue.payload[field.id], value)) {- if (props.create) {- props.issue.payload[field.id] = value;- } else {- const newPayload = cloneDeep(props.issue.payload);- newPayload[field.id] = value;- patchIssue({- payload: newPayload,- });- }- }- };+ // We also apply it to the CreateContext+ context.updateSchemaDetailList.forEach(+ (detail) => (detail.statement = newStatement)+ );+ } else {+ // otherwise apply it to the only one task in stage+ // i.e. selectedStage.taskList[0]+ const stage = selectedStage.value as StageCreate;+ stage.taskList[0].statement = newStatement;+ }+ } else {+ if (isTenantDeployMode.value) {+ // <del>For tenant deploy mode, we patch the issue's create context</del>+ // nope, we are not allowed to update statement in tenant deploy mode anyway+ } else {+ // otherwise, patch the task+ patchTask(+ (selectedTask.value as Task).id,+ {+ statement: newStatement,+ },+ postUpdated+ );+ }+ }+};- const doCreate = () => {- const issue = cloneDeep(props.issue) as IssueCreate;- if (!isTenantDeployMode.value) {- // for standard issue pipeline (1 * 1 or M * 1)- // copy user edited tasks back to issue.createContext- const taskList = issue.pipeline!.stageList.map(- (stage) => stage.taskList[0]- );- const detailList: UpdateSchemaDetail[] = taskList.map((task) => {- return {- databaseId: task.databaseId!,- databaseName: task.databaseName!,- statement: task.statement,- earliestAllowedTs: task.earliestAllowedTs,- };- });- issue.createContext = {- migrationType: taskList[0].migrationType!,- updateSchemaDetailList: detailList,- };- } else if (isGhostMode.value) {- // for gh-ost mode, copy user edited tasks back to issue.createContext- // only the first subtask (bb.task.database.schema.update.ghost.sync) has statement- const stageList = issue.pipeline!.stageList;- const createContext = issue.createContext as UpdateSchemaGhostContext;- const detailList = createContext.updateSchemaDetailList;- stageList.forEach((stage, i) => {- const detail = detailList[i];- const syncTask = stage.taskList[0];-- detail.databaseId = syncTask.databaseId!;- detail.databaseName = syncTask.databaseName!;- detail.statement = syncTask.statement;- detail.earliestAllowedTs = syncTask.earliestAllowedTs;- });- } else {- // for multi-tenancy issue pipeline (M * N)- // createContext is up-to-date already- // so nothing to do+const applyStatementToOtherStages = (newStatement: string) => {+ for (const stage of (props.issue as IssueCreate).pipeline!.stageList) {+ for (const task of stage.taskList) {+ if (+ task.type == "bb.task.general" ||+ task.type == "bb.task.database.create" ||+ task.type == "bb.task.database.schema.update" ||+ task.type == "bb.task.database.schema.update.ghost.sync" ||+ task.type == "bb.task.database.data.update"+ ) {+ task.statement = newStatement;}-- // then empty issue.pipeline and issue.payload- // because we are no longer passing parameters via issue.pipeline- // we are using issue.createContext instead- delete issue.pipeline;- issue.payload = {};-- issueStore.createIssue(issue).then((createdIssue) => {- // Use replace to omit the new issue url in the navigation history.- router.replace(- `/issue/${issueSlug(createdIssue.name, createdIssue.id)}`- );+ }+ }+};++const updateDescription = (+ newDescription: string,+ postUpdated: (updatedIssue: Issue) => void+) => {+ if (props.create) {+ props.issue.description = newDescription;+ } else {+ patchIssue(+ {+ description: newDescription,+ },+ postUpdated+ );+ }+};++const updateAssigneeId = (newAssigneeId: PrincipalId) => {+ if (props.create) {+ (props.issue as IssueCreate).assigneeId = newAssigneeId;+ } else {+ patchIssue({+ assigneeId: newAssigneeId,+ });+ }+};++const updateEarliestAllowedTime = (newEarliestAllowedTsMs: number) => {+ if (props.create) {+ if (isGhostMode.value) {+ // In gh-ost mode, when creating an issue, all sub-tasks in a stage+ // share the same earliestAllowedTs.+ // So updates on any one of them will be applied to others.+ // (They can be updated independently after creation)+ const taskList = selectedStage.value.taskList as TaskCreate[];+ taskList.forEach((task) => {+ task.earliestAllowedTs = newEarliestAllowedTsMs;});+ } else {+ selectedTask.value.earliestAllowedTs = newEarliestAllowedTsMs;+ }+ } else {+ const taskPatch: TaskPatch = {+ earliestAllowedTs: newEarliestAllowedTsMs,};-- const changeIssueStatus = (newStatus: IssueStatus, comment: string) => {- const issueStatusPatch: IssueStatusPatch = {- status: newStatus,- comment: comment,- };- issueStore- .updateIssueStatus({- issueId: (props.issue as Issue).id,- issueStatusPatch,- })- .then(() => {- // pollIssue(POST_CHANGE_POLL_INTERVAL);- });- };-- const changeTaskStatus = (- task: Task,- newStatus: TaskStatus,- comment: string- ) => {- // Switch to the stage view containing this task- selectStageId(task.stage.id);- nextTick().then(() => {- selectTaskId(task.id);+ patchTask((selectedTask.value as Task).id, taskPatch);+ }+};++const addSubscriberId = (subscriberId: PrincipalId) => {+ issueSubscriberStore.createSubscriber({+ issueId: (props.issue as Issue).id,+ subscriberId,+ });+};++const removeSubscriberId = (subscriberId: PrincipalId) => {+ issueSubscriberStore.deleteSubscriber({+ issueId: (props.issue as Issue).id,+ subscriberId,+ });+};++const updateCustomField = (field: InputField | OutputField, value: any) => {+ if (!isEqual(props.issue.payload[field.id], value)) {+ if (props.create) {+ props.issue.payload[field.id] = value;+ } else {+ const newPayload = cloneDeep(props.issue.payload);+ newPayload[field.id] = value;+ patchIssue({+ payload: newPayload,});-- const taskStatusPatch: TaskStatusPatch = {- status: newStatus,- comment: comment,+ }+ }+};++const doCreate = () => {+ const issue = cloneDeep(props.issue) as IssueCreate;+ if (!isTenantDeployMode.value) {+ // for standard issue pipeline (1 * 1 or M * 1)+ // copy user edited tasks back to issue.createContext+ const taskList = issue.pipeline!.stageList.map(+ (stage) => stage.taskList[0]+ );+ const detailList: UpdateSchemaDetail[] = taskList.map((task) => {+ return {+ databaseId: task.databaseId!,+ databaseName: task.databaseName!,+ statement: task.statement,+ earliestAllowedTs: task.earliestAllowedTs,};- taskStore- .updateStatus({- issueId: (props.issue as Issue).id,- pipelineId: (props.issue as Issue).pipeline.id,- taskId: task.id,- taskStatusPatch,- })- .then(() => {- // pollIssue(POST_CHANGE_POLL_INTERVAL);- emit("status-changed", true);- });- };-- const runTaskChecks = (task: Task) => {- taskStore- .runChecks({- issueId: (props.issue as Issue).id,- pipelineId: (props.issue as Issue).pipeline.id,- taskId: task.id,- })- .then(() => {- // pollIssue(POST_CHANGE_POLL_INTERVAL);- emit("status-changed", true);- });- };-- const patchIssue = (- issuePatch: IssuePatch,- postUpdated?: (updatedIssue: Issue) => void- ) => {- issueStore- .patchIssue({- issueId: (props.issue as Issue).id,- issuePatch,- })- .then((updatedIssue) => {- // issue/patchIssue already fetches the new issue, so we schedule- // the next poll in NORMAL_POLL_INTERVAL- // pollIssue(NORMAL_POLL_INTERVAL);- emit("status-changed", false);- if (postUpdated) {- postUpdated(updatedIssue);- }- });- };-- const patchTask = (- taskId: TaskId,- taskPatch: TaskPatch,- postUpdated?: (updatedTask: Task) => void- ) => {- taskStore- .patchTask({- issueId: (props.issue as Issue).id,- pipelineId: (props.issue as Issue).pipeline.id,- taskId,- taskPatch,- })- .then((updatedTask) => {- // For now, the only task/patchTask is to change statement, which will trigger async task check.- // Thus we use the short poll interval- // pollIssue(POST_CHANGE_POLL_INTERVAL);- emit("status-changed", true);- if (postUpdated) {- postUpdated(updatedTask);- }- });+ });+ issue.createContext = {+ migrationType: taskList[0].migrationType!,+ updateSchemaDetailList: detailList,};-- const currentPipelineType = computed((): PipelineType => {- return pipelineType(props.issue.pipeline!);+ } else if (isGhostMode.value) {+ // for gh-ost mode, copy user edited tasks back to issue.createContext+ // only the first subtask (bb.task.database.schema.update.ghost.sync) has statement+ const stageList = issue.pipeline!.stageList;+ const createContext = issue.createContext as UpdateSchemaGhostContext;+ const detailList = createContext.updateSchemaDetailList;+ stageList.forEach((stage, i) => {+ const detail = detailList[i];+ const syncTask = stage.taskList[0];++ detail.databaseId = syncTask.databaseId!;+ detail.databaseName = syncTask.databaseName!;+ detail.statement = syncTask.statement;+ detail.earliestAllowedTs = syncTask.earliestAllowedTs;});-- const selectedStage = computed((): Stage | StageCreate => {- const stageSlug = router.currentRoute.value.query.stage as string;- const taskSlug = router.currentRoute.value.query.task as string;- // For stage slug, we support both index based and id based.- // Index based is used when creating the new task and is the one used when clicking the UI.- // Id based is used when the context only has access to the stage id (e.g. Task only contains StageId)- if (stageSlug) {- const index = indexFromSlug(stageSlug);- if (index < props.issue.pipeline!.stageList.length) {- return props.issue.pipeline!.stageList[index];- }- const stageId = idFromSlug(stageSlug);- const stageList = (props.issue as Issue).pipeline.stageList;- for (const stage of stageList) {- if (stage.id == stageId) {- return stage;- }- }- } else if (!props.create && taskSlug) {- const taskId = idFromSlug(taskSlug);- const stageList = (props.issue as Issue).pipeline.stageList;- for (const stage of stageList) {- for (const task of stage.taskList) {- if (task.id == taskId) {- return stage;- }- }- }- }- if (props.create) {- return props.issue.pipeline!.stageList[0];- }- return activeStage((props.issue as Issue).pipeline);+ } else {+ // for multi-tenancy issue pipeline (M * N)+ // createContext is up-to-date already+ // so nothing to do+ }++ // then empty issue.pipeline and issue.payload+ // because we are no longer passing parameters via issue.pipeline+ // we are using issue.createContext instead+ delete issue.pipeline;+ issue.payload = {};++ issueStore.createIssue(issue).then((createdIssue) => {+ // Use replace to omit the new issue url in the navigation history.+ router.replace(`/issue/${issueSlug(createdIssue.name, createdIssue.id)}`);+ });+};++const changeIssueStatus = (newStatus: IssueStatus, comment: string) => {+ const issueStatusPatch: IssueStatusPatch = {+ status: newStatus,+ comment: comment,+ };+ issueStore+ .updateIssueStatus({+ issueId: (props.issue as Issue).id,+ issueStatusPatch,+ })+ .then(() => {+ // pollIssue(POST_CHANGE_POLL_INTERVAL);});-- const selectStageId = (- stageId: StageId,- task: string | undefined = undefined- ) => {- const stageList = props.issue.pipeline!.stageList;- const index = stageList.findIndex((item, index) => {- if (props.create) {- return index == stageId;- }- return (item as Stage).id == stageId;- });- router.replace({- name: "workspace.issue.detail",- query: {- ...router.currentRoute.value.query,- stage: stageSlug(stageList[index].name, index),- task,- },- });- };-- const selectTask = (stageId: StageId, taskSlug: string) => {- selectStageId(stageId, taskSlug);- };-- const selectTaskId = (taskId: TaskId) => {- const taskList = selectedStage.value.taskList as Task[];- const task = taskList.find((t) => t.id === taskId);- if (!task) return;- const slug = taskSlug(task.name, task.id);- const stage = selectedStage.value as Stage;- selectTask(stage.id, slug);- };-- const selectedTask = computed((): Task | TaskCreate => {- const taskSlug = route.query.task as string;- const { taskList } = selectedStage.value;- if (taskSlug) {- const index = indexFromSlug(taskSlug);- if (index < taskList.length) {- return taskList[index];- }- const id = idFromSlug(taskSlug);- for (let i = 0; i < taskList.length; i++) {- const task = taskList[i] as Task;- if (task.id === id) {- return task;- }- }- }- return taskList[0];+};++const changeTaskStatus = (+ task: Task,+ newStatus: TaskStatus,+ comment: string+) => {+ // Switch to the stage view containing this task+ selectStageId(task.stage.id);+ nextTick().then(() => {+ selectTaskId(task.id);+ });++ const taskStatusPatch: TaskStatusPatch = {+ status: newStatus,+ comment: comment,+ };+ taskStore+ .updateStatus({+ issueId: (props.issue as Issue).id,+ pipelineId: (props.issue as Issue).pipeline.id,+ taskId: task.id,+ taskStatusPatch,+ })+ .then(() => {+ // pollIssue(POST_CHANGE_POLL_INTERVAL);+ emit("status-changed", true);});-- const statement = (stage: Stage): string => {- const task = stage.taskList[0];- switch (task.type) {- case "bb.task.general":- return ((task as Task).payload as TaskGeneralPayload).statement || "";- case "bb.task.database.create":- return (- ((task as Task).payload as TaskDatabaseCreatePayload).statement ||- ""- );- case "bb.task.database.schema.update":- return (- ((task as Task).payload as TaskDatabaseSchemaUpdatePayload)- .statement || ""- );- case "bb.task.database.data.update":- return (- ((task as Task).payload as TaskDatabaseDataUpdatePayload)- .statement || ""- );- case "bb.task.database.restore":- return "";- case "bb.task.database.schema.update.ghost.sync":- case "bb.task.database.schema.update.ghost.cutover":- case "bb.task.database.schema.update.ghost.drop-original-table":- return ""; // should never reach here+};++const runTaskChecks = (task: Task) => {+ taskStore+ .runChecks({+ issueId: (props.issue as Issue).id,+ pipelineId: (props.issue as Issue).pipeline.id,+ taskId: task.id,+ })+ .then(() => {+ // pollIssue(POST_CHANGE_POLL_INTERVAL);+ emit("status-changed", true);+ });+};++const patchIssue = (+ issuePatch: IssuePatch,+ postUpdated?: (updatedIssue: Issue) => void+) => {+ issueStore+ .patchIssue({+ issueId: (props.issue as Issue).id,+ issuePatch,+ })+ .then((updatedIssue) => {+ // issue/patchIssue already fetches the new issue, so we schedule+ // the next poll in NORMAL_POLL_INTERVAL+ // pollIssue(NORMAL_POLL_INTERVAL);+ emit("status-changed", false);+ if (postUpdated) {+ postUpdated(updatedIssue);}- };-- const isTenantDeployMode = computed((): boolean => {- if (project.value.tenantMode !== "TENANT") return false;- return (- props.issue.type === "bb.issue.database.schema.update" ||- props.issue.type === "bb.issue.database.data.update"- );});-- const isGhostMode = computed((): boolean => {- if (!isDev()) return false;-- return props.issue.type === "bb.issue.database.schema.update.ghost";+};++const patchTask = (+ taskId: TaskId,+ taskPatch: TaskPatch,+ postUpdated?: (updatedTask: Task) => void+) => {+ taskStore+ .patchTask({+ issueId: (props.issue as Issue).id,+ pipelineId: (props.issue as Issue).pipeline.id,+ taskId,+ taskPatch,+ })+ .then((updatedTask) => {+ // For now, the only task/patchTask is to change statement, which will trigger async task check.+ // Thus we use the short poll interval+ // pollIssue(POST_CHANGE_POLL_INTERVAL);+ emit("status-changed", true);+ if (postUpdated) {+ postUpdated(updatedTask);+ }});+};- const isGhostSyncTaskSelected = computed((): boolean => {- return (- selectedTask.value.type === "bb.task.database.schema.update.ghost.sync"- );- });+const currentPipelineType = computed((): PipelineType => {+ return pipelineType(props.issue.pipeline!);+});- const selectedStatement = computed((): string => {- if (isTenantDeployMode.value) {- // In tenant mode, the entire issue shares only one SQL statement- if (props.create) {- const issueCreate = props.issue as IssueCreate;- const context = issueCreate.createContext as UpdateSchemaContext;- return context.updateSchemaDetailList[0].statement;- } else {- const issue = props.issue as Issue;- const task = issue.pipeline.stageList[0].taskList[0];- const payload = task.payload as TaskDatabaseSchemaUpdatePayload;- return payload.statement;- }- } else if (isGhostMode.value) {- // In gh-ost mode, each stage can own its SQL statement- // But only for task.type === "bb.task.database.schema.update.ghost.sync"- const task = selectedTask.value;- if (task.type === "bb.task.database.schema.update.ghost.sync") {- if (props.create) {- return (task as TaskCreate).statement;- } else {- const payload = (task as Task)- .payload as TaskDatabaseSchemaUpdateGhostSyncPayload;- return payload.statement;- }- } else {- return "";- }- } else {- if (router.currentRoute.value.query.sql) {- const sql = router.currentRoute.value.query.sql as string;- updateStatement(sql);+const selectedStage = computed((): Stage | StageCreate => {+ const stageSlug = router.currentRoute.value.query.stage as string;+ const taskSlug = router.currentRoute.value.query.task as string;+ // For stage slug, we support both index based and id based.+ // Index based is used when creating the new task and is the one used when clicking the UI.+ // Id based is used when the context only has access to the stage id (e.g. Task only contains StageId)+ if (stageSlug) {+ const index = indexFromSlug(stageSlug);+ if (index < props.issue.pipeline!.stageList.length) {+ return props.issue.pipeline!.stageList[index];+ }+ const stageId = idFromSlug(stageSlug);+ const stageList = (props.issue as Issue).pipeline.stageList;+ for (const stage of stageList) {+ if (stage.id == stageId) {+ return stage;+ }+ }+ } else if (!props.create && taskSlug) {+ const taskId = idFromSlug(taskSlug);+ const stageList = (props.issue as Issue).pipeline.stageList;+ for (const stage of stageList) {+ for (const task of stage.taskList) {+ if (task.id == taskId) {+ return stage;}-- const task = (selectedStage.value as StageCreate).taskList[0];- return task.statement;}- });+ }+ }+ if (props.create) {+ return props.issue.pipeline!.stageList[0];+ }+ return activeStage((props.issue as Issue).pipeline);+});- const selectedMigrateType = computed((): MigrationType => {- if (- !props.create &&- selectedTask.value.type == "bb.task.database.schema.update"- ) {- return (- (selectedTask.value as Task)- .payload as TaskDatabaseSchemaUpdatePayload- ).migrationType;+const selectStageId = (+ stageId: StageId,+ task: string | undefined = undefined+) => {+ const stageList = props.issue.pipeline!.stageList;+ const index = stageList.findIndex((item, index) => {+ if (props.create) {+ return index == stageId;+ }+ return (item as Stage).id == stageId;+ });+ router.replace({+ name: "workspace.issue.detail",+ query: {+ ...router.currentRoute.value.query,+ stage: stageSlug(stageList[index].name, index),+ task,+ },+ });+};++const selectTask = (stageId: StageId, taskSlug: string) => {+ selectStageId(stageId, taskSlug);+};++const selectTaskId = (taskId: TaskId) => {+ const taskList = selectedStage.value.taskList as Task[];+ const task = taskList.find((t) => t.id === taskId);+ if (!task) return;+ const slug = taskSlug(task.name, task.id);+ const stage = selectedStage.value as Stage;+ selectTask(stage.id, slug);+};++const selectedTask = computed((): Task | TaskCreate => {+ const taskSlug = route.query.task as string;+ const { taskList } = selectedStage.value;+ if (taskSlug) {+ const index = indexFromSlug(taskSlug);+ if (index < taskList.length) {+ return taskList[index];+ }+ const id = idFromSlug(taskSlug);+ for (let i = 0; i < taskList.length; i++) {+ const task = taskList[i] as Task;+ if (task.id === id) {+ return task;}- return "MIGRATE";- });+ }+ }+ return taskList[0];+});- const allowEditSidebar = computed(() => {- // For now, we only allow assignee to update the field when the issue- // is 'OPEN'. This reduces flexibility as creator must ask assignee to- // change any fields if there is typo. On the other hand, this avoids- // the trouble that the creator changes field value when the creator- // is performing the issue based on the old value.- // For now, we choose to be on the safe side at the cost of flexibility.+const statement = (stage: Stage): string => {+ const task = stage.taskList[0];+ switch (task.type) {+ case "bb.task.general":+ return ((task as Task).payload as TaskGeneralPayload).statement || "";+ case "bb.task.database.create":return (- props.create ||- ((props.issue as Issue).status == "OPEN" &&- (props.issue as Issue).assignee?.id == currentUser.value.id)+ ((task as Task).payload as TaskDatabaseCreatePayload).statement || "");- });-- const allowEditOutput = computed(() => {+ case "bb.task.database.schema.update":return (- props.create ||- ((props.issue as Issue).status == "OPEN" &&- (props.issue as Issue).assignee?.id == currentUser.value.id)+ ((task as Task).payload as TaskDatabaseSchemaUpdatePayload).statement ||+ "");- });-- const allowEditNameAndDescription = computed(() => {+ case "bb.task.database.data.update":return (- props.create ||- ((props.issue as Issue).status == "OPEN" &&- ((props.issue as Issue).assignee?.id == currentUser.value.id ||- (props.issue as Issue).creator.id == currentUser.value.id))+ ((task as Task).payload as TaskDatabaseDataUpdatePayload).statement ||+ "");- });+ case "bb.task.database.restore":+ return "";+ case "bb.task.database.schema.update.ghost.sync":+ case "bb.task.database.schema.update.ghost.cutover":+ case "bb.task.database.schema.update.ghost.drop-original-table":+ return ""; // should never reach here+ }+};++const isTenantDeployMode = computed((): boolean => {+ if (project.value.tenantMode !== "TENANT") return false;+ return (+ props.issue.type === "bb.issue.database.schema.update" ||+ props.issue.type === "bb.issue.database.data.update"+ );+});- const allowEditStatement = computed(() => {- // if creating an issue, it's editable- if (props.create) {- return true;- }- const checkTask = (task: Task) => {- return (- task.status == "PENDING" ||- task.status == "PENDING_APPROVAL" ||- task.status == "FAILED"- );- };+const isGhostMode = computed((): boolean => {+ if (!isDev()) return false;++ return props.issue.type === "bb.issue.database.schema.update.ghost";+});+const isGhostSyncTaskSelected = computed((): boolean => {+ return (+ selectedTask.value.type === "bb.task.database.schema.update.ghost.sync"+ );+});++const selectedStatement = computed((): string => {+ if (isTenantDeployMode.value) {+ // In tenant mode, the entire issue shares only one SQL statement+ if (props.create) {+ const issueCreate = props.issue as IssueCreate;+ const context = issueCreate.createContext as UpdateSchemaContext;+ return context.updateSchemaDetailList[0].statement;+ } else {const issue = props.issue as Issue;- // if not creating, we are allowed to edit sql statement only when:- // 1. issue.status is OPEN- // 2. AND currentUser is the creator- // 3. AND workflowType is UI- if (issue.status !== "OPEN") return false;- if (issue.creator.id !== currentUser.value.id) return false;- if (issue.project.workflowType !== "UI") return false;-- if (isTenantDeployMode.value) {- // <del>then if in tenant deploy mode, EVERY task must be PENDING or PENDING_APPROVAL or FAILED</del>- // nope, we are not allowed to update statement in tenant deploy mode anyway- // const allTasks = issue.pipeline.stageList.flatMap(- // (stage) => stage.taskList- // );- // return allTasks.every((task) => checkTask(task));- return false;+ const task = issue.pipeline.stageList[0].taskList[0];+ const payload = task.payload as TaskDatabaseSchemaUpdatePayload;+ return payload.statement;+ }+ } else if (isGhostMode.value) {+ // In gh-ost mode, each stage can own its SQL statement+ // But only for task.type === "bb.task.database.schema.update.ghost.sync"+ const task = selectedTask.value;+ if (task.type === "bb.task.database.schema.update.ghost.sync") {+ if (props.create) {+ return (task as TaskCreate).statement;} else {- // otherwise, check `selectedTask`, expected to be PENDING or PENDING_APPROVAL or FAILED- return checkTask(selectedTask.value as Task);+ const payload = (task as Task)+ .payload as TaskDatabaseSchemaUpdateGhostSyncPayload;+ return payload.statement;}- });+ } else {+ return "";+ }+ } else {+ if (router.currentRoute.value.query.sql) {+ const sql = router.currentRoute.value.query.sql as string;+ updateStatement(sql);+ }++ const task = (selectedStage.value as StageCreate).taskList[0];+ return task.statement;+ }+});- const showCancelBanner = computed(() => {- return !props.create && (props.issue as Issue).status == "CANCELED";- });+const selectedMigrateType = computed((): MigrationType => {+ if (+ !props.create &&+ selectedTask.value.type == "bb.task.database.schema.update"+ ) {+ return (+ (selectedTask.value as Task).payload as TaskDatabaseSchemaUpdatePayload+ ).migrationType;+ }+ return "MIGRATE";+});- const showSuccessBanner = computed(() => {- return !props.create && (props.issue as Issue).status == "DONE";- });+const allowEditSidebar = computed(() => {+ // For now, we only allow assignee to update the field when the issue+ // is 'OPEN'. This reduces flexibility as creator must ask assignee to+ // change any fields if there is typo. On the other hand, this avoids+ // the trouble that the creator changes field value when the creator+ // is performing the issue based on the old value.+ // For now, we choose to be on the safe side at the cost of flexibility.+ return (+ props.create ||+ ((props.issue as Issue).status == "OPEN" &&+ (props.issue as Issue).assignee?.id == currentUser.value.id)+ );+});- const showPendingApproval = computed(() => {- if (props.create) {- return false;- }+const allowEditOutput = computed(() => {+ return (+ props.create ||+ ((props.issue as Issue).status == "OPEN" &&+ (props.issue as Issue).assignee?.id == currentUser.value.id)+ );+});- const task = activeTask((props.issue as Issue).pipeline);- return task.status == "PENDING_APPROVAL";- });+const allowEditNameAndDescription = computed(() => {+ return (+ props.create ||+ ((props.issue as Issue).status == "OPEN" &&+ ((props.issue as Issue).assignee?.id == currentUser.value.id ||+ (props.issue as Issue).creator.id == currentUser.value.id))+ );+});- const showPipelineFlowBar = computed(() => {- return currentPipelineType.value != "NO_PIPELINE";- });+const allowEditStatement = computed(() => {+ // if creating an issue, it's editable+ if (props.create) {+ return true;+ }+ const checkTask = (task: Task) => {+ return (+ task.status == "PENDING" ||+ task.status == "PENDING_APPROVAL" ||+ task.status == "FAILED"+ );+ };++ const issue = props.issue as Issue;+ // if not creating, we are allowed to edit sql statement only when:+ // 1. issue.status is OPEN+ // 2. AND currentUser is the creator+ // 3. AND workflowType is UI+ if (issue.status !== "OPEN") return false;+ if (issue.creator.id !== currentUser.value.id) return false;+ if (issue.project.workflowType !== "UI") return false;++ if (isTenantDeployMode.value) {+ // <del>then if in tenant deploy mode, EVERY task must be PENDING or PENDING_APPROVAL or FAILED</del>+ // nope, we are not allowed to update statement in tenant deploy mode anyway+ // const allTasks = issue.pipeline.stageList.flatMap(+ // (stage) => stage.taskList+ // );+ // return allTasks.every((task) => checkTask(task));+ return false;+ } else {+ // otherwise, check `selectedTask`, expected to be PENDING or PENDING_APPROVAL or FAILED+ return checkTask(selectedTask.value as Task);+ }+});- const showIssueOutputPanel = computed(() => {- return !props.create && issueTemplate.value.outputFieldList.length > 0;- });+const showPipelineFlowBar = computed(() => {+ return currentPipelineType.value != "NO_PIPELINE";+});- const showIssueTaskStatementPanel = computed(() => {- const task = selectedTask.value;- return (+const showIssueOutputPanel = computed(() => {+ return !props.create && issueTemplate.value.outputFieldList.length > 0;+});++const showIssueTaskStatementPanel = computed(() => {+ const task = selectedTask.value;+ return (+ task.type == "bb.task.general" ||+ task.type == "bb.task.database.create" ||+ task.type == "bb.task.database.schema.update" ||+ task.type == "bb.task.database.schema.update.ghost.sync" ||+ task.type == "bb.task.database.data.update"+ );+});++const showIssueTaskStatementApply = computed(() => {+ if (!props.create) {+ return false;+ }+ if (isTenantDeployMode.value) {+ return false;+ }+ let count = 0;+ for (const stage of (props.issue as IssueCreate).pipeline!.stageList) {+ for (const task of stage.taskList) {+ if (task.type == "bb.task.general" ||task.type == "bb.task.database.create" ||task.type == "bb.task.database.schema.update" ||task.type == "bb.task.database.schema.update.ghost.sync" ||task.type == "bb.task.database.data.update"- );- });-- const showIssueTaskStatementApply = computed(() => {- if (!props.create) {- return false;- }- if (isTenantDeployMode.value) {- return false;- }- let count = 0;- for (const stage of (props.issue as IssueCreate).pipeline!.stageList) {- for (const task of stage.taskList) {- if (- task.type == "bb.task.general" ||- task.type == "bb.task.database.create" ||- task.type == "bb.task.database.schema.update" ||- task.type == "bb.task.database.schema.update.ghost.sync" ||- task.type == "bb.task.database.data.update"- ) {- count++;- }- }- }- return count > 1;- });-- const database = computed((): Database | undefined => {- if (props.create) {- const databaseId = (selectedTask.value as TaskCreate).databaseId;- if (databaseId) {- return useDatabaseStore().getDatabaseById(databaseId);- }- return undefined;- }- return (selectedTask.value as Task).database;- });-- const instance = computed((): Instance => {- if (props.create) {- // If database is available, then we derive the instance from database because we always fetch database's instance.- if (database.value) {- return database.value.instance;- }- return useInstanceStore().getInstanceById(- (selectedTask.value as TaskCreate).instanceId- );- }- return (selectedTask.value as Task).instance;- });-- const sqlHint = (): string | undefined => {- if (!props.create && selectedMigrateType.value == "BASELINE") {- return `This is a baseline migration and bytebase won't apply the SQL to the database, it will only record a baseline history`;- }- if (instance.value.engine === "SNOWFLAKE") {- return `Use <<schema>>.<<table>> to specify a Snowflake table`;+ ) {+ count++;}- return undefined;- };+ }+ }+ return count > 1;+});- onMounted(() => {- // Always scroll to top, the scrollBehavior doesn't seem to work.- // The hypothesis is that because the scroll bar is in the nested- // route, thus setting the scrollBehavior in the global router- // won't work.- document.getElementById("issue-detail-top")!.scrollIntoView();- });+const database = computed((): Database | undefined => {+ if (props.create) {+ const databaseId = (selectedTask.value as TaskCreate).databaseId;+ if (databaseId) {+ return useDatabaseStore().getDatabaseById(databaseId);+ }+ return undefined;+ }+ return (selectedTask.value as Task).database;+});- const hasBackwardCompatibilityFeature = featureToRef(- "bb.feature.backward-compatibility"+const instance = computed((): Instance => {+ if (props.create) {+ // If database is available, then we derive the instance from database because we always fetch database's instance.+ if (database.value) {+ return database.value.instance;+ }+ return useInstanceStore().getInstanceById(+ (selectedTask.value as TaskCreate).instanceId);+ }+ return (selectedTask.value as Task).instance;+});- const supportBackwardCompatibilityFeature = computed((): boolean => {- const engine = database.value?.instance.engine;- return engine === "MYSQL" || engine === "TIDB";- });+const sqlHint = (): string | undefined => {+ if (!props.create && selectedMigrateType.value == "BASELINE") {+ return `This is a baseline migration and bytebase won't apply the SQL to the database, it will only record a baseline history`;+ }+ if (instance.value.engine === "SNOWFLAKE") {+ return `Use <<schema>>.<<table>> to specify a Snowflake table`;+ }+ return undefined;+};++onMounted(() => {+ // Always scroll to top, the scrollBehavior doesn't seem to work.+ // The hypothesis is that because the scroll bar is in the nested+ // route, thus setting the scrollBehavior in the global router+ // won't work.+ document.getElementById("issue-detail-top")!.scrollIntoView();+});- return {- database,- instance,- sqlHint,- updateName,- updateDescription,- updateStatement,- updateEarliestAllowedTime,- applyStatementToOtherStages,- updateAssigneeId,- addSubscriberId,- removeSubscriberId,- updateCustomField,- doCreate,- changeIssueStatus,- changeTaskStatus,- runTaskChecks,- currentPipelineType,- currentUser,- project,- isTenantDeployMode,- isGhostMode,- isGhostSyncTaskSelected,- issueTemplate,- selectedStage,- selectedTask,- selectStageId,- selectTask,- selectTaskId,- statement,- selectedStatement,- selectedMigrateType,- allowEditSidebar,- allowEditOutput,- allowEditNameAndDescription,- allowEditStatement,- showCancelBanner,- showSuccessBanner,- showPendingApproval,- showPipelineFlowBar,- showIssueOutputPanel,- showIssueTaskStatementPanel,- showIssueTaskStatementApply,- hasBackwardCompatibilityFeature,- supportBackwardCompatibilityFeature,- };- },+const hasBackwardCompatibilityFeature = featureToRef(+ "bb.feature.backward-compatibility"+);++const supportBackwardCompatibilityFeature = computed((): boolean => {+ const engine = database.value?.instance.engine;+ return engine === "MYSQL" || engine === "TIDB";});</script>diff --git a/frontend/src/plugins/issue/template.ts b/frontend/src/plugins/issue/template.tsindex d800d78c2a..73b06bbd91 100644--- a/frontend/src/plugins/issue/template.ts+++ b/frontend/src/plugins/issue/template.ts@@ -18,7 +18,7 @@ const allIssueTemplateList: IssueTemplate[] = [DatabaseSchemaBaselineTemplate,];-export function defaulTemplate(): IssueTemplate {+export function defaultTemplate(): IssueTemplate {return DefaultTemplate;}diff --git a/frontend/src/views/IssueDetail.vue b/frontend/src/views/IssueDetail.vueindex 834477167a..cfb7298a1e 100644--- a/frontend/src/views/IssueDetail.vue+++ b/frontend/src/views/IssueDetail.vue@@ -48,7 +48,7 @@ import {UpdateSchemaGhostContext,} from "../types";import {- defaulTemplate as defaultTemplate,+ defaultTemplate,templateForType,IssueTemplate,TemplateType,