Initial commit of UX refactor

This commit is contained in:
Dean 2022-08-22 12:49:05 +01:00
parent db746c1c23
commit 098c67ce5d
5 changed files with 210 additions and 57 deletions

View File

@ -1,4 +1,4 @@
export default function positionDropdown(element, { anchor, align }) { export default function positionDropdown(element, { anchor, align, maxWidth }) {
let positionSide = "top" let positionSide = "top"
let maxHeight = 0 let maxHeight = 0
let dimensions = getDimensions(anchor) let dimensions = getDimensions(anchor)
@ -34,13 +34,24 @@ export default function positionDropdown(element, { anchor, align }) {
} }
function calcLeftPosition() { function calcLeftPosition() {
return align === "right" let left
? dimensions.left + dimensions.width - dimensions.containerWidth
: dimensions.left if (align == "right") {
left = dimensions.left + dimensions.width - dimensions.containerWidth
} else if (align == "right-side") {
left = dimensions.left + dimensions.width
} else {
left = dimensions.left
}
return left
} }
element.style.position = "absolute" element.style.position = "absolute"
element.style.zIndex = "9999" element.style.zIndex = "9999"
if (maxWidth) {
element.style.maxWidth = `${maxWidth}px`
}
element.style.minWidth = `${dimensions.width}px` element.style.minWidth = `${dimensions.width}px`
element.style.maxHeight = `${maxHeight.toFixed(0)}px` element.style.maxHeight = `${maxHeight.toFixed(0)}px`
element.style.transformOrigin = `center ${positionSide}` element.style.transformOrigin = `center ${positionSide}`
@ -54,10 +65,8 @@ export default function positionDropdown(element, { anchor, align }) {
element.style.left = `${calcLeftPosition(dimensions).toFixed(0)}px` element.style.left = `${calcLeftPosition(dimensions).toFixed(0)}px`
}) })
}) })
resizeObserver.observe(anchor) resizeObserver.observe(anchor)
resizeObserver.observe(element) resizeObserver.observe(element)
return { return {
destroy() { destroy() {
resizeObserver.disconnect() resizeObserver.disconnect()

View File

@ -11,6 +11,7 @@
export let align = "right" export let align = "right"
export let portalTarget export let portalTarget
export let dataCy export let dataCy
export let maxWidth
export let direction = "bottom" export let direction = "bottom"
export let showTip = false export let showTip = false
@ -45,7 +46,7 @@
<Portal target={portalTarget}> <Portal target={portalTarget}>
<div <div
tabindex="0" tabindex="0"
use:positionDropdown={{ anchor, align }} use:positionDropdown={{ anchor, align, maxWidth }}
use:clickOutside={hide} use:clickOutside={hide}
on:keydown={handleEscape} on:keydown={handleEscape}
class={"spectrum-Popover is-open " + (tooltipClasses || "")} class={"spectrum-Popover is-open " + (tooltipClasses || "")}

View File

@ -359,6 +359,7 @@ const getProviderContextBindings = (asset, dataProviders) => {
providerId, providerId,
// Table ID is used by JSON fields to know what table the field is in // Table ID is used by JSON fields to know what table the field is in
tableId: table?._id, tableId: table?._id,
category: "Data",
}) })
}) })
}) })
@ -385,6 +386,7 @@ const getUserBindings = () => {
// datasource options, based on bindable properties // datasource options, based on bindable properties
fieldSchema, fieldSchema,
providerId: "user", providerId: "user",
category: "Current User",
}) })
}) })
return bindings return bindings
@ -401,11 +403,13 @@ const getDeviceBindings = () => {
type: "context", type: "context",
runtimeBinding: `${safeDevice}.${makePropSafe("mobile")}`, runtimeBinding: `${safeDevice}.${makePropSafe("mobile")}`,
readableBinding: `Device.Mobile`, readableBinding: `Device.Mobile`,
category: "Device",
}) })
bindings.push({ bindings.push({
type: "context", type: "context",
runtimeBinding: `${safeDevice}.${makePropSafe("tablet")}`, runtimeBinding: `${safeDevice}.${makePropSafe("tablet")}`,
readableBinding: `Device.Tablet`, readableBinding: `Device.Tablet`,
category: "Device",
}) })
} }
return bindings return bindings
@ -460,6 +464,7 @@ const getStateBindings = () => {
type: "context", type: "context",
runtimeBinding: `${safeState}.${makePropSafe(key)}`, runtimeBinding: `${safeState}.${makePropSafe(key)}`,
readableBinding: `State.${key}`, readableBinding: `State.${key}`,
category: "State",
})) }))
} }
return bindings return bindings
@ -482,11 +487,13 @@ const getUrlBindings = asset => {
type: "context", type: "context",
runtimeBinding: `${safeURL}.${makePropSafe(param)}`, runtimeBinding: `${safeURL}.${makePropSafe(param)}`,
readableBinding: `URL.${param}`, readableBinding: `URL.${param}`,
category: "URL",
})) }))
const queryParamsBinding = { const queryParamsBinding = {
type: "context", type: "context",
runtimeBinding: makePropSafe("query"), runtimeBinding: makePropSafe("query"),
readableBinding: "Query params", readableBinding: "Query params",
category: "URL",
} }
return urlParamBindings.concat([queryParamsBinding]) return urlParamBindings.concat([queryParamsBinding])
} }
@ -497,6 +504,7 @@ const getRoleBindings = () => {
type: "context", type: "context",
runtimeBinding: `trim "${role._id}"`, runtimeBinding: `trim "${role._id}"`,
readableBinding: `Role.${role.name}`, readableBinding: `Role.${role.name}`,
category: "Role",
} }
}) })
} }

