Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Add RequestDatabasePrepForm as the pre-step to compose the create task
天舟8935fb1d9f8b
diff --git a/frontend/src/components/QuickActionPanel.vue b/frontend/src/components/QuickActionPanel.vueindex 2e0034a7ef..9cff6130c2 100644--- a/frontend/src/components/QuickActionPanel.vue+++ b/frontend/src/components/QuickActionPanel.vue@@ -111,10 +111,7 @@v-if="quickAction == 'quickaction.bytebase.database.request'"class="flex flex-col items-center w-28">- <router-link- to="/task/new?template=bytebase.database.create"- class="p-3 btn-icon-primary"- >+ <button class="btn-icon-primary p-3" @click.prevent="requestDatabase"><svgclass="w-6 h-6"fill="none"@@ -245,14 +242,22 @@</template></div><BBModal- v-if="state.showCreateInstanceModal"- :title="'Create Instance'"- @close="state.showCreateInstanceModal = false"+ v-if="state.showModal"+ :title="state.modalTitle"+ @close="state.showModal = false">- <InstanceForm- :create="true"- @dismiss="state.showCreateInstanceModal = false"- />+ <template+ v-if="state.quickActionType == 'quickaction.bytebase.instance.create'"+ >+ <InstanceForm :create="true" @dismiss="state.showModal = false" />+ </template>+ <template+ v-else-if="+ state.quickActionType == 'quickaction.bytebase.database.request'+ "+ >+ <RequestDatabasePrepForm @dismiss="state.showModal = false" />+ </template></BBModal></template>@@ -260,15 +265,20 @@import { reactive, PropType } from "vue";import { useStore } from "vuex";import InstanceForm from "../components/InstanceForm.vue";+import RequestDatabasePrepForm from "../components/RequestDatabasePrepForm.vue";+import { QuickActionType } from "../types";interface LocalState {- showCreateInstanceModal: Boolean;+ showModal: Boolean;+ modalTitle: string;+ quickActionType: QuickActionType;}export default {name: "QuickActionPanel",components: {InstanceForm,+ RequestDatabasePrepForm,},props: {quickActionList: {@@ -280,11 +290,21 @@ export default {const store = useStore();const state = reactive<LocalState>({- showCreateInstanceModal: false,+ showModal: false,+ modalTitle: "",+ quickActionType: "quickaction.bytebase.instance.create",});const createInstance = () => {- state.showCreateInstanceModal = true;+ state.modalTitle = "Create instance";+ state.quickActionType = "quickaction.bytebase.instance.create";+ state.showModal = true;+ };++ const requestDatabase = () => {+ state.modalTitle = "Request database";+ state.quickActionType = "quickaction.bytebase.database.request";+ state.showModal = true;};const createEnvironment = () => {@@ -298,6 +318,7 @@ export default {return {state,createInstance,+ requestDatabase,createEnvironment,reorderEnvironment,};diff --git a/frontend/src/components/RequestDatabasePrepForm.vue b/frontend/src/components/RequestDatabasePrepForm.vuenew file mode 100644index 0000000000..5689a37bba--- /dev/null+++ b/frontend/src/components/RequestDatabasePrepForm.vue@@ -0,0 +1,188 @@+<template>+ <form class="mx-4 space-y-6 divide-y divide-block-border">+ <div class="grid gap-y-6 gap-x-4 grid-cols-4">+ <div class="col-span-2 col-start-2 w-64">+ <label for="environment" class="textlabel">+ Environment <span style="color: red">*</span>+ </label>+ <EnvironmentSelect+ class="mt-1"+ id="environment"+ name="environment"+ :selectedId="state.environmentId"+ @select-environment-id="+ (environmentId) => {+ state.environmentId = environmentId;+ }+ "+ />+ </div>++ <template v-if="state.environmentId">+ <div class="col-span-2 col-start-2 w-64 space-y-2">+ <div class="hidden sm:flex sm:flex-row radio-set justify-between">+ <div class="radio">+ <input+ name="Create new"+ tabindex="-1"+ type="radio"+ class="btn"+ value="ON"+ v-model="state.create"+ />+ <label class="label whitespace-nowrap">Create new</label>+ </div>+ <div class="radio">+ <input+ name="Access existing"+ tabindex="-1"+ type="radio"+ class="btn"+ value="OFF"+ v-model="state.create"+ />+ <label class="label whitespace-nowrap">Access existing DB</label>+ </div>+ </div>++ <div class="space-y-1">+ <label for="database" class="textlabel">+ Database name <span style="color: red">*</span>+ </label>+ <BBTextField+ v-if="state.create == 'ON'"+ type="text"+ class="w-full text-sm"+ :required="true"+ :value="state.databaseName"+ :placeholder="'New database name'"+ @end-editing="(text) => (state.databaseName = text)"+ @input="state.databaseName = $event.target.value"+ />+ <div v-else class="flex flex-row space-x-4">+ <DatabaseSelect+ :selectedId="state.databaseId"+ :mode="'ENVIRONMENT'"+ :environmentId="state.environmentId"+ @select-database-id="+ (databaseId) => {+ state.databaseId = databaseId;+ }+ "+ />+ <BBSwitch+ :label="'Read only'"+ :value="state.readOnly"+ @toggle="+ (on) => {+ state.readOnly = on;+ }+ "+ />+ </div>+ </div>+ </div>+ </template>+ </div>+ <!-- Create button group -->+ <div class="pt-4 flex justify-end">+ <button+ type="button"+ class="btn-normal py-2 px-4"+ @click.prevent="cancel"+ >+ Cancel+ </button>+ <button+ class="btn-primary ml-3 inline-flex justify-center py-2 px-4"+ :disabled="!allowRequest"+ @click.prevent="request"+ >+ Request+ </button>+ </div>+ </form>+</template>++<script lang="ts">+import { computed, reactive, onMounted, onUnmounted } from "vue";+import { useRouter } from "vue-router";+import isEmpty from "lodash-es/isEmpty";+import DatabaseSelect from "../components/DatabaseSelect.vue";+import EnvironmentSelect from "../components/EnvironmentSelect.vue";+import { EnvironmentId } from "../types";++interface LocalState {+ environmentId?: EnvironmentId;+ // Radio button only accept string value+ create: "ON" | "OFF";+ databaseName?: string;+ databaseId?: string;+ readonly: boolean;+}++export default {+ name: "RequestDatabasePrepForm",+ emits: ["dismiss"],+ props: {},+ components: { DatabaseSelect, EnvironmentSelect },+ setup(props, { emit }) {+ const router = useRouter();++ const keyboardHandler = (e: KeyboardEvent) => {+ if (e.code == "Escape") {+ cancel();+ }+ };++ onMounted(() => {+ document.addEventListener("keydown", keyboardHandler);+ });++ onUnmounted(() => {+ document.removeEventListener("keydown", keyboardHandler);+ });++ const state = reactive<LocalState>({+ create: "ON",+ readonly: true,+ });++ const allowRequest = computed(() => {+ return (+ state.environmentId &&+ ((state.create == "ON" && !isEmpty(state.databaseName)) ||+ (state.create == "OFF" && state.databaseId))+ );+ });++ const cancel = () => {+ emit("dismiss");+ };++ const request = () => {+ emit("dismiss");+ if (state.create == "ON") {+ router.push({+ name: "workspace.task.detail",+ params: {+ taskSlug: "new",+ },+ query: {+ template: "bytebase.database.create",+ environment: state.environmentId,+ database: state.databaseName,+ },+ });+ }+ };++ return {+ state,+ allowRequest,+ cancel,+ request,+ };+ },+};+</script>diff --git a/frontend/src/plugins/task/DatabaseCreateTemplate.ts b/frontend/src/plugins/task/DatabaseCreateTemplate.tsindex 245e638ab8..fe65618c99 100644--- a/frontend/src/plugins/task/DatabaseCreateTemplate.ts+++ b/frontend/src/plugins/task/DatabaseCreateTemplate.ts@@ -42,7 +42,7 @@ const template: TaskTemplate = {{category: "INPUT",id: TaskBuiltinFieldId.ENVIRONMENT,- slug: "env",+ slug: "environment",name: "Environment",type: "Environment",required: true,@@ -53,7 +53,7 @@ const template: TaskTemplate = {{category: "INPUT",id: TaskBuiltinFieldId.DATABASE,- slug: "db",+ slug: "database",name: "DB name",type: "NewDatabase",required: true,