From 8489ae36a4a4a5ed99c087165425ab192fe41ca6 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Wed, 6 Jul 2022 12:58:55 +0100 Subject: [PATCH] take into account pagination --- .../settings/UserGroupPicker.svelte | 12 +++- .../portal/manage/groups/[groupId].svelte | 51 +++++++++++++---- .../_components/CreateEditGroupModal.svelte | 10 +++- .../builder/portal/manage/groups/index.svelte | 2 +- .../_components/AppsTableRenderer.svelte | 1 - .../_components/GroupsTableRenderer.svelte | 9 +-- .../builder/portal/manage/users/index.svelte | 57 ++++++++++++++++++- packages/builder/src/stores/portal/groups.js | 1 + .../worker/src/api/routes/global/groups.js | 4 +- 9 files changed, 122 insertions(+), 25 deletions(-) diff --git a/packages/builder/src/components/settings/UserGroupPicker.svelte b/packages/builder/src/components/settings/UserGroupPicker.svelte index 8e67331b09..31354bde83 100644 --- a/packages/builder/src/components/settings/UserGroupPicker.svelte +++ b/packages/builder/src/components/settings/UserGroupPicker.svelte @@ -1,13 +1,19 @@
@@ -26,7 +32,9 @@
{#each filtered as item}
{ + select(item._id) + }} style="padding-bottom: var(--spacing-m)" class="selection" > 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 9c6cd6241f..f460993859 100644 --- a/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte +++ b/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte @@ -14,7 +14,7 @@ StatusLight, } from "@budibase/bbui" import UserGroupPicker from "components/settings/UserGroupPicker.svelte" - + import { createPaginationStore } from "helpers/pagination" import { users, apps, groups } from "stores/portal" import { onMount } from "svelte" import { RoleUtils } from "@budibase/frontend-core" @@ -24,24 +24,23 @@ let popover let searchTerm = "" let selectedUsers = [] + let prevSearch = undefined, + search = undefined + $: page = $pageInfo.page + $: fetchUsers(page, search) $: group = $groups.find(x => x._id === groupId) - $: filteredUsers = $users.filter( - user => - selectedUsers && - user?.email?.toLowerCase().includes(searchTerm.toLowerCase()) - ) - $: console.log(group) + let pageInfo = createPaginationStore() + async function addAll() { - selectedUsers = [...selectedUsers, ...filteredUsers] group.users = selectedUsers await groups.actions.save(group) } async function selectUser(id) { let selectedUser = selectedUsers.includes(id) - let enrichedUser = $users.find(user => user._id === id) - + let enrichedUser = $users.data.find(user => user._id === id) if (selectedUser) { + console.log selectedUsers = selectedUsers.filter(id => id !== selectedUser) let newUsers = group.users.filter(user => user._id !== id) group.users = newUsers @@ -52,16 +51,43 @@ await groups.actions.save(group) } + $: filtered = + $users.data?.filter(x => !group?.users.map(y => y._id).includes(x._id)) || + [] + $: console.log(filtered) async function removeUser(id) { let newUsers = group.users.filter(user => user._id !== id) group.users = newUsers await groups.actions.save(group) } + + 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") + } + } + + function onChange(e) { + console.log(e) + } + onMount(async () => { try { await groups.actions.init() - await users.init() await apps.load() } catch (error) { notifications.error("Error fetching User Group data") @@ -91,11 +117,12 @@
diff --git a/packages/builder/src/pages/builder/portal/manage/groups/_components/CreateEditGroupModal.svelte b/packages/builder/src/pages/builder/portal/manage/groups/_components/CreateEditGroupModal.svelte index 75cb1fd6ec..22a59c2193 100644 --- a/packages/builder/src/pages/builder/portal/manage/groups/_components/CreateEditGroupModal.svelte +++ b/packages/builder/src/pages/builder/portal/manage/groups/_components/CreateEditGroupModal.svelte @@ -22,13 +22,19 @@
diff --git a/packages/builder/src/pages/builder/portal/manage/groups/index.svelte b/packages/builder/src/pages/builder/portal/manage/groups/index.svelte index 898a2e4e0a..2821adaf37 100644 --- a/packages/builder/src/pages/builder/portal/manage/groups/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/groups/index.svelte @@ -96,7 +96,7 @@ - +