Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Designer user side panel UX updates. #10468

Merged
merged 10 commits into from
May 15, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@
let inviting = false
let searchFocus = false

// Initially filter entities without app access
// Show all when false
let filterByAppAccess = true

let appInvites = []
let filteredInvites = []
let filteredUsers = []
let filteredGroups = []
let selectedGroup
let userOnboardResponse = null

let userLimitReachedModal

$: queryIsEmail = emailValidator(query) === true
Expand All @@ -52,15 +55,32 @@
}

const filterInvites = async query => {
if (!prodAppId) {
return
}

appInvites = await getInvites()
if (!query || query == "") {
filteredInvites = appInvites

//On Focus behaviour
if (!filterByAppAccess && (!query || query == "")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB but just a quick FYI that (!query || query == "") is redundant - !query by itself will already account for empty strings.

filteredInvites =
appInvites.length > 100 ? appInvites.slice(0, 100) : [...appInvites]
return
}
filteredInvites = appInvites.filter(invite => invite.email.includes(query))

filteredInvites = appInvites.filter(invite => {
const inviteInfo = invite.info?.apps
if ((!query || query == "") && inviteInfo && prodAppId) {
return Object.keys(inviteInfo).includes(prodAppId)
}
return invite.email.includes(query)
})
}

$: filterInvites(query)
$: filterByAppAccess, prodAppId, filterInvites(query)
$: if (searchFocus === true) {
filterByAppAccess = false
}

const usersFetch = fetchData({
API,
Expand All @@ -79,9 +99,9 @@
}
await usersFetch.update({
query: {
appId: query ? null : prodAppId,
appId: query || !filterByAppAccess ? null : prodAppId,
email: query,
paginated: query ? null : false,
paginated: query || !filterByAppAccess ? null : false,
},
})
await usersFetch.refresh()
Expand All @@ -107,7 +127,12 @@
}

const debouncedUpdateFetch = Utils.debounce(searchUsers, 250)
$: debouncedUpdateFetch(query, $store.builderSidePanel, loaded)
$: debouncedUpdateFetch(
query,
$store.builderSidePanel,
loaded,
filterByAppAccess
)

const updateAppUser = async (user, role) => {
if (!prodAppId) {
Expand Down Expand Up @@ -182,9 +207,10 @@
}

const searchGroups = (userGroups, query) => {
let filterGroups = query?.length
? userGroups
: getAppGroups(userGroups, prodAppId)
let filterGroups =
query?.length || !filterByAppAccess
? userGroups
: getAppGroups(userGroups, prodAppId)
return filterGroups
.filter(group => {
if (!query?.length) {
Expand Down Expand Up @@ -214,7 +240,7 @@
}

// Adds the 'role' attribute and sets it to the current app.
$: enrichedGroups = getEnrichedGroups($groups)
$: enrichedGroups = getEnrichedGroups($groups, filterByAppAccess)
$: filteredGroups = searchGroups(enrichedGroups, query)
$: groupUsers = buildGroupUsers(filteredGroups, filteredUsers)
$: allUsers = [...filteredUsers, ...groupUsers]
Expand All @@ -226,7 +252,7 @@
specific roles for the app.
*/
const buildGroupUsers = (userGroups, filteredUsers) => {
if (query) {
if (query || !filterByAppAccess) {
return []
}
// Must exclude users who have explicit privileges
Expand Down Expand Up @@ -351,7 +377,6 @@

onMount(() => {
rendered = true
searchFocus = true
})

function handleKeyDown(evt) {
Expand Down Expand Up @@ -417,7 +442,6 @@
autocomplete="off"
disabled={inviting}
value={query}
autofocus
on:input={e => {
query = e.target.value.trim()
}}
Expand All @@ -428,16 +452,20 @@

<span
class="search-input-icon"
class:searching={query}
class:searching={query || !filterByAppAccess}
on:click={() => {
if (!filterByAppAccess) {
filterByAppAccess = true
}
if (!query) {
return
}
query = null
userOnboardResponse = null
filterByAppAccess = true
}}
>
<Icon name={query ? "Close" : "Search"} />
<Icon name={!filterByAppAccess || query ? "Close" : "Search"} />
</span>
</div>

Expand Down Expand Up @@ -481,6 +509,8 @@
</div>
</div>
<div class="auth-entity-access">
<!-- {#key filteredInvites} -->
<!-- {invite.info.apps?.[prodAppId]} -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some commented out code left over.

<RoleSelect
placeholder={false}
value={invite.info.apps?.[prodAppId]}
Expand All @@ -496,6 +526,7 @@
autoWidth
align="right"
/>
<!-- {/key} -->
</div>
</div>
{/each}
Expand Down Expand Up @@ -555,7 +586,7 @@

{#if filteredUsers?.length}
<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-access-title">Access</div>
</div>
Expand Down