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): IssueDetail part.1 (#1257)
Liu Jib5dec706826a
diff --git a/frontend/src/components/Issue/IssueDetailLayout.vue b/frontend/src/components/Issue/IssueDetailLayout.vueindex 571d7beb3d..c3d2580143 100644--- a/frontend/src/components/Issue/IssueDetailLayout.vue+++ b/frontend/src/components/Issue/IssueDetailLayout.vue@@ -40,38 +40,13 @@<!-- Stage Flow Bar --><template v-if="showPipelineFlowBar"><template v-if="isTenantDeployMode">- <PipelineTenantFlow- v-if="project"- :create="create"- :project="project"- :pipeline="(issue as Issue).pipeline"- :selected-stage="selectedStage"- :selected-task="selectedTask"- class="border-t border-b"- @select-stage-id="selectStageId"- @select-task="selectTask"- />+ <PipelineTenantFlow v-if="project" class="border-t border-b" /></template><template v-else-if="isGhostMode">- <PipelineGhostFlow- v-if="project"- :create="create"- :project="project"- :pipeline="issue.pipeline!"- :selected-stage="selectedStage"- :selected-task="selectedTask"- class="border-t border-b"- @select-stage="selectStageId"- @select-task="selectTask"- />+ <PipelineGhostFlow v-if="project" class="border-t border-b" /></template><template v-else>- <PipelineSimpleFlow- :create="create"- :pipeline="(issue as Issue).pipeline"- :selected-stage="selectedStage"- @select-stage-id="selectStageId"- />+ <PipelineSimpleFlow class="border-t border-b" /></template><div v-if="!create" class="px-4 py-4 md:flex md:flex-col border-b">@@ -129,7 +104,7 @@@add-subscriber-id="addSubscriberId"@remove-subscriber-id="removeSubscriberId"@update-custom-field="updateCustomField"- @select-stage-id="selectStageId"+ @select-stage-id="selectStageOrTask"@select-task-id="selectTaskId"/></div>@@ -230,7 +205,7 @@import { computed, nextTick, onMounted, PropType, watchEffect } from "vue";import { useRoute, useRouter } from "vue-router";-import { cloneDeep, isEqual } from "lodash-es";+import { cloneDeep, isEmpty, isEqual } from "lodash-es";import {idFromSlug,issueSlug,@@ -241,6 +216,8 @@ import {stageSlug,taskSlug,isDev,+ activeTaskInStage,+ activeTask,} from "@/utils";import IssueBanner from "./IssueBanner.vue";import IssueHighlightPanel from "./IssueHighlightPanel.vue";@@ -303,6 +280,7 @@ import {useUIStateStore,} from "@/store";import formatSQL from "../MonacoEditor/sqlFormatter";+import { provideIssueContext } from "./context";const props = defineProps({create: {@@ -602,7 +580,7 @@ const changeTaskStatus = (comment: string) => {// Switch to the stage view containing this task- selectStageId(task.stage.id);+ selectStageOrTask(task.stage.id);nextTick().then(() => {selectTaskId(task.id);});@@ -719,14 +697,14 @@ const selectedStage = computed((): Stage | StageCreate => {return activeStage((props.issue as Issue).pipeline);});-const selectStageId = (+const selectStageOrTask = (stageId: StageId,- task: string | undefined = undefined+ taskSlug: string | undefined = undefined) => {const stageList = props.issue.pipeline!.stageList;const index = stageList.findIndex((item, index) => {if (props.create) {- return index == stageId;+ return index === stageId;}return (item as Stage).id == stageId;});@@ -735,22 +713,18 @@ const selectStageId = (query: {...router.currentRoute.value.query,stage: stageSlug(stageList[index].name, index),- task,+ task: taskSlug,},});};-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);+ selectStageOrTask(stage.id, slug);};const selectedTask = computed((): Task | TaskCreate => {@@ -1031,4 +1005,49 @@ const supportBackwardCompatibilityFeature = computed((): boolean => {const engine = database.value?.instance.engine;return engine === "MYSQL" || engine === "TIDB";});++const taskStatusOfStage = (stage: Stage | StageCreate) => {+ if (props.create) {+ return stage.taskList[0].status;+ }+ const activeTask = activeTaskInStage(stage as Stage);+ return activeTask.status;+};++const isValidStage = (stage: Stage | StageCreate) => {+ if (!props.create) {+ return true;+ }++ for (const task of stage.taskList) {+ if (+ task.type === "bb.task.database.create" ||+ task.type === "bb.task.database.schema.update" ||+ task.type === "bb.task.database.data.update" ||+ task.type === "bb.task.database.schema.update.ghost.sync"+ ) {+ if (isEmpty((task as TaskCreate).statement)) {+ return false;+ }+ }+ }+ return true;+};++provideIssueContext(+ {+ create: computed(() => props.create),+ issue: computed(() => props.issue),+ project: project,+ selectedStage,+ selectedTask,+ isValidStage,+ taskStatusOfStage,+ activeStageOfPipeline: activeStage,+ activeTaskOfPipeline: activeTask,+ activeTaskOfStage: activeTaskInStage,+ selectStageOrTask: selectStageOrTask,+ },+ true // root context+);</script>diff --git a/frontend/src/components/Issue/PipelineGhostFlow.vue b/frontend/src/components/Issue/PipelineGhostFlow.vueindex 0f31056743..5d7d1f203c 100644--- a/frontend/src/components/Issue/PipelineGhostFlow.vue+++ b/frontend/src/components/Issue/PipelineGhostFlow.vue@@ -1,73 +1,10 @@<template>- <div class="w-full">- <div class="lg:flex lg:items-center divide-y lg:divide-y-0 border-b">- <div- v-for="(stage, i) in pipeline.stageList"- :key="i"- class="stage-wrapper flex-1 md:flex md:flex-col items-center justify-start"- >- <div class="stage-header" :class="stageClass(stage)">- <span class="pl-4 py-2 flex items-center text-sm font-medium">- <TaskStatusIcon- :create="create"- :active="isActiveStage(stage)"- :status="taskStatusOfStage(stage)"- />- <div- class="text cursor-pointer hover:underline hidden lg:ml-4 lg:flex lg:flex-col"- @click.prevent="onClickStage(stage, i)"- >- <span class="text-xs">{{ stage.name }}</span>- <span class="text-sm">{{ taskNameOfStage(stage) }}</span>- </div>- <div- class="text ml-4 cursor-pointer flex items-center space-x-2 lg:hidden"- @click.prevent="onClickStage(stage, i)"- >- <span class="text-sm min-w-32">{{ stage.name }}</span>- <span class="text-sm flex-1">{{ taskNameOfStage(stage) }}</span>- </div>- <div- class="tooltip-wrapper"- @click.prevent="onClickStage(stage, i)"- >- <span class="tooltip whitespace-nowrap">- Missing SQL statement- </span>- <span- v-if="!isValidStage(stage)"- 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>- </span>- </div>- </span>-- <!-- Arrow separator -->- <div- v-if="i < pipeline.stageList.length - 1"- class="hidden lg:block absolute top-0 right-0 h-full w-5"- aria-hidden="true"- >- <svg- class="h-full w-full text-gray-300"- viewBox="0 0 22 80"- fill="none"- preserveAspectRatio="none"- >- <path- d="M0 -2L20 40L0 82"- vector-effect="non-scaling-stroke"- stroke="currentcolor"- stroke-linejoin="round"- />- </svg>- </div>- </div>- </div>- </div>+ <div class="divide-y">+ <PipelineStageList>+ <template #task-name-of-stage="{ stage }">+ {{ taskNameOfStage(stage) }}+ </template>+ </PipelineStageList><!--We don't parse the tasks' dependency relationships here, since we have exactly 1@@ -83,9 +20,7 @@<divclass="task px-2 py-1 cursor-pointer border rounded md:w-64 flex justify-between items-center":class="taskClass(task)"- @click="- onClickTask(selectedStageId, task.name, create ? j + 1 : task.id)- "+ @click="onClickTask(task, j)"><div class="flex-1"><div class="flex items-center pb-1">@@ -136,107 +71,69 @@</template><script lang="ts" setup>-import { computed, PropType, watchEffect } from "vue";-import {+import { computed, watchEffect } from "vue";+import { NScrollbar } from "naive-ui";+import { useI18n } from "vue-i18n";+import type {Pipeline,Stage,StageCreate,- PipelineCreate,Task,TaskCreate,- Project,Database,} from "@/types";import { activeTask, activeTaskInStage, taskSlug } from "@/utils";-import { isEmpty } from "lodash-es";import TaskStatusIcon from "./TaskStatusIcon.vue";import { useDatabaseStore } from "@/store";-import { NScrollbar } from "naive-ui";import { BBProgressPie } from "@/bbkit";-import { useI18n } from "vue-i18n";--const props = defineProps({- create: {- required: true,- type: Boolean,- },- project: {- required: true,- type: Object as PropType<Project>,- },- pipeline: {- required: true,- type: Object as PropType<Pipeline | PipelineCreate>,- },- selectedStage: {- required: true,- type: Object as PropType<Stage | StageCreate>,- },- selectedTask: {- type: Object as PropType<Task | TaskCreate | undefined>,- default: undefined,- },-});--const emit = defineEmits<{- (e: "select-task", stageIdOrIndex: number, taskSlug: string): void;- (e: "select-stage", stageIdOrIndex: number): void;-}>();+import PipelineStageList from "./PipelineStageList.vue";+import { useIssueContext } from "./context";const { t } = useI18n();const databaseStore = useDatabaseStore();-watchEffect(function prepare() {- if (props.create) {- databaseStore.fetchDatabaseListByProjectId(props.project.id);+const {+ create,+ issue,+ project,+ selectedStage,+ selectedTask,+ selectStageOrTask,+} = useIssueContext();++const pipeline = computed(() => issue.value.pipeline!);++watchEffect(() => {+ if (create.value) {+ databaseStore.fetchDatabaseListByProjectId(project.value.id);}});+const taskList = computed(() => {+ return selectedStage.value.taskList;+});+const databaseOfTask = (task: Task | TaskCreate): Database => {- if (props.create) {+ if (create.value) {return databaseStore.getDatabaseById((task as TaskCreate).databaseId!);}return (task as Task).database!;};-const isSelectedStage = (stage: Stage | StageCreate): boolean => {- return stage === props.selectedStage;-};-const isSelectedTask = (task: Task | TaskCreate): boolean => {- return task === props.selectedTask;-};--const isActiveStage = (stage: Stage | StageCreate): boolean => {- if (props.create) {- return false;- }-- const task = activeTaskInStage(stage as Stage);- if (activeTask(props.pipeline as Pipeline).id === task.id) {- return true;- }- return false;+ return task === selectedTask.value;};const isActiveTask = (task: Task | TaskCreate): boolean => {- if (props.create) {+ if (create.value) {return false;}task = task as Task;- return activeTask(props.pipeline as Pipeline).id === task.id;-};--const taskStatusOfStage = (stage: Stage | StageCreate) => {- if (props.create) {- return stage.taskList[0].status;- }- const activeTask = activeTaskInStage(stage as Stage);- return activeTask.status;+ return activeTask(pipeline.value as Pipeline).id === task.id;};const taskNameOfStage = (stage: Stage | StageCreate) => {- if (props.create) {+ if (create.value) {return stage.taskList[0].status;}const activeTask = activeTaskInStage(stage as Stage);@@ -253,35 +150,17 @@ const taskNameOfTask = (task: Task | TaskCreate) => {return t(`task.type.${task.type.replace(/\./g, "-")}`);};-const isValidStage = (stage: Stage | StageCreate) => {- if (!props.create) {- return true;+const selectedStageIdOrIndex = computed(() => {+ if (!create.value) {+ return (selectedStage.value as Stage).id;}- for (const task of (stage as StageCreate).taskList) {- if (task.type === "bb.task.database.schema.update.ghost.sync") {- if (isEmpty(task.statement)) {- return false;- }- }- }- return true;-};--const taskList = computed(() => {- return props.selectedStage.taskList;-});--const selectedStageId = computed(() => {- if (!props.create) {- return (props.selectedStage as Stage).id;- }- return (props.pipeline.stageList as StageCreate[]).indexOf(- props.selectedStage as StageCreate+ return (pipeline.value.stageList as StageCreate[]).indexOf(+ selectedStage.value as StageCreate);});const getTaskProgress = (task: Task | TaskCreate) => {- if (props.create) {+ if (create.value) {return 0;}if (task.type !== "bb.task.database.schema.update.ghost.sync") return 0;@@ -297,70 +176,26 @@ const getTaskProgress = (task: Task | TaskCreate) => {return 0;};-const stageClass = (stage: Stage | StageCreate): string[] => {- const classes: string[] = [];- if (props.create) classes.push("create");- if (isSelectedStage(stage)) classes.push("selected");- if (isActiveStage(stage)) classes.push("active");- const task = activeTaskInStage(stage as Stage);- classes.push(`status_${task.status.toLowerCase()}`);-- return classes;-};-const taskClass = (task: Task | TaskCreate): string[] => {const classes: string[] = [];if (isSelectedTask(task)) classes.push("selected");if (isActiveTask(task)) classes.push("active");- if (props.create) classes.push("create");+ if (create.value) classes.push("create");classes.push(`status_${task.status.toLowerCase()}`);return classes;};-const onClickStage = (stage: Stage | StageCreate, index: number) => {- if (props.create) {- emit("select-stage", index);- return;- }- const { id } = stage as Stage;- emit("select-stage", id);-};--const onClickTask = (stageId: number, taskName: string, taskId: number) => {+const onClickTask = (task: Task | TaskCreate, index: number) => {+ const stageId = selectedStageIdOrIndex.value;+ const taskName = task.name;+ const taskId = create.value ? index + 1 : (task as Task).id;const ts = taskSlug(taskName, taskId);- emit("select-task", stageId, ts);++ selectStageOrTask(stageId, ts);};</script><style scoped lang="postcss">-.stage-header {- @apply cursor-default flex items-center justify-start w-full relative;-}--.stage-header.selected .text {- @apply underline;-}-.stage-header.active .text {- @apply font-bold;-}-.stage-header.status_done .text {- @apply text-control;-}-.stage-header.status_pending .text,-.stage-header.status_pending_approval .text {- @apply text-control;-}-.stage-header.active.status_pending .text,-.stage-header.active.status_pending_approval .text {- @apply text-info;-}-.stage-header.status_running .text {- @apply text-info;-}-.stage-header.status_failed .text {- @apply text-red-500;-}-.task.selected {@apply border-info;}diff --git a/frontend/src/components/Issue/PipelineSimpleFlow.vue b/frontend/src/components/Issue/PipelineSimpleFlow.vueindex cb0763ae9b..a83b729bf5 100644--- a/frontend/src/components/Issue/PipelineSimpleFlow.vue+++ b/frontend/src/components/Issue/PipelineSimpleFlow.vue@@ -1,301 +1,31 @@<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 overflow-auto"- >- <li- v-for="(item, index) in itemList"- :key="index"- class="relative md:flex-1 md:flex"- >- <div- class="cursor-default group flex items-center justify-between w-full"- >- <span class="tab-item">- <div- 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'">- <span- v-if="activeTask(pipeline).id === item.taskId"- class="h-2 w-2 bg-info rounded-full"- aria-hidden="true"- ></span>- <span- v-else- class="h-1.5 w-1.5 bg-control rounded-full"- aria-hidden="true"- ></span>- </template>- <template v-else-if="item.taskStatus === 'PENDING_APPROVAL'">- <heroicons-outline:user class="w-4 h-4" />- </template>- <template v-else-if="item.taskStatus == 'RUNNING'">- <span- class="h-2.5 w-2.5 bg-info rounded-full"- style="- animation: pulse 2.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;- "- aria-hidden="true"- ></span>- </template>- <template v-else-if="item.taskStatus == 'DONE'">- <heroicons-solid:check class="w-5 h-5" />- </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"- aria-hidden="true"- >!</span- >- </template>- </div>- <div- class="hidden cursor-pointer hover:underline lg:ml-4 lg:flex lg:flex-col pipeline-item"- :class="- (flowItemTextClass(item) || '') +- (item.valid ? '' : ' ' + 'no-valid')- "- @click.prevent="clickItem(item)"- >- <span class="text-xs">{{ item.stageName }}</span>- <n-ellipsis class="text-sm" :line-clamp="1" :tooltip="true">- {{ item.taskName }}- </n-ellipsis>- </div>- <div- class="ml-4 w-full group cursor-pointer grid grid-cols-3 lg:hidden"- :class="flowItemTextClass(item)"- @click.prevent="clickItem(item)"- >- <span class="col-span-1 text-sm">{{ item.stageName }}</span>- <span class="col-span-2 text-sm ml-4">{{ item.taskName }}</span>-- <span class="col-span-1 text-sm">{{ item.stageName }}</span>- <span class="col-span-2 text-sm ml-4">{{ item.taskName }}</span>- </div>- <div- v-if="!item.valid"- class="tooltip-wrapper"- @click.prevent="clickItem(item)"- >- <n-popover trigger="hover">- <template #trigger>- <span- 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- >- </span>- </template>- <span>Missing SQL statement</span>- </n-popover>- </div>- </span>- </div>-- <!-- Arrow separator -->- <div- v-if="index != itemList.length - 1"- class="hidden lg:block absolute top-0 right-0 h-full w-5"- aria-hidden="true"- >- <svg- class="h-full w-full text-gray-300"- viewBox="0 0 22 80"- fill="none"- preserveAspectRatio="none"- >- <path- d="M0 -2L20 40L0 82"- vector-effect="non-scaling-stroke"- stroke="currentcolor"- stroke-linejoin="round"- />- </svg>- </div>- </li>- </ol>- </nav>+ <div>+ <PipelineStageList>+ <template #task-name-of-stage="{ stage }">+ {{ taskNameOfStage(stage) }}+ </template>+ </PipelineStageList>+ </div></template>-<script lang="ts">-import { computed, defineComponent, PropType } from "vue";-import {- Pipeline,- TaskStatus,- TaskId,- Stage,- StageId,- StageCreate,- PipelineCreate,- Task,- TaskCreate,-} from "../../types";-import { activeTask, activeTaskInStage } from "../../utils";-import { isEmpty } from "lodash-es";-import { NEllipsis, NPopover } from "naive-ui";-interface FlowItem {- stageId: StageId;- stageName: string;- taskId: TaskId;- taskName: string;- taskStatus: TaskStatus;- valid: boolean;-}--export default defineComponent({- name: "PipelineSimpleFlow",- components: { NEllipsis, NPopover },- props: {- create: {- required: true,- type: Boolean,- },- pipeline: {- required: true,- type: Object as PropType<Pipeline | PipelineCreate>,- },- selectedStage: {- required: true,- type: Object as PropType<Stage | StageCreate>,- },- },- emits: ["select-stage-id"],- setup(props, { emit }) {- const itemList = computed<FlowItem[]>(() => {- return props.pipeline.stageList.map((stage, index) => {- let activeTask = stage.taskList[0];- let taskName = activeTask.name;- let valid = true;- if (props.create) {- for (const task of stage.taskList) {- if (- task.type == "bb.task.database.create" ||- task.type == "bb.task.database.schema.update" ||- task.type == "bb.task.database.data.update"- ) {- if (isEmpty((task as TaskCreate).statement)) {- valid = false;- break;- }- }- }- } else {- activeTask = activeTaskInStage(stage as Stage);- if (stage.taskList.length > 1) {- for (let i = 0; i < stage.taskList.length; i++) {- if ((stage.taskList[i] as Task).id == (activeTask as Task).id) {- taskName = `${activeTask.name} (${i + 1}/${- stage.taskList.length- })`;- break;- }- }- }- }-- return {- stageId: props.create ? index : (stage as Stage).id,- stageName: stage.name,- taskId: props.create ? index : (activeTask as Task).id,- taskName: taskName,- taskStatus: activeTask.status,- valid,- };- });- });-- const flowItemIconClass = (item: FlowItem) => {- switch (item.taskStatus) {- case "PENDING":- if (- !props.create &&- activeTask(props.pipeline as Pipeline).id === item.taskId- ) {- return "bg-white border-2 border-info text-info ";- }- return "bg-white border-2 border-control";- case "PENDING_APPROVAL":- if (- !props.create &&- activeTask(props.pipeline as Pipeline).id === item.taskId- ) {- return "bg-white border-2 border-info text-info";- }- return "bg-white border-2 border-control";- case "RUNNING":- return "bg-white border-2 border-info text-info";- case "DONE":- return "bg-success text-white";- case "FAILED":- return "bg-error text-white";- }- };-- const flowItemTextClass = (item: FlowItem) => {- let textClass =- !props.create &&- activeTask(props.pipeline as Pipeline).id === item.taskId- ? "font-bold "- : "font-normal ";- // For create, since we don't have stage id yet, we just compare name instead.- // Not 100% accurate, but should be fine most of the time.- if (- (props.create &&- item.stageName == (props.selectedStage as StageCreate).name) ||- (!props.create && item.stageId == (props.selectedStage as Stage).id)- ) {- textClass += "underline ";- }- switch (item.taskStatus) {- case "DONE":- return textClass + "text-control";- case "PENDING":- case "PENDING_APPROVAL":- if (- !props.create &&- activeTask(props.pipeline as Pipeline).id === item.taskId- ) {- return textClass + "text-info";- }- return textClass + "text-control";- case "RUNNING":- return textClass + "text-info";- case "FAILED":- return textClass + "text-red-500";- }- };-- const clickItem = (item: FlowItem) => {- emit("select-stage-id", item.stageId);- };-- return {- itemList,- activeTask,- flowItemIconClass,- flowItemTextClass,- clickItem,- };- },-});+<script lang="ts" setup>+import type { Stage, StageCreate } from "@/types";+import { activeTaskInStage } from "@/utils";+import { useIssueContext } from "./context";++const { create } = useIssueContext();++const taskNameOfStage = (stage: Stage | StageCreate) => {+ if (create.value) {+ return stage.taskList[0].status;+ }+ const activeTask = activeTaskInStage(stage as Stage);+ const { taskList } = stage as Stage;+ for (let i = 0; i < stage.taskList.length; i++) {+ if (taskList[i].id == activeTask.id) {+ return `${activeTask.name} (${i + 1}/${stage.taskList.length})`;+ }+ }+ return activeTask.name;+};</script>--<style scoped>-.pipeline-item {- flex-basis: 80%;-}--.pipeline-item.no-valid {- flex-basis: calc(80% - 2.5rem);-}--.tab-item {- @apply w-full pl-4 py-2 flex items-center text-sm font-medium;-- min-width: 300px;-}-</style>diff --git a/frontend/src/components/Issue/PipelineStageList.vue b/frontend/src/components/Issue/PipelineStageList.vuenew file mode 100644index 0000000000..88da17f456--- /dev/null+++ b/frontend/src/components/Issue/PipelineStageList.vue@@ -0,0 +1,157 @@+<template>+ <div class="lg:flex divide-y lg:divide-y-0">+ <div+ v-for="(stage, i) in issue.pipeline?.stageList"+ :key="i"+ class="stage-item"+ :class="stageClass(stage, i)"+ >+ <TaskStatusIcon+ :create="create"+ :active="isActiveStage(stage)"+ :status="taskStatusOfStage(stage, i)"+ />++ <div class="text" @click.prevent="onClickStage(stage, i)">+ <span class="text-sm min-w-32 lg:text-xs lg:min-w-fit">{{+ stage.name+ }}</span>+ <span class="text-sm flex-1 ml-4 lg:ml-0">+ <slot name="task-name-of-stage" :stage="stage" :index="i" />+ </span>+ </div>++ <NPopover v-if="!isValidStage(stage, i)" trigger="hover" placement="top">+ <template #trigger>+ <span+ class="ml-2 w-5 h-5 flex justify-center rounded-full select-none bg-error text-white hover:bg-error-hover font-normal absolute right-3"+ @click="onClickStage(stage, i)"+ >+ !+ </span>+ </template>+ <span>Missing SQL statement</span>+ </NPopover>++ <!-- Arrow separator -->+ <div+ v-if="i < issue.pipeline?.stageList.length - 1"+ class="hidden lg:block absolute top-0 bottom-0 right-0 w-5 pointer-events-none"+ aria-hidden="true"+ >+ <svg+ class="h-full w-full text-gray-300"+ viewBox="0 0 22 80"+ fill="none"+ preserveAspectRatio="none"+ >+ <path+ d="M0 -2L20 40L0 82"+ vector-effect="non-scaling-stroke"+ stroke="currentcolor"+ stroke-linejoin="round"+ />+ </svg>+ </div>+ </div>+ </div>+</template>++<script lang="ts" setup>+import { NPopover } from "naive-ui";+import { Issue, Stage, StageCreate } from "@/types";+import TaskStatusIcon from "./TaskStatusIcon.vue";+import { useIssueContext } from "./context";++const {+ create,+ issue,+ selectedStage,+ isValidStage,+ activeTaskOfPipeline,+ activeTaskOfStage,+ taskStatusOfStage,+ selectStageOrTask,+} = useIssueContext();++const isSelectedStage = (stage: Stage | StageCreate): boolean => {+ return stage === selectedStage.value;+};++const isActiveStage = (stage: Stage | StageCreate): boolean => {+ if (create.value) {+ // In create mode we don't have an ActiveStage+ return false;+ }++ const activeTask = activeTaskOfPipeline((issue.value as Issue).pipeline);+ const taskFound = (stage as Stage).taskList.find(+ (t) => t.id === activeTask.id+ );+ if (taskFound) {+ // A stage is "Active" if the ActiveTaskOfPipeline is inside this stage+ return true;+ }++ return false;+};++const stageClass = (stage: Stage | StageCreate, index: number): string[] => {+ const classList: string[] = [];++ if (!isValidStage(stage, index)) classList.push("invalid");+ if (create.value) classList.push("create");+ if (isSelectedStage(stage)) classList.push("selected");+ if (isActiveStage(stage)) classList.push("active");+ const task = activeTaskOfStage(stage as Stage);+ classList.push(`status_${task.status.toLowerCase()}`);++ return classList;+};++const onClickStage = (stage: Stage | StageCreate, index: number) => {+ if (create.value) {+ selectStageOrTask(index);+ return;+ }+ selectStageOrTask((stage as Stage).id);+};+</script>++<style scoped lang="postcss">+.stage-item {+ @apply cursor-default flex items-center justify-start w-full px-4 py-2 text-sm font-medium relative;+ @apply lg:w-auto lg:flex-1;+}+.stage-item.invalid {+ @apply pr-10;+}++.stage-item .text {+ @apply cursor-pointer ml-4 flex items-center flex-1;+ @apply lg:flex-col lg:items-start;+}+.stage-item.selected .text {+ @apply underline;+}+.stage-item.active .text {+ @apply font-bold;+}+.stage-item.status_done .text {+ @apply text-control;+}+.stage-item.status_pending .text,+.stage-item.status_pending_approval .text {+ @apply text-control;+}+.stage-item.active.status_pending .text,+.stage-item.active.status_pending_approval .text {+ @apply text-info;+}+.stage-item.status_running .text {+ @apply text-info;+}+.stage-item.status_failed .text {+ @apply text-red-500;+}+</style>diff --git a/frontend/src/components/Issue/PipelineTenantFlow.vue b/frontend/src/components/Issue/PipelineTenantFlow.vueindex 9ecbf4a2df..eae2925901 100644--- a/frontend/src/components/Issue/PipelineTenantFlow.vue+++ b/frontend/src/components/Issue/PipelineTenantFlow.vue@@ -1,70 +1,10 @@<template>- <div class="w-full">- <div class="lg:flex divide-y lg:divide-y-0 border-b">- <div- v-for="(item, i) in itemList"- :key="i"- class="stage-wrapper flex-1 md:flex md:flex-col items-center justify-start"- >- <div class="stage-header" :class="stageClass(item.stage)">- <span class="pl-4 py-2 flex items-center text-sm font-medium">- <TaskStatusIcon- :create="create"- :active="isActiveStage(item.stage)"- :status="item.taskStatus"- />- <div- class="text cursor-pointer hover:underline hidden lg:ml-4 lg:flex lg:flex-col"- @click.prevent="clickItem(item)"- >- <span class="text-xs">{{ item.stageName }}</span>- <span class="text-sm">{{ item.taskName }}</span>- </div>- <div- class="text ml-4 cursor-pointer flex items-center space-x-2 lg:hidden"- @click.prevent="clickItem(item)"- >- <span class="text-sm min-w-32">{{ item.stageName }}</span>- <span class="text-sm flex-1">{{ item.taskName }}</span>- </div>- <div class="tooltip-wrapper" @click.prevent="clickItem(item)">- <span class="tooltip whitespace-nowrap"- >Missing SQL statement</span- >- <span- v-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"- >- <span class="text-center font-normal" aria-hidden="true"- >!</span- >- </span>- </div>- </span>-- <!-- Arrow separator -->- <div- v-if="i < itemList.length - 1"- class="hidden lg:block absolute top-0 right-0 h-full w-5"- aria-hidden="true"- >- <svg- class="h-full w-full text-gray-300"- viewBox="0 0 22 80"- fill="none"- preserveAspectRatio="none"- >- <path- d="M0 -2L20 40L0 82"- vector-effect="non-scaling-stroke"- stroke="currentcolor"- stroke-linejoin="round"- />- </svg>- </div>- </div>- </div>- </div>+ <div class="divide-y">+ <PipelineStageList>+ <template #task-name-of-stage="{ stage }">+ {{ taskNameOfStage(stage) }}+ </template>+ </PipelineStageList><div class="task-list gap-2 p-2 md:grid md:grid-cols-2 lg:grid-cols-4"><div@@ -72,7 +12,7 @@:key="j"class="task px-2 py-1 cursor-pointer border rounded":class="taskClass(task)"- @click="clickTask(selectedStageId, task.name, create ? j + 1 : task.id)"+ @click="onClickTask(task, j)"><div class="flex items-center pb-1"><TaskStatusIcon@@ -99,240 +39,103 @@</div></template>-<script lang="ts">-import { computed, defineComponent, PropType, watchEffect } from "vue";+<script lang="ts" setup>+import { computed, watchEffect } from "vue";import {Pipeline,- TaskStatus,- TaskId,Stage,- StageId,StageCreate,- PipelineCreate,Task,TaskCreate,- Project,Database,-} from "../../types";-import { activeTask, activeTaskInStage, taskSlug } from "../../utils";-import { isEmpty } from "lodash-es";+} from "@/types";+import { activeTask, activeTaskInStage, taskSlug } from "@/utils";import TaskStatusIcon from "./TaskStatusIcon.vue";import { useDatabaseStore } from "@/store";+import { useIssueContext } from "./context";-interface FlowItem {- stageId: StageId;- stageName: string;- taskId: TaskId;- taskName: string;- taskStatus: TaskStatus;- valid: boolean;- stage: Stage | StageCreate;- taskList: (Task | TaskCreate)[];-}--export default defineComponent({- name: "PipelineTenantFlow",- components: {- TaskStatusIcon,- },- props: {- create: {- required: true,- type: Boolean,- },- project: {- required: true,- type: Object as PropType<Project>,- },- pipeline: {- required: true,- type: Object as PropType<Pipeline | PipelineCreate>,- },- selectedStage: {- required: true,- type: Object as PropType<Stage | StageCreate>,- },- selectedTask: {- type: Object as PropType<Task | TaskCreate | undefined>,- default: undefined,- },- },- emits: ["select-stage-id", "select-task"],- setup(props, { emit }) {- const databaseStore = useDatabaseStore();-- watchEffect(function prepare() {- if (props.create) {- databaseStore.fetchDatabaseListByProjectId(props.project.id);- }- });-- const databaseForTask = (task: Task | TaskCreate): Database => {- if (props.create) {- return databaseStore.getDatabaseById((task as TaskCreate).databaseId!);- } else {- return (task as Task).database!;- }- };-- const isSelectedStage = (stage: Stage | StageCreate): boolean => {- return stage === props.selectedStage;- };-- const isSelectedTask = (task: Task | TaskCreate): boolean => {- return task === props.selectedTask;- };-- const isActiveStage = (stage: Stage | StageCreate): boolean => {- if (props.create) return false;-- const task = activeTaskInStage(stage as Stage);- if (activeTask(props.pipeline as Pipeline).id === task.id) {- return true;- }- return false;- };-- const isActiveTask = (task: Task | TaskCreate): boolean => {- if (props.create) return false;- task = task as Task;- return activeTask(props.pipeline as Pipeline).id === task.id;- };-- const itemList = computed<FlowItem[]>(() => {- return props.pipeline.stageList.map((stage, index) => {- let activeTask = stage.taskList[0];- let taskName = activeTask.name;- let valid = true;- if (props.create) {- for (const task of stage.taskList) {- if (- task.type == "bb.task.database.create" ||- task.type == "bb.task.database.schema.update" ||- task.type == "bb.task.database.data.update"- ) {- if (isEmpty((task as TaskCreate).statement)) {- valid = false;- break;- }- }- }- } else {- activeTask = activeTaskInStage(stage as Stage);- if (stage.taskList.length > 1) {- for (let i = 0; i < stage.taskList.length; i++) {- if ((stage.taskList[i] as Task).id == (activeTask as Task).id) {- taskName = `${activeTask.name} (${i + 1}/${- stage.taskList.length- })`;- break;- }- }- }- }-- return {- stageId: props.create ? index : (stage as Stage).id,- stageName: stage.name,- taskId: props.create ? index : (activeTask as Task).id,- taskName: taskName,- taskStatus: activeTask.status,- stage,- taskList: stage.taskList,- valid,- };- });- });-- const taskList = computed(() => {- return props.selectedStage.taskList;- });-- const selectedStageId = computed(() => {- if (!props.create) {- return (props.selectedStage as Stage).id;- } else {- return props.pipeline.stageList.indexOf(props.selectedStage as any);- }- });+const {+ create,+ issue,+ project,+ selectedStage,+ selectedTask,+ selectStageOrTask,+} = useIssueContext();- const stageClass = (stage: Stage | StageCreate): string[] => {- const classes: string[] = [];- if (props.create) classes.push("create");- if (isSelectedStage(stage)) classes.push("selected");- if (isActiveStage(stage)) classes.push("active");- const task = activeTaskInStage(stage as Stage);- classes.push(`status_${task.status.toLowerCase()}`);+const pipeline = computed(() => issue.value.pipeline!);- return classes;- };+const databaseStore = useDatabaseStore();- const taskClass = (task: Task | TaskCreate) => {- const classes: string[] = [];- if (isSelectedTask(task)) classes.push("selected");- if (isActiveTask(task)) classes.push("active");- if (props.create) classes.push("create");- classes.push(`status_${task.status.toLowerCase()}`);- return classes;- };-- const clickItem = (item: FlowItem) => {- emit("select-stage-id", item.stageId);- };-- const clickTask = (stageId: number, taskName: string, taskId: number) => {- const ts = taskSlug(taskName, taskId);- emit("select-task", stageId, ts);- };+watchEffect(() => {+ if (create.value) {+ databaseStore.fetchDatabaseListByProjectId(project.value.id);+ }+});- return {- isSelectedStage,- isSelectedTask,- isActiveStage,- isActiveTask,- itemList,- taskList,- selectedStageId,- activeTask,- stageClass,- taskClass,- clickItem,- clickTask,- databaseForTask,- };- },+const taskList = computed(() => selectedStage.value.taskList);++const isSelectedTask = (task: Task | TaskCreate): boolean => {+ return task === selectedTask.value;+};++const isActiveTask = (task: Task | TaskCreate): boolean => {+ if (create.value) return false;+ task = task as Task;+ return activeTask(pipeline.value as Pipeline).id === task.id;+};++const databaseForTask = (task: Task | TaskCreate): Database => {+ if (create.value) {+ return databaseStore.getDatabaseById((task as TaskCreate).databaseId!);+ } else {+ return (task as Task).database!;+ }+};++const selectedStageIdOrIndex = computed(() => {+ if (!create.value) {+ return (selectedStage.value as Stage).id;+ }+ return (pipeline.value.stageList as StageCreate[]).indexOf(+ selectedStage.value as StageCreate+ );});++const taskNameOfStage = (stage: Stage | StageCreate) => {+ if (create.value) {+ return stage.taskList[0].status;+ }+ const activeTask = activeTaskInStage(stage as Stage);+ const { taskList } = stage as Stage;+ for (let i = 0; i < stage.taskList.length; i++) {+ if (taskList[i].id == activeTask.id) {+ return `${activeTask.name} (${i + 1}/${stage.taskList.length})`;+ }+ }+ return activeTask.name;+};++const taskClass = (task: Task | TaskCreate) => {+ const classes: string[] = [];+ if (isSelectedTask(task)) classes.push("selected");+ if (isActiveTask(task)) classes.push("active");+ if (create.value) classes.push("create");+ classes.push(`status_${task.status.toLowerCase()}`);+ return classes;+};++const onClickTask = (task: Task | TaskCreate, index: number) => {+ const stageId = selectedStageIdOrIndex.value;+ const taskName = task.name;+ const taskId = create.value ? index + 1 : (task as Task).id;+ const ts = taskSlug(taskName, taskId);++ selectStageOrTask(stageId, ts);+};</script><style scoped lang="postcss">-.stage-header {- @apply cursor-default flex items-center justify-start w-full relative;-}--.stage-header.selected .text {- @apply underline;-}-.stage-header.active .text {- @apply font-bold;-}-.stage-header.status_done .text {- @apply text-control;-}-.stage-header.status_pending .text,-.stage-header.status_pending_approval .text {- @apply text-control;-}-.stage-header.active.status_pending .text,-.stage-header.active.status_pending_approval .text {- @apply text-info;-}-.stage-header.status_running .text {- @apply text-info;-}-.stage-header.status_failed .text {- @apply text-red-500;-}-.task.selected {@apply border-info;}diff --git a/frontend/src/components/Issue/context/IssueContext.ts b/frontend/src/components/Issue/context/IssueContext.tsnew file mode 100644index 0000000000..b83afa24eb--- /dev/null+++ b/frontend/src/components/Issue/context/IssueContext.ts@@ -0,0 +1,38 @@+import {+ Issue,+ IssueCreate,+ Pipeline,+ Project,+ Stage,+ StageCreate,+ Task,+ TaskCreate,+ TaskStatus,+} from "@/types";+import { Ref } from "vue";++type IssueContext = {+ // base params+ create: Ref<boolean>;+ project: Ref<Project>;+ issue: Ref<Issue | IssueCreate>;++ // states+ selectedStage: Ref<Stage | StageCreate>;+ selectedTask: Ref<Task | TaskCreate>;++ // logic functions+ isValidStage: (stage: Stage | StageCreate, index: number) => boolean;+ activeStageOfPipeline: (pipeline: Pipeline) => Stage;+ activeTaskOfPipeline: (pipeline: Pipeline) => Task;+ activeTaskOfStage: (stage: Stage) => Task;+ taskStatusOfStage: (stage: Stage | StageCreate, index: number) => TaskStatus;++ // event handlers+ selectStageOrTask: (+ stageIdOrIndex: number,+ taskSlug?: string | undefined+ ) => void;+};++export default IssueContext;diff --git a/frontend/src/components/Issue/context/index.ts b/frontend/src/components/Issue/context/index.tsnew file mode 100644index 0000000000..9d977cc6c3--- /dev/null+++ b/frontend/src/components/Issue/context/index.ts@@ -0,0 +1,24 @@+import { inject, provide, InjectionKey } from "vue";+import IssueContext from "./IssueContext";++export const KEY = Symbol(+ "bb.issue.ui-state-context"+) as InjectionKey<IssueContext>;++export const useIssueContext = () => {+ return inject(KEY)!;+};++export const provideIssueContext = (+ context: Partial<IssueContext>,+ root = false+) => {+ if (!root) {+ const parentContext = useIssueContext();+ context = {+ ...parentContext,+ ...context,+ };+ }+ provide(KEY, context as IssueContext);+};