Allow removing users from user assignment modal and add validation to prevent invalid submissions

This commit is contained in:
Andrew Kingston 2022-08-03 14:27:44 +01:00
parent d1cce411c8
commit 60565abfbf
3 changed files with 64 additions and 22 deletions

View File

@ -34,6 +34,7 @@
export let isOptionSelected = () => false export let isOptionSelected = () => false
export let isPlaceholder = false export let isPlaceholder = false
export let placeholderOption = null export let placeholderOption = null
export let showClearIcon = true
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
let primaryOpen = false let primaryOpen = false
@ -129,7 +130,7 @@
class:labelPadding={iconData} class:labelPadding={iconData}
class:open={primaryOpen} class:open={primaryOpen}
/> />
{#if primaryValue} {#if primaryValue && showClearIcon}
<button <button
on:click={() => onClearPrimary()} on:click={() => onClearPrimary()}
type="reset" type="reset"

View File

@ -27,6 +27,7 @@
export let primaryOptions = [] export let primaryOptions = []
export let secondaryOptions = [] export let secondaryOptions = []
export let searchTerm export let searchTerm
export let showClearIcon = true
let primaryLabel let primaryLabel
let secondaryLabel let secondaryLabel
@ -120,6 +121,7 @@
{secondaryValue} {secondaryValue}
{primaryLabel} {primaryLabel}
{secondaryLabel} {secondaryLabel}
{showClearIcon}
on:pickprimary={onPickPrimary} on:pickprimary={onPickPrimary}
on:picksecondary={onPickSecondary} on:picksecondary={onPickSecondary}
on:search={updateSearchTerm} on:search={updateSearchTerm}

View File

@ -4,6 +4,7 @@
PickerDropdown, PickerDropdown,
ActionButton, ActionButton,
Layout, Layout,
Icon,
notifications, notifications,
} from "@budibase/bbui" } from "@budibase/bbui"
import { roles } from "stores/backend" import { roles } from "stores/backend"
@ -28,7 +29,8 @@
return appId === app.appId return appId === app.appId
}) })
}) })
$: valid =
appData?.length && !appData?.some(x => !x.id?.length || !x.role?.length)
$: optionSections = { $: optionSections = {
...($auth.groupsEnabled && ...($auth.groupsEnabled &&
filteredGroups.length && { filteredGroups.length && {
@ -83,6 +85,10 @@
function addNewInput() { function addNewInput() {
appData = [...appData, { id: "", role: "" }] appData = [...appData, { id: "", role: "" }]
} }
const removeItem = index => {
appData = appData.filter((x, idx) => idx !== index)
}
</script> </script>
<ModalContent <ModalContent
@ -92,28 +98,61 @@
cancelText="Cancel" cancelText="Cancel"
onConfirm={() => addData(appData)} onConfirm={() => addData(appData)}
showCloseIcon={false} showCloseIcon={false}
disabled={!valid}
> >
<Layout noPadding gap="XS"> {#if appData?.length}
{#each appData as input, index} <Layout noPadding gap="XS">
<PickerDropdown {#each appData as input, index}
autocomplete <div class="item">
primaryOptions={optionSections} <div class="picker">
secondaryOptions={$roles} <PickerDropdown
secondaryPlaceholder="Access" autocomplete
bind:primaryValue={input.id} showClearIcon={false}
bind:secondaryValue={input.role} primaryOptions={optionSections}
bind:searchTerm={search} secondaryOptions={$roles}
getPrimaryOptionLabel={group => group.name} secondaryPlaceholder="Access"
getPrimaryOptionValue={group => group.name} bind:primaryValue={input.id}
getPrimaryOptionIcon={group => group.icon} bind:secondaryValue={input.role}
getPrimaryOptionColour={group => group.colour} bind:searchTerm={search}
getSecondaryOptionLabel={role => role.name} getPrimaryOptionLabel={group => group.name}
getSecondaryOptionValue={role => role._id} getPrimaryOptionValue={group => group.name}
getSecondaryOptionColour={role => RoleUtils.getRoleColour(role._id)} getPrimaryOptionIcon={group => group.icon}
/> getPrimaryOptionColour={group => group.colour}
{/each} getSecondaryOptionLabel={role => role.name}
</Layout> getSecondaryOptionValue={role => role._id}
getSecondaryOptionColour={role =>
RoleUtils.getRoleColour(role._id)}
/>
</div>
<div class="icon">
<Icon
name="Close"
hoverable
size="S"
on:click={() => removeItem(index)}
/>
</div>
</div>
{/each}
</Layout>
{/if}
<div> <div>
<ActionButton on:click={addNewInput} icon="Add">Add email</ActionButton> <ActionButton on:click={addNewInput} icon="Add">Add email</ActionButton>
</div> </div>
</ModalContent> </ModalContent>
<style>
.item {
position: relative;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
.picker {
width: calc(100% - 30px);
}
.icon {
width: 20px;
}
</style>