From 93f11584df084e7ffb52e63f133de3626d0b0a54 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Wed, 6 Jul 2022 14:30:15 +0100 Subject: [PATCH] access tab refreshing correctly --- .../src/pages/builder/portal/_layout.svelte | 3 ++ .../builder/portal/manage/auth/index.svelte | 1 + .../portal/manage/groups/[groupId].svelte | 3 +- .../builder/portal/manage/users/index.svelte | 45 +++++++++---------- .../overview/_components/AccessTab.svelte | 45 +++++++++++++++---- .../_components/AssignmentModal.svelte | 5 +-- packages/builder/src/stores/backend/roles.js | 1 + 7 files changed, 66 insertions(+), 37 deletions(-) diff --git a/packages/builder/src/pages/builder/portal/_layout.svelte b/packages/builder/src/pages/builder/portal/_layout.svelte index 1e7ba9cb4e..a79b318a35 100644 --- a/packages/builder/src/pages/builder/portal/_layout.svelte +++ b/packages/builder/src/pages/builder/portal/_layout.svelte @@ -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 diff --git a/packages/builder/src/pages/builder/portal/manage/auth/index.svelte b/packages/builder/src/pages/builder/portal/manage/auth/index.svelte index bc77329a32..26e4c2b538 100644 --- a/packages/builder/src/pages/builder/portal/manage/auth/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/auth/index.svelte @@ -219,6 +219,7 @@ try { await organisation.init() } catch (error) { + console.log("hello1") notifications.error("Error getting org config") } diff --git a/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte b/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte index f460993859..8939d44449 100644 --- a/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte +++ b/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte @@ -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 diff --git a/packages/builder/src/pages/builder/portal/manage/users/index.svelte b/packages/builder/src/pages/builder/portal/manage/users/index.svelte index a7e45002f5..0f55dd8dcc 100644 --- a/packages/builder/src/pages/builder/portal/manage/users/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/users/index.svelte @@ -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() } diff --git a/packages/builder/src/pages/builder/portal/overview/_components/AccessTab.svelte b/packages/builder/src/pages/builder/portal/overview/_components/AccessTab.svelte index df44351ce1..2d4c853f2e 100644 --- a/packages/builder/src/pages/builder/portal/overview/_components/AccessTab.svelte +++ b/packages/builder/src/pages/builder/portal/overview/_components/AccessTab.svelte @@ -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 @@ - +