Skip to content

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

Use a new Task type which is decoupled from the underlying API model

Tianzhou Chen501791a0bdfc
diff --git a/frontend/src/components/TaskTable.vue b/frontend/src/components/TaskTable.vue
index dc985b7492..bdacf2d219 100644
--- a/frontend/src/components/TaskTable.vue
+++ b/frontend/src/components/TaskTable.vue
@@ -8,7 +8,7 @@
<template v-slot:body="{ rowData: task }">
<BBTableCell :leftPadding="4" class="w-4 table-cell">
<TaskStatusIcon
- :taskStatus="task.attributes.status"
+ :taskStatus="task.status"
:stageStatus="activeStage(task).status"
/>
</BBTableCell>
@@ -20,35 +20,29 @@
<span
class="flex items-center justify-center px-1.5 py-0.5 rounded-full text-xs font-mono bg-gray-500 text-white"
>
- {{ task.attributes.category }}
+ {{ task.category }}
</span>
</BBTableCell>
<BBTableCell class="w-24 table-cell">
{{ activeEnvironmentName(task) }}
</BBTableCell>
<BBTableCell :leftPadding="1" class="truncate">
- {{ task.attributes.name }}
+ {{ task.name }}
</BBTableCell>
<BBTableCell class="w-12 hidden sm:table-cell">
<BBStepBar :stepList="stageList(task)" />
</BBTableCell>
<BBTableCell :rightPadding="4" class="w-32 hidden md:table-cell">
- {{ humanizeTs(task.attributes.lastUpdatedTs) }}
+ {{ humanizeTs(task.lastUpdatedTs) }}
</BBTableCell>
<BBTableCell class="w-32 hidden sm:table-cell">
<div class="flex flex-row items-center">
<BBAvatar
:size="'small'"
- :username="
- task.attributes.assignee
- ? task.attributes.assignee.name
- : 'Unassigned'
- "
+ :username="task.assignee ? task.assignee.name : 'Unassigned'"
/>
<span class="ml-2">{{
- task.attributes.assignee
- ? task.attributes.assignee.name
- : "Unassigned"
+ task.assignee ? task.assignee.name : "Unassigned"
}}</span>
</div>
</BBTableCell>
@@ -128,7 +122,7 @@ export default {
const router = useRouter();
const stageList = function (task: Task): BBStep[] {
- return task.attributes.stageProgressList.map((stageProgress) => {
+ return task.stageProgressList.map((stageProgress) => {
let stepStatus: BBStepStatus = "PENDING";
switch (stageProgress.status) {
case "PENDING":
@@ -163,7 +157,7 @@ export default {
const clickTask = function (section: number, row: number) {
const task = props.taskSectionList[section].list[row];
- router.push(`/task/${taskSlug(task.attributes.name, task.id)}`);
+ router.push(`/task/${taskSlug(task.name, task.id)}`);
};
return {
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 78f3f1233a..de6e47734b 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -227,8 +227,7 @@ const routes: Array<RouteRecordRaw> = [
if (slug.toLowerCase() == "new") {
return "New";
}
- return store.getters["task/taskById"](idFromSlug(slug))
- .attributes.name;
+ return store.getters["task/taskById"](idFromSlug(slug)).name;
},
},
components: {
diff --git a/frontend/src/store/modules/task.ts b/frontend/src/store/modules/task.ts
index ec021e5ef8..c4494628d2 100644
--- a/frontend/src/store/modules/task.ts
+++ b/frontend/src/store/modules/task.ts
@@ -6,8 +6,16 @@ import {
TaskNew,
TaskPatch,
TaskState,
+ ResourceObject,
} from "../../types";
+function convert(task: ResourceObject): Task {
+ return {
+ id: task.id,
+ ...(task.attributes as Omit<Task, "id">),
+ };
+}
+
const state: () => TaskState = () => ({
taskListByUser: new Map(),
taskById: new Map(),
@@ -25,13 +33,17 @@ const getters = {
const actions = {
async fetchTaskListForUser({ commit }: any, userId: UserId) {
- const taskList = (await axios.get(`/api/task?userid=${userId}`)).data.data;
+ const taskList = (
+ await axios.get(`/api/task?userid=${userId}`)
+ ).data.data.map((task: ResourceObject) => {
+ return convert(task);
+ });
commit("setTaskListForUser", { userId, taskList });
return taskList;
},
async fetchTaskById({ commit }: any, taskId: TaskId) {
- const task = (await axios.get(`/api/task/${taskId}`)).data.data;
+ const task = convert((await axios.get(`/api/task/${taskId}`)).data.data);
commit("setTaskById", {
taskId,
task,
@@ -40,11 +52,13 @@ const actions = {
},
async createTask({ commit }: any, newTask: TaskNew) {
- const createdTask = (
- await axios.post(`/api/task`, {
- data: newTask,
- })
- ).data.data;
+ const createdTask = convert(
+ (
+ await axios.post(`/api/task`, {
+ data: newTask,
+ })
+ ).data.data
+ );
commit("setTaskById", {
taskId: createdTask.id,
@@ -64,14 +78,16 @@ const actions = {
taskPatch: TaskPatch;
}
) {
- const updatedTask = (
- await axios.patch(`/api/task/${taskId}`, {
- data: {
- type: "taskpatch",
- attributes: taskPatch,
- },
- })
- ).data.data;
+ const updatedTask = convert(
+ (
+ await axios.patch(`/api/task/${taskId}`, {
+ data: {
+ type: "taskpatch",
+ attributes: taskPatch,
+ },
+ })
+ ).data.data
+ );
commit("setTaskById", {
taskId: taskId,
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index 2588d0b1e0..3783a40c4d 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -9,6 +9,8 @@ export type UserId = string;
// For now, Principal is equal to UserId, in the future it may contain other id such as application, bot etc.
export type PrincipalId = UserId;
+export type MemberId = string;
+
export type StageId = string;
export type TaskId = string;
@@ -56,6 +58,7 @@ export type Principal = {
export type RoleType = "OWNER" | "DBA" | "DEVELOPER";
export type Member = {
+ id: MemberId;
createdTs: number;
lastUpdatedTs: number;
role: RoleType;
@@ -107,37 +110,34 @@ export type TaskStatus = "OPEN" | "DONE" | "CANCELED";
export type TaskPayload = { [key: string]: any };
-export type Task = ResourceObject & {
- attributes: {
- name: string;
- createdTs: number;
- lastUpdatedTs: number;
- status: TaskStatus;
- category: "DDL" | "DML" | "OPS";
- type: TaskType;
- description: string;
- stageProgressList: StageProgress[];
- creatorId: PrincipalId;
- assigneeId: PrincipalId;
- creator: UserDisplay;
- assignee?: UserDisplay;
- subscriberIdList: Array<string>;
- payload: TaskPayload;
- };
+export type Task = {
+ id: TaskId;
+ name: string;
+ createdTs: number;
+ lastUpdatedTs: number;
+ status: TaskStatus;
+ category: "DDL" | "DML" | "OPS";
+ type: TaskType;
+ description: string;
+ stageProgressList: StageProgress[];
+ creatorId: PrincipalId;
+ assigneeId: PrincipalId;
+ creator: UserDisplay;
+ assignee?: UserDisplay;
+ subscriberIdList: Array<string>;
+ payload: TaskPayload;
};
-export type TaskNew = Omit<ResourceObject, "id"> & {
- attributes: {
- name: string;
- type: TaskType;
- description: string;
- stageProgressList: StageProgress[];
- creatorId: PrincipalId;
- assigneeId: PrincipalId;
- creator: UserDisplay;
- assignee?: UserDisplay;
- payload: TaskPayload;
- };
+export type TaskNew = {
+ name: string;
+ type: TaskType;
+ description: string;
+ stageProgressList: StageProgress[];
+ creatorId: PrincipalId;
+ assigneeId: PrincipalId;
+ creator: UserDisplay;
+ assignee?: UserDisplay;
+ payload: TaskPayload;
};
export type TaskPatch = {
diff --git a/frontend/src/utils/task.ts b/frontend/src/utils/task.ts
index dad8e57894..bfee7610bd 100644
--- a/frontend/src/utils/task.ts
+++ b/frontend/src/utils/task.ts
@@ -2,7 +2,7 @@ import { Task, StageProgress, EnvironmentId } from "../types";
import { templateForType } from "../plugins";
export function activeStage(task: Task): StageProgress {
- for (const stageProgress of task.attributes.stageProgressList) {
+ for (const stageProgress of task.stageProgressList) {
if (
stageProgress.status === "PENDING" ||
stageProgress.status === "RUNNING" ||
@@ -13,9 +13,7 @@ export function activeStage(task: Task): StageProgress {
return stageProgress;
}
}
- return task.attributes.stageProgressList[
- task.attributes.stageProgressList.length - 1
- ];
+ return task.stageProgressList[task.stageProgressList.length - 1];
}
export function activeStageIsRunning(task: Task): boolean {
@@ -27,13 +25,13 @@ export function activeEnvironmentId(task: Task): EnvironmentId | null {
if (stageProgress.type === "ENVIRONMENT") {
return stageProgress.environmentId!;
}
- const taskTemplate = templateForType(task.attributes.type);
+ const taskTemplate = templateForType(task.type);
if (taskTemplate) {
const inputFieldList =
taskTemplate.fieldList?.filter((item) => item.category === "INPUT") || [];
for (const field of inputFieldList) {
if (field.type === "Environment") {
- return task.attributes.payload[field.id];
+ return task.payload[field.id];
}
}
}
diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue
index 87f0db2ac7..4d1a87ed03 100644
--- a/frontend/src/views/Home.vue
+++ b/frontend/src/views/Home.vue
@@ -16,7 +16,7 @@
{
title: 'Recently Closed',
list: filteredList(state.closeList).sort((a, b) => {
- return b.attributes.lastUpdatedTs - a.attributes.lastUpdatedTs;
+ return b.lastUpdatedTs - a.lastUpdatedTs;
}),
},
]"
@@ -68,26 +68,21 @@ export default {
state.closeList = [];
for (const task of taskList) {
// "OPEN"
- if (task.attributes.status === "OPEN") {
+ if (task.status === "OPEN") {
if (
- task.attributes.creatorId === currentUser.id ||
- task.attributes.assigneeId === currentUser.id
+ task.creatorId === currentUser.id ||
+ task.assigneeId === currentUser.id
) {
state.attentionList.push(task);
- } else if (
- task.attributes.subscriberIdList.includes(currentUser.id)
- ) {
+ } else if (task.subscriberIdList.includes(currentUser.id)) {
state.subscribeList.push(task);
}
}
// "DONE" or "CANCELED"
- else if (
- task.attributes.status === "DONE" ||
- task.attributes.status === "CANCELED"
- ) {
+ else if (task.status === "DONE" || task.status === "CANCELED") {
if (
- task.attributes.creator.id === currentUser.id ||
- task.attributes.assignee?.id === currentUser.id
+ task.creator.id === currentUser.id ||
+ task.assignee?.id === currentUser.id
) {
state.closeList.push(task);
}
@@ -134,7 +129,7 @@ export default {
const aStatusOrder = statusOrder(activeStage(a).status);
const bStatusOrder = statusOrder(activeStage(b).status);
if (aStatusOrder == bStatusOrder) {
- return b.attributes.lastUpdatedTs - a.attributes.lastUpdatedTs;
+ return b.lastUpdatedTs - a.lastUpdatedTs;
}
return aStatusOrder - bStatusOrder;
};
diff --git a/frontend/src/views/TaskDescription.vue b/frontend/src/views/TaskDescription.vue
index 78edf07740..a3035cab44 100644
--- a/frontend/src/views/TaskDescription.vue
+++ b/frontend/src/views/TaskDescription.vue
@@ -33,7 +33,7 @@
v-if="state.edit"
type="button"
class="mt-0.5 px-3 border border-control-border rounded-sm text-control bg-control-bg hover:bg-control-bg-hover disabled:bg-control-bg disabled:opacity-50 disabled:cursor-not-allowed text-sm leading-5 font-normal focus:ring-control focus:outline-none focus-visible:ring-2 focus:ring-offset-2"
- :disabled="editDescription == task.attributes.description"
+ :disabled="editDescription == task.description"
@click.prevent="saveEdit"
>
Save
@@ -101,7 +101,7 @@ export default {
},
components: {},
setup(props, { emit }) {
- const editDescription = ref(props.task.attributes.description);
+ const editDescription = ref(props.task.description);
const editDescriptionTextArea = ref();
const state = reactive<LocalState>({
@@ -116,7 +116,7 @@ export default {
if (e.code == "Escape") {
cancelEdit();
} else if (e.code == "Enter" && e.metaKey) {
- if (editDescription.value != props.task.attributes.description) {
+ if (editDescription.value != props.task.description) {
saveEdit();
}
}
@@ -155,7 +155,7 @@ export default {
);
const beginEdit = () => {
- editDescription.value = props.task.attributes.description;
+ editDescription.value = props.task.description;
state.edit = true;
nextTick(() => {
editDescriptionTextArea.value.focus();
@@ -165,7 +165,7 @@ export default {
const saveEdit = () => {
emit("update-description", editDescription.value, (updatedTask: Task) => {
state.edit = false;
- editDescription.value = updatedTask.attributes.description;
+ editDescription.value = updatedTask.description;
nextTick(() => {
sizeToFit(editDescriptionTextArea.value);
});
@@ -174,7 +174,7 @@ export default {
const cancelEdit = () => {
state.edit = false;
- editDescription.value = props.task.attributes.description;
+ editDescription.value = props.task.description;
nextTick(() => {
sizeToFit(editDescriptionTextArea.value);
});
diff --git a/frontend/src/views/TaskDetail.vue b/frontend/src/views/TaskDetail.vue
index a01307077d..11d151dabf 100644
--- a/frontend/src/views/TaskDetail.vue
+++ b/frontend/src/views/TaskDetail.vue
@@ -302,7 +302,7 @@ export default {
title: "",
});
- const taskTemplate = templateForType(state.task.attributes.type)!;
+ const taskTemplate = templateForType(state.task.type)!;
const outputFieldList =
taskTemplate.fieldList?.filter((item) => item.category == "OUTPUT") || [];
@@ -345,7 +345,7 @@ export default {
// )) {
// if (
// field.required &&
- // isEmpty(state.task.attributes.payload[field.id])
+ // isEmpty(state.task.payload[field.id])
// ) {
// return;
// }
@@ -358,20 +358,6 @@ export default {
};
const updateAssignee = (newAssignee: UserDisplay) => {
- // if (newStatus === "DONE") {
- // if (template.fieldList) {
- // for (const field of template.fieldList.filter(
- // (item) => item.category == "OUTPUT"
- // )) {
- // if (
- // field.required &&
- // isEmpty(state.task.attributes.payload[field.id])
- // ) {
- // return;
- // }
- // }
- // }
- // }
patchTask({
assignee: newAssignee,
});
@@ -381,10 +367,10 @@ export default {
if (field.preprocessor) {
value = field.preprocessor(value);
}
- state.task.attributes.payload[field.id] = value;
+ state.task.payload[field.id] = value;
if (!state.new) {
patchTask({
- payload: state.task.attributes.payload,
+ payload: state.task.payload,
});
}
};
@@ -393,9 +379,7 @@ export default {
store
.dispatch("task/createTask", state.task)
.then((createdTask) => {
- router.push(
- `/task/${taskSlug(createdTask.attributes.name, createdTask.id)}`
- );
+ router.push(`/task/${taskSlug(createdTask.name, createdTask.id)}`);
})
.catch((error) => {
console.log(error);
@@ -413,7 +397,7 @@ export default {
...taskPatch,
producer: {
id: currentUser.id,
- name: currentUser.attributes.name,
+ name: currentUser.name,
},
},
})
@@ -457,10 +441,7 @@ export default {
for (const field of taskTemplate.fieldList.filter(
(item) => item.category == "INPUT"
)) {
- if (
- field.required &&
- isEmpty(state.task.attributes.payload[field.id])
- ) {
+ if (field.required && isEmpty(state.task.payload[field.id])) {
return false;
}
}
@@ -473,9 +454,9 @@ export default {
const applicableStageTransitionList = () => {
return STAGE_TRANSITION_LIST.filter((transition) => {
const actionListForRole =
- currentUser.id === state.task.attributes.creatorId
+ currentUser.id === state.task.creatorId
? CREATOR_APPLICABLE_STAGE_ACTION_LIST
- : currentUser.id === state.task.attributes.assigneeId
+ : currentUser.id === state.task.assigneeId
? ASSIGNEE_APPLICABLE_STAGE_ACTION_LIST
: GUEST_APPLICABLE_STAGE_ACTION_LIST;
const stage = activeStage(state.task as Task);
@@ -499,7 +480,7 @@ export default {
};
const showTaskFlowBar = computed(() => {
- return !state.new && state.task.attributes.stageProgressList.length > 1;
+ return !state.new && state.task.stageProgressList.length > 1;
});
const showTaskOutputPanel = computed(() => {
diff --git a/frontend/src/views/TaskFlow.vue b/frontend/src/views/TaskFlow.vue
index 9fbe3f3788..beb6b94d8d 100644
--- a/frontend/src/views/TaskFlow.vue
+++ b/frontend/src/views/TaskFlow.vue
@@ -131,7 +131,7 @@ export default {
components: {},
setup(props, ctx) {
const stageList = computed<FlowItem[]>(() => {
- return props.task.attributes.stageProgressList.map((stageProgress) => {
+ return props.task.stageProgressList.map((stageProgress) => {
return {
id: stageProgress.id,
title: stageProgress.name,
diff --git a/frontend/src/views/TaskHighlightPanel.vue b/frontend/src/views/TaskHighlightPanel.vue
index 0d00e90db6..ee33af4a4e 100644
--- a/frontend/src/views/TaskHighlightPanel.vue
+++ b/frontend/src/views/TaskHighlightPanel.vue
@@ -6,24 +6,24 @@
<div class="flex items-center">
<TaskStatusIcon
v-if="!$props.new"
- :taskStatus="task.attributes.status"
+ :taskStatus="task.status"
:stageStatus="activeStage(task).status"
/>
<p
class="ml-2 text-xl font-bold leading-7 text-main whitespace-nowrap md:w-96 lg:w-160 truncate"
>
- {{ task.attributes.name }}
+ {{ task.name }}
</p>
</div>
<div v-if="!$props.new">
<p class="mt-2 text-sm text-gray-500">
#{{ task.id }} opened by
<span href="#" class="font-medium text-control">{{
- task.attributes.creator.name
+ task.creator.name
}}</span>
at
<span href="#" class="font-medium text-control">{{
- moment(task.attributes.lastUpdatedTs).format("LLL")
+ moment(task.lastUpdatedTs).format("LLL")
}}</span>
</p>
</div>
diff --git a/frontend/src/views/TaskOutputPanel.vue b/frontend/src/views/TaskOutputPanel.vue
index 1b5075217a..9ff0256f67 100644
--- a/frontend/src/views/TaskOutputPanel.vue
+++ b/frontend/src/views/TaskOutputPanel.vue
@@ -16,8 +16,8 @@
:name="field.id"
:value="
field.preprocessor
- ? field.preprocessor(task.attributes.payload[field.id])
- : task.attributes.payload[field.id]
+ ? field.preprocessor(task.payload[field.id])
+ : task.payload[field.id]
"
@input="$emit('update-custom-field', field, $event.target.value)"
/>
diff --git a/frontend/src/views/TaskSidebar.vue b/frontend/src/views/TaskSidebar.vue
index b9df0299ed..354818ba1e 100644
--- a/frontend/src/views/TaskSidebar.vue
+++ b/frontend/src/views/TaskSidebar.vue
@@ -7,7 +7,7 @@
<div class="z-10 w-full">
<TaskStatusSelect
:disabled="activeStageIsRunning(task)"
- :selectedStatus="task.attributes.status"
+ :selectedStatus="task.status"
@change-status="
(value) => {
$emit('update-task-status', value);
@@ -20,7 +20,7 @@
<h2 class="flex items-center textlabel w-36">Assignee</h2>
<div class="w-full">
<PrincipalSelect
- :selectedId="task.attributes.assignee?.id"
+ :selectedId="task.assignee?.id"
@select-principal="
(value) => {
$emit('update-assignee', value);
@@ -152,13 +152,10 @@
<ul class="w-full">
<li class="flex justify-start items-center space-x-2">
<div class="flex-shrink-0">
- <BBAvatar
- :size="'small'"
- :username="task.attributes.creator.name"
- />
+ <BBAvatar :size="'small'" :username="task.creator.name" />
</div>
<div class="text-sm font-medium text-main">
- {{ task.attributes.creator.name }}
+ {{ task.creator.name }}
</div>
</li>
</ul>
@@ -166,13 +163,13 @@
<div class="flex flex-row space-x-2">
<h2 class="textlabel w-36">Updated</h2>
<span class="textfield w-full">
- {{ moment(task.attributes.lastUpdatedTs).format("LLL") }}</span
+ {{ moment(task.lastUpdatedTs).format("LLL") }}</span
>
</div>
<div class="flex flex-row space-x-2">
<h2 class="textlabel w-36">Created</h2>
<span class="textfield w-full">
- {{ moment(task.attributes.createdTs).format("LLL") }}</span
+ {{ moment(task.createdTs).format("LLL") }}</span
>
</div>
</div>
@@ -258,8 +255,8 @@ export default {
const fieldValue = (field: TaskField): string => {
return field.preprocessor
- ? field.preprocessor(props.task.attributes.payload[field.id])
- : props.task.attributes.payload[field.id];
+ ? field.preprocessor(props.task.payload[field.id])
+ : props.task.payload[field.id];
};
const trySaveCustomTextField = (customFieldIndex: number) => {