Skip to content

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

Instance List initial Stub

Tianzhou Chend84a4ea19780
diff --git a/frontend/src/components/InstanceTable.vue b/frontend/src/components/InstanceTable.vue
new file mode 100644
index 0000000000..be8b024b6a
--- /dev/null
+++ b/frontend/src/components/InstanceTable.vue
@@ -0,0 +1,74 @@
+<template>
+ <BBTable
+ :columnList="state.columnList"
+ :dataSource="instanceList"
+ :showHeader="true"
+ @click-row="clickInstance"
+ >
+ <template v-slot:body="{ rowData: instance }">
+ <BBTableCell :leftPadding="1" class="w-24">
+ <span class="flex justify-center">
+ {{ instance.attributes.environmentName }}
+ </span>
+ </BBTableCell>
+ <BBTableCell class="w-96">
+ <span class="">{{ instance.attributes.name }}</span>
+ </BBTableCell>
+ <BBTableCell class="w-24">
+ {{ instance.attributes.host }}:{{ instance.attributes.port }}
+ </BBTableCell>
+ </template>
+ </BBTable>
+</template>
+
+<script lang="ts">
+import { reactive, PropType } from "vue";
+import { useRouter } from "vue-router";
+import { BBTableColumn } from "../bbkit/types";
+import { humanize } from "../utils";
+import { Instance } from "../types";
+
+interface LocalState {
+ columnList: BBTableColumn[];
+ dataSource: Object[];
+}
+
+export default {
+ name: "InstanceTable",
+ components: {},
+ props: {
+ instanceList: {
+ required: true,
+ type: Object as PropType<Instance[]>,
+ },
+ },
+ setup(props, ctx) {
+ const state = reactive<LocalState>({
+ columnList: [
+ {
+ title: "Environment",
+ },
+ {
+ title: "Name",
+ },
+ {
+ title: "Host:Port",
+ },
+ ],
+ dataSource: [],
+ });
+
+ const router = useRouter();
+
+ const clickInstance = function (section: number, row: number) {
+ router.push(`/instance/${props.instanceList[row].id}`);
+ };
+
+ return {
+ state,
+ humanize,
+ clickInstance,
+ };
+ },
+};
+</script>
diff --git a/frontend/src/miragejs/factories/instance.js b/frontend/src/miragejs/factories/instance.js
index fe5fa64048..7f18acdcbc 100644
--- a/frontend/src/miragejs/factories/instance.js
+++ b/frontend/src/miragejs/factories/instance.js
@@ -13,6 +13,17 @@ export default {
return "prod env " + i;
}
},
+ environmentName(i) {
+ if (i == 0) {
+ return "dev env";
+ } else if (i == 1) {
+ return "test env";
+ } else if (i == 2) {
+ return "staging env";
+ } else {
+ return "prod env " + i;
+ }
+ },
host(i) {
if (i == 0) {
return "localhost";
@@ -35,14 +46,5 @@ export default {
return "5432";
}
},
- username() {
- return "root";
- },
- password() {
- return "root";
- },
- database() {
- return "";
- },
}),
};
diff --git a/frontend/src/miragejs/factories/workspace.js b/frontend/src/miragejs/factories/workspace.js
index b80739d923..d4f67c3e82 100644
--- a/frontend/src/miragejs/factories/workspace.js
+++ b/frontend/src/miragejs/factories/workspace.js
@@ -10,13 +10,6 @@ export default {
return "ws" + (i + 1);
},
afterCreate(workspace, server) {
- for (let i = 0; i < 4; i++) {
- server.create("instance", {
- workspace,
- name: workspace.name + " instance" + i + faker.fake("{{lorem.word}}"),
- });
- }
-
server.create("activity", {
workspace,
name: workspace.name + " activity1 " + faker.fake("{{lorem.word}}"),
diff --git a/frontend/src/miragejs/fixtures/workspaceList.json b/frontend/src/miragejs/fixtures/workspaceList.json
index 111e1331d5..046c93cb19 100644
--- a/frontend/src/miragejs/fixtures/workspaceList.json
+++ b/frontend/src/miragejs/fixtures/workspaceList.json
@@ -1,10 +1,12 @@
[
{
"id": "1",
+ "name": "workspace1",
"slug": "ws1"
},
{
"id": "101",
+ "name": "workspace2",
"slug": "ws101"
}
]
diff --git a/frontend/src/miragejs/routes/index.js b/frontend/src/miragejs/routes/index.js
index 017ed74099..1046e0d1b3 100644
--- a/frontend/src/miragejs/routes/index.js
+++ b/frontend/src/miragejs/routes/index.js
@@ -14,8 +14,10 @@ export default function routes() {
this.namespace = "api";
+ // User
this.get("/user/:id");
+ // Auth
this.post("/auth/login", function (schema, request) {
const loginInfo = this.normalizedRequestAttrs("login-info");
const user = schema.users.findBy({
@@ -45,6 +47,7 @@ export default function routes() {
return schema.users.create(signupInfo);
});
+ // Pipeline
this.get("/pipeline", function (schema, request) {
const {
queryParams: { userid: userId },
@@ -75,29 +78,7 @@ export default function routes() {
);
});
- this.get("/group", function (schema, request) {
- const {
- queryParams: { userid: userId },
- } = request;
-
- if (userId) {
- return schema.groups.where((group) => {
- return (
- group.workspaceId == WORKSPACE_ID &&
- group.groupRoleIds?.find((roleId) => {
- return schema.groupRoles.where({
- userId,
- groupId: group.id,
- });
- })
- );
- });
- }
- return schema.groups.where({
- workspaceId: WORKSPACE_ID,
- });
- });
-
+ // environment
this.get("/environment", function (schema, request) {
return schema.environments
.where((environment) => {
@@ -172,26 +153,32 @@ export default function routes() {
return schema.environments.find(request.params.environmentId).destroy();
});
- this.get("/environment", function (schema, request) {
- return schema.environments
- .where((environment) => {
- return environment.workspaceId == WORKSPACE_ID;
- })
- .sort((a, b) => a.order - b.order);
+ // Instance
+ this.get("/instance", function (schema, request) {
+ return schema.instances.where((instance) => {
+ return instance.workspaceId == WORKSPACE_ID;
+ });
+ });
+
+ this.get("/instance/:id", function (schema, request) {
+ const instance = schema.instances.find(request.params.id);
+ if (instance) {
+ return instance;
+ }
+ return new Response(
+ 404,
+ {},
+ { errors: "Instance " + request.params.id + " not found" }
+ );
});
this.post("/instance", function (schema, request) {
- let order = 0;
const list = schema.instances.where((instance) => {
return instance.workspaceId == WORKSPACE_ID;
});
- if (list.length > 0) {
- order = list.sort((a, b) => b.order - a.order).models[0].order + 1;
- }
const newInstance = {
...this.normalizedRequestAttrs("instance"),
workspaceId: WORKSPACE_ID,
- order,
};
return schema.instances.create(newInstance);
});
@@ -205,18 +192,45 @@ export default function routes() {
return schema.instances.find(request.params.instanceId).destroy();
});
+ // Bookmark
this.get("/bookmark", function (schema, request) {
return schema.bookmarks.where({
workspaceId: WORKSPACE_ID,
});
});
+ // Activity
this.get("/activity", function (schema, request) {
return schema.activities.where({
workspaceId: WORKSPACE_ID,
});
});
+ // Group
+ this.get("/group", function (schema, request) {
+ const {
+ queryParams: { userid: userId },
+ } = request;
+
+ if (userId) {
+ return schema.groups.where((group) => {
+ return (
+ group.workspaceId == WORKSPACE_ID &&
+ group.groupRoleIds?.find((roleId) => {
+ return schema.groupRoles.where({
+ userId,
+ groupId: group.id,
+ });
+ })
+ );
+ });
+ }
+ return schema.groups.where({
+ workspaceId: WORKSPACE_ID,
+ });
+ });
+
+ // Project
this.get("/project", function (schema, request) {
const {
queryParams: { groupid: groupId, userid: userId },
diff --git a/frontend/src/miragejs/seeds/index.js b/frontend/src/miragejs/seeds/index.js
index e8f36a9157..d1439ed2e2 100644
--- a/frontend/src/miragejs/seeds/index.js
+++ b/frontend/src/miragejs/seeds/index.js
@@ -1,3 +1,5 @@
+import faker from "faker";
+
/*
* Mirage JS guide on Seeds: https://miragejs.com/docs/data-layer/factories#in-development
*/
@@ -9,6 +11,7 @@ const workspacesSeeder = (server) => {
// resources from different workspaces.
const workspace2 = server.schema.workspaces.find(101);
+ // Environment
let environmentList1 = [];
for (let i = 0; i < 4; i++) {
environmentList1.push(
@@ -29,6 +32,22 @@ const workspacesSeeder = (server) => {
}
workspace2.update({ environment: environmentList2 });
+ // Instance
+ for (let i = 0; i < 4; i++) {
+ server.create("instance", {
+ workspace: workspace1,
+ name: "ws1 instance " + i + " " + faker.fake("{{lorem.word}}"),
+ });
+ }
+
+ for (let i = 0; i < 4; i++) {
+ server.create("instance", {
+ workspace: workspace2,
+ name: "ws2 instance " + i + " " + faker.fake("{{lorem.word}}"),
+ });
+ }
+
+ // Pipeline
const ws1Owner = server.schema.users.find(1);
const ws1DBA = server.schema.users.find(2);
const ws1Dev1 = server.schema.users.find(3);
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index bcff2d04ef..ef31288062 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -290,6 +290,7 @@ router.beforeEach((to, from, next) => {
const routerSlug = store.getters["router/routeSlug"](to);
const pipelineId = routerSlug.pipelineId;
+ const instanceId = routerSlug.instanceId;
console.log("RouterSlug:", routerSlug);
@@ -308,5 +309,20 @@ router.beforeEach((to, from, next) => {
return;
}
+ if (instanceId) {
+ store
+ .dispatch("instance/fetchInstanceById", instanceId)
+ .then((instance) => {
+ next();
+ })
+ .catch((error) => {
+ next({
+ name: "error.404",
+ replace: false,
+ });
+ });
+ return;
+ }
+
next();
});
diff --git a/frontend/src/store/index.ts b/frontend/src/store/index.ts
index 4dc027f76a..d2d11a2804 100644
--- a/frontend/src/store/index.ts
+++ b/frontend/src/store/index.ts
@@ -3,6 +3,7 @@ import activity from "./modules/activity";
import bookmark from "./modules/bookmark";
import project from "./modules/project";
import environment from "./modules/environment";
+import instance from "./modules/instance";
import repository from "./modules/repository";
import auth from "./modules/auth";
import group from "./modules/group";
@@ -18,6 +19,7 @@ export const store: Store<any> = createStore({
bookmark,
project,
environment,
+ instance,
repository,
auth,
group,
diff --git a/frontend/src/store/modules/instance.ts b/frontend/src/store/modules/instance.ts
index d954977bc4..2949de28e8 100644
--- a/frontend/src/store/modules/instance.ts
+++ b/frontend/src/store/modules/instance.ts
@@ -1,27 +1,38 @@
import axios from "axios";
-import { InstanceId, Instance, InstanceState } from "../../types";
+import { UserId, InstanceId, Instance, InstanceState } from "../../types";
const state: () => InstanceState = () => ({
instanceList: [],
+ instanceById: new Map(),
});
const getters = {
instanceList: (state: InstanceState) => () => {
return state.instanceList;
},
+ instanceById: (state: InstanceState) => (instanceId: InstanceId) => {
+ return state.instanceById.get(instanceId);
+ },
};
const actions = {
async fetchInstanceList({ commit }: any) {
const instanceList = (await axios.get(`/api/instance`)).data.data;
- commit("setInstanceList", {
- instanceList,
- });
+ commit("setInstanceList", { instanceList });
return instanceList;
},
+ async fetchInstanceById({ commit }: any, instanceId: InstanceId) {
+ const instance = (await axios.get(`/api/instance/${instanceId}`)).data.data;
+ commit("setInstanceById", {
+ instanceId,
+ instance,
+ });
+ return instance;
+ },
+
async createInstance(
{ commit }: any,
{ newInstance }: { newInstance: Instance }
@@ -93,6 +104,18 @@ const mutations = {
) {
state.instanceList = instanceList;
},
+ setInstanceById(
+ state: InstanceState,
+ {
+ instanceId,
+ instance,
+ }: {
+ instanceId: InstanceId;
+ instance: Instance;
+ }
+ ) {
+ state.instanceById.set(instanceId, instance);
+ },
appendInstance(
state: InstanceState,
{
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index 24f8dadf04..1898efaad7 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -73,6 +73,7 @@ export type NewEnvironment = Omit<ResourceObject, "id">;
export type Instance = ResourceObject & {
attributes: {
name: string;
+ environmentName: string;
host: string;
port?: string;
username?: string;
@@ -144,6 +145,7 @@ export interface EnvironmentState {
export interface InstanceState {
instanceList: Instance[];
+ instanceById: Map<InstanceId, Instance>;
}
export interface RepositoryState {
diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue
index c372c392aa..fa24ce7ca3 100644
--- a/frontend/src/views/Home.vue
+++ b/frontend/src/views/Home.vue
@@ -42,7 +42,7 @@ import QuickActionPanel from "../components/QuickActionPanel.vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import { UserStateSymbol } from "../components/ProvideUser.vue";
-import { Environment, Pipeline } from "../types";
+import { User, Environment, Pipeline } from "../types";
import environment from "../store/modules/environment";
interface EnvironmentFilter {
@@ -75,7 +75,7 @@ export default {
});
const store = useStore();
const router = useRouter();
- const currentUser = inject<Pipeline>(UserStateSymbol);
+ const currentUser = inject<User>(UserStateSymbol);
const preparePipelineList = () => {
store
diff --git a/frontend/src/views/InstanceDashboard.vue b/frontend/src/views/InstanceDashboard.vue
index 00f323dd12..8524a228b5 100644
--- a/frontend/src/views/InstanceDashboard.vue
+++ b/frontend/src/views/InstanceDashboard.vue
@@ -1,12 +1,116 @@
<template>
- <h1>Instance Dashboard</h1>
- <div class="flex-shrink-0 flex border-t border-block-border p-4"></div>
+ <div class="flex flex-col">
+ <div class="p-4">
+ <QuickActionPanel />
+ </div>
+ <div class="px-2 py-1 border-t">
+ <BBTableTabFilter
+ :itemList="state.environmentFilterList"
+ :selectedIndex="state.selectedFilterIndex"
+ @select-index="selectFilter"
+ />
+ </div>
+ <InstanceTable :instanceList="filteredList(state.instanceList)" />
+ </div>
</template>
<script lang="ts">
+import { watchEffect, computed, reactive, PropType } from "vue";
+import InstanceTable from "../components/InstanceTable.vue";
+import QuickActionPanel from "../components/QuickActionPanel.vue";
+import { useStore } from "vuex";
+import { useRouter } from "vue-router";
+import { Environment, Instance } from "../types";
+
+interface EnvironmentFilter {
+ id: string;
+ title: string;
+}
+
+interface LocalState {
+ instanceList: Instance[];
+ environmentFilterList: EnvironmentFilter[];
+ selectedFilterIndex: number;
+}
+
export default {
name: "InstanceDashboard",
- components: {},
- setup(props, ctx) {},
+ components: {
+ InstanceTable,
+ QuickActionPanel,
+ },
+ setup(props, ctx) {
+ const state = reactive<LocalState>({
+ instanceList: [],
+ environmentFilterList: [],
+ selectedFilterIndex: 0,
+ });
+ const store = useStore();
+ const router = useRouter();
+
+ const prepareInstanceList = () => {
+ store
+ .dispatch("instance/fetchInstanceList")
+ .then((instanceList: Instance[]) => {
+ state.instanceList = instanceList;
+ })
+ .catch((error) => {
+ console.log(error);
+ });
+ };
+
+ const prepareEnvironmentList = () => {
+ store
+ .dispatch("environment/fetchEnvironmentList")
+ .then((list: Environment[]) => {
+ state.environmentFilterList = [
+ {
+ id: "",
+ title: "All",
+ },
+ ...list
+ .map((environment) => {
+ return {
+ id: environment.id,
+ title: environment.attributes.name,
+ };
+ })
+ // Usually env is ordered by ascending importantance, thus we rervese the order to put
+ // more important ones first.
+ .reverse(),
+ ];
+ })
+ .catch((error) => {
+ console.log(error);
+ });
+ };
+
+ const selectFilter = (index: number) => {
+ state.selectedFilterIndex = index;
+ };
+
+ const filteredList = (list: Instance[]) => {
+ if (state.selectedFilterIndex == 0) {
+ // Select "All"
+ return list;
+ }
+ return list.filter((instance) => {
+ return (
+ instance.attributes.environmentName ==
+ state.environmentFilterList[state.selectedFilterIndex].title
+ );
+ });
+ };
+
+ watchEffect(prepareInstanceList);
+
+ watchEffect(prepareEnvironmentList);
+
+ return {
+ state,
+ filteredList,
+ selectFilter,
+ };
+ },
};
</script>
diff --git a/frontend/src/views/InstanceDetail.vue b/frontend/src/views/InstanceDetail.vue
index 2c494a1fd6..939a77969f 100644
--- a/frontend/src/views/InstanceDetail.vue
+++ b/frontend/src/views/InstanceDetail.vue
@@ -192,7 +192,6 @@ import { computed, onMounted, reactive } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import isEqual from "lodash-es/isEqual";
-import InstanceForm from "../components/InstanceForm.vue";
import { Instance, NewInstance } from "../types";
interface LocalState {
@@ -205,9 +204,7 @@ interface LocalState {
export default {
name: "InstanceDetail",
emits: ["delete"],
- components: {
- InstanceForm,
- },
+ components: {},
props: {
instanceId: {
required: true,
@@ -249,7 +246,7 @@ export default {
},
};
} else {
- assignInstance(store.getters["instance/instanceById"]);
+ assignInstance(store.getters["instance/instanceById"](props.instanceId));
}
const valueChanged = computed(() => {