Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Profile dashboard at /u/:principalId
Tianzhou Chencd1e9c93b558
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.tsindex de6e47734b..f4986b403e 100644--- a/frontend/src/router/index.ts+++ b/frontend/src/router/index.ts@@ -107,6 +107,22 @@ const routes: Array<RouteRecordRaw> = [leftSidebar: true,},},+ {+ path: "u/:principalId",+ name: "workspace.profile.detail",+ meta: {+ title: (route: RouteLocationNormalized) => {+ const principalId = route.params.principalId as string;+ return store.getters["principal/principalById"](principalId)+ .name;+ },+ },+ components: {+ content: () => import("../views/ProfileDashboard.vue"),+ leftSidebar: DashboardSidebar,+ },+ props: { content: true },+ },{path: "setting",name: "setting",@@ -122,8 +138,8 @@ const routes: Array<RouteRecordRaw> = [children: [{path: "",- name: "setting.accountprofile",- meta: { title: () => "Account Profile" },+ name: "setting.profile",+ meta: { title: () => "Profile" },component: () => import("../views/SettingAccountProfile.vue"),alias: "account/profile",props: true,@@ -305,6 +321,7 @@ router.beforeEach((to, from, next) => {const routerSlug = store.getters["router/routeSlug"](to);const taskSlug = routerSlug.taskSlug;const instanceSlug = routerSlug.instanceSlug;+ const principalId = routerSlug.principalId;console.log("RouterSlug:", routerSlug);@@ -346,6 +363,21 @@ router.beforeEach((to, from, next) => {return;}+ if (principalId) {+ store+ .dispatch("principal/fetchPrincipalById", principalId)+ .then(() => {+ next();+ })+ .catch((error) => {+ next({+ name: "error.404",+ replace: false,+ });+ });+ return;+ }+next({name: "error.404",replace: false,diff --git a/frontend/src/store/modules/principal.ts b/frontend/src/store/modules/principal.tsindex 507ceb00bb..0abb165b21 100644--- a/frontend/src/store/modules/principal.ts+++ b/frontend/src/store/modules/principal.ts@@ -7,6 +7,14 @@ import {ResourceObject,} from "../../types";+function convert(user: ResourceObject): Principal {+ return {+ id: user.id,+ name: user.attributes.name as string,+ email: user.attributes.email as string,+ };+}+const state: () => PrincipalState = () => ({principalList: [],});@@ -27,6 +35,7 @@ const getters = {return {id: principalId,name: "Unknown User " + principalId,+ email: "",};},};@@ -36,21 +45,37 @@ const actions = {const userList: ResourceObject[] = (await axios.get(`/api/user`)).data.data;const principalList = userList.map((user) => {- return {- id: user.id,- name: user.attributes.name,- };+ return convert(user);});commit("setPrincipalList", principalList);return userList;},++ async fetchPrincipalById({ commit }: any, principalId: PrincipalId) {+ const principal = convert(+ (await axios.get(`/api/user/${principalId}`)).data.data+ );++ commit("replacePrincipalInList", principal);++ return principal;+ },};const mutations = {setPrincipalList(state: PrincipalState, principalList: Principal[]) {state.principalList = principalList;},++ replacePrincipalInList(state: PrincipalState, updatedPrincipal: Principal) {+ const i = state.principalList.findIndex(+ (item: Principal) => item.id == updatedPrincipal.id+ );+ if (i != -1) {+ state.principalList[i] = updatedPrincipal;+ }+ },};export default {diff --git a/frontend/src/store/modules/router.ts b/frontend/src/store/modules/router.tsindex 2ac272f739..8133ced25e 100644--- a/frontend/src/store/modules/router.ts+++ b/frontend/src/store/modules/router.ts@@ -32,6 +32,18 @@ const getters = {instanceSlug: instanceComponents[1],};}++ // /u/:principalId+ // Total 2 elements, 2nd element is the principal id+ const profileComponents = currentRoute.path.match(+ "/u/([0-9a-zA-Z_-]+)"+ ) || ["/", undefined];+ if (profileComponents[1]) {+ return {+ principalId: profileComponents[1],+ };+ }+return {};},};diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.tsindex 1a4d28bb77..9d8c215b40 100644--- a/frontend/src/types/bytebase.ts+++ b/frontend/src/types/bytebase.ts@@ -43,6 +43,7 @@ export type NewUser = Omit<User, "id">;export type Principal = {id: PrincipalId;name: string;+ email: string;};// RoleMapping@@ -239,6 +240,7 @@ export type SignupInfo = {export type RouterSlug = {taskSlug?: string;instanceSlug?: string;+ principalId?: PrincipalId;};export type Notification = {diff --git a/frontend/src/views/ProfileDashboard.vue b/frontend/src/views/ProfileDashboard.vuenew file mode 100644index 0000000000..f7150afce0--- /dev/null+++ b/frontend/src/views/ProfileDashboard.vue@@ -0,0 +1,124 @@+<template>+ <div class="h-screen flex overflow-hidden bg-white">+ <div class="flex flex-col min-w-0 flex-1 overflow-hidden">+ <div class="flex-1 relative z-0 flex overflow-hidden">+ <main+ class="flex-1 relative z-0 overflow-y-auto focus:outline-none xl:order-last"+ tabindex="0"+ >+ <article>+ <!-- Profile header -->+ <div>+ <div class="h-32 w-full bg-accent lg:h-48"></div>+ <div class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8">+ <div class="-mt-20 sm:flex sm:items-end sm:space-x-5">+ <BBAvatar :size="'huge'" :username="principal.name" />+ <div+ class="mt-6 sm:flex-1 sm:min-w-0 sm:flex sm:items-center sm:justify-end sm:space-x-6 sm:pb-1"+ >+ <div+ class="mt-6 flex flex-col justify-stretch space-y-3 sm:flex-row sm:space-y-0 sm:space-x-4"+ >+ <button v-if="false" type="button" class="btn-normal">+ <!-- Heroicon name: solid/mail -->+ <svg+ class="-ml-1 mr-2 h-5 w-5 text-control-light"+ xmlns="http://www.w3.org/2000/svg"+ viewBox="0 0 20 20"+ fill="currentColor"+ aria-hidden="true"+ >+ <path+ d="M2.003 5.884L10 9.882l7.997-3.998A2 2 0 0016 4H4a2 2 0 00-1.997 1.884z"+ />+ <path+ d="M18 8.118l-8 4-8-4V14a2 2 0 002 2h12a2 2 0 002-2V8.118z"+ />+ </svg>+ <span>Message</span>+ </button>+ <button+ v-if="isCurrentUser"+ type="button"+ class="btn-normal"+ @click.prevent="editUser"+ >+ <!-- Heroicon name: solid/pencil -->+ <svg+ class="-ml-1 mr-2 h-5 w-5 text-control-light"+ fill="currentColor"+ viewBox="0 0 20 20"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ d="M13.586 3.586a2 2 0 112.828 2.828l-.793.793-2.828-2.828.793-.793zM11.379 5.793L3 14.172V17h2.828l8.38-8.379-2.83-2.828z"+ ></path>+ </svg>+ <span>Edit</span>+ </button>+ </div>+ </div>+ </div>+ <div class="block mt-6 min-w-0 flex-1">+ <h1 class="text-2xl font-bold text-main truncate">+ {{ principal.name }}+ </h1>+ </div>+ </div>+ </div>++ <!-- Description list -->+ <div class="mt-6 max-w-5xl mx-auto px-4 sm:px-6 lg:px-8">+ <dl class="grid grid-cols-1 gap-x-4 gap-y-8 sm:grid-cols-2">+ <div class="sm:col-span-1">+ <dt class="text-sm font-medium text-control-light">Email</dt>+ <dd class="mt-1 text-sm text-main">+ {{ principal.email }}+ </dd>+ </div>+ </dl>+ </div>+ </article>+ </main>+ </div>+ </div>+ </div>+</template>++<script lang="ts">+import { computed } from "vue";+import { useStore } from "vuex";+import { useRouter } from "vue-router";+import { PrincipalId } from "../types";++export default {+ name: "ProfileDashboard",+ props: {+ principalId: {+ required: true,+ type: String,+ },+ },+ components: {},+ setup(props, ctx) {+ const store = useStore();+ const router = useRouter();++ const currentUser = computed(() => store.getters["auth/currentUser"]());++ const principal = computed(() => {+ return store.getters["principal/principalById"](props.principalId);+ });++ const isCurrentUser = computed(() => {+ return currentUser.value.id == principal.value.id;+ });++ const editUser = () => {+ router.push({ name: "setting.profile" });+ };++ return { isCurrentUser, principal, editUser };+ },+};+</script>