Skip to content

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

Fetch roleMapping in the ProvideContext instead of everytime loading the PrincipalSelect

Tianzhou Chen8cc135430308
diff --git a/frontend/src/components/MemberInvite.vue b/frontend/src/components/MemberInvite.vue
index 23bce02cea..a28e391edf 100644
--- a/frontend/src/components/MemberInvite.vue
+++ b/frontend/src/components/MemberInvite.vue
@@ -80,7 +80,7 @@
</div>
</div>
- <div class="border-b border-gray-200 py-1">
+ <div class="border-b border-gray-200 py-1 select-none">
<ul class="divide-y divide-gray-200">
<li
v-for="(invite, index) in state.inviteList"
diff --git a/frontend/src/components/PrincipalSelect.vue b/frontend/src/components/PrincipalSelect.vue
index 5d0dd93437..dd69c3faef 100644
--- a/frontend/src/components/PrincipalSelect.vue
+++ b/frontend/src/components/PrincipalSelect.vue
@@ -1,7 +1,7 @@
<template>
<BBSelect
- :selectedItem="state.selectedPrincipal"
- :itemList="state.principalList"
+ :selectedItem="selectedPrincipal"
+ :itemList="principalList"
:placeholder="'Unassigned'"
@select-item="(item) => $emit('select-principal', item)"
>
@@ -19,14 +19,12 @@
</template>
<script lang="ts">
-import { watchEffect, reactive } from "vue";
+import { watchEffect, reactive, computed } from "vue";
import { useStore } from "vuex";
import { RoleMapping, Principal } from "../types";
interface LocalState {
showMenu: boolean;
- principalList: Principal[];
- selectedPrincipal?: Principal;
}
export default {
@@ -40,27 +38,22 @@ export default {
setup(props, { emit }) {
const state = reactive<LocalState>({
showMenu: false,
- principalList: [],
});
const store = useStore();
- const preparePrincipalList = () => {
- store
- .dispatch("roleMapping/fetchRoleMappingList")
- .then((list: RoleMapping[]) => {
- state.principalList = list.map((roleMapping: RoleMapping) => {
- return roleMapping.principal;
- });
- state.selectedPrincipal = state.principalList.find(
- (principal) => principal.id == props.selectedId
- );
- })
- .catch((error) => {
- console.log(error);
- });
- };
+ const principalList = computed(() =>
+ store.getters["roleMapping/roleMappingList"]().map(
+ (roleMapping: RoleMapping) => {
+ return roleMapping.principal;
+ }
+ )
+ );
- watchEffect(preparePrincipalList);
+ const selectedPrincipal = computed(() =>
+ principalList.value.find(
+ (principal: Principal) => principal.id == props.selectedId
+ )
+ );
const close = () => {
state.showMenu = false;
@@ -68,6 +61,8 @@ export default {
return {
state,
+ principalList,
+ selectedPrincipal,
close,
};
},
diff --git a/frontend/src/components/ProvideContext.vue b/frontend/src/components/ProvideContext.vue
index a2e0309f44..f2c5985c6a 100644
--- a/frontend/src/components/ProvideContext.vue
+++ b/frontend/src/components/ProvideContext.vue
@@ -22,6 +22,7 @@ export default {
"bookmark/fetchBookmarkListByUser",
currentUser.value.id
);
+ await store.dispatch("roleMapping/fetchRoleMappingList");
await store.dispatch("uistate/restoreExpandState");
},
};