From a44729d7ecbf6a2d062339820394129ceff1c4d0 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 28 Feb 2023 12:49:40 +0000 Subject: [PATCH] Add role footer for admins and developers, remove wasted API calls --- packages/bbui/src/Form/Core/Picker.svelte | 14 +++++++++++++ packages/bbui/src/Form/Core/Select.svelte | 2 ++ packages/bbui/src/Form/Select.svelte | 2 ++ .../src/components/common/RoleSelect.svelte | 21 +++++++++++++------ .../_components/BuilderSidePanel.svelte | 20 ++++++++++++------ 5 files changed, 47 insertions(+), 12 deletions(-) diff --git a/packages/bbui/src/Form/Core/Picker.svelte b/packages/bbui/src/Form/Core/Picker.svelte index 4e7bd7ba78..f5fd3750d4 100644 --- a/packages/bbui/src/Form/Core/Picker.svelte +++ b/packages/bbui/src/Form/Core/Picker.svelte @@ -34,6 +34,7 @@ export let fetchTerm = null export let customPopoverHeight export let align = "left" + export let footer = null const dispatch = createEventDispatcher() @@ -210,6 +211,12 @@ {/each} {/if} + + {#if footer} + + {/if} @@ -286,4 +293,11 @@ .popover-content :global(.spectrum-Search .spectrum-Textfield-icon) { top: 9px; } + + .footer { + padding: 4px 12px 12px 12px; + font-style: italic; + max-width: 160px; + font-size: 12px; + } diff --git a/packages/bbui/src/Form/Core/Select.svelte b/packages/bbui/src/Form/Core/Select.svelte index a1ae2107c8..a329933670 100644 --- a/packages/bbui/src/Form/Core/Select.svelte +++ b/packages/bbui/src/Form/Core/Select.svelte @@ -19,6 +19,7 @@ export let autocomplete = false export let sort = false export let align + export let footer = null const dispatch = createEventDispatcher() @@ -68,6 +69,7 @@ {options} {autoWidth} {align} + {footer} {getOptionLabel} {getOptionValue} {getOptionIcon} diff --git a/packages/bbui/src/Form/Select.svelte b/packages/bbui/src/Form/Select.svelte index 44ce51eff2..17074968fa 100644 --- a/packages/bbui/src/Form/Select.svelte +++ b/packages/bbui/src/Form/Select.svelte @@ -23,6 +23,7 @@ export let autocomplete = false export let customPopoverHeight export let align + export let footer = null const dispatch = createEventDispatcher() const onChange = e => { @@ -50,6 +51,7 @@ {autoWidth} {sort} {align} + {footer} {getOptionLabel} {getOptionValue} {getOptionIcon} diff --git a/packages/builder/src/components/common/RoleSelect.svelte b/packages/builder/src/components/common/RoleSelect.svelte index f94f048945..6a1448b714 100644 --- a/packages/builder/src/components/common/RoleSelect.svelte +++ b/packages/builder/src/components/common/RoleSelect.svelte @@ -13,16 +13,24 @@ export let allowRemove = false export let disabled = false export let align + export let footer = null + export let allowedRoles = null const dispatch = createEventDispatcher() const RemoveID = "remove" - $: options = getOptions($roles, allowPublic, allowRemove) + $: options = getOptions($roles, allowPublic, allowRemove, allowedRoles) - const getOptions = (roles, allowPublic) => { + const getOptions = (roles, allowPublic, allowRemove, allowedRoles) => { + if (allowedRoles?.length) { + console.log(allowedRoles) + console.log(roles) + return roles.filter(role => allowedRoles.includes(role._id)) + } + let newRoles = [...roles] if (allowRemove) { - roles = [ - ...roles, + newRoles = [ + ...newRoles, { _id: RemoveID, name: "Remove", @@ -30,9 +38,9 @@ ] } if (allowPublic) { - return roles + return newRoles } - return roles.filter(role => role._id !== Constants.Roles.PUBLIC) + return newRoles.filter(role => role._id !== Constants.Roles.PUBLIC) } const getColor = role => { @@ -63,6 +71,7 @@ {quiet} {disabled} {align} + {footer} bind:value on:change={onChange} {options} diff --git a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte index b53b218c74..a350a044c9 100644 --- a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte @@ -84,7 +84,7 @@ const isBuilderOrAdmin = user.admin?.global || user.builder?.global let role = undefined if (isBuilderOrAdmin) { - role = "ADMIN" + role = Constants.Roles.ADMIN } else { const appRole = Object.keys(user.roles).find(x => x === prodAppId) if (appRole) { @@ -134,6 +134,9 @@ return } try { + if (user.role === role) { + return + } await updateAppUser(user, role) } catch (error) { console.error(error) @@ -369,9 +372,12 @@ } } - const roleNote = user => { - if (user.group) { - return "Part of a group" + const getRoleFooter = user => { + if (!user.role && user.group) { + return "This user has been given access via their group" + } + if (user.isBuilderOrAdmin) { + return "This user's role grants admin access to all apps" } return null } @@ -557,7 +563,7 @@
{ onUpdateUser(user) }} - disabled={user.isBuilderOrAdmin} autoWidth align="right" + allowedRoles={user.isBuilderOrAdmin + ? [Constants.Roles.ADMIN] + : null} />