Skip to content

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

Unify task template inputFieldList and outputFieldList into a single list

Tianzhou Chenc41be56f17e1
diff --git a/frontend/src/plugins/task/template.ts b/frontend/src/plugins/task/template.ts
index 350c823d04..727a88a2ea 100644
--- a/frontend/src/plugins/task/template.ts
+++ b/frontend/src/plugins/task/template.ts
@@ -53,15 +53,9 @@ export const taskTemplateList: TaskTemplate[] = [
},
};
},
- outputFieldList: [
- {
- id: 1,
- name: "Data Source URL",
- required: true,
- },
- ],
- inputFieldList: [
+ fieldList: [
{
+ category: "INPUT",
id: 1,
slug: "db",
name: "Database Name",
@@ -74,6 +68,14 @@ export const taskTemplateList: TaskTemplate[] = [
return name?.toLowerCase();
},
},
+ {
+ category: "OUTPUT",
+ id: 99,
+ slug: "datasource",
+ name: "Data Source URL",
+ type: "String",
+ required: true,
+ },
],
},
];
diff --git a/frontend/src/plugins/types.ts b/frontend/src/plugins/types.ts
index 4cccc4263f..f0a5925c32 100644
--- a/frontend/src/plugins/types.ts
+++ b/frontend/src/plugins/types.ts
@@ -4,6 +4,7 @@ import { Environment, TaskNew, User } from "../types";
export type TaskFieldType = "String";
export type TaskField = {
+ category: "INPUT" | "OUTPUT";
// 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.
@@ -43,6 +44,5 @@ export type TemplateOutputField = {
export type TaskTemplate = {
type: string;
buildTask: (ctx: TemplateContext) => TaskNew;
- outputFieldList?: TemplateOutputField[];
- inputFieldList?: TaskField[];
+ fieldList?: TaskField[];
};
diff --git a/frontend/src/views/TaskDetail.vue b/frontend/src/views/TaskDetail.vue
index 05b06a110a..ac21dbc0b2 100644
--- a/frontend/src/views/TaskDetail.vue
+++ b/frontend/src/views/TaskDetail.vue
@@ -44,8 +44,10 @@
<!-- Output Panel -->
<TaskOutputPanel
- v-if="!state.new && template.outputFieldList?.length > 0"
+ v-if="!state.new && outputFieldList.length > 0"
:task="state.task"
+ :fieldList="outputFieldList"
+ @update-field="updateField"
/>
<!-- Main Content -->
@@ -63,6 +65,7 @@
<TaskSidebar
class="lg:hidden"
:task="state.task"
+ :fieldList="inputFieldList || []"
@update-field="updateField"
/>
<div class="lg:hidden my-4 border-t border-block-border" />
@@ -75,6 +78,7 @@
<TaskSidebar
class="hidden lg:block lg:w-64 lg:pl-8 xl:w-72"
:task="state.task"
+ :fieldList="inputFieldList || []"
@update-field="updateField"
/>
</div>
@@ -106,7 +110,7 @@ import {
TaskStatus,
StageStatus,
} from "../types";
-import { taskTemplateList, TaskField } from "../plugins";
+import { taskTemplateList, TaskField, TaskTemplate } from "../plugins";
type TaskTransitionType =
| "bytebase.task.resolve"
@@ -146,6 +150,11 @@ interface Transition {
from: SourceWorkflowStatus;
to: (status: WorkflowStatus) => WorkflowStatus;
allowedRoleList: RoleType[];
+ validatorList?: ((
+ task: Task,
+ template: TaskTemplate,
+ targetStatus: WorkflowStatus
+ ) => boolean)[];
}
const TRANSITION_LIST: Transition[] = [
@@ -164,6 +173,20 @@ const TRANSITION_LIST: Transition[] = [
};
},
allowedRoleList: ["ASSIGNEE", "CREATOR"],
+ validatorList: [
+ (task: Task, template: TaskTemplate, targetStatus: WorkflowStatus) => {
+ if (template.fieldList) {
+ for (const field of template.fieldList.filter(
+ (item) => item.category == "OUTPUT"
+ )) {
+ if (field.required && isEmpty(task.attributes.payload[field.id])) {
+ return false;
+ }
+ }
+ }
+ return true;
+ },
+ ],
},
{
type: "bytebase.task.abort",
@@ -238,6 +261,12 @@ export default {
title: `Unknown template '${templateName}'.`,
});
}
+ const outputFieldList = taskTemplate.fieldList?.filter(
+ (item) => item.category == "OUTPUT"
+ );
+ const inputFieldList = taskTemplate.fieldList?.filter(
+ (item) => item.category == "INPUT"
+ );
const environmentList = computed(() => {
return store.getters["environment/environmentList"]();
@@ -317,11 +346,24 @@ export default {
};
const doChangeStatus = (transition: Transition) => {
+ const targetStatus = transition.to({
+ taskStatus: (state.task as Task).attributes.status,
+ stageStatus: activeStage(state.task as Task).status,
+ });
+ if (transition.validatorList) {
+ for (const validator of transition.validatorList) {
+ const result = validator(
+ state.task as Task,
+ taskTemplate,
+ targetStatus
+ );
+ if (!result) {
+ return;
+ }
+ }
+ }
patchTask({
- status: transition.to({
- taskStatus: (state.task as Task).attributes.status,
- stageStatus: activeStage(state.task as Task).status,
- }).taskStatus,
+ status: targetStatus.taskStatus,
});
};
@@ -329,8 +371,10 @@ export default {
if (state.new) {
// Create
if (buttonIndex == 0) {
- if (template.inputFieldList) {
- for (const field of template.inputFieldList) {
+ if (template.fieldList) {
+ for (const field of template.fieldList.filter(
+ (item) => item.category == "INPUT"
+ )) {
if (
field.required &&
isEmpty(state.task.attributes.payload[field.id])
@@ -386,6 +430,8 @@ export default {
applicableTransitionList,
actionButtonClass,
currentUser,
+ outputFieldList,
+ inputFieldList,
};
},
};
diff --git a/frontend/src/views/TaskOutputPanel.vue b/frontend/src/views/TaskOutputPanel.vue
index 0335a878ea..68d5c4cb15 100644
--- a/frontend/src/views/TaskOutputPanel.vue
+++ b/frontend/src/views/TaskOutputPanel.vue
@@ -5,21 +5,25 @@
>
<h2 class="px-4 text-lg font-medium">Result</h2>
- <div v-if="template" class="my-2 mx-4 space-y-2">
- <template
- v-for="(field, index) in template.outputFieldList"
- :key="index"
- >
+ <div class="my-2 mx-4 space-y-2">
+ <template v-for="(field, index) in fieldList" :key="index">
<div class="flex">
<span
class="z-0 whitespace-nowrap inline-flex items-center px-3 rounded-l-md border border-l border-r-0 border-control-border bg-gray-50 text-control-light sm:text-sm"
>
{{ field.name }}
+ <span v-if="field.required" class="text-red-600">*</span>
</span>
<input
type="text"
- :name="field.id"
class="z-10 flex-1 min-w-0 block w-full px-3 py-2 border border-r border-control-border focus:ring-control focus:border-control sm:text-sm"
+ :name="field.id"
+ :value="
+ field.preprocessor
+ ? field.preprocessor(task.attributes.payload[field.id])
+ : task.attributes.payload[field.id]
+ "
+ @input="$emit('update-field', field, $event.target.value)"
/>
<!-- Disallow tabbing since the focus ring is partially covered by the text field due to overlaying -->
<button
@@ -69,7 +73,7 @@
<script lang="ts">
import { PropType, reactive } from "vue";
-import { taskTemplateList } from "../plugins";
+import { TaskField } from "../plugins";
import { Task } from "../types";
interface LocalState {}
@@ -82,16 +86,16 @@ export default {
required: true,
type: Object as PropType<Task>,
},
+ fieldList: {
+ required: true,
+ type: Object as PropType<TaskField[]>,
+ },
},
components: {},
setup(props, ctx) {
const state = reactive<LocalState>({});
- const template = taskTemplateList.find(
- (template) => template.type == props.task.attributes.type
- );
-
- return { state, template };
+ return { state };
},
};
</script>
diff --git a/frontend/src/views/TaskSidebar.vue b/frontend/src/views/TaskSidebar.vue
index 1654d9f428..d0e385f630 100644
--- a/frontend/src/views/TaskSidebar.vue
+++ b/frontend/src/views/TaskSidebar.vue
@@ -38,33 +38,28 @@
</li>
</ul>
</div>
- <template v-if="template">
- <template
- v-for="(field, index) in template.inputFieldList"
- :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>
+ <template v-for="(field, index) in 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>
- </template>
+ </div>
</template>
</template>
</div>
@@ -108,7 +103,7 @@
<script lang="ts">
import { PropType, watchEffect, reactive } from "vue";
import isEmpty from "lodash-es/isEmpty";
-import { taskTemplateList } from "../plugins";
+import { TaskField } from "../plugins";
import { Task } from "../types";
interface LocalState {
@@ -123,6 +118,10 @@ export default {
required: true,
type: Object as PropType<Task>,
},
+ fieldList: {
+ required: true,
+ type: Object as PropType<TaskField[]>,
+ },
},
components: {},
setup(props, { emit }) {
@@ -136,11 +135,7 @@ export default {
watchEffect(refreshState);
- const template = taskTemplateList.find(
- (template) => template.type == props.task.attributes.type
- );
-
- return { state, template };
+ return { state };
},
};
</script>