View File

@ -9,6 +9,9 @@
Body, Body,
Layout, Layout,
Button, Button,
ActionButton,
Icon,
Popover,
} from "@budibase/bbui" } from "@budibase/bbui"
import { createEventDispatcher, onMount } from "svelte" import { createEventDispatcher, onMount } from "svelte"
import { import {
@ -45,6 +48,21 @@
let jsValue = initialValueJS ? value : null let jsValue = initialValueJS ? value : null
let hbsValue = initialValueJS ? null : value let hbsValue = initialValueJS ? null : value
let selectedCategory = null
let categoryIcons = {
Device: "DevicePhone",
"Current User": "User",
Helpers: "MagicWand",
Data: "Data",
State: "AutomatedSegment",
URL: "RailTop",
Role: "UsersLock",
}
let popover
let popoverAnchor
let hoverHelper
$: usingJS = mode === "JavaScript" $: usingJS = mode === "JavaScript"
$: searchRgx = new RegExp(search, "ig") $: searchRgx = new RegExp(search, "ig")
$: categories = Object.entries(groupBy("category", bindings)) $: categories = Object.entries(groupBy("category", bindings))
@ -55,10 +73,25 @@
return binding.readableBinding.match(searchRgx) return binding.readableBinding.match(searchRgx)
}), }),
})) }))
.filter(category => category.bindings?.length > 0) .filter(category => {
return (
category.bindings?.length > 0 &&
(!selectedCategory ? true : selectedCategory === category.name)
)
})
$: filteredHelpers = helpers?.filter(helper => { $: filteredHelpers = helpers?.filter(helper => {
return helper.label.match(searchRgx) || helper.description.match(searchRgx) return helper.label.match(searchRgx) || helper.description.match(searchRgx)
}) })
$: categoryNames = [
...categories.reduce((acc, cat) => {
acc.push(cat[0])
return acc
}, []),
"Helpers",
]
$: codeMirrorHints = bindings?.map(x => `$("${x.readableBinding}")`) $: codeMirrorHints = bindings?.map(x => `$("${x.readableBinding}")`)
const updateValue = val => { const updateValue = val => {
@ -140,23 +173,91 @@
}) })
</script> </script>
<span class="detailPopover">
<Popover
align="right-side"
bind:this={popover}
anchor={popoverAnchor}
maxWidth={300}
observe={false}
>
<Layout gap="S">
{#if selectedCategory === "Helpers" || search}
<div class="helper">
<div class="helper__name">{hoverHelper.displayText}</div>
<div class="helper__description">
{@html hoverHelper.description}
</div>
<pre class="helper__example">{getHelperExample(
hoverHelper,
usingJS
)}</pre>
</div>
{/if}
</Layout>
</Popover>
</span>
<DrawerContent> <DrawerContent>
<svelte:fragment slot="sidebar"> <svelte:fragment slot="sidebar">
<div class="container"> <Layout noPadding gap="S">
<section> {#if selectedCategory}
<div>
<ActionButton
secondary
icon={"ArrowLeft"}
on:click={() => {
selectedCategory = null
}}
>
Back
</ActionButton>
</div>
{/if}
{#if !selectedCategory}
<div class="heading">Search</div> <div class="heading">Search</div>
<Search placeholder="Search" bind:value={search} /> <Search placeholder="Search" bind:value={search} />
</section> {/if}
{#each filteredCategories as category}
{#if category.bindings?.length} {#if !selectedCategory && !search}
<section> <ul class="category-list">
<div class="heading">{category.name}</div> {#each categoryNames as categoryName}
<li
on:click={() => {
selectedCategory = categoryName
}}
>
<Icon name={categoryIcons[categoryName]} />
<span class="category-name">{categoryName} </span>
<span class="category-chevron"><Icon name="ChevronRight" /></span>
</li>
{/each}
</ul>
{/if}
{#if selectedCategory || search}
{#each filteredCategories as category}
{#if category.bindings?.length}
<div class="cat-heading">
<Icon name={categoryIcons[category.name]} />{category.name}
</div>
<ul> <ul>
{#each category.bindings as binding} {#each category.bindings as binding}
<li on:click={() => addBinding(binding)}> <!-- {JSON.stringify(binding)} -->
<li class="binding" on:click={() => addBinding(binding)}>
<span class="binding__label">{binding.readableBinding}</span> <span class="binding__label">{binding.readableBinding}</span>
{#if binding.type} <!-- {#if binding.type}
<span class="binding__type">{binding.type}</span> <span class="binding__typeWrap">
<span class="binding__type">{binding.type}</span>
</span>
{/if} -->
{#if binding.fieldSchema?.type}
<span class="binding__typeWrap">
<span class="binding__type">
{binding.fieldSchema.type}
</span>
</span>
{/if} {/if}
{#if binding.description} {#if binding.description}
<br /> <br />
@ -167,31 +268,44 @@
</li> </li>
{/each} {/each}
</ul> </ul>
</section> {/if}
{/each}
{#if selectedCategory === "Helpers" || search}
{#if filteredHelpers?.length}
<div class="heading">Helpers</div>
<ul class="helpers">
{#each filteredHelpers as helper}
<li
on:click={() => addHelper(helper, usingJS)}
on:mouseenter={e => {
// if (e.target !== this) return
popoverAnchor = e.target
hoverHelper = helper
popover.show()
e.stopPropagation()
}}
on:mouseleave={() => {
popover.hide()
popoverAnchor = null
hoverHelper = null
}}
on:focus={() => {}}
on:blur={() => {}}
>
<span class="binding__label">{helper.displayText}</span>
{#if helper.type}
<span class="binding__typeWrap">
<span class="binding__type">{helper.type}</span>
</span>
{/if}
</li>
{/each}
</ul>
{/if}
{/if} {/if}
{/each}
{#if filteredHelpers?.length}
<section>
<div class="heading">Helpers</div>
<ul>
{#each filteredHelpers as helper}
<li on:click={() => addHelper(helper, usingJS)}>
<div class="helper">
<div class="helper__name">{helper.displayText}</div>
<div class="helper__description">
{@html helper.description}
</div>
<pre class="helper__example">{getHelperExample(
helper,
usingJS
)}</pre>
</div>
</li>
{/each}
</ul>
</section>
{/if} {/if}
</div> </Layout>
</svelte:fragment> </svelte:fragment>
<div class="main"> <div class="main">
<Tabs selected={mode} on:select={onChangeMode}> <Tabs selected={mode} on:select={onChangeMode}>
@ -241,6 +355,35 @@
</DrawerContent> </DrawerContent>
<style> <style>
ul.helpers li * {
pointer-events: none;
}
ul.category-list li {
display: flex;
gap: var(--spacing-m);
align-items: center;
}
ul.category-list .category-name {
font-weight: 600;
text-transform: capitalize;
}
ul.category-list .category-chevron {
flex: 1;
text-align: right;
}
ul.category-list .category-chevron :global(div.icon),
.cat-heading :global(div.icon) {
display: inline-block;
}
li.binding {
display: flex;
align-items: center;
}
li.binding .binding__typeWrap {
flex: 1;
text-align: right;
text-transform: capitalize;
}
.main :global(textarea) { .main :global(textarea) {
min-height: 202px !important; min-height: 202px !important;
} }
@ -251,23 +394,20 @@
padding: var(--spacing-s) var(--spacing-xl); padding: var(--spacing-s) var(--spacing-xl);
} }
.container { .heading,
margin: calc(-1 * var(--spacing-xl)); .cat-heading {
}
.heading {
font-size: var(--font-size-s); font-size: var(--font-size-s);
font-weight: 600; font-weight: 600;
text-transform: uppercase; text-transform: uppercase;
color: var(--spectrum-global-color-gray-600); color: var(--spectrum-global-color-gray-600);
padding: var(--spacing-xl) 0 var(--spacing-m) 0;
} }
section { .cat-heading {
padding: 0 var(--spacing-xl) var(--spacing-xl) var(--spacing-xl); display: flex;
} gap: var(--spacing-m);
section:not(:first-child) { align-items: center;
border-top: var(--border-light);
} }
ul { ul {
list-style: none; list-style: none;
padding: 0; padding: 0;
@ -278,7 +418,7 @@
font-size: var(--font-size-s); font-size: var(--font-size-s);
padding: var(--spacing-m); padding: var(--spacing-m);
border-radius: 4px; border-radius: 4px;
border: var(--border-light); background-color: var(--spectrum-global-color-gray-200);
transition: background-color 130ms ease-in-out, color 130ms ease-in-out, transition: background-color 130ms ease-in-out, color 130ms ease-in-out,
border-color 130ms ease-in-out; border-color 130ms ease-in-out;
word-wrap: break-word; word-wrap: break-word;
@ -292,12 +432,8 @@
li:hover { li:hover {
color: var(--spectrum-global-color-gray-900); color: var(--spectrum-global-color-gray-900);
background-color: var(--spectrum-global-color-gray-50); background-color: var(--spectrum-global-color-gray-50);
border-color: var(--spectrum-global-color-gray-500);
cursor: pointer; cursor: pointer;
} }
li:hover :global(*) {
color: var(--spectrum-global-color-gray-900) !important;
}
.binding__label { .binding__label {
font-weight: 600; font-weight: 600;

View File

@ -15,7 +15,6 @@
} }
return bindings?.map(binding => ({ return bindings?.map(binding => ({
...binding, ...binding,
category: "Bindable Values",
type: null, type: null,
})) }))
} }