Prevent adding rows when no non-autocolumn columns exist

This commit is contained in:
Andrew Kingston 2023-07-05 14:37:43 +01:00
parent dd921f456f
commit 638b537792
9 changed files with 33 additions and 45 deletions

View File

@ -1,16 +0,0 @@
<script>
import { ActionButton } from "@budibase/bbui"
import { getContext } from "svelte"
const { config, dispatch } = getContext("grid")
</script>
<ActionButton
icon="TableColumnAddRight"
quiet
size="M"
on:click={() => dispatch("add-column")}
disabled={!$config.allowSchemaChanges}
>
Add column
</ActionButton>

View File

@ -1,18 +0,0 @@
<script>
import { ActionButton } from "@budibase/bbui"
import { getContext } from "svelte"
const { dispatch, columns, stickyColumn, config, loaded } = getContext("grid")
</script>
<ActionButton
icon="TableRowAddBottom"
quiet
size="M"
on:click={() => dispatch("add-row-inline")}
disabled={!loaded ||
!$config.allowAddRows ||
(!$columns.length && !$stickyColumn)}
>
Add row
</ActionButton>

View File

@ -71,6 +71,7 @@
contentLines,
gridFocused,
error,
canAddRows,
} = context
// Keep config store up to date with props
@ -143,7 +144,7 @@
<HeaderRow />
<GridBody />
</div>
{#if allowAddRows}
{#if $canAddRows}
<NewRow />
{/if}
<div class="overlays">

View File

@ -9,7 +9,7 @@
renderedRows,
renderedColumns,
rowVerticalInversionIndex,
config,
canAddRows,
hoveredRowId,
dispatch,
isDragging,
@ -43,7 +43,7 @@
invertY={idx >= $rowVerticalInversionIndex}
/>
{/each}
{#if $config.allowAddRows && $renderedColumns.length}
{#if $canAddRows}
<div
class="blank"
class:highlighted={$hoveredRowId === BlankRowID}

View File

@ -27,7 +27,6 @@
rowVerticalInversionIndex,
columnHorizontalInversionIndex,
selectedRows,
config,
} = getContext("grid")
let visible = false
@ -147,7 +146,7 @@
</script>
<!-- New row FAB -->
{#if !visible && !selectedRowCount && $config.allowAddRows && firstColumn}
{#if !visible && !selectedRowCount}
<div
class="new-row-fab"
on:click={() => dispatch("add-row-inline")}

View File

@ -13,11 +13,10 @@
rows,
selectedRows,
stickyColumn,
renderedColumns,
renderedRows,
focusedCellId,
hoveredRowId,
config,
canAddRows,
selectedCellMap,
focusedRow,
scrollLeft,
@ -93,7 +92,7 @@
{/if}
</div>
{/each}
{#if $config.allowAddRows && ($renderedColumns.length || $stickyColumn)}
{#if $canAddRows}
<div
class="row new"
on:mouseenter={$isDragging

View File

@ -16,6 +16,7 @@
config,
menu,
gridFocused,
canAddRows,
} = getContext("grid")
const ignoredOriginSelectors = [
@ -45,7 +46,7 @@
e.preventDefault()
focusFirstCell()
} else if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
if ($config.allowAddRows) {
if ($canAddRows) {
e.preventDefault()
dispatch("add-row-inline")
}
@ -99,7 +100,7 @@
}
break
case "Enter":
if ($config.allowAddRows) {
if ($canAddRows) {
dispatch("add-row-inline")
}
}

View File

@ -17,6 +17,7 @@
focusedCellAPI,
focusedRowId,
notifications,
canAddRows,
} = getContext("grid")
$: style = makeStyle($menu)
@ -93,7 +94,7 @@
</MenuItem>
<MenuItem
icon="Duplicate"
disabled={isNewRow || !$config.allowAddRows}
disabled={isNewRow || !$canAddRows}
on:click={duplicate}
>
Duplicate row

View File

@ -70,6 +70,9 @@ export const deriveStores = context => {
rowHeight,
stickyColumn,
width,
columns,
stickyColumns,
config,
} = context
// Derive the row that contains the selected cell
@ -112,7 +115,25 @@ export const deriveStores = context => {
return ($stickyColumn?.width || 0) + $width + GutterWidth < 1100
})
// Derive if we're able to add rows
const canAddRows = derived(
[config, columns, stickyColumn],
([$config, $columns, $stickyColumn]) => {
// Check if we have a normal column
let allCols = $columns || []
if ($stickyColumn) {
allCols = [...allCols, $stickyColumn]
}
const normalCols = allCols.filter(column => {
return column.visible && !column.schema?.autocolumn
})
// Check if we're allowed to add rows
return $config.allowAddRows && normalCols.length > 0
}
)
return {
canAddRows,
focusedRow,
contentLines,
compact,