Skip to content

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

Add TaskCheckBar to IssueDetailView

天舟7b74cd541e0b
diff --git a/frontend/src/components/IssueStagePanel.vue b/frontend/src/components/IssueStagePanel.vue
index 1a691333f0..88068d24d9 100644
--- a/frontend/src/components/IssueStagePanel.vue
+++ b/frontend/src/components/IssueStagePanel.vue
@@ -20,43 +20,18 @@
{{ task.name }}
</div>
</div>
- <div class="mb-2">
- <BBTabFilter
- :tabItemList="tabItemList(task)"
- :selectedIndex="state.selectedIndex"
- @select-index="
- (index) => {
- state.selectedIndex = index;
- }
- "
- />
- </div>
- <TaskRunTable
- v-if="state.selectedIndex == RUN_TAB"
- :taskRunList="task.taskRunList"
- />
- <TaskCheckRunTable
- v-else-if="state.selectedIndex == CHECK_TAB"
- :taskCheckRunList="filteredTaskCheckRunList(task.taskCheckRunList)"
- />
+ <TaskRunTable :taskRunList="task.taskRunList" />
</div>
</div>
</template>
<script lang="ts">
import { reactive, watch, PropType, computed } from "vue";
-import TaskCheckRunTable from "../components/TaskCheckRunTable.vue";
import TaskRunTable from "../components/TaskRunTable.vue";
-import { Stage, Task, TaskCheckRun, TaskCheckType } from "../types";
+import { Stage, Task } from "../types";
import { activeTaskInStage } from "../utils";
-import { BBTabFilterItem } from "../bbkit/types";
-
-const RUN_TAB = 0;
-const CHECK_TAB = 1;
-interface LocalState {
- selectedIndex: number;
-}
+interface LocalState {}
export default {
name: "IssueStagePanel",
@@ -66,68 +41,21 @@ export default {
type: Object as PropType<Stage>,
},
},
- components: { TaskCheckRunTable, TaskRunTable },
+ components: { TaskRunTable },
setup(props, { emit }) {
- const state = reactive<LocalState>({
- selectedIndex: RUN_TAB,
- });
+ const state = reactive<LocalState>({});
watch(
() => props.stage,
(curStage, _) => {}
);
- // For a particular check type, only returns the most recent one
- const filteredTaskCheckRunList = (list: TaskCheckRun[]): TaskCheckRun[] => {
- const result: TaskCheckRun[] = [];
- for (const run of list) {
- const index = result.findIndex((item) => item.type == run.type);
- if (index >= 0 && result[index].updatedTs < run.updatedTs) {
- result[index] = run;
- } else {
- result.push(run);
- }
- }
- return result;
- };
-
- const tabItemList = (task: Task): BBTabFilterItem[] => {
- let showRunAlert = false;
- let showCheckAlert = false;
-
- for (const run of task.taskRunList) {
- if (run.status == "FAILED") {
- showRunAlert = true;
- break;
- }
- }
- for (const run of filteredTaskCheckRunList(task.taskCheckRunList)) {
- for (const result of run.result.resultList) {
- if (result.status == "ERROR") {
- showCheckAlert = true;
- break;
- }
- }
- if (showCheckAlert) {
- break;
- }
- }
- return [
- { title: "Runs", alert: showRunAlert },
- { title: "Checks", alert: showCheckAlert },
- ];
- };
-
const activeTask = computed((): Task => {
return activeTaskInStage(props.stage);
});
return {
- RUN_TAB,
- CHECK_TAB,
state,
- filteredTaskCheckRunList,
- tabItemList,
activeTask,
};
},
diff --git a/frontend/src/components/TaskCheckBadgeBar.vue b/frontend/src/components/TaskCheckBadgeBar.vue
new file mode 100644
index 0000000000..a22b433cb0
--- /dev/null
+++ b/frontend/src/components/TaskCheckBadgeBar.vue
@@ -0,0 +1,202 @@
+<template>
+ <div class="flex items-center space-x-2">
+ <template
+ v-for="(checkRun, index) in filteredTaskCheckRunList"
+ :key="index"
+ >
+ <button
+ class="
+ inline-flex
+ items-center
+ px-3
+ py-0.5
+ rounded-full
+ text-sm
+ border border-control-border
+ hover:bg-control-bg-hover
+ text-main
+ "
+ :class="
+ showSelection && checkRun.type == state.selectedTaskCheckRun.type
+ ? 'bg-control-bg-hover'
+ : ''
+ "
+ @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>
+ </template>
+ <template v-else-if="checkRun.status == 'DONE'">
+ <template v-if="taskCheckStatus(checkRun) == 'SUCCESS'">
+ <svg
+ class="-ml-1 mr-1.5 h-4 w-4 text-success"
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ stroke-width="2"
+ d="M5 13l4 4L19 7"
+ ></path>
+ </svg>
+ </template>
+ <template v-else-if="taskCheckStatus(checkRun) == 'WARN'">
+ <span class="mr-1.5 font-medium text-warning" aria-hidden="true"
+ >!</span
+ >
+ </template>
+ <template v-else-if="taskCheckStatus(checkRun) == 'ERROR'">
+ <svg
+ class="-ml-1 mr-1.5 h-4 w-4 text-error"
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ stroke-width="2"
+ d="M6 18L18 6M6 6l12 12"
+ ></path>
+ </svg>
+ </template>
+ </template>
+ <template v-else-if="checkRun.status == 'FAILED'">
+ <svg
+ class="-ml-1 mr-1.5 h-4 w-4 text-error"
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ stroke-width="2"
+ d="M6 18L18 6M6 6l12 12"
+ ></path>
+ </svg>
+ </template>
+ <template v-else-if="checkRun.status == 'CANCELED'">
+ <svg
+ class="-ml-1 mr-1.5 h-4 w-4 text-control"
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ stroke-width="2"
+ d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636"
+ ></path>
+ </svg>
+ </template>
+ {{ checkRun.name }}
+ </button>
+ </template>
+ </div>
+</template>
+
+<script lang="ts">
+import { computed, PropType, reactive, watch } from "vue";
+import { TaskCheckRun, TaskCheckStatus, TaskCheckType } from "../types";
+
+interface LocalState {
+ selectedTaskCheckRun?: TaskCheckRun;
+}
+
+export default {
+ name: "TaskCheckBadgeBar",
+ emits: ["select-task-check-run"],
+ props: {
+ taskCheckRunList: {
+ required: true,
+ type: Object as PropType<TaskCheckRun[]>,
+ },
+ showSelection: {
+ default: false,
+ type: Boolean,
+ },
+ selectedTaskCheckRun: {
+ type: Object as PropType<TaskCheckRun>,
+ },
+ },
+ components: {},
+ setup(props, { emit }) {
+ const state = reactive<LocalState>({
+ selectedTaskCheckRun: props.selectedTaskCheckRun,
+ });
+
+ watch(
+ () => props.selectedTaskCheckRun,
+ (curNew, _) => {
+ state.selectedTaskCheckRun = curNew;
+ }
+ );
+
+ // For a particular check type, only returns the most recent one
+ const filteredTaskCheckRunList = computed((): TaskCheckRun[] => {
+ const result: TaskCheckRun[] = [];
+ for (const run of props.taskCheckRunList) {
+ const index = result.findIndex((item) => item.type == run.type);
+ if (index >= 0 && result[index].createdTs < run.createdTs) {
+ result[index] = run;
+ } else {
+ result.push(run);
+ }
+ }
+ return result;
+ });
+
+ // Returns the most severe status
+ const taskCheckStatus = (taskCheckRun: TaskCheckRun): TaskCheckStatus => {
+ let value: TaskCheckStatus = "SUCCESS";
+ for (const result of taskCheckRun.result.resultList) {
+ if (result.status == "ERROR") {
+ return "ERROR";
+ }
+ if (result.status == "WARN") {
+ value = "WARN";
+ }
+ }
+ return value;
+ };
+
+ const selectTaskCheckRun = (taskCheckRun: TaskCheckRun) => {
+ emit("select-task-check-run", taskCheckRun);
+ };
+
+ return {
+ state,
+ filteredTaskCheckRunList,
+ taskCheckStatus,
+ selectTaskCheckRun,
+ };
+ },
+};
+</script>
diff --git a/frontend/src/components/TaskCheckBar.vue b/frontend/src/components/TaskCheckBar.vue
new file mode 100644
index 0000000000..2f125fe1e2
--- /dev/null
+++ b/frontend/src/components/TaskCheckBar.vue
@@ -0,0 +1,168 @@
+<template>
+ <div class="flex items-center space-x-2">
+ <button
+ type="button"
+ class="btn-small py-0.5"
+ :disabled="hasRunningTaskCheck"
+ @click.prevent="runChecks"
+ >
+ {{ hasRunningTaskCheck ? "Checking..." : "Run checks" }}
+ </button>
+ <TaskCheckBadgeBar
+ :taskCheckRunList="task.taskCheckRunList"
+ @select-task-check-run="
+ (checkRun) => {
+ viewCheckRunDetail(checkRun);
+ }
+ "
+ />
+ <BBModal
+ v-if="state.showModal"
+ :title="`Check result for '${task.name}'`"
+ @close="dimissModal"
+ >
+ <div class="divide-y divide-block-border space-y-4 w-208">
+ <TaskCheckBadgeBar
+ :taskCheckRunList="task.taskCheckRunList"
+ :showSelection="true"
+ :selectedTaskCheckRun="state.selectedTaskCheckRun"
+ @select-task-check-run="
+ (checkRun) => {
+ viewCheckRunDetail(checkRun);
+ }
+ "
+ />
+ <BBTabFilter
+ class="pt-4"
+ :tabItemList="tabItemList"
+ :selectedIndex="state.selectedTabIndex"
+ @select-index="
+ (index) => {
+ state.selectedTaskCheckRun = tabTaskCheckRunList[index];
+ state.selectedTabIndex = index;
+ }
+ "
+ />
+ <TaskCheckRunPanel :taskCheckRun="state.selectedTaskCheckRun" />
+ <div class="pt-4 flex justify-end">
+ <button
+ type="button"
+ class="btn-primary py-2 px-4"
+ @click.prevent="dimissModal"
+ >
+ Close
+ </button>
+ </div>
+ </div>
+ </BBModal>
+ </div>
+</template>
+
+<script lang="ts">
+import { computed, PropType, reactive } from "vue";
+import { Task, TaskCheckRun, TaskCheckStatus } from "../types";
+import TaskCheckBadgeBar from "./TaskCheckBadgeBar.vue";
+import TaskCheckRunPanel from "./TaskCheckRunPanel.vue";
+import { BBTabFilterItem } from "../bbkit/types";
+import { cloneDeep } from "lodash";
+import { humanizeTs } from "../utils";
+
+interface LocalState {
+ showModal: boolean;
+ selectedTaskCheckRun?: TaskCheckRun;
+ selectedTabIndex: number;
+}
+
+export default {
+ name: "TaskCheckBar",
+ emits: ["run-checks"],
+ props: {
+ task: {
+ required: true,
+ type: Object as PropType<Task>,
+ },
+ },
+ components: { TaskCheckBadgeBar, TaskCheckRunPanel },
+ setup(props, { emit }) {
+ const state = reactive<LocalState>({
+ showModal: false,
+ selectedTabIndex: 0,
+ });
+
+ const tabTaskCheckRunList = computed((): TaskCheckRun[] => {
+ if (!state.selectedTaskCheckRun) {
+ return [];
+ }
+
+ const list: TaskCheckRun[] = [];
+ for (const check of props.task.taskCheckRunList) {
+ if (check.type == state.selectedTaskCheckRun.type) {
+ list.push(check);
+ }
+ }
+ const clonedList = cloneDeep(list);
+ clonedList.sort(
+ (a: TaskCheckRun, b: TaskCheckRun) => b.createdTs - a.createdTs
+ );
+ return clonedList;
+ });
+
+ const tabItemList = computed((): BBTabFilterItem[] => {
+ return tabTaskCheckRunList.value.map((item, index) => {
+ return {
+ title: index == 0 ? "Latest" : humanizeTs(item.createdTs),
+ alert: false,
+ };
+ });
+ });
+
+ const hasRunningTaskCheck = computed((): boolean => {
+ for (const check of props.task.taskCheckRunList) {
+ if (check.status == "RUNNING") {
+ return true;
+ }
+ }
+ return false;
+ });
+
+ // Returns the most severe status
+ const taskCheckStatus = (taskCheckRun: TaskCheckRun): TaskCheckStatus => {
+ let value: TaskCheckStatus = "SUCCESS";
+ for (const result of taskCheckRun.result.resultList) {
+ if (result.status == "ERROR") {
+ return "ERROR";
+ }
+ if (result.status == "WARN") {
+ value = "WARN";
+ }
+ }
+ return value;
+ };
+
+ const viewCheckRunDetail = (taskCheckRun: TaskCheckRun) => {
+ state.selectedTaskCheckRun = taskCheckRun;
+ state.showModal = true;
+ };
+
+ const dimissModal = () => {
+ state.showModal = false;
+ state.selectedTaskCheckRun = undefined;
+ };
+
+ const runChecks = () => {
+ emit("run-checks", props.task);
+ };
+
+ return {
+ state,
+ tabTaskCheckRunList,
+ tabItemList,
+ hasRunningTaskCheck,
+ taskCheckStatus,
+ viewCheckRunDetail,
+ dimissModal,
+ runChecks,
+ };
+ },
+};
+</script>
diff --git a/frontend/src/components/TaskCheckRunTable.vue b/frontend/src/components/TaskCheckRunPanel.vue
similarity index 69%
rename from frontend/src/components/TaskCheckRunTable.vue
rename to frontend/src/components/TaskCheckRunPanel.vue
index 6ceff9bd32..2b520d9aab 100644
--- a/frontend/src/components/TaskCheckRunTable.vue
+++ b/frontend/src/components/TaskCheckRunPanel.vue
@@ -1,20 +1,14 @@
<template>
<BBTable
:columnList="columnList"
- :sectionDataSource="checkSectionList"
+ :dataSource="taskCheckRun.result.resultList"
:showHeader="false"
:leftBordered="true"
:rightBordered="true"
+ :topBordered="true"
+ :bottomBordered="true"
:rowClickable="false"
>
- <template v-slot:header>
- <BBTableHeaderCell
- :leftPadding="4"
- class="w-4"
- :title="columnList[0].title"
- />
- <BBTableHeaderCell class="w-48" :title="columnList[1].title" />
- </template>
<template v-slot:body="{ rowData: checkResult }">
<BBTableCell :leftPadding="4" class="table-cell w-12">
<div class="flex flex-row space-x-2">
@@ -71,36 +65,46 @@
</div>
</div>
</BBTableCell>
+ <BBTableCell class="table-cell w-16">
+ {{ checkResult.title }}
+ </BBTableCell>
<BBTableCell class="table-cell w-48">
{{ checkResult.content }}
</BBTableCell>
+ <BBTableCell class="table-cell w-16">
+ {{ humanizeTs(taskCheckRun.createdTs) }}
+ </BBTableCell>
</template>
</BBTable>
</template>
<script lang="ts">
-import { computed, PropType } from "vue";
-import PrincipalAvatar from "./PrincipalAvatar.vue";
-import { BBTableColumn, BBTableSectionDataSource } from "../bbkit/types";
-import { TaskCheckStatus, TaskCheckResult, TaskCheckRun } from "../types";
-import { humanizeTs } from "../utils";
+import { PropType } from "vue";
+import { BBTableColumn } from "../bbkit/types";
+import { TaskCheckStatus, TaskCheckRun } from "../types";
const columnList: BBTableColumn[] = [
{
title: "",
},
+ {
+ title: "Title",
+ },
{
title: "Detail",
},
+ {
+ title: "Created",
+ },
];
export default {
- name: "TaskCheckRunTable",
- components: { PrincipalAvatar },
+ name: "TaskCheckRunPanel",
+ components: {},
props: {
- taskCheckRunList: {
+ taskCheckRun: {
required: true,
- type: Object as PropType<TaskCheckRun[]>,
+ type: Object as PropType<TaskCheckRun>,
},
},
setup(props, ctx) {
@@ -115,29 +119,9 @@ export default {
}
};
- const checkSectionList = computed(() => {
- const sectionList: BBTableSectionDataSource<TaskCheckResult>[] = [];
- for (const taskCheck of props.taskCheckRunList) {
- let title = "";
- switch (taskCheck.type) {
- case "bb.task-check.database.statement.advise":
- title = "Statement lint";
- break;
- }
-
- sectionList.push({
- title: `${title} at ${humanizeTs(taskCheck.updatedTs)}`,
- list: taskCheck.result.resultList,
- });
- }
-
- return sectionList;
- });
-
return {
columnList,
statusIconClass,
- checkSectionList,
};
},
};
diff --git a/frontend/src/store/modules/task.ts b/frontend/src/store/modules/task.ts
index 80f8bd45f5..e724530860 100644
--- a/frontend/src/store/modules/task.ts
+++ b/frontend/src/store/modules/task.ts
@@ -207,6 +207,28 @@ const actions = {
return task;
},
+
+ async runChecks(
+ { dispatch, rootGetters }: any,
+ {
+ issueId,
+ pipelineId,
+ taskId,
+ }: {
+ issueId: IssueId;
+ pipelineId: PipelineId;
+ taskId: TaskId;
+ }
+ ) {
+ const data = (
+ await axios.post(`/api/pipeline/${pipelineId}/task/${taskId}/check`)
+ ).data;
+ const task = convertPartial(data.data, data.included, rootGetters);
+
+ dispatch("issue/fetchIssueById", issueId, { root: true });
+
+ return task;
+ },
};
const mutations = {};
diff --git a/frontend/src/types/pipeline/task.ts b/frontend/src/types/pipeline/task.ts
index 2ef4458903..24ebf23d11 100644
--- a/frontend/src/types/pipeline/task.ts
+++ b/frontend/src/types/pipeline/task.ts
@@ -127,7 +127,9 @@ export type TaskRun = {
export type TaskCheckRunStatus = "RUNNING" | "DONE" | "FAILED" | "CANCELED";
-export type TaskCheckType = "bb.task-check.database.statement.advise";
+export type TaskCheckType =
+ | "bb.task-check.database.statement.fake-advise"
+ | "bb.task-check.database.statement.syntax";
export type TaskCheckDatabaseStatementAdvisePayload = {
statement: string;
diff --git a/frontend/src/views/IssueDetail.vue b/frontend/src/views/IssueDetail.vue
index 258abe7cac..73ddf23ca3 100644
--- a/frontend/src/views/IssueDetail.vue
+++ b/frontend/src/views/IssueDetail.vue
@@ -135,8 +135,14 @@
/>
</div>
<div class="lg:hidden border-t border-block-border" />
- <div class="w-full py-6 pr-4">
+ <div class="w-full py-4 pr-4">
<section v-if="showIssueTaskStatementPanel" class="border-b mb-4">
+ <div v-if="!state.create" class="mb-4">
+ <TaskCheckBar
+ :task="selectedTask"
+ @run-checks="runTaskChecks"
+ />
+ </div>
<!-- The way this is written is awkward and is to workaround an issue in IssueTaskStatementPanel.
The statement panel is in non-edit mode when not creating the issue, and we use v-highlight
to apply syntax highlighting when the panel is in non-edit mode. However, the v-highlight
@@ -262,6 +268,7 @@ 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 {
UNKNOWN_ID,
Issue,
@@ -328,6 +335,7 @@ export default {
IssueSidebar,
IssueStatusTransitionButtonGroup,
PipelineSimpleFlow,
+ TaskCheckBar,
},
setup(props, ctx) {
@@ -817,6 +825,18 @@ export default {
});
};
+ 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
@@ -1091,10 +1111,12 @@ export default {
doRollback,
changeIssueStatus,
changeTaskStatus,
+ runTaskChecks,
currentPipelineType,
currentUser,
issueTemplate,
selectedStage,
+ selectedTask,
selectStageId,
statement,
rollbackStatement,