From 8102c54bc30da8182de5fe94e7ef30962dc538b3 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 5 May 2023 09:36:18 +0100 Subject: [PATCH] Add searching for users back --- .../portal/users/groups/[groupId].svelte | 47 ++++++++++++++++--- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/packages/builder/src/pages/builder/portal/users/groups/[groupId].svelte b/packages/builder/src/pages/builder/portal/users/groups/[groupId].svelte index ccd945fc24..6e5f337314 100644 --- a/packages/builder/src/pages/builder/portal/users/groups/[groupId].svelte +++ b/packages/builder/src/pages/builder/portal/users/groups/[groupId].svelte @@ -16,6 +16,7 @@ import { fetchData } from "@budibase/frontend-core" import { API } from "api" import UserGroupPicker from "components/settings/UserGroupPicker.svelte" + import { createPaginationStore } from "helpers/pagination" import { users, apps, groups, auth, features } from "stores/portal" import { onMount, setContext } from "svelte" import { roles } from "stores/backend" @@ -30,7 +31,7 @@ export let groupId - const fetchUsers = fetchData({ + const fetchGroupUsers = fetchData({ API, datasource: { type: "groupUser", @@ -84,12 +85,17 @@ let popoverAnchor let popover let searchTerm = "" + let prevSearch = undefined + let pageInfo = createPaginationStore() let loaded = false let editModal, deleteModal $: scimEnabled = $features.isScimEnabled $: readonly = !$auth.isAdmin || scimEnabled + $: page = $pageInfo.page + $: fetchUsers(page, searchTerm) $: group = $groups.find(x => x._id === groupId) + $: filtered = $users.data $: groupApps = $apps .filter(app => groups.actions @@ -106,6 +112,25 @@ } } + 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, email: search }) + pageInfo.fetched($users.hasNextPage, $users.nextPage) + } catch (error) { + notifications.error("Error getting user list") + } + } + async function deleteGroup() { try { await groups.actions.delete(group) @@ -201,7 +226,7 @@