access tab refreshing correctly
This commit is contained in:
parent
8489ae36a4
commit
93f11584df
|
@ -127,7 +127,10 @@
|
|||
} else {
|
||||
try {
|
||||
await organisation.init()
|
||||
await roles.fetch()
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
|
||||
notifications.error("Error getting org config")
|
||||
}
|
||||
loaded = true
|
||||
|
|
|
@ -219,6 +219,7 @@
|
|||
try {
|
||||
await organisation.init()
|
||||
} catch (error) {
|
||||
console.log("hello1")
|
||||
notifications.error("Error getting org config")
|
||||
}
|
||||
|
||||
|
|
|
@ -26,10 +26,11 @@
|
|||
let selectedUsers = []
|
||||
let prevSearch = undefined,
|
||||
search = undefined
|
||||
let pageInfo = createPaginationStore()
|
||||
|
||||
$: page = $pageInfo.page
|
||||
$: fetchUsers(page, search)
|
||||
$: group = $groups.find(x => x._id === groupId)
|
||||
let pageInfo = createPaginationStore()
|
||||
|
||||
async function addAll() {
|
||||
group.users = selectedUsers
|
||||
|
|
|
@ -76,34 +76,29 @@
|
|||
$: fetchUsers(page, search)
|
||||
|
||||
$: {
|
||||
if ($users.data) {
|
||||
enrichedUsers = $users.data.map(user => {
|
||||
let userGroups = []
|
||||
let userApps = []
|
||||
$groups.forEach(group => {
|
||||
console.log(group)
|
||||
if (group.users) {
|
||||
group.users?.forEach(y => {
|
||||
if (y._id === user._id) {
|
||||
console.log("hello")
|
||||
userGroups.push(group)
|
||||
userApps = group.apps
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
return {
|
||||
...user,
|
||||
name: user.firstName ? user.firstName + " " + user.lastName : "",
|
||||
userGroups,
|
||||
apps: [...new Set(Object.keys(user.roles))],
|
||||
enrichedUsers = $users.data?.map(user => {
|
||||
let userGroups = []
|
||||
let userApps = []
|
||||
$groups.forEach(group => {
|
||||
console.log(group)
|
||||
if (group.users) {
|
||||
group.users?.forEach(y => {
|
||||
if (y._id === user._id) {
|
||||
console.log("hello")
|
||||
userGroups.push(group)
|
||||
userApps = group.apps
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
} else {
|
||||
enrichedUsers = []
|
||||
}
|
||||
return {
|
||||
...user,
|
||||
name: user.firstName ? user.firstName + " " + user.lastName : "",
|
||||
userGroups,
|
||||
apps: [...new Set(Object.keys(user.roles))],
|
||||
}
|
||||
})
|
||||
}
|
||||
$: console.log(enrichedUsers)
|
||||
function showOnboardingTypeModal() {
|
||||
onboardingTypeModal.show()
|
||||
}
|
||||
|
|
|
@ -14,18 +14,27 @@
|
|||
import RoleSelect from "components/common/RoleSelect.svelte"
|
||||
import { users, groups, apps } from "stores/portal"
|
||||
import AssignmentModal from "./AssignmentModal.svelte"
|
||||
import { createPaginationStore } from "helpers/pagination"
|
||||
|
||||
export let app
|
||||
|
||||
let assignmentModal
|
||||
let appGroups = []
|
||||
let appUsers = []
|
||||
let pageInfo = createPaginationStore()
|
||||
let prevSearch = undefined,
|
||||
search = undefined
|
||||
|
||||
$: page = $pageInfo.page
|
||||
$: fetchUsers(page, search)
|
||||
|
||||
$: appUsers =
|
||||
$users.data?.filter(x => {
|
||||
return Object.keys(x.roles).find(y => {
|
||||
return extractAppId(y) === extractAppId(app.appId)
|
||||
})
|
||||
}) || []
|
||||
|
||||
$: appUsers = $users.filter(x => {
|
||||
return Object.keys(x.roles).find(y => {
|
||||
return extractAppId(y) === extractAppId(app.appId)
|
||||
})
|
||||
})
|
||||
$: appGroups = $groups.filter(x => {
|
||||
return x.apps.find(y => {
|
||||
return y.appId === app.appId
|
||||
|
@ -48,7 +57,7 @@
|
|||
|
||||
groups.actions.save(matchedGroup)
|
||||
} else if (data.id.startsWith(us_prefix)) {
|
||||
let matchedUser = $users.find(user => {
|
||||
let matchedUser = $users.data.find(user => {
|
||||
return user._id === data.id
|
||||
})
|
||||
|
||||
|
@ -60,10 +69,30 @@
|
|||
await users.save(newUser)
|
||||
}
|
||||
})
|
||||
await pageInfo.reset()
|
||||
}
|
||||
|
||||
async function fetchUsers(page, search) {
|
||||
if ($pageInfo.loading) {
|
||||
return
|
||||
}
|
||||
// need to remove the page if they've started searching
|
||||
if (search && !prevSearch) {
|
||||
pageInfo.reset()
|
||||
page = undefined
|
||||
}
|
||||
prevSearch = search
|
||||
try {
|
||||
pageInfo.loading()
|
||||
await users.search({ page, search })
|
||||
pageInfo.fetched($users.hasNextPage, $users.nextPage)
|
||||
} catch (error) {
|
||||
notifications.error("Error getting user list")
|
||||
}
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
try {
|
||||
await users.init()
|
||||
await groups.actions.init()
|
||||
await apps.load()
|
||||
} catch (error) {
|
||||
|
@ -115,7 +144,7 @@
|
|||
</div>
|
||||
|
||||
<Modal bind:this={assignmentModal}>
|
||||
<AssignmentModal {addData} />
|
||||
<AssignmentModal userData={$users.data} {addData} />
|
||||
</Modal>
|
||||
|
||||
<style>
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
import { RoleUtils } from "@budibase/frontend-core"
|
||||
|
||||
export let addData
|
||||
export let userData = []
|
||||
$: optionSections = {
|
||||
groups: {
|
||||
data: $groups,
|
||||
|
@ -14,7 +15,7 @@
|
|||
getColour: group => group.color,
|
||||
},
|
||||
users: {
|
||||
data: $users,
|
||||
data: userData,
|
||||
getLabel: user => user.email,
|
||||
getValue: user => user._id,
|
||||
getIcon: user => user.icon,
|
||||
|
@ -27,8 +28,6 @@
|
|||
function addNewInput() {
|
||||
appData = [...appData, { id: "", role: "" }]
|
||||
}
|
||||
|
||||
$: console.log(appData)
|
||||
</script>
|
||||
|
||||
<ModalContent
|
||||
|
|
|
@ -7,6 +7,7 @@ export function createRolesStore() {
|
|||
const actions = {
|
||||
fetch: async () => {
|
||||
const roles = await API.getRoles()
|
||||
console.log(roles)
|
||||
set(roles)
|
||||
},
|
||||
delete: async role => {
|
||||
|
|
Loading…
Reference in New Issue