Add searching for users back

This commit is contained in:
Adria Navarro 2023-05-05 09:36:18 +01:00
parent 10fcca92f6
commit 8102c54bc3
1 changed files with 40 additions and 7 deletions

View File

@ -16,6 +16,7 @@
import { fetchData } from "@budibase/frontend-core" import { fetchData } from "@budibase/frontend-core"
import { API } from "api" import { API } from "api"
import UserGroupPicker from "components/settings/UserGroupPicker.svelte" import UserGroupPicker from "components/settings/UserGroupPicker.svelte"
import { createPaginationStore } from "helpers/pagination"
import { users, apps, groups, auth, features } from "stores/portal" import { users, apps, groups, auth, features } from "stores/portal"
import { onMount, setContext } from "svelte" import { onMount, setContext } from "svelte"
import { roles } from "stores/backend" import { roles } from "stores/backend"
@ -30,7 +31,7 @@
export let groupId export let groupId
const fetchUsers = fetchData({ const fetchGroupUsers = fetchData({
API, API,
datasource: { datasource: {
type: "groupUser", type: "groupUser",
@ -84,12 +85,17 @@
let popoverAnchor let popoverAnchor
let popover let popover
let searchTerm = "" let searchTerm = ""
let prevSearch = undefined
let pageInfo = createPaginationStore()
let loaded = false let loaded = false
let editModal, deleteModal let editModal, deleteModal
$: scimEnabled = $features.isScimEnabled $: scimEnabled = $features.isScimEnabled
$: readonly = !$auth.isAdmin || scimEnabled $: readonly = !$auth.isAdmin || scimEnabled
$: page = $pageInfo.page
$: fetchUsers(page, searchTerm)
$: group = $groups.find(x => x._id === groupId) $: group = $groups.find(x => x._id === groupId)
$: filtered = $users.data
$: groupApps = $apps $: groupApps = $apps
.filter(app => .filter(app =>
groups.actions 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() { async function deleteGroup() {
try { try {
await groups.actions.delete(group) await groups.actions.delete(group)
@ -201,7 +226,7 @@
<Table <Table
schema={userSchema} schema={userSchema}
data={$fetchUsers.rows} data={$fetchGroupUsers?.users}
allowEditRows={false} allowEditRows={false}
customPlaceholder customPlaceholder
customRenderers={customUserTableRenderers} customRenderers={customUserTableRenderers}
@ -214,11 +239,19 @@
<div class="pagination"> <div class="pagination">
<Pagination <Pagination
page={$fetchUsers.pageNumber + 1} page={$fetchGroupUsers.pageNumber + 1}
hasPrevPage={$fetchUsers.loading ? false : $fetchUsers.hasPrevPage} hasPrevPage={$fetchGroupUsers.loading
hasNextPage={$fetchUsers.loading ? false : $fetchUsers.hasNextPage} ? false
goToPrevPage={$fetchUsers.loading ? null : fetchUsers.prevPage} : $fetchGroupUsers.hasPrevPage}
goToNextPage={$fetchUsers.loading ? null : fetchUsers.nextPage} hasNextPage={$fetchGroupUsers.loading
? false
: $fetchGroupUsers.hasNextPage}
goToPrevPage={$fetchGroupUsers.loading
? null
: fetchGroupUsers.prevPage}
goToNextPage={$fetchGroupUsers.loading
? null
: fetchGroupUsers.nextPage}
/> />
</div> </div>
</Layout> </Layout>