Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Show different action button based on different task state.
Tianzhou Chenf5ec15487819
diff --git a/frontend/src/plugins/task/template.ts b/frontend/src/plugins/task/template.tsindex b7ddd4d403..5f6234765f 100644--- a/frontend/src/plugins/task/template.ts+++ b/frontend/src/plugins/task/template.ts@@ -1,8 +1,29 @@import { TaskTemplate, TemplateContext, Stage } from "../types";export const taskTemplateList: TaskTemplate[] = [+ {+ type: "bytebase.general",+ stageListBuilder: (ctx: TemplateContext): Stage[] => {+ return [+ {+ id: 1,+ name: "Request",+ type: "SIMPLE",+ },+ ];+ },+ },{type: "bytebase.datasource.create",+ stageListBuilder: (ctx: TemplateContext): Stage[] => {+ return [+ {+ id: 1,+ name: "Request Data Source",+ type: "ENVIRONMENT",+ },+ ];+ },outputFieldList: [{id: 1,@@ -35,13 +56,5 @@ export const taskTemplateList: TaskTemplate[] = [},},],- stageListBuilder: (ctx: TemplateContext): Stage[] => {- return [- {- name: "Request Data Source",- type: "SIMPLE",- },- ];- },},];diff --git a/frontend/src/plugins/types.ts b/frontend/src/plugins/types.tsindex 9251148941..9dcbc65870 100644--- a/frontend/src/plugins/types.ts+++ b/frontend/src/plugins/types.ts@@ -2,6 +2,8 @@ import { Environment } from "../types";// Stageexport type Stage = {+ // Similar to TaskField.id below+ id: number;name: string;type: "SIMPLE" | "ENVIRONMENT";};@@ -38,7 +40,7 @@ export type TemplateContext = {environmentList: Environment[];};-export type TemplateOutput = {+export type TemplateOutputField = {// Similar to TaskField.id aboveid: number;name: string;@@ -47,7 +49,7 @@ export type TemplateOutput = {export type TaskTemplate = {type: string;- outputFieldList: TemplateOutputField[];- fieldList: TaskField[];stageListBuilder: (ctx: TemplateContext) => Stage[];+ outputFieldList?: TemplateOutputField[];+ fieldList?: TaskField[];};diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.tsindex d1e14ba097..b6922c02dd 100644--- a/frontend/src/types/bytebase.ts+++ b/frontend/src/types/bytebase.ts@@ -37,7 +37,7 @@ export type NewBookmark = Omit<Bookmark, "id">;export type Activity = ResourceObject & {};export type ActivityNew = Omit<Activity, "id">;-type TaskTypeGeneral = "bytebase.general";+type TaskTypeGeneral = "bytebase.genera.create";type TaskTypeDataSource = "bytebase.datasource.create";diff --git a/frontend/src/views/TaskDetail.vue b/frontend/src/views/TaskDetail.vueindex 907ba59c1d..2d0d8e8d7e 100644--- a/frontend/src/views/TaskDetail.vue+++ b/frontend/src/views/TaskDetail.vue@@ -6,11 +6,42 @@><!-- Highlight Panel --><div class="bg-white">- <TaskHighlightPanel- :task="state.task"- :enableButton="enableHighlightButton"- @click-button="doClickHighlightPanelButton"- />+ <TaskHighlightPanel :task="state.task">+ <template v-if="state.new">+ <button+ type="button"+ class="btn-primary px-4 py-2"+ @click.prevent="doCreate"+ :disabled="!enableHighlightButton(0)"+ >+ Create+ </button>+ </template>+ <template v-else>+ <template v-if="pendingState() !== 'CLOSED'">+ <button+ type="button"+ class="btn-normal px-4 py-2"+ :disabled="pendingState() === 'RUNNING'"+ >+ Close+ </button>+ </template>++ <template v-if="pendingState() === 'APPROVAL'">+ <button type="button" class="btn-primary px-4 py-2">Approve</button>+ </template>+ <template v-else-if="pendingState() === 'RESOLVE'">+ <button type="button" class="btn-primary px-4 py-2">Resolve</button>+ </template>+ <template v-else-if="pendingState() === 'RUNNING'">+ <button type="button" class="btn-primary px-4 py-2">Cancel</button>+ </template>+ <template v-else-if="pendingState() === 'CLOSED'">+ <button type="button" class="btn-normal px-4 py-2">Reopen</button>+ </template>+ </template>+ </TaskHighlightPanel></div><!-- Flow Bar -->@@ -20,7 +51,10 @@/><!-- Output Panel -->- <TaskOutputPanel v-if="!state.new" :task="state.task" />+ <TaskOutputPanel+ v-if="!state.new && template.outputFieldList?.length > 0"+ :task="state.task"+ /><!-- Main Content --><main@@ -58,7 +92,7 @@</template><script lang="ts">-import { onMounted, watchEffect, reactive, inject } from "vue";+import { computed, onMounted, watchEffect, reactive, inject } from "vue";import { useStore } from "vuex";import { useRouter } from "vue-router";import cloneDeep from "lodash-es/cloneDeep";@@ -73,7 +107,7 @@ import TaskContent from "../views/TaskContent.vue";import TaskActivityPanel from "../views/TaskActivityPanel.vue";import TaskSidebar from "../views/TaskSidebar.vue";import { User, Task, TaskNew } from "../types";-import { taskTemplateList, TaskField } from "../plugins";+import { taskTemplateList, TaskField, Stage } from "../plugins";interface LocalState {new: boolean;@@ -137,9 +171,17 @@ export default {watchEffect(prepareTask);+ const environmentList = computed(() => {+ return store.getters["environment/environmentList"]();+ });+const template = taskTemplateList.find((template) => template.type == state.task.attributes.type- );+ )!;++ const stageList = template.stageListBuilder({+ environmentList: environmentList.value,+ });onMounted(() => {// Always scroll to top, the scrollBehavior doesn't seem to work.@@ -170,20 +212,11 @@ export default {});};- const doClickHighlightPanelButton = (buttonIndex: number) => {- if (state.new) {- // Create- if (buttonIndex == 0) {- doCreate();- }- }- };-const enableHighlightButton = (buttonIndex: number): boolean => {if (state.new) {// Createif (buttonIndex == 0) {- if (template) {+ if (template.fieldList) {for (const field of template.fieldList) {if (field.required &&@@ -198,12 +231,38 @@ export default {return true;};+ const pendingState = (): "APPROVAL" | "RESOLVE" | "RUNNING" | "CLOSED" => {+ if (+ state.task.attributes.status === "DONE" ||+ state.task.attributes.status === "CANCELED"+ ) {+ return "CLOSED";+ } else {+ const currentStage = stageList.find(+ (stage) => stage.id == state.task.attributes.currentStageId+ );+ if (currentStage) {+ if (currentStage.type === "SIMPLE") {+ return "RESOLVE";+ } else if (currentStage.type === "ENVIRONMENT") {+ if (state.task.attributes.status === "RUNNING") {+ return "RUNNING";+ }+ return "APPROVAL";+ }+ }+ return "CLOSED";+ }+ };+return {state,+ template,humanize,updateField,- doClickHighlightPanelButton,+ doCreate,enableHighlightButton,+ pendingState,};},};diff --git a/frontend/src/views/TaskHighlightPanel.vue b/frontend/src/views/TaskHighlightPanel.vueindex 7dce834832..eba055f489 100644--- a/frontend/src/views/TaskHighlightPanel.vue+++ b/frontend/src/views/TaskHighlightPanel.vue@@ -31,20 +31,7 @@</div></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"- @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>- <button type="button" class="btn-primary px-4 py-2">Resolve</button>- </template>+ <slot /></div></div></div>@@ -61,19 +48,11 @@ 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) {