Skip to content

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

Basic UI support for extended fields in task detail page.

Tianzhou Chendc3d6c88b30b
diff --git a/frontend/src/components/TaskTable.vue b/frontend/src/components/TaskTable.vue
index 3b06dfb2e3..311c70f052 100644
--- a/frontend/src/components/TaskTable.vue
+++ b/frontend/src/components/TaskTable.vue
@@ -74,7 +74,7 @@
<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.type }}
+ {{ task.attributes.category }}
</span>
</BBTableCell>
<BBTableCell class="w-24 table-cell">
diff --git a/frontend/src/miragejs/factories/task.js b/frontend/src/miragejs/factories/task.js
index b2c062d9a1..80f0597149 100644
--- a/frontend/src/miragejs/factories/task.js
+++ b/frontend/src/miragejs/factories/task.js
@@ -15,7 +15,7 @@ export default {
status() {
return "RUNNING";
},
- type() {
+ category() {
let dice = Math.random();
if (dice < 0.33) {
return "DDL";
@@ -25,6 +25,9 @@ export default {
return "OPS";
}
},
+ type() {
+ return "bytebase.datasource.create";
+ },
content() {
return faker.fake("{{lorem.paragraphs}}");
},
@@ -55,5 +58,14 @@ export default {
subscriberIdList() {
return new Array();
},
+ payload() {
+ return {
+ type: "bytebase.datasource.create",
+ fieldList: {
+ // Requested Database name
+ 1: "Mydb",
+ },
+ };
+ },
}),
};
diff --git a/frontend/src/plugins/index.ts b/frontend/src/plugins/index.ts
new file mode 100644
index 0000000000..c83069421f
--- /dev/null
+++ b/frontend/src/plugins/index.ts
@@ -0,0 +1,2 @@
+export * from "./task/template";
+export * from "./types";
diff --git a/frontend/src/plugins/task/template.ts b/frontend/src/plugins/task/template.ts
new file mode 100644
index 0000000000..366de53dee
--- /dev/null
+++ b/frontend/src/plugins/task/template.ts
@@ -0,0 +1,19 @@
+import { TaskTemplate } from "../types";
+
+export const taskTemplateList: TaskTemplate[] = [
+ {
+ type: "bytebase.datasource.create",
+ fieldList: [
+ {
+ id: 1,
+ slug: "db",
+ name: "Database Name",
+ type: "String",
+ required: true,
+ preprocessor: (name: string): string => {
+ return name.toLowerCase();
+ },
+ },
+ ],
+ },
+];
diff --git a/frontend/src/plugins/types.ts b/frontend/src/plugins/types.ts
new file mode 100644
index 0000000000..91db14b0c1
--- /dev/null
+++ b/frontend/src/plugins/types.ts
@@ -0,0 +1,30 @@
+export type TaskFieldType = "String";
+
+export type TaskField = {
+ // Used as the key to store the data. This must NOT be changed after
+ // in use, otherwise, it will cause data loss/corruption. Its design
+ // is very similar to the message field id in Protocol Buffers.
+ id: number;
+ // Used as the key to generate UI artifacts (e.g. query parameter).
+ // Though changing it won't have catastrophic consequence like changing
+ // id, we strongly recommend NOT to change it as well, otherwise, previous
+ // generated artifacts based on this info such as URL would become invalid.
+ // slug will be formmatted to lowercase and replace any space with "-",
+ // e.g. "foo Bar" => "foo-bar"
+ slug: string;
+ // The display name. OK to change.
+ name: string;
+ // Field type. This must NOT be changed after in use. Similar to id field.
+ type: TaskFieldType;
+ // Whether the field is required.
+ required: boolean;
+ // Preprocessor such as enforcing lowercase.
+ preprocessor?: (item: any) => any;
+ // Placeholder displayed on UI.
+ placeholder?: string;
+};
+
+export type TaskTemplate = {
+ type: string;
+ fieldList: TaskField[];
+};
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index af881f6a1f..6390a57c0f 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -63,6 +63,7 @@ export type Task = ResourceObject & {
name: string;
};
subscriberIdList: Array<string>;
+ payload: any;
};
};
export type TaskNew = Omit<Task, "id">;
diff --git a/frontend/src/views/TaskDetail.vue b/frontend/src/views/TaskDetail.vue
index 11da9b0a02..79cf6a7423 100644
--- a/frontend/src/views/TaskDetail.vue
+++ b/frontend/src/views/TaskDetail.vue
@@ -6,7 +6,11 @@
>
<!-- Page header -->
<div class="bg-white">
- <TaskHighlightPanel :task="state.task" />
+ <TaskHighlightPanel
+ :task="state.task"
+ :enableButton="enableHighlightButton"
+ @click-button="doClickHighlightPanelButton"
+ />
</div>
<!-- Flow -->
@@ -25,7 +29,11 @@
>
<div>
<TaskContentBar v-if="false" :task="state.task" />
- <TaskSidebar class="lg:hidden" :task="state.task" />
+ <TaskSidebar
+ class="lg:hidden"
+ :task="state.task"
+ @update-field="updateField"
+ />
<div class="lg:hidden my-4 border-t border-block-border" />
<TaskContent :task="state.task" />
</div>
@@ -36,6 +44,7 @@
<TaskSidebar
class="hidden lg:block lg:w-64 lg:pl-8 xl:w-72"
:task="state.task"
+ @update-field="updateField"
/>
</div>
</div>
@@ -46,6 +55,7 @@
<script lang="ts">
import { onMounted, reactive, inject } from "vue";
import { useStore } from "vuex";
+import isEmpty from "lodash-es/isEmpty";
import { UserStateSymbol } from "../components/ProvideUser.vue";
import { humanize } from "../utils";
import TaskActivityPanel from "../views/TaskActivityPanel.vue";
@@ -55,6 +65,7 @@ import TaskContent from "../views/TaskContent.vue";
import TaskContentBar from "../views/TaskContentBar.vue";
import TaskSidebar from "../views/TaskSidebar.vue";
import { User, Task } from "../types";
+import { taskTemplateList, TaskField } from "../plugins";
interface LocalState {
new: boolean;
@@ -92,6 +103,7 @@ export default {
attributes: {
name: "New Task",
status: "PENDING",
+ type: "bytebase.datasource.create",
content: "Need a new database",
currentStageId: "1",
stageProgressList: [
@@ -109,11 +121,20 @@ export default {
id: currentUser!.id,
name: currentUser!.attributes.name,
},
+ payload: {
+ 1: "mydb",
+ },
},
}
- : store.getters["task/taskById"](props.taskId),
+ : JSON.parse(
+ JSON.stringify(store.getters["task/taskById"](props.taskId))
+ ),
});
+ const template = taskTemplateList.find(
+ (template) => template.type == state.task.attributes.type
+ );
+
onMounted(() => {
// Always scroll to top, the scrollBehavior doesn't seem to work.
// The hypothesis is that because the scroll bar is in the nested
@@ -122,7 +143,52 @@ export default {
document.getElementById("task-detail-top")!.scrollIntoView();
});
- return { state, humanize };
+ const updateField = (field: TaskField, value: string) => {
+ if (field.preprocessor) {
+ value = field.preprocessor(value);
+ }
+ state.task.attributes.payload[field.id] = value;
+ };
+
+ const doCreate = () => {
+ console.log("Create", state.task);
+ };
+
+ const doClickHighlightPanelButton = (buttonIndex: number) => {
+ if (state.new) {
+ // Create
+ if (buttonIndex == 0) {
+ doCreate();
+ }
+ }
+ };
+
+ const enableHighlightButton = (buttonIndex: number): boolean => {
+ if (state.new) {
+ // Create
+ if (buttonIndex == 0) {
+ if (template) {
+ for (const field of template.fieldList) {
+ if (
+ field.required &&
+ isEmpty(state.task.attributes.payload[field.id])
+ ) {
+ return false;
+ }
+ }
+ }
+ }
+ }
+ return true;
+ };
+
+ return {
+ state,
+ humanize,
+ updateField,
+ doClickHighlightPanelButton,
+ enableHighlightButton,
+ };
},
};
</script>
diff --git a/frontend/src/views/TaskHighlightPanel.vue b/frontend/src/views/TaskHighlightPanel.vue
index 6b40c7c987..821788b3ef 100644
--- a/frontend/src/views/TaskHighlightPanel.vue
+++ b/frontend/src/views/TaskHighlightPanel.vue
@@ -32,7 +32,14 @@
</div>
<div class="mt-6 flex space-x-3 md:mt-0 md:ml-4">
<template v-if="state.new">
- <button type="button" class="btn-primary px-4 py-2">Create</button>
+ <button
+ type="button"
+ class="btn-primary px-4 py-2"
+ @click.prevent="$emit('click-button', 0)"
+ :disabled="!enableButton(0)"
+ >
+ Create
+ </button>
</template>
<template v-else>
<button type="button" class="btn-normal px-4 py-2">Close</button>
@@ -54,11 +61,19 @@ interface LocalState {
export default {
name: "TaskHighlightPanel",
+ emits: ["click-button"],
props: {
task: {
required: true,
type: Object as PropType<Task>,
},
+ enableButton: {
+ // [TODO]: Don't know how to declare function type as property...
+ type: Function,
+ default: (index: number) => {
+ return true;
+ },
+ },
},
components: {},
setup(props, ctx) {
diff --git a/frontend/src/views/TaskSidebar.vue b/frontend/src/views/TaskSidebar.vue
index 1685488b64..ac64710933 100644
--- a/frontend/src/views/TaskSidebar.vue
+++ b/frontend/src/views/TaskSidebar.vue
@@ -18,17 +18,32 @@
</li>
</ul>
</div>
- <div>
- <h2 class="textlabel">Requested Database Name</h2>
- <div class="mt-3">
- <input
- type="text"
- name="db"
- class="textfield w-full"
- placeholder="Your DB Name"
- />
- </div>
- </div>
+ <template v-if="template">
+ <template v-for="(field, index) in template.fieldList" :key="index">
+ <template v-if="field.type == 'String'">
+ <div>
+ <h2 class="textlabel">
+ {{ field.name }}
+ <span v-if="field.required" class="text-red-600">*</span>
+ </h2>
+ <div class="mt-3">
+ <input
+ type="text"
+ class="textfield w-full"
+ :name="field.id"
+ :value="
+ field.preprocessor
+ ? field.preprocessor(task.attributes.payload[field.id])
+ : task.attributes.payload[field.id]
+ "
+ :placeholder="field.placeholder"
+ @input="$emit('update-field', field, $event.target.value)"
+ />
+ </div>
+ </div>
+ </template>
+ </template>
+ </template>
</div>
<div
v-if="!state.new"
@@ -85,6 +100,7 @@
<script lang="ts">
import { PropType, reactive } from "vue";
import isEmpty from "lodash-es/isEmpty";
+import { taskTemplateList } from "../plugins";
import { Task } from "../types";
interface LocalState {
@@ -93,6 +109,7 @@ interface LocalState {
export default {
name: "TaskSidebar",
+ emits: ["update-field"],
props: {
task: {
required: true,
@@ -100,12 +117,16 @@ export default {
},
},
components: {},
- setup(props, ctx) {
+ setup(props, { emit }) {
const state = reactive<LocalState>({
new: isEmpty(props.task.id),
});
- return { state };
+ const template = taskTemplateList.find(
+ (template) => template.type == props.task.attributes.type
+ );
+
+ return { state, template };
},
};
</script>