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

Refactor grid column handling #12094

Merged
merged 9 commits into from
Oct 26, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,8 @@
disabled={deleteColName !== originalName}
>
<p>
Are you sure you wish to delete the column <b>{originalName}?</b>
Are you sure you wish to delete the column
<b on:click={() => (deleteColName = originalName)}>{originalName}?</b>
Your data will be deleted and this action cannot be undone - enter the column
name to confirm.
</p>
Expand Down Expand Up @@ -810,4 +811,11 @@
gap: 8px;
display: flex;
}
b {
transition: color 130ms ease-out;
}
b:hover {
cursor: pointer;
color: var(--spectrum-global-color-gray-900);
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
}
.alert-wrap {
display: flex;
width: 100%;
flex: 0 0 auto;
margin: -28px -40px 14px -40px;
}
.alert-wrap :global(> *) {
flex: 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
export let invertX = false
export let invertY = false
export let contentLines = 1
export let hidden = false

const emptyError = writable(null)

Expand Down Expand Up @@ -78,6 +79,7 @@
{focused}
{selectedUser}
{readonly}
{hidden}
error={$error}
on:click={() => focusedCellId.set(cellId)}
on:contextmenu={e => menu.actions.open(cellId, e)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
export let defaultHeight = false
export let center = false
export let readonly = false
export let hidden = false

$: style = getStyle(width, selectedUser)

Expand All @@ -30,6 +31,7 @@
class:error
class:center
class:readonly
class:hidden
class:default-height={defaultHeight}
class:selected-other={selectedUser != null}
class:alt={rowIdx % 2 === 1}
Expand Down Expand Up @@ -81,6 +83,9 @@
.cell.center {
align-items: center;
}
.cell.hidden {
content-visibility: hidden;
}

/* Cell border */
.cell.focused:after,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
isResizing,
rand,
sort,
renderedColumns,
visibleColumns,
dispatch,
subscribe,
config,
Expand Down Expand Up @@ -50,7 +50,7 @@

$: sortedBy = column.name === $sort.column
$: canMoveLeft = orderable && idx > 0
$: canMoveRight = orderable && idx < $renderedColumns.length - 1
$: canMoveRight = orderable && idx < $visibleColumns.length - 1
$: sortingLabels = getSortingLabels(column.schema?.type)
$: searchable = isColumnSearchable(column)
$: resetSearchValue(column.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
const {
bounds,
renderedRows,
renderedColumns,
visibleColumns,
rowVerticalInversionIndex,
hoveredRowId,
dispatch,
Expand All @@ -17,7 +17,7 @@

let body

$: renderColumnsWidth = $renderedColumns.reduce(
$: columnsWidth = $visibleColumns.reduce(
(total, col) => (total += col.width),
0
)
Expand Down Expand Up @@ -47,7 +47,7 @@
<div
class="blank"
class:highlighted={$hoveredRowId === BlankRowID}
style="width:{renderColumnsWidth}px"
style="width:{columnsWidth}px"
on:mouseenter={$isDragging ? null : () => ($hoveredRowId = BlankRowID)}
on:mouseleave={$isDragging ? null : () => ($hoveredRowId = null)}
on:click={() => dispatch("add-row-inline")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
focusedCellId,
reorder,
selectedRows,
renderedColumns,
visibleColumns,
hoveredRowId,
selectedCellMap,
focusedRow,
Expand All @@ -19,6 +19,7 @@
isDragging,
dispatch,
rows,
columnRenderMap,
} = getContext("grid")

$: rowSelected = !!$selectedRows[row._id]
Expand All @@ -34,7 +35,7 @@
on:mouseleave={$isDragging ? null : () => ($hoveredRowId = null)}
on:click={() => dispatch("rowclick", rows.actions.cleanRow(row))}
>
{#each $renderedColumns as column, columnIdx (column.name)}
{#each $visibleColumns as column, columnIdx}
{@const cellId = `${row._id}-${column.name}`}
<DataCell
{cellId}
Expand All @@ -51,6 +52,7 @@
selectedUser={$selectedCellMap[cellId]}
width={column.width}
contentLines={$contentLines}
hidden={!$columnRenderMap[column.name]}
/>
{/each}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
maxScrollLeft,
bounds,
hoveredRowId,
hiddenColumnsWidth,
menu,
} = getContext("grid")

Expand All @@ -23,10 +22,10 @@
let initialTouchX
let initialTouchY

$: style = generateStyle($scroll, $rowHeight, $hiddenColumnsWidth)
$: style = generateStyle($scroll, $rowHeight)

const generateStyle = (scroll, rowHeight, hiddenWidths) => {
const offsetX = scrollHorizontally ? -1 * scroll.left + hiddenWidths : 0
const generateStyle = (scroll, rowHeight) => {
const offsetX = scrollHorizontally ? -1 * scroll.left : 0
const offsetY = scrollVertically ? -1 * (scroll.top % rowHeight) : 0
return `transform: translate3d(${offsetX}px, ${offsetY}px, 0);`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import HeaderCell from "../cells/HeaderCell.svelte"
import { TempTooltip, TooltipType } from "@budibase/bbui"

const { renderedColumns, config, hasNonAutoColumn, datasource, loading } =
const { visibleColumns, config, hasNonAutoColumn, datasource, loading } =
getContext("grid")
</script>

<div class="header">
<GridScrollWrapper scrollHorizontally>
<div class="row">
{#each $renderedColumns as column, idx}
{#each $visibleColumns as column, idx}
<HeaderCell {column} {idx}>
<slot name="edit-column" />
</HeaderCell>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
import { getContext, onMount } from "svelte"
import { Icon, Popover, clickOutside } from "@budibase/bbui"

const { renderedColumns, scroll, hiddenColumnsWidth, width, subscribe } =
getContext("grid")
const { visibleColumns, scroll, width, subscribe } = getContext("grid")

let anchor
let open = false

$: columnsWidth = $renderedColumns.reduce(
$: columnsWidth = $visibleColumns.reduce(
(total, col) => (total += col.width),
0
)
$: end = $hiddenColumnsWidth + columnsWidth - 1 - $scroll.left
$: end = columnsWidth - 1 - $scroll.left
$: left = Math.min($width - 40, end)

const close = () => {
Expand All @@ -34,7 +33,7 @@
<Popover
bind:open
{anchor}
align={$renderedColumns.length ? "right" : "left"}
align={$visibleColumns.length ? "right" : "left"}
offset={0}
popoverTarget={document.getElementById(`add-column-button`)}
customZindex={100}
Expand Down
48 changes: 24 additions & 24 deletions packages/frontend-core/src/components/grid/layout/NewRow.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
datasource,
subscribe,
renderedRows,
renderedColumns,
visibleColumns,
rowHeight,
hasNextPage,
maxScrollTop,
Expand All @@ -31,14 +31,15 @@
refreshing,
config,
filter,
columnRenderMap,
} = getContext("grid")

let visible = false
let isAdding = false
let newRow
let offset = 0

$: firstColumn = $stickyColumn || $renderedColumns[0]
$: firstColumn = $stickyColumn || $visibleColumns[0]
$: width = GutterWidth + ($stickyColumn?.width || 0)
$: $datasource, (visible = false)
$: invertY = shouldInvertY(offset, $rowVerticalInversionIndex, $renderedRows)
Expand Down Expand Up @@ -211,29 +212,28 @@
<div class="normal-columns" transition:fade|local={{ duration: 130 }}>
<GridScrollWrapper scrollHorizontally attachHandlers>
<div class="row">
{#each $renderedColumns as column, columnIdx}
{#each $visibleColumns as column, columnIdx}
{@const cellId = `new-${column.name}`}
{#key cellId}
<DataCell
{cellId}
{column}
{updateValue}
rowFocused
row={newRow}
focused={$focusedCellId === cellId}
width={column.width}
topRow={offset === 0}
invertX={columnIdx >= $columnHorizontalInversionIndex}
{invertY}
>
{#if column?.schema?.autocolumn}
<div class="readonly-overlay">Can't edit auto column</div>
{/if}
{#if isAdding}
<div in:fade={{ duration: 130 }} class="loading-overlay" />
{/if}
</DataCell>
{/key}
<DataCell
{cellId}
{column}
{updateValue}
rowFocused
row={newRow}
focused={$focusedCellId === cellId}
width={column.width}
topRow={offset === 0}
invertX={columnIdx >= $columnHorizontalInversionIndex}
{invertY}
hidden={!$columnRenderMap[column.name]}
>
{#if column?.schema?.autocolumn}
<div class="readonly-overlay">Can't edit auto column</div>
{/if}
{#if isAdding}
<div in:fade={{ duration: 130 }} class="loading-overlay" />
{/if}
</DataCell>
{/each}
</div>
</GridScrollWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { getContext } from "svelte"
import { GutterWidth } from "../lib/constants"

const { resize, renderedColumns, stickyColumn, isReordering, scrollLeft } =
const { resize, visibleColumns, stickyColumn, isReordering, scrollLeft } =
getContext("grid")

$: offset = GutterWidth + ($stickyColumn?.width || 0)
Expand All @@ -26,7 +26,7 @@
<div class="resize-indicator" />
</div>
{/if}
{#each $renderedColumns as column}
{#each $visibleColumns as column}
<div
class="resize-slider"
class:visible={activeColumn === column.name}
Expand Down
Loading
Loading