On focus search behaviour renders to 100 invites, all groups and the first page of current users

This commit is contained in:
Dean 2023-05-02 14:35:15 +01:00
parent 530c4fb00f
commit bb98160317
1 changed files with 28 additions and 23 deletions

View File

@ -28,9 +28,9 @@
let inviting = false let inviting = false
let searchFocus = false let searchFocus = false
//Or searching = true? // Initially filter entities without app access
let filtered = true // Show all when false
$: console.log("filtering enabled ", filtered) let filterByAppAccess = true
let appInvites = [] let appInvites = []
let filteredInvites = [] let filteredInvites = []
@ -38,7 +38,6 @@
let filteredGroups = [] let filteredGroups = []
let selectedGroup let selectedGroup
let userOnboardResponse = null let userOnboardResponse = null
let userLimitReachedModal let userLimitReachedModal
$: queryIsEmail = emailValidator(query) === true $: queryIsEmail = emailValidator(query) === true
@ -63,8 +62,9 @@
appInvites = await getInvites() appInvites = await getInvites()
//On Focus behaviour //On Focus behaviour
if (!filtered && (!query || query == "")) { if (!filterByAppAccess && (!query || query == "")) {
filteredInvites = [...appInvites] filteredInvites =
appInvites.length > 100 ? appInvites.slice(0, 100) : [...appInvites]
return return
} }
@ -77,9 +77,9 @@
}) })
} }
$: filtered, prodAppId, filterInvites(query) $: filterByAppAccess, prodAppId, filterInvites(query)
$: if (searchFocus === true) { $: if (searchFocus === true) {
filtered = false filterByAppAccess = false
} }
const usersFetch = fetchData({ const usersFetch = fetchData({
@ -99,9 +99,9 @@
} }
await usersFetch.update({ await usersFetch.update({
query: { query: {
appId: query ? null : prodAppId, appId: query || !filterByAppAccess ? null : prodAppId,
email: query, email: query,
paginated: query ? null : false, paginated: query || !filterByAppAccess ? null : false,
}, },
}) })
await usersFetch.refresh() await usersFetch.refresh()
@ -127,7 +127,12 @@
} }
const debouncedUpdateFetch = Utils.debounce(searchUsers, 250) const debouncedUpdateFetch = Utils.debounce(searchUsers, 250)
$: debouncedUpdateFetch(query, $store.builderSidePanel, loaded) $: debouncedUpdateFetch(
query,
$store.builderSidePanel,
loaded,
filterByAppAccess
)
const updateAppUser = async (user, role) => { const updateAppUser = async (user, role) => {
if (!prodAppId) { if (!prodAppId) {
@ -202,9 +207,10 @@
} }
const searchGroups = (userGroups, query) => { const searchGroups = (userGroups, query) => {
let filterGroups = query?.length let filterGroups =
? userGroups query?.length || !filterByAppAccess
: getAppGroups(userGroups, prodAppId) ? userGroups
: getAppGroups(userGroups, prodAppId)
return filterGroups return filterGroups
.filter(group => { .filter(group => {
if (!query?.length) { if (!query?.length) {
@ -234,7 +240,7 @@
} }
// Adds the 'role' attribute and sets it to the current app. // Adds the 'role' attribute and sets it to the current app.
$: enrichedGroups = getEnrichedGroups($groups) $: enrichedGroups = getEnrichedGroups($groups, filterByAppAccess)
$: filteredGroups = searchGroups(enrichedGroups, query) $: filteredGroups = searchGroups(enrichedGroups, query)
$: groupUsers = buildGroupUsers(filteredGroups, filteredUsers) $: groupUsers = buildGroupUsers(filteredGroups, filteredUsers)
$: allUsers = [...filteredUsers, ...groupUsers] $: allUsers = [...filteredUsers, ...groupUsers]
@ -246,7 +252,7 @@
specific roles for the app. specific roles for the app.
*/ */
const buildGroupUsers = (userGroups, filteredUsers) => { const buildGroupUsers = (userGroups, filteredUsers) => {
if (query) { if (query || !filterByAppAccess) {
return [] return []
} }
// Must exclude users who have explicit privileges // Must exclude users who have explicit privileges
@ -371,7 +377,6 @@
onMount(() => { onMount(() => {
rendered = true rendered = true
// searchFocus = true
}) })
function handleKeyDown(evt) { function handleKeyDown(evt) {
@ -447,20 +452,20 @@
<span <span
class="search-input-icon" class="search-input-icon"
class:searching={query || !filtered} class:searching={query || !filterByAppAccess}
on:click={() => { on:click={() => {
if (!filtered) { if (!filterByAppAccess) {
filtered = true filterByAppAccess = true
} }
if (!query) { if (!query) {
return return
} }
query = null query = null
userOnboardResponse = null userOnboardResponse = null
filtered = true filterByAppAccess = true
}} }}
> >
<Icon name={!filtered || query ? "Close" : "Search"} /> <Icon name={!filterByAppAccess || query ? "Close" : "Search"} />
</span> </span>
</div> </div>
@ -581,7 +586,7 @@
{#if filteredUsers?.length} {#if filteredUsers?.length}
<div class="auth-entity-section"> <div class="auth-entity-section">
<div class="auth-entity-header "> <div class="auth-entity-header">
<div class="auth-entity-title">Users</div> <div class="auth-entity-title">Users</div>
<div class="auth-entity-access-title">Access</div> <div class="auth-entity-access-title">Access</div>
</div> </div>