Skip to content

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

Add task check to the issue detail view

天舟83ce243cd4c5
diff --git a/api/task_check_run.go b/api/task_check_run.go
index 6e469d8340..4aa697bcd1 100644
--- a/api/task_check_run.go
+++ b/api/task_check_run.go
@@ -30,21 +30,21 @@ func (e TaskCheckRunStatus) String() string {
return "UNKNOWN"
}
-type TaskCheckLevel string
+type TaskCheckStatus string
const (
- TaskCheckLevelInfo TaskCheckLevel = "INFO"
- TaskCheckLevelWarn TaskCheckLevel = "WARN"
- TaskCheckLevelError TaskCheckLevel = "ERROR"
+ TaskCheckStatusSuccess TaskCheckStatus = "SUCCESS"
+ TaskCheckStatusWarn TaskCheckStatus = "WARN"
+ TaskCheckStatusError TaskCheckStatus = "ERROR"
)
-func (e TaskCheckLevel) String() string {
+func (e TaskCheckStatus) String() string {
switch e {
- case TaskCheckLevelInfo:
- return "INFO"
- case TaskCheckLevelWarn:
+ case TaskCheckStatusSuccess:
+ return "SUCCESS"
+ case TaskCheckStatusWarn:
return "WARN"
- case TaskCheckLevelError:
+ case TaskCheckStatusError:
return "ERROR"
}
return "UNKNOWN"
@@ -62,9 +62,9 @@ type TaskCheckDatabaseStatementAdvisePayload struct {
}
type TaskCheckResult struct {
- Level TaskCheckLevel `json:"level"`
- Title string `json:"title"`
- Content string `json:"content"`
+ Status TaskCheckStatus `json:"status"`
+ Title string `json:"title"`
+ Content string `json:"content"`
}
type TaskCheckRunResultPayload struct {
diff --git a/frontend/src/components/IssueStagePanel.vue b/frontend/src/components/IssueStagePanel.vue
index 0fd994e91a..9c4ecbd431 100644
--- a/frontend/src/components/IssueStagePanel.vue
+++ b/frontend/src/components/IssueStagePanel.vue
@@ -1,7 +1,7 @@
<template>
<div class="space-y-4">
<div v-for="(task, index) in stage.taskList" :key="index">
- <div class="flex flex-row items-center mb-2 space-x-1">
+ <div class="flex flex-row items-center space-x-1">
<svg
v-if="stage.taskList.length > 1 && activeTask.id == task.id"
class="w-5 h-5 text-info"
@@ -20,18 +20,42 @@
{{ task.name }}
</div>
</div>
- <TaskRunTable :taskRunList="task.taskRunList" />
+ <div class="mb-2">
+ <BBTabFilter
+ :tabList="tabList"
+ :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="task.taskCheckRunList"
+ />
</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 } from "../types";
import { activeTaskInStage } from "../utils";
-interface LocalState {}
+const RUN_TAB = 0;
+const CHECK_TAB = 1;
+
+interface LocalState {
+ selectedIndex: number;
+}
export default {
name: "IssueStagePanel",
@@ -41,20 +65,26 @@ export default {
type: Object as PropType<Stage>,
},
},
- components: { TaskRunTable },
+ components: { TaskCheckRunTable, TaskRunTable },
setup(props, { emit }) {
- const state = reactive<LocalState>({});
+ const state = reactive<LocalState>({
+ selectedIndex: RUN_TAB,
+ });
watch(
() => props.stage,
(curStage, _) => {}
);
+ const tabList = computed((): string[] => {
+ return ["Run", "Check"];
+ });
+
const activeTask = computed((): Task => {
return activeTaskInStage(props.stage);
});
- return { state, activeTask };
+ return { RUN_TAB, CHECK_TAB, state, tabList, activeTask };
},
};
</script>
diff --git a/frontend/src/components/TaskCheckRunTable.vue b/frontend/src/components/TaskCheckRunTable.vue
new file mode 100644
index 0000000000..6ceff9bd32
--- /dev/null
+++ b/frontend/src/components/TaskCheckRunTable.vue
@@ -0,0 +1,144 @@
+<template>
+ <BBTable
+ :columnList="columnList"
+ :sectionDataSource="checkSectionList"
+ :showHeader="false"
+ :leftBordered="true"
+ :rightBordered="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">
+ <div
+ class="
+ relative
+ w-5
+ h-5
+ flex flex-shrink-0
+ items-center
+ justify-center
+ rounded-full
+ select-none
+ "
+ :class="statusIconClass(checkResult.status)"
+ >
+ <template v-if="checkResult.status == 'SUCCESS'">
+ <svg
+ class="w-4 h-4"
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 20 20"
+ fill="currentColor"
+ aria-hidden="true"
+ >
+ <path
+ fill-rule="evenodd"
+ d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
+ clip-rule="evenodd"
+ />
+ </svg>
+ </template>
+ <template v-if="checkResult.status == 'WARN'">
+ <svg
+ class="h-4 w-4"
+ xmlns="http://www.w3.org/2000/svg"
+ fill="none"
+ viewBox="0 0 24 24"
+ stroke="currentColor"
+ aria-hidden="true"
+ >
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ stroke-width="2"
+ d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
+ ></path>
+ </svg>
+ </template>
+ <template v-else-if="checkResult.status == 'ERROR'">
+ <span class="text-white font-medium text-base" aria-hidden="true"
+ >!</span
+ >
+ </template>
+ </div>
+ </div>
+ </BBTableCell>
+ <BBTableCell class="table-cell w-48">
+ {{ checkResult.content }}
+ </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";
+
+const columnList: BBTableColumn[] = [
+ {
+ title: "",
+ },
+ {
+ title: "Detail",
+ },
+];
+
+export default {
+ name: "TaskCheckRunTable",
+ components: { PrincipalAvatar },
+ props: {
+ taskCheckRunList: {
+ required: true,
+ type: Object as PropType<TaskCheckRun[]>,
+ },
+ },
+ setup(props, ctx) {
+ const statusIconClass = (status: TaskCheckStatus) => {
+ switch (status) {
+ case "SUCCESS":
+ return "bg-success text-white";
+ case "WARN":
+ return "bg-warning text-white";
+ case "ERROR":
+ return "bg-error text-white";
+ }
+ };
+
+ 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,
+ };
+ },
+};
+</script>
diff --git a/frontend/src/store/modules/task.ts b/frontend/src/store/modules/task.ts
index 861e96e1e5..78adb4ad37 100644
--- a/frontend/src/store/modules/task.ts
+++ b/frontend/src/store/modules/task.ts
@@ -11,6 +11,7 @@ import {
Stage,
StageId,
Task,
+ TaskCheckRun,
TaskId,
TaskRun,
TaskState,
@@ -36,6 +37,30 @@ function convertTaskRun(
};
}
+function convertTaskCheckRun(
+ taskCheckRun: ResourceObject,
+ includedList: ResourceObject[],
+ rootGetters: any
+): TaskCheckRun {
+ const result = taskCheckRun.attributes.result
+ ? JSON.parse(taskCheckRun.attributes.result as string)
+ : undefined;
+
+ const payload = taskCheckRun.attributes.payload
+ ? JSON.parse(taskCheckRun.attributes.payload as string)
+ : undefined;
+
+ return {
+ ...(taskCheckRun.attributes as Omit<
+ TaskCheckRun,
+ "id" | "result" | "payload"
+ >),
+ id: parseInt(taskCheckRun.id),
+ result,
+ payload,
+ };
+}
+
function convertPartial(
task: ResourceObject,
includedList: ResourceObject[],
@@ -66,6 +91,25 @@ function convertPartial(
}
}
+ const taskCheckRunList: TaskCheckRun[] = [];
+ const taskCheckRunIdList = task.relationships!.taskCheckRun
+ .data as ResourceIdentifier[];
+ // Needs to iterate through taskIdList to maintain the order
+ for (const idItem of taskCheckRunIdList) {
+ for (const item of includedList || []) {
+ if (item.type == "taskCheckRun") {
+ if (idItem.id == item.id) {
+ const taskCheckRun: TaskCheckRun = convertTaskCheckRun(
+ item,
+ includedList,
+ rootGetters
+ );
+ taskCheckRunList.push(taskCheckRun);
+ }
+ }
+ }
+ }
+
const instanceId = (task.relationships!.instance.data as ResourceIdentifier)
.id;
let instance: Instance = empty("INSTANCE") as Instance;
@@ -98,6 +142,7 @@ function convertPartial(
| "instance"
| "database"
| "taskRunList"
+ | "taskCheckRunList"
| "pipeline"
| "stage"
>),
@@ -108,6 +153,7 @@ function convertPartial(
instance,
database,
taskRunList,
+ taskCheckRunList,
};
}
diff --git a/frontend/src/types/id.ts b/frontend/src/types/id.ts
index 74bda56c42..6cd03aeda7 100644
--- a/frontend/src/types/id.ts
+++ b/frontend/src/types/id.ts
@@ -27,6 +27,8 @@ export type TaskId = IdType;
export type TaskRunId = IdType;
+export type TaskCheckRunId = IdType;
+
export type ActivityId = IdType;
export type InboxId = IdType;
diff --git a/frontend/src/types/pipeline/task.ts b/frontend/src/types/pipeline/task.ts
index 649f7a7d96..2ef4458903 100644
--- a/frontend/src/types/pipeline/task.ts
+++ b/frontend/src/types/pipeline/task.ts
@@ -1,3 +1,4 @@
+import { TaskCheckRunId } from "..";
import { Database } from "../database";
import {
BackupId,
@@ -62,6 +63,7 @@ export type Task = {
// Related fields
taskRunList: TaskRun[];
+ taskCheckRunList: TaskCheckRun[];
pipeline: Pipeline;
stage: Stage;
@@ -122,3 +124,42 @@ export type TaskRun = {
comment: string;
payload?: TaskPayload;
};
+
+export type TaskCheckRunStatus = "RUNNING" | "DONE" | "FAILED" | "CANCELED";
+
+export type TaskCheckType = "bb.task-check.database.statement.advise";
+
+export type TaskCheckDatabaseStatementAdvisePayload = {
+ statement: string;
+};
+
+export type TaskCheckStatus = "SUCCESS" | "WARN" | "ERROR";
+
+export type TaskCheckResult = {
+ status: TaskCheckStatus;
+ title: string;
+ content: string;
+};
+
+export type TaskCheckRunResultPayload = {
+ resultList: TaskCheckResult[];
+};
+
+export type TaskCheckRun = {
+ id: TaskCheckRunId;
+
+ // Standard fields
+ creator: Principal;
+ createdTs: number;
+ updater: Principal;
+ updatedTs: number;
+
+ // Domain specific fields
+ taskId: TaskId;
+ name: string;
+ status: TaskCheckRunStatus;
+ type: TaskCheckType;
+ comment: string;
+ result: TaskCheckRunResultPayload;
+ payload?: TaskPayload;
+};
diff --git a/plugin/advisor/advisor.go b/plugin/advisor/advisor.go
index 5adaa9cd84..c1c054599a 100644
--- a/plugin/advisor/advisor.go
+++ b/plugin/advisor/advisor.go
@@ -10,17 +10,17 @@ import (
"go.uber.org/zap"
)
-type Severity string
+type Status string
const (
- Info Severity = "INFO"
- Warn Severity = "WARN"
- Error Severity = "ERROR"
+ Success Status = "SUCCESS"
+ Warn Status = "WARN"
+ Error Status = "ERROR"
)
-func (e Severity) String() string {
+func (e Status) String() string {
switch e {
- case Info:
+ case Success:
return "INFO"
case Warn:
return "WARN"
@@ -37,9 +37,9 @@ const (
)
type Advice struct {
- Severity Severity
- Title string
- Content string
+ Status Status
+ Title string
+ Content string
}
type AdvisorContext struct {
diff --git a/plugin/advisor/fake/fake_advisor.go b/plugin/advisor/fake/fake_advisor.go
index 9c0c38038f..1cb73a7c5c 100644
--- a/plugin/advisor/fake/fake_advisor.go
+++ b/plugin/advisor/fake/fake_advisor.go
@@ -22,19 +22,19 @@ type Advisor struct {
func (adv *Advisor) Check(ctx advisor.AdvisorContext, statement string) ([]advisor.Advice, error) {
return []advisor.Advice{
{
- Severity: advisor.Info,
- Title: "INFO check",
- Content: "Fake check returnings INFO result",
+ Status: advisor.Success,
+ Title: "INFO check",
+ Content: "Fake check returnings INFO result",
},
{
- Severity: advisor.Warn,
- Title: "WARN check",
- Content: "Fake check returnings WARN result",
+ Status: advisor.Warn,
+ Title: "WARN check",
+ Content: "Fake check returnings WARN result",
},
{
- Severity: advisor.Error,
- Title: "ERROR check",
- Content: "Fake check returnings ERROR result",
+ Status: advisor.Error,
+ Title: "ERROR check",
+ Content: "Fake check returnings ERROR result",
},
}, nil
}
diff --git a/server/task_check_executor_statement_lint.go b/server/task_check_executor_statement_lint.go
index 9b9ce6ad07..69262df077 100644
--- a/server/task_check_executor_statement_lint.go
+++ b/server/task_check_executor_statement_lint.go
@@ -34,18 +34,18 @@ func (exec *TaskCheckStatementLintExecutor) Run(ctx context.Context, server *Ser
result = []api.TaskCheckResult{}
for _, advice := range adviceList {
- level := api.TaskCheckLevelInfo
- switch advice.Severity {
- case advisor.Info:
- level = api.TaskCheckLevelInfo
+ status := api.TaskCheckStatusSuccess
+ switch advice.Status {
+ case advisor.Success:
+ status = api.TaskCheckStatusSuccess
case advisor.Warn:
- level = api.TaskCheckLevelWarn
+ status = api.TaskCheckStatusWarn
case advisor.Error:
- level = api.TaskCheckLevelError
+ status = api.TaskCheckStatusError
}
result = append(result, api.TaskCheckResult{
- Level: level,
+ Status: status,
Title: advice.Title,
Content: advice.Content,
})