Merge branch 'master' into test-template-import

This commit is contained in:
Sam Rose 2024-05-30 10:02:28 +01:00 committed by GitHub
commit a271110805
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 158 additions and 87 deletions

View File

@ -57,6 +57,7 @@
class:fullWidth class:fullWidth
class="spectrum-ActionButton spectrum-ActionButton--size{size}" class="spectrum-ActionButton spectrum-ActionButton--size{size}"
class:active class:active
class:disabled
{disabled} {disabled}
on:longPress on:longPress
on:click|preventDefault on:click|preventDefault
@ -109,19 +110,22 @@
background: var(--spectrum-global-color-gray-300); background: var(--spectrum-global-color-gray-300);
border-color: var(--spectrum-global-color-gray-500); border-color: var(--spectrum-global-color-gray-500);
} }
.noPadding {
padding: 0;
min-width: 0;
}
.spectrum-ActionButton--quiet { .spectrum-ActionButton--quiet {
padding: 0 8px; padding: 0 8px;
} }
.spectrum-ActionButton--quiet.is-selected { .spectrum-ActionButton--quiet.is-selected {
color: var(--spectrum-global-color-gray-900); color: var(--spectrum-global-color-gray-900);
} }
.noPadding {
padding: 0;
min-width: 0;
}
.is-selected:not(.emphasized) .spectrum-Icon { .is-selected:not(.emphasized) .spectrum-Icon {
color: var(--spectrum-global-color-gray-900); color: var(--spectrum-global-color-gray-900);
} }
.is-selected.disabled .spectrum-Icon {
color: var(--spectrum-global-color-gray-500);
}
.tooltip { .tooltip {
position: absolute; position: absolute;
pointer-events: none; pointer-events: none;

View File

@ -11,6 +11,7 @@
import { import {
decodeJSBinding, decodeJSBinding,
encodeJSBinding, encodeJSBinding,
processObjectSync,
processStringSync, processStringSync,
} from "@budibase/string-templates" } from "@budibase/string-templates"
import { readableToRuntimeBinding } from "dataBinding" import { readableToRuntimeBinding } from "dataBinding"
@ -153,13 +154,6 @@
debouncedEval(expression, context, snippets) debouncedEval(expression, context, snippets)
} }
const getBindingValue = (binding, context, snippets) => {
const js = `return $("${binding.runtimeBinding}")`
const hbs = encodeJSBinding(js)
const res = processStringSync(hbs, { ...context, snippets })
return JSON.stringify(res, null, 2)
}
const highlightJSON = json => { const highlightJSON = json => {
return formatHighlight(json, { return formatHighlight(json, {
keyColor: "#e06c75", keyColor: "#e06c75",
@ -172,11 +166,27 @@
} }
const enrichBindings = (bindings, context, snippets) => { const enrichBindings = (bindings, context, snippets) => {
return bindings.map(binding => { // Create a single big array to enrich in one go
const bindingStrings = bindings.map(binding => {
if (binding.runtimeBinding.startsWith('trim "')) {
// Account for nasty hardcoded HBS bindings for roles, for legacy
// compatibility
return `{{ ${binding.runtimeBinding} }}`
} else {
return `{{ literal ${binding.runtimeBinding} }}`
}
})
const bindingEvauations = processObjectSync(bindingStrings, {
...context,
snippets,
})
// Enrich bindings with evaluations and highlighted HTML
return bindings.map((binding, idx) => {
if (!context) { if (!context) {
return binding return binding
} }
const value = getBindingValue(binding, context, snippets) const value = JSON.stringify(bindingEvauations[idx], null, 2)
return { return {
...binding, ...binding,
value, value,

View File

@ -75,13 +75,6 @@
if (!context || !binding.value || binding.value === "") { if (!context || !binding.value || binding.value === "") {
return return
} }
// Roles have always been broken for JS. We need to exclude them from
// showing a popover as it will show "Error while executing JS".
if (binding.category === "Role") {
return
}
stopHidingPopover() stopHidingPopover()
popoverAnchor = target popoverAnchor = target
hoverTarget = { hoverTarget = {

View File

@ -127,7 +127,7 @@
flex-direction: column; flex-direction: column;
} }
label { label {
white-space: nowrap; word-wrap: break-word;
} }
label.hidden { label.hidden {
padding: 0; padding: 0;

View File

@ -1,7 +1,8 @@
<script> <script>
import { getContext } from "svelte" import { getContext } from "svelte"
import { ActionButton, Popover, Toggle, Icon } from "@budibase/bbui" import { ActionButton, Popover, Icon } from "@budibase/bbui"
import { getColumnIcon } from "../lib/utils" import { getColumnIcon } from "../lib/utils"
import ToggleActionButtonGroup from "./ToggleActionButtonGroup.svelte"
const { columns, datasource, stickyColumn, dispatch } = getContext("grid") const { columns, datasource, stickyColumn, dispatch } = getContext("grid")
@ -11,31 +12,45 @@
$: anyHidden = $columns.some(col => !col.visible) $: anyHidden = $columns.some(col => !col.visible)
$: text = getText($columns) $: text = getText($columns)
const toggleColumn = async (column, visible) => { const toggleColumn = async (column, permission) => {
datasource.actions.addSchemaMutation(column.name, { visible }) const visible = permission !== PERMISSION_OPTIONS.HIDDEN
await datasource.actions.saveSchemaMutations()
dispatch(visible ? "show-column" : "hide-column")
}
const toggleAll = async visible => { datasource.actions.addSchemaMutation(column.name, { visible })
let mutations = {}
$columns.forEach(column => {
mutations[column.name] = { visible }
})
datasource.actions.addSchemaMutations(mutations)
await datasource.actions.saveSchemaMutations() await datasource.actions.saveSchemaMutations()
dispatch(visible ? "show-column" : "hide-column") dispatch(visible ? "show-column" : "hide-column")
} }
const getText = columns => { const getText = columns => {
const hidden = columns.filter(col => !col.visible).length const hidden = columns.filter(col => !col.visible).length
return hidden ? `Hide columns (${hidden})` : "Hide columns" return hidden ? `Columns (${hidden} restricted)` : "Columns"
}
const PERMISSION_OPTIONS = {
WRITABLE: "writable",
HIDDEN: "hidden",
}
const options = [
{ icon: "Edit", value: PERMISSION_OPTIONS.WRITABLE, tooltip: "Writable" },
{
icon: "VisibilityOff",
value: PERMISSION_OPTIONS.HIDDEN,
tooltip: "Hidden",
},
]
function columnToPermissionOptions(column) {
if (!column.visible) {
return PERMISSION_OPTIONS.HIDDEN
}
return PERMISSION_OPTIONS.WRITABLE
} }
</script> </script>
<div bind:this={anchor}> <div bind:this={anchor}>
<ActionButton <ActionButton
icon="VisibilityOff" icon="ColumnSettings"
quiet quiet
size="M" size="M"
on:click={() => (open = !open)} on:click={() => (open = !open)}
@ -54,25 +69,25 @@
<Icon size="S" name={getColumnIcon($stickyColumn)} /> <Icon size="S" name={getColumnIcon($stickyColumn)} />
{$stickyColumn.label} {$stickyColumn.label}
</div> </div>
<Toggle disabled size="S" value={true} />
<ToggleActionButtonGroup
disabled
value={PERMISSION_OPTIONS.WRITABLE}
{options}
/>
{/if} {/if}
{#each $columns as column} {#each $columns as column}
<div class="column"> <div class="column">
<Icon size="S" name={getColumnIcon(column)} /> <Icon size="S" name={getColumnIcon(column)} />
{column.label} {column.label}
</div> </div>
<Toggle <ToggleActionButtonGroup
size="S" on:click={e => toggleColumn(column, e.detail)}
value={column.visible} value={columnToPermissionOptions(column)}
on:change={e => toggleColumn(column, e.detail)} {options}
disabled={column.primaryDisplay}
/> />
{/each} {/each}
</div> </div>
<div class="buttons">
<ActionButton on:click={() => toggleAll(true)}>Show all</ActionButton>
<ActionButton on:click={() => toggleAll(false)}>Hide all</ActionButton>
</div>
</div> </div>
</Popover> </Popover>
@ -83,15 +98,11 @@
flex-direction: column; flex-direction: column;
gap: 12px; gap: 12px;
} }
.buttons {
display: flex;
flex-direction: row;
gap: 8px;
}
.columns { .columns {
display: grid; display: grid;
align-items: center; align-items: center;
grid-template-columns: 1fr auto; grid-template-columns: 1fr auto;
gap: 8px;
} }
.columns :global(.spectrum-Switch) { .columns :global(.spectrum-Switch) {
margin-right: 0; margin-right: 0;

View File

@ -0,0 +1,43 @@
<script>
import { createEventDispatcher } from "svelte"
let dispatch = createEventDispatcher()
import { ActionButton, AbsTooltip, TooltipType } from "@budibase/bbui"
export let value
export let options
export let disabled
</script>
<div class="permissionPicker">
{#each options as option}
<AbsTooltip text={option.tooltip} type={TooltipType.Info}>
<ActionButton
on:click={() => dispatch("click", option.value)}
{disabled}
size="S"
icon={option.icon}
quiet
selected={option.value === value}
noPadding
/>
</AbsTooltip>
{/each}
</div>
<style>
.permissionPicker {
display: flex;
gap: var(--spacing-xs);
padding-left: calc(var(--spacing-xl) * 2);
}
.permissionPicker :global(.spectrum-Icon) {
width: 14px;
}
.permissionPicker :global(.spectrum-ActionButton) {
width: 28px;
height: 28px;
}
</style>

View File

@ -16,9 +16,10 @@
scroll, scroll,
isDragging, isDragging,
buttonColumnWidth, buttonColumnWidth,
showVScrollbar,
} = getContext("grid") } = getContext("grid")
let measureContainer let container
$: buttons = $props.buttons?.slice(0, 3) || [] $: buttons = $props.buttons?.slice(0, 3) || []
$: columnsWidth = $visibleColumns.reduce( $: columnsWidth = $visibleColumns.reduce(
@ -39,7 +40,7 @@
const width = entries?.[0]?.contentRect?.width ?? 0 const width = entries?.[0]?.contentRect?.width ?? 0
buttonColumnWidth.set(width) buttonColumnWidth.set(width)
}) })
observer.observe(measureContainer) observer.observe(container)
}) })
</script> </script>
@ -50,7 +51,7 @@
class:hidden={$buttonColumnWidth === 0} class:hidden={$buttonColumnWidth === 0}
> >
<div class="content" on:mouseleave={() => ($hoveredRowId = null)}> <div class="content" on:mouseleave={() => ($hoveredRowId = null)}>
<GridScrollWrapper scrollVertically attachHandlers> <GridScrollWrapper scrollVertically attachHandlers bind:ref={container}>
{#each $renderedRows as row} {#each $renderedRows as row}
{@const rowSelected = !!$selectedRows[row._id]} {@const rowSelected = !!$selectedRows[row._id]}
{@const rowHovered = $hoveredRowId === row._id} {@const rowHovered = $hoveredRowId === row._id}
@ -59,7 +60,6 @@
class="row" class="row"
on:mouseenter={$isDragging ? null : () => ($hoveredRowId = row._id)} on:mouseenter={$isDragging ? null : () => ($hoveredRowId = row._id)}
on:mouseleave={$isDragging ? null : () => ($hoveredRowId = null)} on:mouseleave={$isDragging ? null : () => ($hoveredRowId = null)}
bind:this={measureContainer}
> >
<GridCell <GridCell
width="auto" width="auto"
@ -67,7 +67,7 @@
selected={rowSelected} selected={rowSelected}
highlighted={rowHovered || rowFocused} highlighted={rowHovered || rowFocused}
> >
<div class="buttons"> <div class="buttons" class:offset={$showVScrollbar}>
{#each buttons as button} {#each buttons as button}
<Button <Button
newStyles newStyles
@ -121,6 +121,9 @@
gap: var(--cell-padding); gap: var(--cell-padding);
height: inherit; height: inherit;
} }
.buttons.offset {
padding-right: calc(var(--cell-padding) + 2 * var(--scroll-bar-size) - 2px);
}
.buttons :global(.spectrum-Button-Label) { .buttons :global(.spectrum-Button-Label) {
display: flex; display: flex;
align-items: center; align-items: center;

View File

@ -18,7 +18,7 @@
import UserAvatars from "./UserAvatars.svelte" import UserAvatars from "./UserAvatars.svelte"
import KeyboardManager from "../overlays/KeyboardManager.svelte" import KeyboardManager from "../overlays/KeyboardManager.svelte"
import SortButton from "../controls/SortButton.svelte" import SortButton from "../controls/SortButton.svelte"
import HideColumnsButton from "../controls/HideColumnsButton.svelte" import ColumnsSettingButton from "../controls/ColumnsSettingButton.svelte"
import SizeButton from "../controls/SizeButton.svelte" import SizeButton from "../controls/SizeButton.svelte"
import NewRow from "./NewRow.svelte" import NewRow from "./NewRow.svelte"
import { createGridWebsocket } from "../lib/websocket" import { createGridWebsocket } from "../lib/websocket"
@ -29,6 +29,7 @@
Padding, Padding,
SmallRowHeight, SmallRowHeight,
ControlsHeight, ControlsHeight,
ScrollBarSize,
} from "../lib/constants" } from "../lib/constants"
export let API = null export let API = null
@ -145,14 +146,14 @@
class:quiet class:quiet
on:mouseenter={() => gridFocused.set(true)} on:mouseenter={() => gridFocused.set(true)}
on:mouseleave={() => gridFocused.set(false)} on:mouseleave={() => gridFocused.set(false)}
style="--row-height:{$rowHeight}px; --default-row-height:{DefaultRowHeight}px; --gutter-width:{GutterWidth}px; --max-cell-render-overflow:{MaxCellRenderOverflow}px; --content-lines:{$contentLines}; --min-height:{$minHeight}px; --controls-height:{ControlsHeight}px;" style="--row-height:{$rowHeight}px; --default-row-height:{DefaultRowHeight}px; --gutter-width:{GutterWidth}px; --max-cell-render-overflow:{MaxCellRenderOverflow}px; --content-lines:{$contentLines}; --min-height:{$minHeight}px; --controls-height:{ControlsHeight}px; --scroll-bar-size:{ScrollBarSize}px;"
> >
{#if showControls} {#if showControls}
<div class="controls"> <div class="controls">
<div class="controls-left"> <div class="controls-left">
<slot name="filter" /> <slot name="filter" />
<SortButton /> <SortButton />
<HideColumnsButton /> <ColumnsSettingButton />
<SizeButton /> <SizeButton />
<slot name="controls" /> <slot name="controls" />
</div> </div>

View File

@ -18,6 +18,7 @@
export let scrollVertically = false export let scrollVertically = false
export let scrollHorizontally = false export let scrollHorizontally = false
export let attachHandlers = false export let attachHandlers = false
export let ref
// Used for tracking touch events // Used for tracking touch events
let initialTouchX let initialTouchX
@ -109,7 +110,7 @@
on:touchmove={attachHandlers ? handleTouchMove : null} on:touchmove={attachHandlers ? handleTouchMove : null}
on:click|self={() => ($focusedCellId = null)} on:click|self={() => ($focusedCellId = null)}
> >
<div {style} class="inner"> <div {style} class="inner" bind:this={ref}>
<slot /> <slot />
</div> </div>
</div> </div>

View File

@ -119,7 +119,7 @@
<!-- svelte-ignore a11y-no-static-element-interactions --> <!-- svelte-ignore a11y-no-static-element-interactions -->
<div <div
class="v-scrollbar" class="v-scrollbar"
style="--size:{ScrollBarSize}px; top:{barTop}px; height:{barHeight}px;" style="top:{barTop}px; height:{barHeight}px;"
on:mousedown={startVDragging} on:mousedown={startVDragging}
on:touchstart={startVDragging} on:touchstart={startVDragging}
class:dragging={isDraggingV} class:dragging={isDraggingV}
@ -129,7 +129,7 @@
<!-- svelte-ignore a11y-no-static-element-interactions --> <!-- svelte-ignore a11y-no-static-element-interactions -->
<div <div
class="h-scrollbar" class="h-scrollbar"
style="--size:{ScrollBarSize}px; left:{barLeft}px; width:{barWidth}px;" style="left:{barLeft}px; width:{barWidth}px;"
on:mousedown={startHDragging} on:mousedown={startHDragging}
on:touchstart={startHDragging} on:touchstart={startHDragging}
class:dragging={isDraggingH} class:dragging={isDraggingH}
@ -149,11 +149,11 @@
opacity: 1; opacity: 1;
} }
.v-scrollbar { .v-scrollbar {
width: var(--size); width: var(--scroll-bar-size);
right: var(--size); right: var(--scroll-bar-size);
} }
.h-scrollbar { .h-scrollbar {
height: var(--size); height: var(--scroll-bar-size);
bottom: var(--size); bottom: var(--scroll-bar-size);
} }
</style> </style>

View File

@ -404,8 +404,11 @@ export const createActions = context => {
// Save change // Save change
try { try {
// Mark as in progress // Increment change count for this row
inProgressChanges.update(state => ({ ...state, [rowId]: true })) inProgressChanges.update(state => ({
...state,
[rowId]: (state[rowId] || 0) + 1,
}))
// Update row // Update row
const changes = get(rowChangeCache)[rowId] const changes = get(rowChangeCache)[rowId]
@ -423,17 +426,25 @@ export const createActions = context => {
await refreshRow(saved.id) await refreshRow(saved.id)
} }
// Wipe row change cache now that we've saved the row // Wipe row change cache for any values which have been saved
const liveChanges = get(rowChangeCache)[rowId]
rowChangeCache.update(state => { rowChangeCache.update(state => {
delete state[rowId] Object.keys(changes || {}).forEach(key => {
if (changes[key] === liveChanges?.[key]) {
delete state[rowId][key]
}
})
return state return state
}) })
} catch (error) { } catch (error) {
handleValidationError(rowId, error) handleValidationError(rowId, error)
} }
// Mark as completed // Decrement change count for this row
inProgressChanges.update(state => ({ ...state, [rowId]: false })) inProgressChanges.update(state => ({
...state,
[rowId]: (state[rowId] || 1) - 1,
}))
} }
// Updates a value of a row // Updates a value of a row
@ -553,7 +564,6 @@ export const initialise = context => {
previousFocusedCellId, previousFocusedCellId,
rows, rows,
validation, validation,
focusedCellId,
} = context } = context
// Wipe the row change cache when changing row // Wipe the row change cache when changing row
@ -571,20 +581,12 @@ export const initialise = context => {
if (!id) { if (!id) {
return return
} }
// Stop if we changed row const { id: rowId, field } = parseCellID(id)
const split = parseCellID(id) const hasChanges = field in (get(rowChangeCache)[rowId] || {})
const oldRowId = split.id const hasErrors = validation.actions.rowHasErrors(rowId)
const oldColumn = split.field const isSavingChanges = get(inProgressChanges)[rowId]
const { id: newRowId } = parseCellID(get(focusedCellId)) if (rowId && !hasErrors && hasChanges && !isSavingChanges) {
if (oldRowId !== newRowId) { await rows.actions.applyRowChanges(rowId)
return
}
// Otherwise we just changed cell in the same row
const hasChanges = oldColumn in (get(rowChangeCache)[oldRowId] || {})
const hasErrors = validation.actions.rowHasErrors(oldRowId)
const isSavingChanges = get(inProgressChanges)[oldRowId]
if (oldRowId && !hasErrors && hasChanges && !isSavingChanges) {
await rows.actions.applyRowChanges(oldRowId)
} }
}) })
} }

View File

@ -109,6 +109,7 @@ export const initialise = context => {
maxScrollTop, maxScrollTop,
scrollLeft, scrollLeft,
maxScrollLeft, maxScrollLeft,
buttonColumnWidth,
} = context } = context
// Ensure scroll state never goes invalid, which can happen when changing // Ensure scroll state never goes invalid, which can happen when changing
@ -194,8 +195,10 @@ export const initialise = context => {
// Ensure column is not cutoff on right edge // Ensure column is not cutoff on right edge
else { else {
const $buttonColumnWidth = get(buttonColumnWidth)
const rightEdge = column.left + column.width const rightEdge = column.left + column.width
const rightBound = $bounds.width + $scroll.left - FocusedCellMinOffset const rightBound =
$bounds.width + $scroll.left - FocusedCellMinOffset - $buttonColumnWidth
delta = rightEdge - rightBound delta = rightEdge - rightBound
if (delta > 0) { if (delta > 0) {
scroll.update(state => ({ scroll.update(state => ({