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(frontend): move components/Issue* to components/Issue/* (#327)
Liu Ji9816d26e6ddd
diff --git a/frontend/src/components/IssueActivityPanel.vue b/frontend/src/components/Issue/IssueActivityPanel.vuesimilarity index 99%rename from frontend/src/components/IssueActivityPanel.vuerename to frontend/src/components/Issue/IssueActivityPanel.vueindex 6cbffccb24..b14be5088b 100644--- a/frontend/src/components/IssueActivityPanel.vue+++ b/frontend/src/components/Issue/IssueActivityPanel.vue@@ -25,7 +25,7 @@><imgclass="mt-1"- src="../assets/logo-icon.svg"+ src="../../assets/logo-icon.svg"alt="Bytebase"/></div>@@ -343,7 +343,7 @@ import {} from "vue";import { useStore } from "vuex";import { useRouter } from "vue-router";-import PrincipalAvatar from "../components/PrincipalAvatar.vue";+import PrincipalAvatar from "../PrincipalAvatar.vue";import {Issue,Activity,@@ -357,15 +357,15 @@ import {ActivityCreate,IssueSubscriber,ActivityTaskFileCommitPayload,-} from "../types";+} from "../../types";import {findTaskById,issueActivityActionSentence,issueSlug,sizeToFit,taskSlug,-} from "../utils";-import { IssueTemplate, IssueBuiltinFieldId } from "../plugins";+} from "../../utils";+import { IssueTemplate, IssueBuiltinFieldId } from "../../plugins";import { useI18n } from "vue-i18n";import dayjs from "dayjs";diff --git a/frontend/src/components/Issue/IssueBanner.vue b/frontend/src/components/Issue/IssueBanner.vuenew file mode 100644index 0000000000..49ee1a3add--- /dev/null+++ b/frontend/src/components/Issue/IssueBanner.vue@@ -0,0 +1,43 @@+<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>+</template>++<script lang="ts" setup>+import { computed, defineProps } from "vue";+import { Issue } from "../../types";+import { activeTask } from "../../utils";++const props = defineProps<{+ issue: Issue;+}>();++const showCancelBanner = computed(() => {+ return props.issue.status == "CANCELED";+});++const showSuccessBanner = computed(() => {+ return props.issue.status == "DONE";+});++const showPendingApproval = computed(() => {+ const task = activeTask(props.issue.pipeline);+ return task.status == "PENDING_APPROVAL";+});+</script>diff --git a/frontend/src/components/IssueDescriptionPanel.vue b/frontend/src/components/Issue/IssueDescriptionPanel.vuesimilarity index 95%rename from frontend/src/components/IssueDescriptionPanel.vuerename to frontend/src/components/Issue/IssueDescriptionPanel.vueindex 58efd5e89f..d0a9043ab4 100644--- a/frontend/src/components/IssueDescriptionPanel.vue+++ b/frontend/src/components/Issue/IssueDescriptionPanel.vue@@ -54,7 +54,7 @@:readonly="!state.editing"@input="(e) => {- sizeToFit(e.target);+ sizeToFit(e.target as HTMLTextAreaElement);// When creating the issue, we will emit the event on keystroke to update the in-memory state.if (create) {$emit('update-description', state.editDescription);@@ -63,7 +63,7 @@"@focus="(e) => {- sizeToFit(e.target);+ sizeToFit(e.target as HTMLTextAreaElement);}"></textarea>@@ -78,16 +78,17 @@ import {ref,reactive,watch,+ defineComponent,} from "vue";-import { Issue } from "../types";-import { sizeToFit } from "../utils";+import { Issue } from "../../types";+import { sizeToFit } from "../../utils";interface LocalState {editing: boolean;editDescription: string;}-export default {+export default defineComponent({name: "IssueDescriptionPanel",props: {issue: {@@ -203,5 +204,5 @@ export default {cancelEdit,};},-};+});</script>diff --git a/frontend/src/components/IssueHighlightPanel.vue b/frontend/src/components/Issue/IssueHighlightPanel.vuesimilarity index 93%rename from frontend/src/components/IssueHighlightPanel.vuerename to frontend/src/components/Issue/IssueHighlightPanel.vueindex 4b34cde2e4..8165877d72 100644--- a/frontend/src/components/IssueHighlightPanel.vue+++ b/frontend/src/components/Issue/IssueHighlightPanel.vue@@ -18,7 +18,7 @@:bordered="false":value="state.name":placeholder="'Issue name'"- @end-editing="(text) => trySaveName(text)"+ @end-editing="(text: string) => trySaveName(text)"/></div><div v-if="!create">@@ -44,7 +44,7 @@class="mt-1 text-sm text-control-light flex flex-row items-center space-x-1"><template v-if="pushEvent.vcsType.startsWith('GITLAB')">- <img class="h-4 w-auto" src="../assets/gitlab-logo.svg" />+ <img class="h-4 w-auto" src="../../assets/gitlab-logo.svg" /></template><a :href="vcsBranchUrl" target="_blank" class="normal-link">{{ `${vcsBranch}@${pushEvent.repositoryFullPath}` }}@@ -80,9 +80,13 @@<script lang="ts">import { reactive, watch, PropType, computed, defineComponent } from "vue";-import IssueStatusIcon from "../components/IssueStatusIcon.vue";-import { activeTask } from "../utils";-import { TaskDatabaseSchemaUpdatePayload, Issue, VCSPushEvent } from "../types";+import IssueStatusIcon from "./IssueStatusIcon.vue";+import { activeTask } from "../../utils";+import {+ TaskDatabaseSchemaUpdatePayload,+ Issue,+ VCSPushEvent,+} from "../../types";interface LocalState {editing: boolean;diff --git a/frontend/src/components/IssueOutputPanel.vue b/frontend/src/components/Issue/IssueOutputPanel.vuesimilarity index 75%rename from frontend/src/components/IssueOutputPanel.vuerename to frontend/src/components/Issue/IssueOutputPanel.vueindex b0f1e9455f..b5d35fc110 100644--- a/frontend/src/components/IssueOutputPanel.vue+++ b/frontend/src/components/Issue/IssueOutputPanel.vue@@ -25,46 +25,18 @@<div class="flex flex-row"><inputtype="text"- class="- flex-1- min-w-0- block- w-full- px-3- py-2- rounded-l-md- border border-r border-control-border- focus:mr-0.5 focus:ring-control focus:border-control- sm:text-sm- disabled:bg-gray-50- "+ class="flex-1 min-w-0 block w-full px-3 py-2 rounded-l-md border border-r border-control-border focus:mr-0.5 focus:ring-control focus:border-control sm:text-sm disabled:bg-gray-50":disabled="!allowEdit":name="field.id":value="fieldValue(field)"autocomplete="off"- @blur="$emit('update-custom-field', field, $event.target.value)"+ @blur="(e: any) => $emit('update-custom-field', field, e.target.value)"/><!-- Disallow tabbing since the focus ring is partially covered by the text field due to overlaying --><buttontabindex="-1":disabled="!fieldValue(field)"- class="- -ml-px- px-2- py-2- border border-gray-300- text-sm- font-medium- text-control-light- disabled:text-gray-300- bg-gray-50- hover:bg-gray-100- disabled:bg-gray-50- focus:ring-control focus:outline-none- focus-visible:ring-2- focus:ring-offset-1- disabled:cursor-not-allowed- "+ class="-ml-px px-2 py-2 border border-gray-300 text-sm font-medium text-control-light disabled:text-gray-300 bg-gray-50 hover:bg-gray-100 disabled:bg-gray-50 focus:ring-control focus:outline-none focus-visible:ring-2 focus:ring-offset-1 disabled:cursor-not-allowed"@click.prevent="copyText(field)"><heroicons-outline:clipboard class="w-6 h-6" />@@ -72,23 +44,7 @@<buttontabindex="-1":disabled="!isValidLink(fieldValue(field))"- class="- -ml-px- px-2- py-2- border border-gray-300- text-sm- font-medium- rounded-r-md- text-control-light- disabled:text-gray-300- bg-gray-50- hover:bg-gray-100- disabled:bg-gray-50- focus:ring-control focus:outline-none- focus-visible:ring-2- focus:ring-offset-1- "+ class="-ml-px px-2 py-2 border border-gray-300 text-sm font-medium rounded-r-md text-control-light disabled:text-gray-300 bg-gray-50 hover:bg-gray-100 disabled:bg-gray-50 focus:ring-control focus:outline-none focus-visible:ring-2 focus:ring-offset-1"@click.prevent="goToLink(fieldValue(field))"><heroicons-outline:external-link class="w-6 h-6" />@@ -107,7 +63,7 @@:environmentId="environmentId":selectedId="fieldValue(field) || UNKNOWN_ID"@select-database-id="- (databaseId) => {+ (databaseId: number) => {trySaveCustomField(field, databaseId);}"@@ -133,20 +89,20 @@</template><script lang="ts">-import { PropType, computed, reactive } from "vue";+import { PropType, computed, reactive, defineComponent } from "vue";import { useStore } from "vuex";import { useRouter } from "vue-router";import isEqual from "lodash-es/isEqual";import { toClipboard } from "@soerenmartius/vue3-clipboard";-import DatabaseSelect from "../components/DatabaseSelect.vue";-import { activeEnvironment } from "../utils";-import { OutputField, IssueContext } from "../plugins";-import { DatabaseId, EnvironmentId, Issue, UNKNOWN_ID } from "../types";+import DatabaseSelect from "../DatabaseSelect.vue";+import { activeEnvironment } from "../../utils";+import { OutputField, IssueContext } from "../../plugins";+import { DatabaseId, EnvironmentId, Issue, UNKNOWN_ID } from "../../types";// eslint-disable-next-line @typescript-eslint/no-empty-interfaceinterface LocalState {}-export default {+export default defineComponent({name: "IssueOutputPanel",components: { DatabaseSelect },props: {@@ -249,5 +205,5 @@ export default {trySaveCustomField,};},-};+});</script>diff --git a/frontend/src/components/IssueSidebar.vue b/frontend/src/components/Issue/IssueSidebar.vuesimilarity index 95%rename from frontend/src/components/IssueSidebar.vuerename to frontend/src/components/Issue/IssueSidebar.vueindex abed4d4020..a6780f0b12 100644--- a/frontend/src/components/IssueSidebar.vue+++ b/frontend/src/components/Issue/IssueSidebar.vue@@ -28,7 +28,7 @@:selectedId="create ? issue.assigneeId : issue.assignee?.id":allowed-role-list="['OWNER', 'DBA']"@select-principal-id="- (principalId) => {+ (principalId: number) => {$emit('update-assignee-id', principalId);}"@@ -48,7 +48,7 @@:required="true":value="fieldValue(field)":placeholder="field.placeholder"- @end-editing="(text) => trySaveCustomField(field, text)"+ @end-editing="(text: string) => trySaveCustomField(field, text)"/></template><template v-else-if="field.type == 'Boolean'">@@ -56,7 +56,7 @@:disabled="!allowEditCustomField(field)":value="fieldValue(field)"@toggle="- (on) => {+ (on: boolean) => {trySaveCustomField(field, on);}"@@ -75,7 +75,7 @@<div class="col-span-2"><StageSelect:pipeline="issue.pipeline"- :selected-i-d="selectedStage.id"+ :selected-id="selectedStage.id"@select-stage-id="(stageId) => $emit('select-stage-id', stageId)"/></div>@@ -226,14 +226,14 @@ import { computed, defineComponent, PropType, reactive, watch } from "vue";import { useStore } from "vuex";import isEqual from "lodash-es/isEqual";import { NDatePicker } from "naive-ui";-import PrincipalAvatar from "../components/PrincipalAvatar.vue";-import MemberSelect from "../components/MemberSelect.vue";-import StageSelect from "../components/StageSelect.vue";-import IssueStatusIcon from "../components/IssueStatusIcon.vue";-import IssueSubscriberPanel from "../components/IssueSubscriberPanel.vue";-import InstanceEngineIcon from "../components/InstanceEngineIcon.vue";+import PrincipalAvatar from "../PrincipalAvatar.vue";+import MemberSelect from "../MemberSelect.vue";+import StageSelect from "./StageSelect.vue";+import IssueStatusIcon from "./IssueStatusIcon.vue";+import IssueSubscriberPanel from "./IssueSubscriberPanel.vue";+import InstanceEngineIcon from "../InstanceEngineIcon.vue";-import { InputField } from "../plugins";+import { InputField } from "../../plugins";import {Database,Environment,@@ -248,8 +248,8 @@ import {Instance,ONBOARDING_ISSUE_ID,TaskDatabaseCreatePayload,-} from "../types";-import { allTaskList, databaseSlug, isDBAOrOwner } from "../utils";+} from "../../types";+import { allTaskList, databaseSlug, isDBAOrOwner } from "../../utils";import { useRouter } from "vue-router";import dayjs from "dayjs";import isSameOrAfter from "dayjs/plugin/isSameOrAfter";diff --git a/frontend/src/components/IssueStagePanel.vue b/frontend/src/components/Issue/IssueStagePanel.vuesimilarity index 81%rename from frontend/src/components/IssueStagePanel.vuerename to frontend/src/components/Issue/IssueStagePanel.vueindex ae9e60d36e..a478bdf083 100644--- a/frontend/src/components/IssueStagePanel.vue+++ b/frontend/src/components/Issue/IssueStagePanel.vue@@ -17,15 +17,15 @@</template><script lang="ts">-import { reactive, PropType, computed } from "vue";-import TaskRunTable from "../components/TaskRunTable.vue";-import { Stage, Task } from "../types";-import { activeTaskInStage } from "../utils";+import { reactive, PropType, computed, defineComponent } from "vue";+import TaskRunTable from "./TaskRunTable.vue";+import { Stage, Task } from "../../types";+import { activeTaskInStage } from "../../utils";// eslint-disable-next-line @typescript-eslint/no-empty-interfaceinterface LocalState {}-export default {+export default defineComponent({name: "IssueStagePanel",components: { TaskRunTable },props: {@@ -46,5 +46,5 @@ export default {activeTask,};},-};+});</script>diff --git a/frontend/src/components/IssueStatusIcon.vue b/frontend/src/components/Issue/IssueStatusIcon.vuesimilarity index 97%rename from frontend/src/components/IssueStatusIcon.vuerename to frontend/src/components/Issue/IssueStatusIcon.vueindex ab943f8a3b..79b6bc4792 100644--- a/frontend/src/components/IssueStatusIcon.vue+++ b/frontend/src/components/Issue/IssueStatusIcon.vue@@ -33,7 +33,7 @@<script lang="ts">import { PropType } from "vue";-import { TaskStatus, IssueStatus } from "../types";+import { TaskStatus, IssueStatus } from "../../types";type SizeType = "small" | "normal";diff --git a/frontend/src/components/IssueStatusTransitionButtonGroup.vue b/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vuesimilarity index 96%rename from frontend/src/components/IssueStatusTransitionButtonGroup.vuerename to frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vueindex 11b45fb102..c331353427 100644--- a/frontend/src/components/IssueStatusTransitionButtonGroup.vue+++ b/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue@@ -33,8 +33,8 @@class="text-control-light"aria-label="User menu"aria-haspopup="true"- @click.prevent="$refs.menu.toggle($event)"- @contextmenu.capture.prevent="$refs.menu.toggle($event)"+ @click.prevent="menu?.toggle($event, {})"+ @contextmenu.capture.prevent="menu?.toggle($event, {})"><heroicons-solid:dots-vertical class="w-6 h-6" /></button>@@ -116,16 +116,16 @@</template><script lang="ts">-import { PropType, computed, reactive, defineComponent } from "vue";+import { PropType, computed, reactive, defineComponent, ref } from "vue";import { Store, useStore } from "vuex";-import StatusTransitionForm from "../components/StatusTransitionForm.vue";+import StatusTransitionForm from "./StatusTransitionForm.vue";import {activeTask,allTaskList,applicableTaskTransition,isDBAOrOwner,TaskStatusTransition,-} from "../utils";+} from "../../utils";import {ASSIGNEE_APPLICABLE_ACTION_LIST,CREATOR_APPLICABLE_ACTION_LIST,@@ -139,10 +139,11 @@ import {SYSTEM_BOT_ID,Task,UNKNOWN_ID,-} from "../types";-import { IssueTemplate } from "../plugins";+} from "../../types";+import { IssueTemplate } from "../../plugins";import isEmpty from "lodash-es/isEmpty";import { useI18n } from "vue-i18n";+import { BBContextMenu } from "../../bbkit";interface UpdateStatusModalState {mode: "ISSUE" | "TASK";@@ -189,6 +190,7 @@ export default defineComponent({setup(props, { emit }) {const { t } = useI18n();const store = useStore();+ const menu = ref<InstanceType<typeof BBContextMenu>>();const updateStatusModalState = reactive<UpdateStatusModalState>({mode: "ISSUE",@@ -441,6 +443,7 @@ export default defineComponent({};return {+ menu,updateStatusModalState,applicableTaskStatusTransitionList,tryStartTaskStatusTransition,diff --git a/frontend/src/components/IssueSubscriberPanel.vue b/frontend/src/components/Issue/IssueSubscriberPanel.vuesimilarity index 96%rename from frontend/src/components/IssueSubscriberPanel.vuerename to frontend/src/components/Issue/IssueSubscriberPanel.vueindex 65572ff5bf..b0d09d93e9 100644--- a/frontend/src/components/IssueSubscriberPanel.vue+++ b/frontend/src/components/Issue/IssueSubscriberPanel.vue@@ -54,8 +54,8 @@ import {watchEffect,defineComponent,} from "vue";-import PrincipalAvatar from "../components/PrincipalAvatar.vue";-import { Issue, IssueSubscriber } from "../types";+import PrincipalAvatar from "../PrincipalAvatar.vue";+import { Issue, IssueSubscriber } from "../../types";import { useStore } from "vuex";// eslint-disable-next-line @typescript-eslint/no-empty-interfacediff --git a/frontend/src/components/IssueTable.vue b/frontend/src/components/Issue/IssueTable.vuesimilarity index 97%rename from frontend/src/components/IssueTable.vuerename to frontend/src/components/Issue/IssueTable.vueindex f0c9d047b5..3ed9155368 100644--- a/frontend/src/components/IssueTable.vue+++ b/frontend/src/components/Issue/IssueTable.vue@@ -95,7 +95,7 @@<BBStepBar:step-list="taskStepList(issue)"@click-step="- (step) => {+ (step: any) => {clickIssueStep(issue, step);}"@@ -129,8 +129,8 @@ import {BBTableSectionDataSource,BBStep,BBStepStatus,-} from "../bbkit/types";-import IssueStatusIcon from "../components/IssueStatusIcon.vue";+} from "../../bbkit/types";+import IssueStatusIcon from "./IssueStatusIcon.vue";import {issueSlug,activeEnvironment,@@ -138,8 +138,8 @@ import {activeTask,stageSlug,activeTaskInStage,-} from "../utils";-import { Issue, Task } from "../types";+} from "../../utils";+import { Issue, Task } from "../../types";type Mode = "ALL" | "PROJECT";diff --git a/frontend/src/components/IssueTaskStatementPanel.vue b/frontend/src/components/Issue/IssueTaskStatementPanel.vuesimilarity index 97%rename from frontend/src/components/IssueTaskStatementPanel.vuerename to frontend/src/components/Issue/IssueTaskStatementPanel.vueindex f058af557a..02a73141e6 100644--- a/frontend/src/components/IssueTaskStatementPanel.vue+++ b/frontend/src/components/Issue/IssueTaskStatementPanel.vue@@ -72,7 +72,7 @@"@input="(e) => {- sizeToFit(e.target);+ sizeToFit(e.target as HTMLTextAreaElement);// When creating the issue, we will emit the event on keystroke to update the in-memory state.if (create) {$emit('update-statement', state.editStatement);@@ -81,7 +81,7 @@"@focus="(e) => {- sizeToFit(e.target);+ sizeToFit(e.target as HTMLTextAreaElement);}"></textarea>@@ -112,7 +112,7 @@ import {watch,defineComponent,} from "vue";-import { sizeToFit } from "../utils";+import { sizeToFit } from "../../utils";interface LocalState {editing: boolean;diff --git a/frontend/src/views/PipelineSimpleFlow.vue b/frontend/src/components/Issue/PipelineSimpleFlow.vuesimilarity index 85%rename from frontend/src/views/PipelineSimpleFlow.vuerename to frontend/src/components/Issue/PipelineSimpleFlow.vueindex 499d408681..d2243ce16b 100644--- a/frontend/src/views/PipelineSimpleFlow.vue+++ b/frontend/src/components/Issue/PipelineSimpleFlow.vue@@ -1,11 +1,7 @@<template><nav aria-label="Pipeline"><ol- class="- border-t border-b border-block-border- divide-y divide-gray-300- lg:flex lg:divide-y-0- "+ class="border-t border-b border-block-border divide-y divide-gray-300 lg:flex lg:divide-y-0"><liv-for="(item, index) in itemList"@@ -17,16 +13,7 @@><span class="pl-4 py-2 flex items-center text-sm font-medium"><div- class="- relative- w-6- h-6- flex flex-shrink-0- items-center- justify-center- rounded-full- select-none- "+ class="relative w-6 h-6 flex flex-shrink-0 items-center justify-center rounded-full select-none":class="flowItemIconClass(item)"><template v-if="item.taskStatus === 'PENDING'">@@ -58,27 +45,14 @@</template><template v-else-if="item.taskStatus == 'FAILED'"><span- class="- h-2.5- w-2.5- rounded-full- text-center- pb-6- font-medium- text-base- "+ class="h-2.5 w-2.5 rounded-full text-center pb-6 font-medium text-base"aria-hidden="true">!</span></template></div><div- class="- hidden- cursor-pointer- hover:underline- lg:ml-4 lg:flex lg:flex-col- "+ class="hidden cursor-pointer hover:underline lg:ml-4 lg:flex lg:flex-col":class="flowItemTextClass(item)"@click.prevent="clickItem(item)">@@ -99,18 +73,7 @@<span class="tooltip">Missing SQL statement</span><spanv-if="!item.valid"- class="- ml-2- w-5- h-5- flex- justify-center- rounded-full- select-none- bg-error- text-white- hover:bg-error-hover- "+ class="ml-2 w-5 h-5 flex justify-center rounded-full select-none bg-error text-white hover:bg-error-hover"><span class="text-center font-normal" aria-hidden="true">!</span@@ -146,7 +109,7 @@</template><script lang="ts">-import { computed, PropType } from "vue";+import { computed, defineComponent, PropType } from "vue";import {Pipeline,TaskStatus,@@ -157,9 +120,9 @@ import {PipelineCreate,Task,TaskCreate,-} from "../types";-import { activeTask, activeTaskInStage } from "../utils";-import isEmpty from "lodash-es/isEmpty";+} from "../../types";+import { activeTask, activeTaskInStage } from "../../utils";+import { isEmpty } from "lodash-es";interface FlowItem {stageId: StageId;@@ -170,7 +133,7 @@ interface FlowItem {valid: boolean;}-export default {+export default defineComponent({name: "PipelineSimpleFlow",props: {create: {@@ -303,5 +266,5 @@ export default {clickItem,};},-};+});</script>diff --git a/frontend/src/components/StageSelect.vue b/frontend/src/components/Issue/StageSelect.vuesimilarity index 92%rename from frontend/src/components/StageSelect.vuerename to frontend/src/components/Issue/StageSelect.vueindex 092454a745..72ba534bfe 100644--- a/frontend/src/components/StageSelect.vue+++ b/frontend/src/components/Issue/StageSelect.vue@@ -21,8 +21,8 @@<script lang="ts">import { defineComponent, PropType, reactive, watch } from "vue";-import { UNKNOWN_ID, Pipeline, StageId } from "../types";-import { activeStage } from "../utils";+import { UNKNOWN_ID, Pipeline, StageId } from "../../types";+import { activeStage } from "../../utils";interface LocalState {selectedId: number;diff --git a/frontend/src/components/StatusTransitionForm.vue b/frontend/src/components/Issue/StatusTransitionForm.vuesimilarity index 96%rename from frontend/src/components/StatusTransitionForm.vuerename to frontend/src/components/Issue/StatusTransitionForm.vueindex 3b41f7427c..492876b1fa 100644--- a/frontend/src/components/StatusTransitionForm.vue+++ b/frontend/src/components/Issue/StatusTransitionForm.vue@@ -34,7 +34,7 @@:environmentId="environmentId":selectedId="state.outputValueList[index]"@select-database-id="- (databaseId) => {+ (databaseId: string) => {state.outputValueList[index] = databaseId;}"@@ -87,12 +87,12 @@:placeholder="$t('issue.status-transition.form.placeholder')"@input="(e) => {- sizeToFit(e.target);+ sizeToFit(e.target as HTMLTextAreaElement);}"@focus="(e) => {- sizeToFit(e.target);+ sizeToFit(e.target as HTMLTextAreaElement);}"></textarea>@@ -125,11 +125,11 @@<script lang="ts">import { computed, reactive, ref, PropType, defineComponent } from "vue";import cloneDeep from "lodash-es/cloneDeep";-import DatabaseSelect from "./DatabaseSelect.vue";+import DatabaseSelect from "../DatabaseSelect.vue";import TaskCheckBar from "./TaskCheckBar.vue";-import { Issue, IssueStatusTransition, Task, TaskCheckRun } from "../types";-import { OutputField } from "../plugins";-import { activeEnvironment, TaskStatusTransition } from "../utils";+import { Issue, IssueStatusTransition, Task, TaskCheckRun } from "../../types";+import { OutputField } from "../../plugins";+import { activeEnvironment, TaskStatusTransition } from "../../utils";type CheckSummary = {successCount: number;diff --git a/frontend/src/components/TaskCheckBadgeBar.vue b/frontend/src/components/Issue/TaskCheckBadgeBar.vuesimilarity index 90%rename from frontend/src/components/TaskCheckBadgeBar.vuerename to frontend/src/components/Issue/TaskCheckBadgeBar.vueindex 52296db4cc..f38b8a630d 100644--- a/frontend/src/components/TaskCheckBadgeBar.vue+++ b/frontend/src/components/Issue/TaskCheckBadgeBar.vue@@ -10,26 +10,7 @@@click.prevent="selectTaskCheckRun(checkRun)"><template v-if="checkRun.status == 'RUNNING'">- <svg- class="animate-spin -ml-1 mr-1.5 h-4 w-4 text-info"- xmlns="http://www.w3.org/2000/svg"- fill="none"- viewBox="0 0 24 24"- >- <circle- class="opacity-25"- cx="12"- cy="12"- r="10"- stroke="currentColor"- stroke-width="4"- ></circle>- <path- class="opacity-75"- fill="currentColor"- d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"- ></path>- </svg>+ <TaskSpinner class="-ml-1 mr-1.5 h-4 w-4 text-info" /></template><template v-else-if="checkRun.status == 'DONE'"><template v-if="taskCheckStatus(checkRun) == 'SUCCESS'">@@ -43,15 +24,15 @@/></template><template v-else-if="taskCheckStatus(checkRun) == 'ERROR'">- <span class="mr-1.5 font-medium text-error" aria-hidden="true"- >!</span- >+ <span class="mr-1.5 font-medium text-error" aria-hidden="true">+ !+ </span></template></template><template v-else-if="checkRun.status == 'FAILED'">- <span class="mr-1.5 font-medium text-error" aria-hidden="true"- >!</span- >+ <span class="mr-1.5 font-medium text-error" aria-hidden="true">+ !+ </span></template><template v-else-if="checkRun.status == 'CANCELED'"><heroicons-outline:ban@@ -67,7 +48,8 @@<script lang="ts">import { computed, defineComponent, PropType, reactive, watch } from "vue";import { useI18n } from "vue-i18n";-import { TaskCheckRun, TaskCheckStatus, TaskCheckType } from "../types";+import { TaskCheckRun, TaskCheckStatus, TaskCheckType } from "../../types";+import TaskSpinner from "./TaskSpinner.vue";interface LocalState {selectedTaskCheckRun?: TaskCheckRun;@@ -75,6 +57,7 @@ interface LocalState {export default defineComponent({name: "TaskCheckBadgeBar",+ components: { TaskSpinner },props: {taskCheckRunList: {required: true,diff --git a/frontend/src/components/TaskCheckBar.vue b/frontend/src/components/Issue/TaskCheckBar.vuesimilarity index 96%rename from frontend/src/components/TaskCheckBar.vuerename to frontend/src/components/Issue/TaskCheckBar.vueindex 78ffdbf9bc..e8c5abca19 100644--- a/frontend/src/components/TaskCheckBar.vue+++ b/frontend/src/components/Issue/TaskCheckBar.vue@@ -41,7 +41,7 @@:tab-item-list="tabItemList":selected-index="state.selectedTabIndex"@select-index="- (index) => {+ (index: number) => {state.selectedTaskCheckRun = tabTaskCheckRunList[index];state.selectedTabIndex = index;}@@ -64,12 +64,12 @@<script lang="ts">import { computed, defineComponent, PropType, reactive } from "vue";-import { Task, TaskCheckRun, TaskCheckStatus } from "../types";+import { Task, TaskCheckRun, TaskCheckStatus } from "../../types";import TaskCheckBadgeBar from "./TaskCheckBadgeBar.vue";import TaskCheckRunPanel from "./TaskCheckRunPanel.vue";-import { BBTabFilterItem } from "../bbkit/types";+import { BBTabFilterItem } from "../../bbkit/types";import { cloneDeep } from "lodash-es";-import { humanizeTs } from "../utils";+import { humanizeTs } from "../../utils";import { useI18n } from "vue-i18n";interface LocalState {diff --git a/frontend/src/components/TaskCheckRunPanel.vue b/frontend/src/components/Issue/TaskCheckRunPanel.vuesimilarity index 98%rename from frontend/src/components/TaskCheckRunPanel.vuerename to frontend/src/components/Issue/TaskCheckRunPanel.vueindex 24c91b1f57..a7f25d4d8a 100644--- a/frontend/src/components/TaskCheckRunPanel.vue+++ b/frontend/src/components/Issue/TaskCheckRunPanel.vue@@ -54,14 +54,14 @@<script lang="ts">import { computed, defineComponent, PropType } from "vue";import { useI18n } from "vue-i18n";-import { BBTableColumn } from "../bbkit/types";+import { BBTableColumn } from "../../bbkit/types";import {TaskCheckStatus,TaskCheckRun,TaskCheckResult,ErrorCode,ERROR_LIST,-} from "../types";+} from "../../types";const columnList: BBTableColumn[] = [{diff --git a/frontend/src/components/TaskRunTable.vue b/frontend/src/components/Issue/TaskRunTable.vuesimilarity index 97%rename from frontend/src/components/TaskRunTable.vuerename to frontend/src/components/Issue/TaskRunTable.vueindex 90357b41a5..87376da0f6 100644--- a/frontend/src/components/TaskRunTable.vue+++ b/frontend/src/components/Issue/TaskRunTable.vue@@ -71,10 +71,10 @@<script lang="ts">import { computed, defineComponent, PropType } from "vue";-import PrincipalAvatar from "./PrincipalAvatar.vue";-import { BBTableColumn } from "../bbkit/types";-import { MigrationErrorCode, Task, TaskRun, TaskRunStatus } from "../types";-import { databaseSlug, instanceSlug, migrationHistorySlug } from "../utils";+import PrincipalAvatar from "../PrincipalAvatar.vue";+import { BBTableColumn } from "../../bbkit/types";+import { MigrationErrorCode, Task, TaskRun, TaskRunStatus } from "../../types";+import { databaseSlug, instanceSlug, migrationHistorySlug } from "../../utils";import { useI18n } from "vue-i18n";type CommentLink = {diff --git a/frontend/src/components/Issue/TaskSpinner.vue b/frontend/src/components/Issue/TaskSpinner.vuenew file mode 100644index 0000000000..d07afd9071--- /dev/null+++ b/frontend/src/components/Issue/TaskSpinner.vue@@ -0,0 +1,30 @@+<template>+ <svg+ class="animate-spin"+ xmlns="http://www.w3.org/2000/svg"+ fill="none"+ viewBox="0 0 24 24"+ >+ <circle+ class="opacity-25"+ cx="12"+ cy="12"+ r="10"+ stroke="currentColor"+ stroke-width="4"+ />+ <path+ class="opacity-75"+ fill="currentColor"+ d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"+ />+ </svg>+</template>++<script lang="ts">+import { defineComponent } from "vue";++export default defineComponent({+ name: "Spinner",+});+</script>diff --git a/frontend/src/components/Issue/index.ts b/frontend/src/components/Issue/index.tsnew file mode 100644index 0000000000..616a7ae6db--- /dev/null+++ b/frontend/src/components/Issue/index.ts@@ -0,0 +1,27 @@+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 IssueTaskStatementPanel from "./IssueTaskStatementPanel.vue";+import IssueDescriptionPanel from "./IssueDescriptionPanel.vue";+import IssueActivityPanel from "./IssueActivityPanel.vue";+import PipelineSimpleFlow from "./PipelineSimpleFlow.vue";+import TaskCheckBar from "./TaskCheckBar.vue";+import IssueTable from "./IssueTable.vue";++export {+ IssueBanner,+ IssueHighlightPanel,+ IssueStagePanel,+ IssueStatusTransitionButtonGroup,+ IssueOutputPanel,+ IssueSidebar,+ IssueTaskStatementPanel,+ IssueDescriptionPanel,+ IssueActivityPanel,+ PipelineSimpleFlow,+ TaskCheckBar,+ IssueTable,+};diff --git a/frontend/src/components/IssueStatusSelect.vue b/frontend/src/components/IssueStatusSelect.vueindex 039d051f27..0b9c02b397 100644--- a/frontend/src/components/IssueStatusSelect.vue+++ b/frontend/src/components/IssueStatusSelect.vue@@ -19,7 +19,7 @@<script lang="ts">import { PropType } from "vue";-import IssueStatusIcon from "../components/IssueStatusIcon.vue";+import IssueStatusIcon from "./Issue/IssueStatusIcon.vue";import { IssueStatus, IssueStatusTransitionType } from "../types";export default {diff --git a/frontend/src/components/MigrationHistoryStatusIcon.vue b/frontend/src/components/MigrationHistoryStatusIcon.vueindex eaeef7644f..a006dd06e0 100644--- a/frontend/src/components/MigrationHistoryStatusIcon.vue+++ b/frontend/src/components/MigrationHistoryStatusIcon.vue@@ -24,11 +24,11 @@</template><script lang="ts">-import { PropType } from "vue";+import { defineComponent, PropType } from "vue";import { MigrationStatus } from "../types";-export default {- name: "IssueStatusIcon",+export default defineComponent({+ name: "MigrationHistoryStatusIcon",props: {status: {required: true,@@ -52,5 +52,5 @@ export default {iconClass,};},-};+});</script>diff --git a/frontend/src/components/ProjectOverviewPanel.vue b/frontend/src/components/ProjectOverviewPanel.vueindex c7f6d08d72..f4f9eaf458 100644--- a/frontend/src/components/ProjectOverviewPanel.vue+++ b/frontend/src/components/ProjectOverviewPanel.vue@@ -76,7 +76,7 @@ import { reactive, watchEffect, PropType } from "vue";import { useStore } from "vuex";import ActivityTable from "../components/ActivityTable.vue";import DatabaseTable from "../components/DatabaseTable.vue";-import IssueTable from "../components/IssueTable.vue";+import { IssueTable } from "../components/Issue";import {Activity,Database,diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vueindex eddfbe74a9..cb1f749148 100644--- a/frontend/src/views/Home.vue+++ b/frontend/src/views/Home.vue@@ -52,7 +52,7 @@ import { watchEffect, computed, onMounted, reactive, ref } from "vue";import { useStore } from "vuex";import { useRouter } from "vue-router";import EnvironmentTabFilter from "../components/EnvironmentTabFilter.vue";-import IssueTable from "../components/IssueTable.vue";+import { IssueTable } from "../components/Issue";import { activeEnvironment, activeTask } from "../utils";import { Environment, Issue, TaskStatus, UNKNOWN_ID } from "../types";diff --git a/frontend/src/views/IssueDashboard.vue b/frontend/src/views/IssueDashboard.vueindex 3b3e697a32..1fdbfb0326 100644--- a/frontend/src/views/IssueDashboard.vue+++ b/frontend/src/views/IssueDashboard.vue@@ -42,7 +42,7 @@import { useRouter } from "vue-router";import { useStore } from "vuex";import EnvironmentTabFilter from "../components/EnvironmentTabFilter.vue";-import IssueTable from "../components/IssueTable.vue";+import { IssueTable } from "../components/Issue";import MemberSelect from "../components/MemberSelect.vue";import { Environment, Issue, PrincipalId, ProjectId } from "../types";import { reactive, ref, computed, onMounted, watchEffect } from "vue";diff --git a/frontend/src/views/IssueDetail.vue b/frontend/src/views/IssueDetail.vueindex 3d37909fde..0166d6defe 100644--- a/frontend/src/views/IssueDetail.vue+++ b/frontend/src/views/IssueDetail.vue@@ -4,24 +4,8 @@class="flex-1 overflow-auto focus:outline-none"tabindex="0">- <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>+ <IssueBanner v-if="!state.create" :issue="issue" />+<!-- Highlight Panel --><div class="bg-white px-4 pb-4"><IssueHighlightPanel@@ -207,7 +191,7 @@</div></template>-<script lang="ts">+<script lang="ts" setup>import {computed,onMounted,@@ -216,7 +200,7 @@ import {watchEffect,reactive,ref,- defineComponent,+ defineProps,} from "vue";import { useStore } from "vuex";import { useRouter } from "vue-router";@@ -232,16 +216,19 @@ import {stageSlug,activeTask,} from "../utils";-import IssueHighlightPanel from "../components/IssueHighlightPanel.vue";-import IssueStagePanel from "../components/IssueStagePanel.vue";-import IssueOutputPanel from "../components/IssueOutputPanel.vue";-import IssueTaskStatementPanel from "../components/IssueTaskStatementPanel.vue";-import IssueDescriptionPanel from "../components/IssueDescriptionPanel.vue";-import IssueActivityPanel from "../components/IssueActivityPanel.vue";-import IssueSidebar from "../components/IssueSidebar.vue";-import IssueStatusTransitionButtonGroup from "../components/IssueStatusTransitionButtonGroup.vue";-import PipelineSimpleFlow from "./PipelineSimpleFlow.vue";-import TaskCheckBar from "../components/TaskCheckBar.vue";+import {+ IssueBanner,+ IssueHighlightPanel,+ IssueStagePanel,+ IssueStatusTransitionButtonGroup,+ IssueOutputPanel,+ IssueSidebar,+ IssueTaskStatementPanel,+ IssueDescriptionPanel,+ IssueActivityPanel,+ PipelineSimpleFlow,+ TaskCheckBar,+} from "../components/Issue";import {UNKNOWN_ID,Issue,@@ -292,949 +279,858 @@ interface LocalState {pollIssueTimer?: ReturnType<typeof setTimeout>;}-export default defineComponent({- name: "IssueDetail",- components: {- IssueHighlightPanel,- IssueStagePanel,- IssueOutputPanel,- IssueTaskStatementPanel,- IssueDescriptionPanel,- IssueActivityPanel,- IssueSidebar,- IssueStatusTransitionButtonGroup,- PipelineSimpleFlow,- TaskCheckBar,- },- props: {- issueSlug: {- required: true,- type: String,- },- },-- setup(props) {- const store = useStore();- const router = useRouter();-- const currentUser = computed(() => store.getters["auth/currentUser"]());-- let newIssueTemplate = ref<IssueTemplate>(defaulTemplate());-- const refreshTemplate = () => {- const issueType = router.currentRoute.value.query.template as IssueType;- if (issueType) {- const template = templateForType(issueType);- if (template) {- newIssueTemplate.value = template;- } else {- store.dispatch("notification/pushNotification", {- module: "bytebase",- style: "WARN",- title: `Unknown template '${issueType}'.`,- description: "Fallback to the default template",- });- }- }-- if (!newIssueTemplate.value) {- newIssueTemplate.value = defaulTemplate();- }- };-- // Vue doesn't natively react to query parameter change- // so we need to manually watch here.- watch(- () => router.currentRoute.value.query.template,- () => {- refreshTemplate();- }- );+const props = defineProps<{ issueSlug: string }>();- watchEffect(refreshTemplate);+const store = useStore();+const router = useRouter();- const buildNewIssue = (): IssueCreate => {- var newIssue: IssueCreate;+const currentUser = computed(() => store.getters["auth/currentUser"]());- // Create rollback issue- if (router.currentRoute.value.query.rollbackIssue) {- const rollbackIssue: Issue = store.getters["issue/issueById"](- parseInt(router.currentRoute.value.query.rollbackIssue as string)- );+let newIssueTemplate = ref<IssueTemplate>(defaulTemplate());- let validState = false;- let title = "";-- // We expect user to create rollback from the original issue, which should have already fetched- // issue remotely. Otherwise, this will return UNKNOWN_ID- if (rollbackIssue.id == UNKNOWN_ID) {- title =- "INVALID STATE, please create rollback from the original issue.";- } else {- if (rollbackIssue.type != "bb.issue.database.schema.update") {- title =- "INVALID STATE, only support to rollback update schema issue.";- } else if (- rollbackIssue.status != "DONE" &&- rollbackIssue.status != "CANCELED"- ) {- title =- "INVALID STATE, only support to rollback issue in closed state.";- } else {- for (const stage of rollbackIssue.pipeline.stageList) {- for (const task of stage.taskList) {- if (- task.status == "DONE" &&- task.type == "bb.task.database.schema.update" &&- !isEmpty(- (task.payload as TaskDatabaseSchemaUpdatePayload)- .rollbackStatement- )- ) {- validState = true;- break;- }- }- if (validState) {- break;- }- }+const refreshTemplate = () => {+ const issueType = router.currentRoute.value.query.template as IssueType;+ if (issueType) {+ const template = templateForType(issueType);+ if (template) {+ newIssueTemplate.value = template;+ } else {+ store.dispatch("notification/pushNotification", {+ module: "bytebase",+ style: "WARN",+ title: `Unknown template '${issueType}'.`,+ description: "Fallback to the default template",+ });+ }+ }++ if (!newIssueTemplate.value) {+ newIssueTemplate.value = defaulTemplate();+ }+};++// Vue doesn't natively react to query parameter change+// so we need to manually watch here.+watch(+ () => router.currentRoute.value.query.template,+ () => {+ refreshTemplate();+ }+);++watchEffect(refreshTemplate);++const buildNewIssue = (): IssueCreate => {+ var newIssue: IssueCreate;++ // Create rollback issue+ if (router.currentRoute.value.query.rollbackIssue) {+ const rollbackIssue: Issue = store.getters["issue/issueById"](+ parseInt(router.currentRoute.value.query.rollbackIssue as string)+ );- if (!validState) {- title =- "INVALID STATE, no applicable update schema task to rollback.";+ let validState = false;+ let title = "";++ // We expect user to create rollback from the original issue, which should have already fetched+ // issue remotely. Otherwise, this will return UNKNOWN_ID+ if (rollbackIssue.id == UNKNOWN_ID) {+ title = "INVALID STATE, please create rollback from the original issue.";+ } else {+ if (rollbackIssue.type != "bb.issue.database.schema.update") {+ title = "INVALID STATE, only support to rollback update schema issue.";+ } else if (+ rollbackIssue.status != "DONE" &&+ rollbackIssue.status != "CANCELED"+ ) {+ title =+ "INVALID STATE, only support to rollback issue in closed state.";+ } else {+ for (const stage of rollbackIssue.pipeline.stageList) {+ for (const task of stage.taskList) {+ if (+ task.status == "DONE" &&+ task.type == "bb.task.database.schema.update" &&+ !isEmpty(+ (task.payload as TaskDatabaseSchemaUpdatePayload)+ .rollbackStatement+ )+ ) {+ validState = true;+ break;}}- }-- if (validState) {- let environmentList: Environment[] = [];- const approvalPolicyList: Policy[] = [];- const databaseList: Database[] = [];- const statementList: string[] = [];- const rollbackStatementList: string[] = [];- for (- let i = rollbackIssue.pipeline.stageList.length - 1;- i >= 0;- i--- ) {- const stage = rollbackIssue.pipeline.stageList[i];- for (let j = stage.taskList.length - 1; j >= 0; j--) {- const task = stage.taskList[j];- if (- task.status == "DONE" &&- task.type == "bb.task.database.schema.update" &&- !isEmpty(- (task.payload as TaskDatabaseSchemaUpdatePayload)- .rollbackStatement- )- ) {- environmentList.push(stage.environment);- approvalPolicyList.push(- store.getters["policy/policyByEnvironmentIdAndType"](- stage.environment.id,- "bb.policy.pipeline-approval"- )- );- databaseList.push(task.database!);- statementList.push(- (task.payload as TaskDatabaseSchemaUpdatePayload)- .rollbackStatement- );- rollbackStatementList.push(- (task.payload as TaskDatabaseSchemaUpdatePayload).statement- );- }- }+ if (validState) {+ break;}+ }- if (environmentList.length == 0) {- newIssue = {- ...defaulTemplate().buildIssue({- environmentList: [],- approvalPolicyList: [],- databaseList: [],- currentUser: currentUser.value,- }),- name: "INVALID STATE, no applicable update schema task to rollback.",- projectId: UNKNOWN_ID,- };- } else {- newIssue = {- ...newIssueTemplate.value.buildIssue({- environmentList,- approvalPolicyList,- databaseList,- statementList,- rollbackStatementList,- currentUser: currentUser.value,- }),- projectId: rollbackIssue.project.id,- name: `[Rollback] issue/${rollbackIssue.id} - ${rollbackIssue.name}`,- description: rollbackIssue.description- ? `====Original issue description BEGIN====\n\n${rollbackIssue.description}\n\n====Original issue description END====\n\n`- : "",- assigneeId: rollbackIssue.assignee.id,- };- }- } else {- newIssue = {- ...defaulTemplate().buildIssue({- environmentList: [],- approvalPolicyList: [],- databaseList: [],- currentUser: currentUser.value,- }),- name: title,- projectId: UNKNOWN_ID,- };+ if (!validState) {+ title =+ "INVALID STATE, no applicable update schema task to rollback.";}- newIssue.rollbackIssueId = rollbackIssue.id;}- // Create issue from normal query parameter- else {- const databaseList: Database[] = [];- if (router.currentRoute.value.query.databaseList) {- for (const databaseId of (- router.currentRoute.value.query.databaseList as string- ).split(","))- databaseList.push(- store.getters["database/databaseById"](databaseId)- );- }-- const environmentList: Environment[] = [];- const approvalPolicyList: Policy[] = [];- if (router.currentRoute.value.query.environment) {- environmentList.push(- store.getters["environment/environmentById"](- router.currentRoute.value.query.environment+ }++ if (validState) {+ let environmentList: Environment[] = [];+ const approvalPolicyList: Policy[] = [];+ const databaseList: Database[] = [];+ const statementList: string[] = [];+ const rollbackStatementList: string[] = [];+ for (let i = rollbackIssue.pipeline.stageList.length - 1; i >= 0; i--) {+ const stage = rollbackIssue.pipeline.stageList[i];+ for (let j = stage.taskList.length - 1; j >= 0; j--) {+ const task = stage.taskList[j];+ if (+ task.status == "DONE" &&+ task.type == "bb.task.database.schema.update" &&+ !isEmpty(+ (task.payload as TaskDatabaseSchemaUpdatePayload)+ .rollbackStatement)- );- } else if (databaseList.length > 0) {- for (const database of databaseList) {- environmentList.push(database.instance.environment);+ ) {+ environmentList.push(stage.environment);+ approvalPolicyList.push(+ store.getters["policy/policyByEnvironmentIdAndType"](+ stage.environment.id,+ "bb.policy.pipeline-approval"+ )+ );+ databaseList.push(task.database!);+ statementList.push(+ (task.payload as TaskDatabaseSchemaUpdatePayload)+ .rollbackStatement+ );+ rollbackStatementList.push(+ (task.payload as TaskDatabaseSchemaUpdatePayload).statement+ );}- } else {- environmentList.push(- ...store.getters["environment/environmentList"]()- );- }-- for (const environment of environmentList) {- approvalPolicyList.push(- store.getters["policy/policyByEnvironmentIdAndType"](- environment.id,- "bb.policy.pipeline-approval"- )- );}+ }+ if (environmentList.length == 0) {+ newIssue = {+ ...defaulTemplate().buildIssue({+ environmentList: [],+ approvalPolicyList: [],+ databaseList: [],+ currentUser: currentUser.value,+ }),+ name: "INVALID STATE, no applicable update schema task to rollback.",+ projectId: UNKNOWN_ID,+ };+ } else {newIssue = {...newIssueTemplate.value.buildIssue({environmentList,approvalPolicyList,databaseList,+ statementList,+ rollbackStatementList,currentUser: currentUser.value,}),- projectId: router.currentRoute.value.query.project- ? parseInt(router.currentRoute.value.query.project as string)- : UNKNOWN_ID,+ projectId: rollbackIssue.project.id,+ name: `[Rollback] issue/${rollbackIssue.id} - ${rollbackIssue.name}`,+ description: rollbackIssue.description+ ? `====Original issue description BEGIN====\n\n${rollbackIssue.description}\n\n====Original issue description END====\n\n`+ : "",+ assigneeId: rollbackIssue.assignee.id,};-- // For demo mode, we assign the issue to the current user, so it can also experience the assignee user flow.- if (store.getters["actuator/isDemo"]()) {- newIssue.assigneeId = currentUser.value.id;- }-- if (router.currentRoute.value.query.name) {- newIssue.name = router.currentRoute.value.query.name as string;- }- if (router.currentRoute.value.query.description) {- newIssue.description = router.currentRoute.value.query- .description as string;- }- if (router.currentRoute.value.query.assignee) {- newIssue.assigneeId = parseInt(- router.currentRoute.value.query.assignee as string- );- }}- for (const field of newIssueTemplate.value.inputFieldList) {- const value = router.currentRoute.value.query[field.slug] as string;- if (value) {- if (field.type == "Boolean") {- newIssue.payload[field.id] =- value != "0" && value.toLowerCase() != "false";- } else {- newIssue.payload[field.id] = value;- }- }+ } else {+ newIssue = {+ ...defaulTemplate().buildIssue({+ environmentList: [],+ approvalPolicyList: [],+ databaseList: [],+ currentUser: currentUser.value,+ }),+ name: title,+ projectId: UNKNOWN_ID,+ };+ }+ newIssue.rollbackIssueId = rollbackIssue.id;+ }+ // Create issue from normal query parameter+ else {+ const databaseList: Database[] = [];+ if (router.currentRoute.value.query.databaseList) {+ for (const databaseId of (+ router.currentRoute.value.query.databaseList as string+ ).split(","))+ databaseList.push(store.getters["database/databaseById"](databaseId));+ }++ const environmentList: Environment[] = [];+ const approvalPolicyList: Policy[] = [];+ if (router.currentRoute.value.query.environment) {+ environmentList.push(+ store.getters["environment/environmentById"](+ router.currentRoute.value.query.environment+ )+ );+ } else if (databaseList.length > 0) {+ for (const database of databaseList) {+ environmentList.push(database.instance.environment);}-- return newIssue;+ } else {+ environmentList.push(...store.getters["environment/environmentList"]());+ }++ for (const environment of environmentList) {+ approvalPolicyList.push(+ store.getters["policy/policyByEnvironmentIdAndType"](+ environment.id,+ "bb.policy.pipeline-approval"+ )+ );+ }++ newIssue = {+ ...newIssueTemplate.value.buildIssue({+ environmentList,+ approvalPolicyList,+ databaseList,+ currentUser: currentUser.value,+ }),+ projectId: router.currentRoute.value.query.project+ ? parseInt(router.currentRoute.value.query.project as string)+ : UNKNOWN_ID,};- const state = reactive<LocalState>({- create: props.issueSlug.toLowerCase() == "new",- newIssue:- props.issueSlug.toLowerCase() == "new" ? buildNewIssue() : undefined,- });-- // pollIssue invalidates the current timer and schedule a new timer in <<interval>> microseconds- const pollIssue = (interval: number) => {- if (state.pollIssueTimer) {- clearInterval(state.pollIssueTimer);+ // For demo mode, we assign the issue to the current user, so it can also experience the assignee user flow.+ if (store.getters["actuator/isDemo"]()) {+ newIssue.assigneeId = currentUser.value.id;+ }++ if (router.currentRoute.value.query.name) {+ newIssue.name = router.currentRoute.value.query.name as string;+ }+ if (router.currentRoute.value.query.description) {+ newIssue.description = router.currentRoute.value.query+ .description as string;+ }+ if (router.currentRoute.value.query.assignee) {+ newIssue.assigneeId = parseInt(+ router.currentRoute.value.query.assignee as string+ );+ }+ }+ for (const field of newIssueTemplate.value.inputFieldList) {+ const value = router.currentRoute.value.query[field.slug] as string;+ if (value) {+ if (field.type == "Boolean") {+ newIssue.payload[field.id] =+ value != "0" && value.toLowerCase() != "false";+ } else {+ newIssue.payload[field.id] = value;}+ }+ }- state.pollIssueTimer = setTimeout(() => {- store.dispatch("issue/fetchIssueById", idFromSlug(props.issueSlug));- pollIssue(Math.min(interval * 2, NORMAL_POLL_INTERVAL));- }, Math.max(1000, Math.min(interval, NORMAL_POLL_INTERVAL) + (Math.random() * 2 - 1) * POLL_JITTER));- };+ return newIssue;+};- const pollOnCreateStateChange = () => {- let interval = NORMAL_POLL_INTERVAL;- // We will poll faster if meets either of the condition- // 1. Created the database create issue, expect creation result quickly.- // 2. Update the database schema, will do connection and syntax check.- if (- (issue.value.type == "bb.issue.database.create" ||- issue.value.type == "bb.issue.database.schema.update") &&- Date.now() - (issue.value as Issue).updatedTs * 1000 < 5000- ) {- interval = POST_CHANGE_POLL_INTERVAL;- }- pollIssue(interval);- };+const state = reactive<LocalState>({+ create: props.issueSlug.toLowerCase() == "new",+ newIssue:+ props.issueSlug.toLowerCase() == "new" ? buildNewIssue() : 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();- if (!state.create) {- pollOnCreateStateChange();- }- });+// pollIssue invalidates the current timer and schedule a new timer in <<interval>> microseconds+const pollIssue = (interval: number) => {+ if (state.pollIssueTimer) {+ clearInterval(state.pollIssueTimer);+ }++ state.pollIssueTimer = setTimeout(() => {+ store.dispatch("issue/fetchIssueById", idFromSlug(props.issueSlug));+ pollIssue(Math.min(interval * 2, NORMAL_POLL_INTERVAL));+ }, Math.max(1000, Math.min(interval, NORMAL_POLL_INTERVAL) + (Math.random() * 2 - 1) * POLL_JITTER));+};++const pollOnCreateStateChange = () => {+ let interval = NORMAL_POLL_INTERVAL;+ // We will poll faster if meets either of the condition+ // 1. Created the database create issue, expect creation result quickly.+ // 2. Update the database schema, will do connection and syntax check.+ if (+ (issue.value.type == "bb.issue.database.create" ||+ issue.value.type == "bb.issue.database.schema.update") &&+ Date.now() - (issue.value as Issue).updatedTs * 1000 < 5000+ ) {+ interval = POST_CHANGE_POLL_INTERVAL;+ }+ pollIssue(interval);+};++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();+ if (!state.create) {+ pollOnCreateStateChange();+ }+});- onUnmounted(() => {- if (state.pollIssueTimer) {- clearInterval(state.pollIssueTimer);- }- });+onUnmounted(() => {+ if (state.pollIssueTimer) {+ clearInterval(state.pollIssueTimer);+ }+});- watch(- () => props.issueSlug,- (cur) => {- const oldCreate = state.create;- state.create = cur.toLowerCase() == "new";- if (!state.create && oldCreate) {- pollOnCreateStateChange();- } else if (state.create && !oldCreate) {- clearInterval(state.pollIssueTimer);- state.newIssue = buildNewIssue();- }- }- );+watch(+ () => props.issueSlug,+ (cur) => {+ const oldCreate = state.create;+ state.create = cur.toLowerCase() == "new";+ if (!state.create && oldCreate) {+ pollOnCreateStateChange();+ } else if (state.create && !oldCreate) {+ clearInterval(state.pollIssueTimer!);+ state.newIssue = buildNewIssue();+ }+ }+);++const issue = computed((): Issue | IssueCreate => {+ return state.create+ ? state.newIssue+ : store.getters["issue/issueById"](idFromSlug(props.issueSlug));+});- const issue = computed((): Issue | IssueCreate => {- return state.create- ? state.newIssue- : store.getters["issue/issueById"](idFromSlug(props.issueSlug));- });+const issueTemplate = computed(+ () => templateForType(issue.value.type) || defaulTemplate()+);- const issueTemplate = computed(- () => templateForType(issue.value.type) || defaulTemplate()+const project = computed((): Project => {+ if (state.create) {+ return store.getters["project/projectById"](+ (issue.value as IssueCreate).projectId);+ }+ return (issue.value as Issue).project;+});- const project = computed((): Project => {- if (state.create) {- return store.getters["project/projectById"](- (issue.value as IssueCreate).projectId- );- }- return (issue.value as Issue).project;- });-- const updateName = (- newName: string,- postUpdated: (updatedIssue: Issue) => void- ) => {- if (state.create) {- state.newIssue!.name = newName;- } else {- patchIssue(- {- name: newName,- },- postUpdated- );- }- };-- const updateStatement = (- newStatement: string,- postUpdated?: (updatedTask: Task) => void- ) => {- if (state.create) {- const stage = selectedStage.value as StageCreate;- stage.taskList[0].statement = newStatement;- } else {- patchTask(- (selectedTask.value as Task).id,- {- statement: newStatement,- },- postUpdated- );- }- };-- const applyStatementToOtherStages = (newStatement: string) => {- for (const stage of (issue.value 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.statement = newStatement;- }- }- }- };-- const updateRollbackStatement = (newStatement: string) => {- const stage = selectedStage.value as StageCreate;- stage.taskList[0].rollbackStatement = newStatement;- };-- const applyRollbackStatementToOtherStages = (newStatement: string) => {- for (const stage of (issue.value as IssueCreate).pipeline.stageList) {- for (const task of stage.taskList) {- if (task.type == "bb.task.database.schema.update") {- task.rollbackStatement = newStatement;- }- }- }- };-- const updateDescription = (- newDescription: string,- postUpdated: (updatedIssue: Issue) => void- ) => {- if (state.create) {- state.newIssue!.description = newDescription;- } else {- patchIssue(- {- description: newDescription,- },- postUpdated- );- }- };-- const updateAssigneeId = (newAssigneeId: PrincipalId) => {- if (state.create) {- state.newIssue!.assigneeId = newAssigneeId;- } else {- patchIssue({- assigneeId: newAssigneeId,- });- }- };+const updateName = (+ newName: string,+ postUpdated: (updatedIssue: Issue) => void+) => {+ if (state.create) {+ state.newIssue!.name = newName;+ } else {+ patchIssue(+ {+ name: newName,+ },+ postUpdated+ );+ }+};++const updateStatement = (+ newStatement: string,+ postUpdated?: (updatedTask: Task) => void+) => {+ if (state.create) {+ const stage = selectedStage.value as StageCreate;+ stage.taskList[0].statement = newStatement;+ } else {+ patchTask(+ (selectedTask.value as Task).id,+ {+ statement: newStatement,+ },+ postUpdated+ );+ }+};- const updateEarliestAllowedTime = (newEarliestAllowedTsMs: number) => {- if (state.create) {- selectedTask.value.earliestAllowedTs = newEarliestAllowedTsMs;- } else {- const taskPatch: TaskPatch = {- earliestAllowedTs: newEarliestAllowedTsMs,- };- patchTask((selectedTask.value as Task).id, taskPatch);+const applyStatementToOtherStages = (newStatement: string) => {+ for (const stage of (issue.value 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.statement = newStatement;}- };-- const addSubscriberId = (subscriberId: PrincipalId) => {- store.dispatch("issueSubscriber/createSubscriber", {- issueId: (issue.value as Issue).id,- subscriberId,- });- };-- const removeSubscriberId = (subscriberId: PrincipalId) => {- store.dispatch("issueSubscriber/deleteSubscriber", {- issueId: (issue.value as Issue).id,- subscriberId,- });- };-- const updateCustomField = (field: InputField | OutputField, value: any) => {- if (!isEqual(issue.value.payload[field.id], value)) {- if (state.create) {- state.newIssue!.payload[field.id] = value;- } else {- const newPayload = cloneDeep(issue.value.payload);- newPayload[field.id] = value;- patchIssue({- payload: newPayload,- });- }+ }+ }+};++const updateRollbackStatement = (newStatement: string) => {+ const stage = selectedStage.value as StageCreate;+ stage.taskList[0].rollbackStatement = newStatement;+};++const applyRollbackStatementToOtherStages = (newStatement: string) => {+ for (const stage of (issue.value as IssueCreate).pipeline.stageList) {+ for (const task of stage.taskList) {+ if (task.type == "bb.task.database.schema.update") {+ task.rollbackStatement = newStatement;}+ }+ }+};++const updateDescription = (+ newDescription: string,+ postUpdated: (updatedIssue: Issue) => void+) => {+ if (state.create) {+ state.newIssue!.description = newDescription;+ } else {+ patchIssue(+ {+ description: newDescription,+ },+ postUpdated+ );+ }+};++const updateAssigneeId = (newAssigneeId: PrincipalId) => {+ if (state.create) {+ state.newIssue!.assigneeId = newAssigneeId;+ } else {+ patchIssue({+ assigneeId: newAssigneeId,+ });+ }+};++const updateEarliestAllowedTime = (newEarliestAllowedTsMs: number) => {+ if (state.create) {+ selectedTask.value.earliestAllowedTs = newEarliestAllowedTsMs;+ } else {+ const taskPatch: TaskPatch = {+ earliestAllowedTs: newEarliestAllowedTsMs,};-- const doCreate = () => {- store- .dispatch("issue/createIssue", state.newIssue)- .then((createdIssue) => {- // Use replace to omit the new issue url in the navigation history.- router.replace(- `/issue/${issueSlug(createdIssue.name, createdIssue.id)}`- );- });- };-- const doRollback = () => {- router.push({- name: "workspace.issue.detail",- params: {- issueSlug: "new",- },- query: {- template: "bb.issue.database.schema.update",- rollbackIssue: (issue.value as Issue).id,- },+ patchTask((selectedTask.value as Task).id, taskPatch);+ }+};++const addSubscriberId = (subscriberId: PrincipalId) => {+ store.dispatch("issueSubscriber/createSubscriber", {+ issueId: (issue.value as Issue).id,+ subscriberId,+ });+};++const removeSubscriberId = (subscriberId: PrincipalId) => {+ store.dispatch("issueSubscriber/deleteSubscriber", {+ issueId: (issue.value as Issue).id,+ subscriberId,+ });+};++const updateCustomField = (field: InputField | OutputField, value: any) => {+ if (!isEqual(issue.value.payload[field.id], value)) {+ if (state.create) {+ state.newIssue!.payload[field.id] = value;+ } else {+ const newPayload = cloneDeep(issue.value.payload);+ newPayload[field.id] = value;+ patchIssue({+ payload: newPayload,});- };-- const changeIssueStatus = (newStatus: IssueStatus, comment: string) => {- const issueStatusPatch: IssueStatusPatch = {- status: newStatus,- comment: comment,- };-- store- .dispatch("issue/updateIssueStatus", {- issueId: (issue.value 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);-- const taskStatusPatch: TaskStatusPatch = {- status: newStatus,- comment: comment,- };-- store- .dispatch("task/updateStatus", {- issueId: (issue.value as Issue).id,- pipelineId: (issue.value as Issue).pipeline.id,- taskId: task.id,- taskStatusPatch,- })- .then(() => {- pollIssue(POST_CHANGE_POLL_INTERVAL);- });- };-- const runTaskChecks = (task: Task) => {- store- .dispatch("task/runChecks", {- issueId: (issue.value as Issue).id,- pipelineId: (issue.value as Issue).pipeline.id,- taskId: task.id,- })- .then(() => {- pollIssue(POST_CHANGE_POLL_INTERVAL);- });- };-- const patchIssue = (- issuePatch: IssuePatch,- postUpdated?: (updatedIssue: Issue) => void- ) => {- store- .dispatch("issue/patchIssue", {- issueId: (issue.value 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);- if (postUpdated) {- postUpdated(updatedIssue);- }- });- };-- const patchTask = (- taskId: TaskId,- taskPatch: TaskPatch,- postUpdated?: (updatedTask: Task) => void- ) => {- store- .dispatch("task/patchTask", {- issueId: (issue.value as Issue).id,- pipelineId: (issue.value 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);- if (postUpdated) {- postUpdated(updatedTask);- }- });- };-- const currentPipelineType = computed((): PipelineType => {- return pipelineType(issue.value.pipeline);+ }+ }+};++const doCreate = () => {+ store.dispatch("issue/createIssue", state.newIssue).then((createdIssue) => {+ // Use replace to omit the new issue url in the navigation history.+ router.replace(`/issue/${issueSlug(createdIssue.name, createdIssue.id)}`);+ });+};++const doRollback = () => {+ router.push({+ name: "workspace.issue.detail",+ params: {+ issueSlug: "new",+ },+ query: {+ template: "bb.issue.database.schema.update",+ rollbackIssue: (issue.value as Issue).id,+ },+ });+};++const changeIssueStatus = (newStatus: IssueStatus, comment: string) => {+ const issueStatusPatch: IssueStatusPatch = {+ status: newStatus,+ comment: comment,+ };++ store+ .dispatch("issue/updateIssueStatus", {+ issueId: (issue.value as Issue).id,+ issueStatusPatch,+ })+ .then(() => {+ pollIssue(POST_CHANGE_POLL_INTERVAL);});-- 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 < issue.value.pipeline.stageList.length) {- return issue.value.pipeline.stageList[index];- }- const stageId = idFromSlug(stageSlug);- const stageList = (issue.value as Issue).pipeline.stageList;- for (const stage of stageList) {- if (stage.id == stageId) {- return stage;- }- }- } else if (!state.create && taskSlug) {- const taskId = idFromSlug(taskSlug);- const stageList = (issue.value as Issue).pipeline.stageList;- for (const stage of stageList) {- for (const task of stage.taskList) {- if (task.id == taskId) {- return stage;- }- }- }+};++const changeTaskStatus = (+ task: Task,+ newStatus: TaskStatus,+ comment: string+) => {+ // Switch to the stage view containing this task+ selectStageId(task.stage.id);++ const taskStatusPatch: TaskStatusPatch = {+ status: newStatus,+ comment: comment,+ };++ store+ .dispatch("task/updateStatus", {+ issueId: (issue.value as Issue).id,+ pipelineId: (issue.value as Issue).pipeline.id,+ taskId: task.id,+ taskStatusPatch,+ })+ .then(() => {+ pollIssue(POST_CHANGE_POLL_INTERVAL);+ });+};++const runTaskChecks = (task: Task) => {+ store+ .dispatch("task/runChecks", {+ issueId: (issue.value as Issue).id,+ pipelineId: (issue.value as Issue).pipeline.id,+ taskId: task.id,+ })+ .then(() => {+ pollIssue(POST_CHANGE_POLL_INTERVAL);+ });+};++const patchIssue = (+ issuePatch: IssuePatch,+ postUpdated?: (updatedIssue: Issue) => void+) => {+ store+ .dispatch("issue/patchIssue", {+ issueId: (issue.value 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);+ if (postUpdated) {+ postUpdated(updatedIssue);}- if (state.create) {- return issue.value.pipeline.stageList[0];+ });+};++const patchTask = (+ taskId: TaskId,+ taskPatch: TaskPatch,+ postUpdated?: (updatedTask: Task) => void+) => {+ store+ .dispatch("task/patchTask", {+ issueId: (issue.value as Issue).id,+ pipelineId: (issue.value 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);+ if (postUpdated) {+ postUpdated(updatedTask);}- return activeStage((issue.value as Issue).pipeline);});+};- const selectStageId = (stageId: StageId) => {- const stageList = issue.value.pipeline.stageList;- const index = stageList.findIndex((item, index) => {- if (state.create) {- return index == stageId;+const currentPipelineType = computed((): PipelineType => {+ return pipelineType(issue.value.pipeline);+});++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 < issue.value.pipeline.stageList.length) {+ return issue.value.pipeline.stageList[index];+ }+ const stageId = idFromSlug(stageSlug);+ const stageList = (issue.value as Issue).pipeline.stageList;+ for (const stage of stageList) {+ if (stage.id == stageId) {+ return stage;+ }+ }+ } else if (!state.create && taskSlug) {+ const taskId = idFromSlug(taskSlug);+ const stageList = (issue.value as Issue).pipeline.stageList;+ for (const stage of stageList) {+ for (const task of stage.taskList) {+ if (task.id == taskId) {+ return stage;}- return (item as Stage).id == stageId;- });- router.replace({- name: "workspace.issue.detail",- query: {- ...router.currentRoute.value.query,- task: undefined,- stage: stageSlug(stageList[index].name, index),- },- });- };+ }+ }+ }+ if (state.create) {+ return issue.value.pipeline.stageList[0];+ }+ return activeStage((issue.value as Issue).pipeline);+});- const selectedTask = computed((): Task | TaskCreate => {- return selectedStage.value.taskList[0];- });+const selectStageId = (stageId: StageId) => {+ const stageList = issue.value.pipeline.stageList;+ const index = stageList.findIndex((item, index) => {+ if (state.create) {+ return index == stageId;+ }+ return (item as Stage).id == stageId;+ });+ router.replace({+ name: "workspace.issue.detail",+ query: {+ ...router.currentRoute.value.query,+ task: undefined,+ stage: stageSlug(stageList[index].name, index),+ },+ });+};- 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.restore":- return "";- }- };+const selectedTask = computed((): Task | TaskCreate => {+ return selectedStage.value.taskList[0];+});- const rollbackStatement = (stage: Stage): string => {- const task = stage.taskList[0];+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.payload as TaskDatabaseSchemaUpdatePayload).rollbackStatement ||+ ((task as Task).payload as TaskDatabaseCreatePayload).statement || ""+ );+ case "bb.task.database.schema.update":+ return (+ ((task as Task).payload as TaskDatabaseSchemaUpdatePayload).statement ||"");- };-- const selectedStatement = computed((): string => {- const task = (selectedStage.value as StageCreate).taskList[0];- return task.statement;- });+ case "bb.task.database.restore":+ return "";+ }+};++const rollbackStatement = (stage: Stage): string => {+ const task = stage.taskList[0];+ return (+ (task.payload as TaskDatabaseSchemaUpdatePayload).rollbackStatement || ""+ );+};++const selectedStatement = computed((): string => {+ const task = (selectedStage.value as StageCreate).taskList[0];+ return task.statement;+});- const selectedRollbackStatement = computed((): string => {- const task = (selectedStage.value as StageCreate).taskList[0];- return task.rollbackStatement;- });+const selectedRollbackStatement = computed((): string => {+ const task = (selectedStage.value as StageCreate).taskList[0];+ return task.rollbackStatement;+});- const selectedMigrateType = computed((): MigrationType => {- if (- !state.create &&- selectedTask.value.type == "bb.task.database.schema.update"- ) {- return (- (selectedTask.value as Task)- .payload as TaskDatabaseSchemaUpdatePayload- ).migrationType;- }- return "MIGRATE";- });+const selectedMigrateType = computed((): MigrationType => {+ if (+ !state.create &&+ selectedTask.value.type == "bb.task.database.schema.update"+ ) {+ return (+ (selectedTask.value as Task).payload as TaskDatabaseSchemaUpdatePayload+ ).migrationType;+ }+ return "MIGRATE";+});- 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 (- state.create ||- ((issue.value as Issue).status == "OPEN" &&- (issue.value as Issue).assignee?.id == currentUser.value.id)- );- });+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 (+ state.create ||+ ((issue.value as Issue).status == "OPEN" &&+ (issue.value as Issue).assignee?.id == currentUser.value.id)+ );+});- const allowEditOutput = computed(() => {- return (- state.create ||- ((issue.value as Issue).status == "OPEN" &&- (issue.value as Issue).assignee?.id == currentUser.value.id)- );- });+const allowEditOutput = computed(() => {+ return (+ state.create ||+ ((issue.value as Issue).status == "OPEN" &&+ (issue.value as Issue).assignee?.id == currentUser.value.id)+ );+});- const allowEditNameAndDescription = computed(() => {- return (- state.create ||- ((issue.value as Issue).status == "OPEN" &&- ((issue.value as Issue).assignee?.id == currentUser.value.id ||- (issue.value as Issue).creator.id == currentUser.value.id))- );- });+const allowEditNameAndDescription = computed(() => {+ return (+ state.create ||+ ((issue.value as Issue).status == "OPEN" &&+ ((issue.value as Issue).assignee?.id == currentUser.value.id ||+ (issue.value as Issue).creator.id == currentUser.value.id))+ );+});- const allowEditStatement = computed(() => {- return (- state.create ||- ((issue.value as Issue).status == "OPEN" &&- (issue.value as Issue).creator.id == currentUser.value.id &&- // Only allow if it's UI workflow- (issue.value as Issue).project.workflowType == "UI" &&- (selectedTask.value.status == "PENDING" ||- selectedTask.value.status == "PENDING_APPROVAL" ||- selectedTask.value.status == "FAILED"))- );- });+const allowEditStatement = computed(() => {+ return (+ state.create ||+ ((issue.value as Issue).status == "OPEN" &&+ (issue.value as Issue).creator.id == currentUser.value.id &&+ // Only allow if it's UI workflow+ (issue.value as Issue).project.workflowType == "UI" &&+ (selectedTask.value.status == "PENDING" ||+ selectedTask.value.status == "PENDING_APPROVAL" ||+ selectedTask.value.status == "FAILED"))+ );+});- // For now, we only support rollback for schema update issue when all below conditions met:- // 1. Issue is in DONE or CANCELED state- // 2. There is at least one completed schema update task and the task contains the rollback statement.- const allowRollback = computed(() => {- if (!state.create) {- if (issue.value.type == "bb.issue.database.schema.update") {- if (- (issue.value as Issue).status == "DONE" ||- (issue.value as Issue).status == "CANCELED"- ) {- for (const stage of (issue.value as Issue).pipeline.stageList) {- for (const task of stage.taskList) {- if (- task.status == "DONE" &&- task.type == "bb.task.database.schema.update" &&- !isEmpty(- (task.payload as TaskDatabaseSchemaUpdatePayload)- .rollbackStatement- )- ) {- return true;- }- }+// For now, we only support rollback for schema update issue when all below conditions met:+// 1. Issue is in DONE or CANCELED state+// 2. There is at least one completed schema update task and the task contains the rollback statement.+const allowRollback = computed(() => {+ if (!state.create) {+ if (issue.value.type == "bb.issue.database.schema.update") {+ if (+ (issue.value as Issue).status == "DONE" ||+ (issue.value as Issue).status == "CANCELED"+ ) {+ for (const stage of (issue.value as Issue).pipeline.stageList) {+ for (const task of stage.taskList) {+ if (+ task.status == "DONE" &&+ task.type == "bb.task.database.schema.update" &&+ !isEmpty(+ (task.payload as TaskDatabaseSchemaUpdatePayload)+ .rollbackStatement+ )+ ) {+ return true;}}}}- return false;- });-- const showCancelBanner = computed(() => {- return !state.create && (issue.value as Issue).status == "CANCELED";- });-- const showSuccessBanner = computed(() => {- return !state.create && (issue.value as Issue).status == "DONE";- });-- const showPendingApproval = computed(() => {- if (state.create) {- return false;- }+ }+ }+ return false;+});- const task = activeTask((issue.value as Issue).pipeline);- return task.status == "PENDING_APPROVAL";- });+const showCancelBanner = computed(() => {+ return !state.create && (issue.value as Issue).status == "CANCELED";+});- const showPipelineFlowBar = computed(() => {- return currentPipelineType.value != "NO_PIPELINE";- });+const showSuccessBanner = computed(() => {+ return !state.create && (issue.value as Issue).status == "DONE";+});- const showIssueOutputPanel = computed(() => {- return !state.create && issueTemplate.value.outputFieldList.length > 0;- });+const showPendingApproval = computed(() => {+ if (state.create) {+ return false;+ }- 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"- );- });+ const task = activeTask((issue.value as Issue).pipeline);+ return task.status == "PENDING_APPROVAL";+});- const showIssueTaskRollbackStatementPanel = computed(() => {- if (project.value.workflowType == "UI") {- return issue.value.type == "bb.issue.database.schema.update";- }- return false;- });+const showPipelineFlowBar = computed(() => {+ return currentPipelineType.value != "NO_PIPELINE";+});- const showIssueTaskStatementApply = computed(() => {- if (!state.create) {- return false;- }- let count = 0;- for (const stage of (issue.value 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"- ) {- count++;- }- }- }- return count > 1;- });+const showIssueOutputPanel = computed(() => {+ return !state.create && issueTemplate.value.outputFieldList.length > 0;+});- const database = computed((): Database | undefined => {- if (state.create) {- const databaseId = selectedStage.value.taskList[0].databaseId;- if (databaseId) {- return store.getters["database/databaseById"](databaseId);- }- return undefined;- }- return selectedStage.value.taskList[0].database;- });+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"+ );+});- const instance = computed((): Instance => {- if (state.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 store.getters["instance/instanceById"](- selectedStage.value.taskList[0].instanceId- );- }- return selectedStage.value.taskList[0].instance;- });+const showIssueTaskRollbackStatementPanel = computed(() => {+ if (project.value.workflowType == "UI") {+ return issue.value.type == "bb.issue.database.schema.update";+ }+ return false;+});- const sqlHint = (isRollBack: boolean): string | undefined => {+const showIssueTaskStatementApply = computed(() => {+ if (!state.create) {+ return false;+ }+ let count = 0;+ for (const stage of (issue.value as IssueCreate).pipeline.stageList) {+ for (const task of stage.taskList) {if (- !isRollBack &&- !state.create &&- selectedMigrateType.value == "BASELINE"+ task.type == "bb.task.general" ||+ task.type == "bb.task.database.create" ||+ task.type == "bb.task.database.schema.update") {- return `This is a baseline migration and bytebase won't apply the SQL to the database, it will only record a baseline history`;+ count++;}- if (!isRollBack && instance.value.engine === "SNOWFLAKE") {- return `Use <<schema>>.<<table>> to specify a Snowflake table`;- }- return undefined;- };+ }+ }+ return count > 1;+});- return {- state,- issue,- database,- instance,- sqlHint,- updateName,- updateDescription,- updateStatement,- updateEarliestAllowedTime,- applyStatementToOtherStages,- updateRollbackStatement,- applyRollbackStatementToOtherStages,- updateAssigneeId,- addSubscriberId,- removeSubscriberId,- updateCustomField,- doCreate,- doRollback,- changeIssueStatus,- changeTaskStatus,- runTaskChecks,- currentPipelineType,- currentUser,- issueTemplate,- selectedStage,- selectedTask,- selectStageId,- statement,- rollbackStatement,- selectedStatement,- selectedRollbackStatement,- selectedMigrateType,- allowEditSidebar,- allowEditOutput,- allowEditNameAndDescription,- allowEditStatement,- allowRollback,- showCancelBanner,- showSuccessBanner,- showPendingApproval,- showPipelineFlowBar,- showIssueOutputPanel,- showIssueTaskStatementPanel,- showIssueTaskRollbackStatementPanel,- showIssueTaskStatementApply,- };- },+const database = computed((): Database | undefined => {+ if (state.create) {+ const databaseId = selectedStage.value.taskList[0].databaseId;+ if (databaseId) {+ return store.getters["database/databaseById"](databaseId);+ }+ return undefined;+ }+ return selectedStage.value.taskList[0].database;});++const instance = computed((): Instance => {+ if (state.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 store.getters["instance/instanceById"](+ selectedStage.value.taskList[0].instanceId+ );+ }+ return selectedStage.value.taskList[0].instance;+});++const sqlHint = (isRollBack: boolean): string | undefined => {+ if (!isRollBack && !state.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 (!isRollBack && instance.value.engine === "SNOWFLAKE") {+ return `Use <<schema>>.<<table>> to specify a Snowflake table`;+ }+ return undefined;+};</script>