Skip to content

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

Need to re-introduce database/databaseListByUserId to make the database list side panel reactive to project transfer

天舟f2109a63d049
diff --git a/frontend/src/components/DatabaseListSidePanel.vue b/frontend/src/components/DatabaseListSidePanel.vue
index ad4155e59f..dd3ad372e8 100644
--- a/frontend/src/components/DatabaseListSidePanel.vue
+++ b/frontend/src/components/DatabaseListSidePanel.vue
@@ -8,7 +8,7 @@
</template>
<script lang="ts">
-import { computed, PropType, reactive, watchEffect } from "vue";
+import { computed, watchEffect } from "vue";
import { useStore } from "vuex";
import cloneDeep from "lodash-es/cloneDeep";
@@ -16,20 +16,12 @@ import { Database, Environment, EnvironmentId } from "../types";
import { databaseSlug, environmentName } from "../utils";
import { BBOutlineItem } from "../bbkit/types";
-interface LocalState {
- databaseList: Database[];
-}
-
export default {
name: "DatabaseListSidePanel",
props: {},
setup(props, ctx) {
const store = useStore();
- const state = reactive<LocalState>({
- databaseList: [],
- });
-
const currentUser = computed(() => store.getters["auth/currentUser"]());
const environmentList = computed(() => {
@@ -41,9 +33,6 @@ export default {
const prepareDatabaseList = () => {
store
.dispatch("database/fetchDatabaseListByUser", currentUser.value.id)
- .then((databaseList) => {
- state.databaseList = databaseList;
- })
.catch((error) => {
console.log(error);
});
@@ -51,12 +40,19 @@ export default {
watchEffect(prepareDatabaseList);
+ // Use this to make the list reactive when project is transferred.
+ const databaseList = computed((): Database[] => {
+ return store.getters["database/databaseListByUserId"](
+ currentUser.value.id
+ );
+ });
+
const databaseListByEnvironment = computed(() => {
const envToDbMap: Map<EnvironmentId, BBOutlineItem[]> = new Map();
for (const environment of environmentList.value) {
envToDbMap.set(environment.id, []);
}
- for (const database of state.databaseList) {
+ for (const database of databaseList.value) {
const dbList = envToDbMap.get(database.instance.environment.id)!;
// dbList may be undefined if the environment is archived
if (dbList) {
@@ -81,6 +77,7 @@ export default {
return {
environmentList,
+ databaseList,
databaseListByEnvironment,
};
},
diff --git a/frontend/src/store/modules/database.ts b/frontend/src/store/modules/database.ts
index be72ea1686..1c7c945632 100644
--- a/frontend/src/store/modules/database.ts
+++ b/frontend/src/store/modules/database.ts
@@ -116,6 +116,23 @@ const getters = {
return state.databaseListByInstanceId.get(instanceId) || [];
},
+ databaseListByUserId: (state: DatabaseState) => (
+ userId: UserId
+ ): Database[] => {
+ const list: Database[] = [];
+ for (let [_, databaseList] of state.databaseListByInstanceId) {
+ databaseList.forEach((item: Database) => {
+ for (const member of item.project.memberList) {
+ if (member.principal.id == userId) {
+ list.push(item);
+ break;
+ }
+ }
+ });
+ }
+ return list;
+ },
+
databaseListByEnvironmentId: (state: DatabaseState) => (
environmentId: EnvironmentId
): Database[] => {