Skip to content

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

Create task hookup and the corresponding UI transition

Tianzhou Chen8677a6937d7e
diff --git a/frontend/src/miragejs/routes/index.js b/frontend/src/miragejs/routes/index.js
index 453c6fc36a..63c5c78260 100644
--- a/frontend/src/miragejs/routes/index.js
+++ b/frontend/src/miragejs/routes/index.js
@@ -78,8 +78,11 @@ export default function routes() {
});
this.post("/task", function (schema, request) {
+ const ts = Date.now();
const newTask = {
...this.normalizedRequestAttrs("task"),
+ createdTs: ts,
+ lastUpdatedTs: ts,
workspaceId: WORKSPACE_ID,
};
return schema.tasks.create(newTask);
@@ -87,7 +90,9 @@ export default function routes() {
this.patch("/task/:taskId", function (schema, request) {
const attrs = this.normalizedRequestAttrs("task");
- return schema.tasks.find(request.params.environmentId).update(attrs);
+ return schema.tasks
+ .find(request.params.environmentId)
+ .update({ ...attrs, lastUpdatedTs: Date.now() });
});
// environment
diff --git a/frontend/src/store/modules/task.ts b/frontend/src/store/modules/task.ts
index d59e82d244..c013daa3c8 100644
--- a/frontend/src/store/modules/task.ts
+++ b/frontend/src/store/modules/task.ts
@@ -1,5 +1,5 @@
import axios from "axios";
-import { UserId, TaskId, Task, TaskState } from "../../types";
+import { UserId, TaskId, Task, TaskNew, TaskState } from "../../types";
const state: () => TaskState = () => ({
taskListByUser: new Map(),
@@ -31,6 +31,36 @@ const actions = {
});
return task;
},
+
+ async createTask({ commit }: any, newTask: TaskNew) {
+ const createdTask = (
+ await axios.post(`/api/task`, {
+ data: newTask,
+ })
+ ).data.data;
+
+ commit("setTaskById", {
+ taskId: createdTask.id,
+ task: createdTask,
+ });
+
+ return createdTask;
+ },
+
+ async patchTask({ commit }: any, task: Task) {
+ const updatedTask = (
+ await axios.patch(`/api/task/${task.id}`, {
+ data: task,
+ })
+ ).data.data;
+
+ commit("setTaskById", {
+ taskId: task.id,
+ task: updatedTask,
+ });
+
+ return updatedTask;
+ },
};
const mutations = {
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index 0447969214..cee35a2ab7 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -24,7 +24,11 @@ export type CommandId = string;
export type CommandRegisterId = string;
// Persistent State Models
-export type User = ResourceObject & {};
+export type User = ResourceObject & {
+ attributes: {
+ name: string;
+ };
+};
export type NewUser = Omit<User, "id">;
export type Bookmark = ResourceObject & {};
@@ -33,13 +37,20 @@ export type NewBookmark = Omit<Bookmark, "id">;
export type Activity = ResourceObject & {};
export type ActivityNew = Omit<Activity, "id">;
+type TaskTypeGeneral = "bytebase.general";
+
+type TaskTypeDataSource = "bytebase.datasource.create";
+
+export type TaskType = TaskTypeGeneral & TaskTypeDataSource;
+
export type Task = ResourceObject & {
attributes: {
name: string;
createdTs: number;
lastUpdatedTs: number;
status: "PENDING" | "RUNNING" | "DONE" | "FAILED" | "CANCELED";
- type: "DDL" | "DML" | "OPS";
+ category: "DDL" | "DML" | "OPS";
+ type: TaskType;
content: string;
currentStageId: string;
stageProgressList: {
@@ -58,15 +69,27 @@ export type Task = ResourceObject & {
id: string;
name: string;
};
+ subscriberIdList: Array<string>;
+ payload: any;
+ };
+};
+
+export type TaskNew = Omit<ResourceObject, "id"> & {
+ attributes: {
+ name: string;
+ type: string;
+ content: string;
+ creator: {
+ id: string;
+ name: string;
+ };
assignee: {
id: string;
name: string;
};
- subscriberIdList: Array<string>;
payload: any;
};
};
-export type TaskNew = Omit<Task, "id">;
export type Environment = ResourceObject & {
attributes: {
diff --git a/frontend/src/views/TaskDetail.vue b/frontend/src/views/TaskDetail.vue
index 79cf6a7423..0fdba53185 100644
--- a/frontend/src/views/TaskDetail.vue
+++ b/frontend/src/views/TaskDetail.vue
@@ -14,7 +14,10 @@
</div>
<!-- Flow -->
- <TaskFlow v-if="!state.new" :task="state.task" />
+ <TaskFlow
+ v-if="state.task.stageProgressList?.length > 0"
+ :task="state.task"
+ />
<div v-else class="border-t border-block-border" />
<!-- Main Content -->
@@ -53,29 +56,30 @@
</template>
<script lang="ts">
-import { onMounted, reactive, inject } from "vue";
+import { onMounted, watchEffect, reactive, inject } from "vue";
import { useStore } from "vuex";
+import { useRouter } from "vue-router";
import isEmpty from "lodash-es/isEmpty";
import { UserStateSymbol } from "../components/ProvideUser.vue";
-import { humanize } from "../utils";
+import { humanize, idFromSlug, taskSlug } from "../utils";
import TaskActivityPanel from "../views/TaskActivityPanel.vue";
import TaskFlow from "../views/TaskFlow.vue";
import TaskHighlightPanel from "../views/TaskHighlightPanel.vue";
import TaskContent from "../views/TaskContent.vue";
import TaskContentBar from "../views/TaskContentBar.vue";
import TaskSidebar from "../views/TaskSidebar.vue";
-import { User, Task } from "../types";
+import { User, Task, TaskNew } from "../types";
import { taskTemplateList, TaskField } from "../plugins";
interface LocalState {
new: boolean;
- task: Task;
+ task: Task | TaskNew;
}
export default {
name: "TaskDetail",
props: {
- taskId: {
+ taskSlug: {
required: true,
type: String,
},
@@ -91,45 +95,44 @@ export default {
setup(props, ctx) {
const store = useStore();
+ const router = useRouter();
const currentUser = inject<User>(UserStateSymbol);
- const state = reactive<LocalState>({
- new: props.taskId.toLowerCase() == "new",
- task:
- props.taskId.toLowerCase() == "new"
- ? {
- type: "task",
- attributes: {
- name: "New Task",
- status: "PENDING",
- type: "bytebase.datasource.create",
- content: "Need a new database",
- currentStageId: "1",
- stageProgressList: [
- {
- stageId: "1",
- stageName: "Request Database",
- status: "CREATED",
+ const refreshState = () => {
+ return {
+ new: props.taskSlug.toLowerCase() == "new",
+ task:
+ props.taskSlug.toLowerCase() == "new"
+ ? {
+ type: "task",
+ attributes: {
+ name: "New General Task",
+ type: "bytebase.general",
+ content: "blablabla",
+ creator: {
+ id: currentUser!.id,
+ name: currentUser!.attributes.name,
},
- ],
- creator: {
- id: currentUser!.id,
- name: currentUser!.attributes.name,
},
- assignee: {
- id: currentUser!.id,
- name: currentUser!.attributes.name,
- },
- payload: {
- 1: "mydb",
- },
- },
- }
- : JSON.parse(
- JSON.stringify(store.getters["task/taskById"](props.taskId))
- ),
- });
+ }
+ : JSON.parse(
+ JSON.stringify(
+ store.getters["task/taskById"](idFromSlug(props.taskSlug))
+ )
+ ),
+ };
+ };
+
+ const state = reactive<LocalState>(refreshState());
+
+ const prepareTask = () => {
+ const updatededState = refreshState();
+ state.new = updatededState.new;
+ state.task = updatededState.task;
+ };
+
+ watchEffect(prepareTask);
const template = taskTemplateList.find(
(template) => template.type == state.task.attributes.type
@@ -152,6 +155,16 @@ export default {
const doCreate = () => {
console.log("Create", state.task);
+ store
+ .dispatch("task/createTask", state.task)
+ .then((createdTask) => {
+ router.push(
+ `/task/${taskSlug(createdTask.attributes.name, createdTask.id)}`
+ );
+ })
+ .catch((error) => {
+ console.log(error);
+ });
};
const doClickHighlightPanelButton = (buttonIndex: number) => {
diff --git a/frontend/src/views/TaskHighlightPanel.vue b/frontend/src/views/TaskHighlightPanel.vue
index 821788b3ef..7dce834832 100644
--- a/frontend/src/views/TaskHighlightPanel.vue
+++ b/frontend/src/views/TaskHighlightPanel.vue
@@ -51,7 +51,7 @@
</template>
<script lang="ts">
-import { PropType, reactive } from "vue";
+import { PropType, watchEffect, reactive } from "vue";
import isEmpty from "lodash-es/isEmpty";
import { Task } from "../types";
@@ -81,6 +81,12 @@ export default {
new: isEmpty(props.task.id),
});
+ const refreshState = () => {
+ state.new = isEmpty(props.task.id);
+ };
+
+ watchEffect(refreshState);
+
return { state };
},
};
diff --git a/frontend/src/views/TaskSidebar.vue b/frontend/src/views/TaskSidebar.vue
index ac64710933..f024e32062 100644
--- a/frontend/src/views/TaskSidebar.vue
+++ b/frontend/src/views/TaskSidebar.vue
@@ -6,14 +6,34 @@
<h2 class="textlabel">Assignee</h2>
<ul class="mt-3 space-y-3">
<li class="flex justify-start items-center space-x-2">
- <div class="flex-shrink-0">
+ <div v-if="task.attributes.assignee" class="flex-shrink-0">
<BBAvatar
:size="'small'"
:username="task.attributes.assignee.name"
/>
</div>
<div class="text-sm font-medium text-gray-900">
- {{ task.attributes.assignee.name }}
+ {{
+ task.attributes.assignee
+ ? task.attributes.assignee.name
+ : "Unassigned"
+ }}
+ </div>
+ </li>
+ </ul>
+ </div>
+ <div>
+ <h2 class="textlabel">Reporter</h2>
+ <ul class="mt-3 space-y-3">
+ <li class="flex justify-start items-center space-x-2">
+ <div class="flex-shrink-0">
+ <BBAvatar
+ :size="'small'"
+ :username="task.attributes.creator.name"
+ />
+ </div>
+ <div class="text-sm font-medium text-gray-900">
+ {{ task.attributes.creator.name }}
</div>
</li>
</ul>
@@ -98,7 +118,7 @@
</template>
<script lang="ts">
-import { PropType, reactive } from "vue";
+import { PropType, watchEffect, reactive } from "vue";
import isEmpty from "lodash-es/isEmpty";
import { taskTemplateList } from "../plugins";
import { Task } from "../types";
@@ -122,6 +142,12 @@ export default {
new: isEmpty(props.task.id),
});
+ const refreshState = () => {
+ state.new = isEmpty(props.task.id);
+ };
+
+ watchEffect(refreshState);
+
const template = taskTemplateList.find(
(template) => template.type == props.task.attributes.type
);