access tab refreshing correctly

This commit is contained in:
Peter Clement 2022-07-06 14:30:15 +01:00
parent b846402d90
commit 18d259b1ba
7 changed files with 66 additions and 37 deletions

View File

@ -127,7 +127,10 @@
} else { } else {
try { try {
await organisation.init() await organisation.init()
await roles.fetch()
} catch (error) { } catch (error) {
console.log(error)
notifications.error("Error getting org config") notifications.error("Error getting org config")
} }
loaded = true loaded = true

View File

@ -219,6 +219,7 @@
try { try {
await organisation.init() await organisation.init()
} catch (error) { } catch (error) {
console.log("hello1")
notifications.error("Error getting org config") notifications.error("Error getting org config")
} }

View File

@ -26,10 +26,11 @@
let selectedUsers = [] let selectedUsers = []
let prevSearch = undefined, let prevSearch = undefined,
search = undefined search = undefined
let pageInfo = createPaginationStore()
$: page = $pageInfo.page $: page = $pageInfo.page
$: fetchUsers(page, search) $: fetchUsers(page, search)
$: group = $groups.find(x => x._id === groupId) $: group = $groups.find(x => x._id === groupId)
let pageInfo = createPaginationStore()
async function addAll() { async function addAll() {
group.users = selectedUsers group.users = selectedUsers

View File

@ -76,8 +76,7 @@
$: fetchUsers(page, search) $: fetchUsers(page, search)
$: { $: {
if ($users.data) { enrichedUsers = $users.data?.map(user => {
enrichedUsers = $users.data.map(user => {
let userGroups = [] let userGroups = []
let userApps = [] let userApps = []
$groups.forEach(group => { $groups.forEach(group => {
@ -99,11 +98,7 @@
apps: [...new Set(Object.keys(user.roles))], apps: [...new Set(Object.keys(user.roles))],
} }
}) })
} else {
enrichedUsers = []
} }
}
$: console.log(enrichedUsers)
function showOnboardingTypeModal() { function showOnboardingTypeModal() {
onboardingTypeModal.show() onboardingTypeModal.show()
} }

View File

@ -14,18 +14,27 @@
import RoleSelect from "components/common/RoleSelect.svelte" import RoleSelect from "components/common/RoleSelect.svelte"
import { users, groups, apps } from "stores/portal" import { users, groups, apps } from "stores/portal"
import AssignmentModal from "./AssignmentModal.svelte" import AssignmentModal from "./AssignmentModal.svelte"
import { createPaginationStore } from "helpers/pagination"
export let app export let app
let assignmentModal let assignmentModal
let appGroups = [] let appGroups = []
let appUsers = [] let appUsers = []
let pageInfo = createPaginationStore()
let prevSearch = undefined,
search = undefined
$: appUsers = $users.filter(x => { $: page = $pageInfo.page
$: fetchUsers(page, search)
$: appUsers =
$users.data?.filter(x => {
return Object.keys(x.roles).find(y => { return Object.keys(x.roles).find(y => {
return extractAppId(y) === extractAppId(app.appId) return extractAppId(y) === extractAppId(app.appId)
}) })
}) }) || []
$: appGroups = $groups.filter(x => { $: appGroups = $groups.filter(x => {
return x.apps.find(y => { return x.apps.find(y => {
return y.appId === app.appId return y.appId === app.appId
@ -48,7 +57,7 @@
groups.actions.save(matchedGroup) groups.actions.save(matchedGroup)
} else if (data.id.startsWith(us_prefix)) { } else if (data.id.startsWith(us_prefix)) {
let matchedUser = $users.find(user => { let matchedUser = $users.data.find(user => {
return user._id === data.id return user._id === data.id
}) })
@ -60,10 +69,30 @@
await users.save(newUser) 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 () => { onMount(async () => {
try { try {
await users.init()
await groups.actions.init() await groups.actions.init()
await apps.load() await apps.load()
} catch (error) { } catch (error) {
@ -115,7 +144,7 @@
</div> </div>
<Modal bind:this={assignmentModal}> <Modal bind:this={assignmentModal}>
<AssignmentModal {addData} /> <AssignmentModal userData={$users.data} {addData} />
</Modal> </Modal>
<style> <style>

View File

@ -5,6 +5,7 @@
import { RoleUtils } from "@budibase/frontend-core" import { RoleUtils } from "@budibase/frontend-core"
export let addData export let addData
export let userData = []
$: optionSections = { $: optionSections = {
groups: { groups: {
data: $groups, data: $groups,
@ -14,7 +15,7 @@
getColour: group => group.color, getColour: group => group.color,
}, },
users: { users: {
data: $users, data: userData,
getLabel: user => user.email, getLabel: user => user.email,
getValue: user => user._id, getValue: user => user._id,
getIcon: user => user.icon, getIcon: user => user.icon,
@ -27,8 +28,6 @@
function addNewInput() { function addNewInput() {
appData = [...appData, { id: "", role: "" }] appData = [...appData, { id: "", role: "" }]
} }
$: console.log(appData)
</script> </script>
<ModalContent <ModalContent

View File

@ -7,6 +7,7 @@ export function createRolesStore() {
const actions = { const actions = {
fetch: async () => { fetch: async () => {
const roles = await API.getRoles() const roles = await API.getRoles()
console.log(roles)
set(roles) set(roles)
}, },
delete: async role => { delete: async role => {