Skip to content

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

Add ProjectNew form and hook with create project quick action

天舟05cc27401350
diff --git a/frontend/src/components/ProjectNew.vue b/frontend/src/components/ProjectNew.vue
new file mode 100644
index 0000000000..cc936baf94
--- /dev/null
+++ b/frontend/src/components/ProjectNew.vue
@@ -0,0 +1,113 @@
+<template>
+ <form class="px-4 py-2 space-y-6 divide-y divide-block-border">
+ <div class="grid gap-y-6 gap-x-4 grid-cols-1">
+ <div class="col-span-1">
+ <label for="name" class="text-lg leading-6 font-medium text-control">
+ Project Name <span class="text-red-600">*</span>
+ </label>
+ <BBTextField
+ class="mt-4 w-full"
+ :required="true"
+ :value="state.project.name"
+ @input="state.project.name = $event.target.value"
+ />
+ </div>
+ </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="!allowCreate"
+ @click.prevent="create"
+ >
+ Create
+ </button>
+ </div>
+ </form>
+</template>
+
+<script lang="ts">
+import { computed, reactive, onMounted, onUnmounted } from "vue";
+import { useStore } from "vuex";
+import { useRouter } from "vue-router";
+import isEmpty from "lodash-es/isEmpty";
+import { Project, ProjectNew } from "../types";
+import { projectSlug } from "../utils";
+
+interface LocalState {
+ project: ProjectNew;
+}
+
+export default {
+ name: "ProjectNew",
+ emits: ["dismiss"],
+ props: {},
+ setup(props, { emit }) {
+ const store = useStore();
+ const router = useRouter();
+
+ const currentUser = computed(() => store.getters["auth/currentUser"]());
+
+ const state = reactive<LocalState>({
+ project: {
+ name: "New Project",
+ creatorId: currentUser.value.id,
+ },
+ });
+
+ const keyboardHandler = (e: KeyboardEvent) => {
+ if (e.code == "Escape") {
+ emit("dismiss");
+ }
+ };
+
+ onMounted(() => {
+ document.addEventListener("keydown", keyboardHandler);
+ });
+
+ onUnmounted(() => {
+ document.removeEventListener("keydown", keyboardHandler);
+ });
+
+ const allowCreate = computed(() => {
+ return !isEmpty(state.project?.name);
+ });
+
+ const create = () => {
+ store
+ .dispatch("project/createProject", state.project)
+ .then((createdProject: Project) => {
+ store.dispatch("notification/pushNotification", {
+ module: "bytebase",
+ style: "SUCCESS",
+ title: `Successfully created project '${createdProject.name}'.`,
+ });
+
+ router.push(`/project/${projectSlug(createdProject)}}`);
+ emit("dismiss");
+ })
+ .catch((err) => {
+ console.error(err);
+ });
+ };
+
+ const cancel = () => {
+ emit("dismiss");
+ };
+
+ return {
+ state,
+ allowCreate,
+ cancel,
+ create,
+ };
+ },
+};
+</script>
diff --git a/frontend/src/components/QuickActionPanel.vue b/frontend/src/components/QuickActionPanel.vue
index 1df638a437..e154b582a1 100644
--- a/frontend/src/components/QuickActionPanel.vue
+++ b/frontend/src/components/QuickActionPanel.vue
@@ -268,6 +268,31 @@
Reorder
</h3>
</div>
+
+ <div
+ v-if="quickAction == 'quickaction.bytebase.project.create'"
+ class="flex flex-col items-center w-28"
+ >
+ <button class="btn-icon-primary p-3" @click.prevent="createProject">
+ <svg
+ class="w-6 h-6"
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ stroke-width="2"
+ d="M4 5a1 1 0 011-1h14a1 1 0 011 1v2a1 1 0 01-1 1H5a1 1 0 01-1-1V5zM4 13a1 1 0 011-1h6a1 1 0 011 1v6a1 1 0 01-1 1H5a1 1 0 01-1-1v-6zM16 13a1 1 0 011-1h2a1 1 0 011 1v6a1 1 0 01-1 1h-2a1 1 0 01-1-1v-6z"
+ ></path>
+ </svg>
+ </button>
+ <h3 class="mt-1 text-center text-base font-normal text-main">
+ Create Project
+ </h3>
+ </div>
</template>
</div>
<BBModal
@@ -276,7 +301,14 @@
@close="state.showModal = false"
>
<template
- v-if="state.quickActionType == 'quickaction.bytebase.instance.create'"
+ v-if="state.quickActionType == 'quickaction.bytebase.project.create'"
+ >
+ <ProjectNew @dismiss="state.showModal = false" />
+ </template>
+ <template
+ v-else-if="
+ state.quickActionType == 'quickaction.bytebase.instance.create'
+ "
>
<InstanceForm :create="true" @dismiss="state.showModal = false" />
</template>
@@ -293,6 +325,7 @@
<script lang="ts">
import { reactive, PropType } from "vue";
import { useStore } from "vuex";
+import ProjectNew from "../components/ProjectNew.vue";
import InstanceForm from "../components/InstanceForm.vue";
import RequestDatabasePrepForm from "../components/RequestDatabasePrepForm.vue";
import { QuickActionType } from "../types";
@@ -306,6 +339,7 @@ interface LocalState {
export default {
name: "QuickActionPanel",
components: {
+ ProjectNew,
InstanceForm,
RequestDatabasePrepForm,
},
@@ -324,6 +358,12 @@ export default {
quickActionType: "quickaction.bytebase.instance.create",
});
+ const createProject = () => {
+ state.modalTitle = "Create project";
+ state.quickActionType = "quickaction.bytebase.project.create";
+ state.showModal = true;
+ };
+
const createInstance = () => {
state.modalTitle = "Create instance";
state.quickActionType = "quickaction.bytebase.instance.create";
@@ -352,6 +392,7 @@ export default {
return {
state,
+ createProject,
createInstance,
createDatabase,
requestDatabase,
diff --git a/frontend/src/miragejs/factories/project.js b/frontend/src/miragejs/factories/project.js
index 3d1e30454e..7c55d52519 100644
--- a/frontend/src/miragejs/factories/project.js
+++ b/frontend/src/miragejs/factories/project.js
@@ -19,7 +19,7 @@ export default {
return Date.now() - i * 3600 * 1000;
},
name(i) {
- return "project " + i;
+ return "project " + (i + 1);
},
}),
};
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 8de9868dba..512ff2523b 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -102,6 +102,7 @@ const routes: Array<RouteRecordRaw> = [
"quickaction.bytebase.database.troubleshoot",
"quickaction.bytebase.database.schema.update",
"quickaction.bytebase.database.request",
+ "quickaction.bytebase.project.create",
],
],
]),
@@ -316,6 +317,11 @@ const routes: Array<RouteRecordRaw> = [
name: "workspace.project",
meta: {
title: () => "Project",
+ quickActionListByRole: new Map([
+ ["OWNER", ["quickaction.bytebase.project.create"]],
+ ["DBA", ["quickaction.bytebase.project.create"]],
+ ["DEVELOPER", ["quickaction.bytebase.project.create"]],
+ ]),
},
components: {
content: () => import("../views/ProjectDashboard.vue"),
diff --git a/frontend/src/store/modules/project.ts b/frontend/src/store/modules/project.ts
index f6a9e0d9dd..4dd1c9bc0e 100644
--- a/frontend/src/store/modules/project.ts
+++ b/frontend/src/store/modules/project.ts
@@ -61,7 +61,6 @@ const actions = {
projectId,
project,
});
- console.log(project);
return project;
},
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index 02091ea1b2..caebef2af6 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -171,6 +171,8 @@ export const unknown = (
return UNKNOWN_ROLE_MAPPING;
case "ENVIRONMENT":
return UNKNOWN_ENVIRONMENT;
+ case "PROJECT":
+ return UNKNOWN_PROJECT;
case "INSTANCE":
return UNKNOWN_INSTANCE;
case "DATABASE":
@@ -872,6 +874,7 @@ export type NotificationFilter = {
export type EnvironmentQuickActionType =
| "quickaction.bytebase.environment.create"
| "quickaction.bytebase.environment.reorder";
+export type ProjectQuickActionType = "quickaction.bytebase.project.create";
export type InstanceQuickActionType = "quickaction.bytebase.instance.create";
export type UserQuickActionType = "quickaction.bytebase.user.manage";
export type DatabaseQuickActionType =
@@ -882,6 +885,7 @@ export type DatabaseQuickActionType =
export type QuickActionType =
| EnvironmentQuickActionType
+ | ProjectQuickActionType
| InstanceQuickActionType
| UserQuickActionType
| DatabaseQuickActionType;