From 61a143628b2fccfc88030b07ba55cdce6a18cc04 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 7 Jun 2023 10:48:08 +0100 Subject: [PATCH 01/46] Revert tableType flag and derive from table instead --- .../builder/src/components/backend/DataTable/DataTable.svelte | 1 - .../backend/DataTable/buttons/grid/GridImportButton.svelte | 4 ++-- .../components/backend/DataTable/modals/ImportModal.svelte | 1 + packages/frontend-core/src/components/grid/layout/Grid.svelte | 2 -- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/DataTable.svelte b/packages/builder/src/components/backend/DataTable/DataTable.svelte index 1b0c92bde0..81df5a475d 100644 --- a/packages/builder/src/components/backend/DataTable/DataTable.svelte +++ b/packages/builder/src/components/backend/DataTable/DataTable.svelte @@ -32,7 +32,6 @@ diff --git a/packages/builder/src/components/backend/DataTable/modals/ImportModal.svelte b/packages/builder/src/components/backend/DataTable/modals/ImportModal.svelte index c020d1a7ac..1696c6ba03 100644 --- a/packages/builder/src/components/backend/DataTable/modals/ImportModal.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/ImportModal.svelte @@ -14,6 +14,7 @@ export let tableId export let tableType + let rows = [] let allValid = false let displayColumn = null diff --git a/packages/frontend-core/src/components/grid/layout/Grid.svelte b/packages/frontend-core/src/components/grid/layout/Grid.svelte index 81f42ca257..dc24fc0d64 100644 --- a/packages/frontend-core/src/components/grid/layout/Grid.svelte +++ b/packages/frontend-core/src/components/grid/layout/Grid.svelte @@ -33,7 +33,6 @@ export let API = null export let tableId = null - export let tableType = null export let schemaOverrides = null export let allowAddRows = true export let allowAddColumns = true @@ -67,7 +66,6 @@ rand, config, tableId: tableIdStore, - tableType, schemaOverrides: schemaOverridesStore, } context = { ...context, ...createEventManagers() } From 752dd93d84fbdc4aa02f363128b77a630cd6451d Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 7 Jun 2023 15:50:38 +0100 Subject: [PATCH 02/46] Add initial grid block, and update grid to keep indentation consistent when row expansion is disabled --- .../new/_components/componentStructure.json | 1 + packages/client/manifest.json | 20 ++++++++++ .../src/components/app/GridBlock.svelte | 37 +++++++++++++++++++ packages/client/src/components/app/index.js | 1 + .../components/grid/cells/GutterCell.svelte | 6 ++- .../src/components/grid/layout/Grid.svelte | 35 ++++++++++-------- 6 files changed, 83 insertions(+), 17 deletions(-) create mode 100644 packages/client/src/components/app/GridBlock.svelte diff --git a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/new/_components/componentStructure.json b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/new/_components/componentStructure.json index d35e7cd515..012ab461f0 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/new/_components/componentStructure.json +++ b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/new/_components/componentStructure.json @@ -3,6 +3,7 @@ "name": "Blocks", "icon": "Article", "children": [ + "gridblock", "tableblock", "cardsblock", "repeaterblock", diff --git a/packages/client/manifest.json b/packages/client/manifest.json index 71637723c1..b3e4438646 100644 --- a/packages/client/manifest.json +++ b/packages/client/manifest.json @@ -5225,5 +5225,25 @@ "type": "schema", "suffix": "repeater" } + }, + "gridblock": { + "block": true, + "name": "Grid block", + "icon": "Table", + "styles": [ + "size" + ], + "size": { + "width": 600, + "height": 400 + }, + "settings": [ + { + "type": "table", + "label": "Table", + "key": "table", + "required": true + } + ] } } diff --git a/packages/client/src/components/app/GridBlock.svelte b/packages/client/src/components/app/GridBlock.svelte new file mode 100644 index 0000000000..aae41b30c6 --- /dev/null +++ b/packages/client/src/components/app/GridBlock.svelte @@ -0,0 +1,37 @@ + + +
+ +
+ + diff --git a/packages/client/src/components/app/index.js b/packages/client/src/components/app/index.js index 70074790ac..060c15a857 100644 --- a/packages/client/src/components/app/index.js +++ b/packages/client/src/components/app/index.js @@ -36,6 +36,7 @@ export { default as markdownviewer } from "./MarkdownViewer.svelte" export { default as embeddedmap } from "./embedded-map/EmbeddedMap.svelte" export { default as grid } from "./Grid.svelte" export { default as sidepanel } from "./SidePanel.svelte" +export { default as gridblock } from "./GridBlock.svelte" export * from "./charts" export * from "./forms" export * from "./table" diff --git a/packages/frontend-core/src/components/grid/cells/GutterCell.svelte b/packages/frontend-core/src/components/grid/cells/GutterCell.svelte index 56c4c20d54..a8e0da85de 100644 --- a/packages/frontend-core/src/components/grid/cells/GutterCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/GutterCell.svelte @@ -70,10 +70,12 @@ color="var(--spectrum-global-color-red-400)" /> - {:else if $config.allowExpandRows} + {:else}
diff --git a/packages/frontend-core/src/components/grid/layout/Grid.svelte b/packages/frontend-core/src/components/grid/layout/Grid.svelte index dc24fc0d64..3fead0c926 100644 --- a/packages/frontend-core/src/components/grid/layout/Grid.svelte +++ b/packages/frontend-core/src/components/grid/layout/Grid.svelte @@ -43,6 +43,9 @@ export let stripeRows = false export let collaboration = true export let showAvatars = true + export let showControls = true + + allowExpandRows = false // Unique identifier for DOM nodes inside this instance const rand = Math.random() @@ -117,22 +120,24 @@ class:stripe={$config.stripeRows} style="--row-height:{$rowHeight}px; --default-row-height:{DefaultRowHeight}px; --gutter-width:{GutterWidth}px; --max-cell-render-height:{MaxCellRenderHeight}px; --max-cell-render-width-overflow:{MaxCellRenderWidthOverflow}px; --content-lines:{$contentLines};" > -
-
- - - - - - - + {#if showControls} +
+
+ + + + + + + +
+
+ {#if showAvatars} + + {/if} +
-
- {#if showAvatars} - - {/if} -
-
+ {/if} {#if $loaded}
From f9a8be507dfc1c607fadba73e2216105ee12d03a Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 7 Jun 2023 15:51:27 +0100 Subject: [PATCH 03/46] Undo hardcoded disabling of row expansion --- packages/frontend-core/src/components/grid/layout/Grid.svelte | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/frontend-core/src/components/grid/layout/Grid.svelte b/packages/frontend-core/src/components/grid/layout/Grid.svelte index 3fead0c926..ae4409ddca 100644 --- a/packages/frontend-core/src/components/grid/layout/Grid.svelte +++ b/packages/frontend-core/src/components/grid/layout/Grid.svelte @@ -45,8 +45,6 @@ export let showAvatars = true export let showControls = true - allowExpandRows = false - // Unique identifier for DOM nodes inside this instance const rand = Math.random() From 5820996e4d55e4c1ffb5dd4ffc5e2ea528fa097c Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 8 Jun 2023 08:35:36 +0100 Subject: [PATCH 04/46] Update grid flags to allow readonly modifications of schema --- packages/client/src/components/app/GridBlock.svelte | 3 +-- .../src/components/grid/cells/HeaderCell.svelte | 4 ++-- .../src/components/grid/controls/AddColumnButton.svelte | 2 +- .../frontend-core/src/components/grid/layout/Grid.svelte | 9 +++------ .../src/components/grid/layout/HeaderRow.svelte | 2 +- .../frontend-core/src/components/grid/stores/columns.js | 6 ++++-- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/client/src/components/app/GridBlock.svelte b/packages/client/src/components/app/GridBlock.svelte index aae41b30c6..3bf7fef231 100644 --- a/packages/client/src/components/app/GridBlock.svelte +++ b/packages/client/src/components/app/GridBlock.svelte @@ -21,9 +21,8 @@ {allowEditRows} {allowDeleteRows} showControls={false} - allowAddColumns={false} - allowEditColumns={false} allowExpandRows={false} + allowSchemaChanges={false} />
diff --git a/packages/frontend-core/src/components/grid/cells/HeaderCell.svelte b/packages/frontend-core/src/components/grid/cells/HeaderCell.svelte index 21ee210233..db2e1a729b 100644 --- a/packages/frontend-core/src/components/grid/cells/HeaderCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/HeaderCell.svelte @@ -163,7 +163,7 @@ Edit column @@ -171,7 +171,7 @@ icon="Label" on:click={makeDisplayColumn} disabled={idx === "sticky" || - !$config.allowEditColumns || + !$config.allowSchemaChanges || bannedDisplayColumnTypes.includes(column.schema.type)} > Use as display column diff --git a/packages/frontend-core/src/components/grid/controls/AddColumnButton.svelte b/packages/frontend-core/src/components/grid/controls/AddColumnButton.svelte index 6ad241eb65..20125bc49c 100644 --- a/packages/frontend-core/src/components/grid/controls/AddColumnButton.svelte +++ b/packages/frontend-core/src/components/grid/controls/AddColumnButton.svelte @@ -10,7 +10,7 @@ quiet size="M" on:click={() => dispatch("add-column")} - disabled={!$config.allowAddColumns} + disabled={!$config.allowSchemaChanges} > Add column diff --git a/packages/frontend-core/src/components/grid/layout/Grid.svelte b/packages/frontend-core/src/components/grid/layout/Grid.svelte index ae4409ddca..e33cb65940 100644 --- a/packages/frontend-core/src/components/grid/layout/Grid.svelte +++ b/packages/frontend-core/src/components/grid/layout/Grid.svelte @@ -35,11 +35,10 @@ export let tableId = null export let schemaOverrides = null export let allowAddRows = true - export let allowAddColumns = true - export let allowEditColumns = true export let allowExpandRows = true export let allowEditRows = true export let allowDeleteRows = true + export let allowSchemaChanges = true export let stripeRows = false export let collaboration = true export let showAvatars = true @@ -53,8 +52,7 @@ const schemaOverridesStore = writable(schemaOverrides) const config = writable({ allowAddRows, - allowAddColumns, - allowEditColumns, + allowSchemaChanges, allowExpandRows, allowEditRows, allowDeleteRows, @@ -88,8 +86,7 @@ $: schemaOverridesStore.set(schemaOverrides) $: config.set({ allowAddRows, - allowAddColumns, - allowEditColumns, + allowSchemaChanges, allowExpandRows, allowEditRows, allowDeleteRows, diff --git a/packages/frontend-core/src/components/grid/layout/HeaderRow.svelte b/packages/frontend-core/src/components/grid/layout/HeaderRow.svelte index 9d6cc2275b..c22ee511a3 100644 --- a/packages/frontend-core/src/components/grid/layout/HeaderRow.svelte +++ b/packages/frontend-core/src/components/grid/layout/HeaderRow.svelte @@ -29,7 +29,7 @@ {/each}
- {#if $config.allowAddColumns} + {#if $config.allowSchemaChanges}
{ } export const deriveStores = context => { - const { table, columns, stickyColumn, API, dispatch } = context + const { table, columns, stickyColumn, API, dispatch, config } = context // Updates the tables primary display column const changePrimaryDisplay = async column => { @@ -95,7 +95,9 @@ export const deriveStores = context => { dispatch("updatetable", newTable) // Update server - await API.saveTable(newTable) + if (get(config).allowSchemaChanges) { + await API.saveTable(newTable) + } } return { From 0ab1346577c7712cf32573a2b32734abb340b679 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 13 Jun 2023 17:17:29 +0100 Subject: [PATCH 05/46] Add settings to grid block for controlling CRUD --- packages/client/manifest.json | 18 ++++++++++++ .../src/components/app/GridBlock.svelte | 10 +++++-- .../src/components/grid/layout/Grid.svelte | 2 +- .../src/components/grid/layout/NewRow.svelte | 28 +++++++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/packages/client/manifest.json b/packages/client/manifest.json index b3e4438646..883d6fa0a6 100644 --- a/packages/client/manifest.json +++ b/packages/client/manifest.json @@ -5243,6 +5243,24 @@ "label": "Table", "key": "table", "required": true + }, + { + "type": "boolean", + "label": "Add rows", + "key": "allowAddRows", + "defaultValue": true + }, + { + "type": "boolean", + "label": "Edit rows", + "key": "allowEditRows", + "defaultValue": true + }, + { + "type": "boolean", + "label": "Delete rows", + "key": "allowDeleteRows", + "defaultValue": true } ] } diff --git a/packages/client/src/components/app/GridBlock.svelte b/packages/client/src/components/app/GridBlock.svelte index 3bf7fef231..7e69fcdcea 100644 --- a/packages/client/src/components/app/GridBlock.svelte +++ b/packages/client/src/components/app/GridBlock.svelte @@ -10,10 +10,13 @@ export let allowDeleteRows const component = getContext("component") - const { styleable, API } = getContext("sdk") + const { styleable, API, builderStore } = getContext("sdk") -
+
diff --git a/packages/frontend-core/src/components/grid/layout/Grid.svelte b/packages/frontend-core/src/components/grid/layout/Grid.svelte index e33cb65940..e6550fa5a5 100644 --- a/packages/frontend-core/src/components/grid/layout/Grid.svelte +++ b/packages/frontend-core/src/components/grid/layout/Grid.svelte @@ -232,7 +232,7 @@ border-bottom: 2px solid var(--spectrum-global-color-gray-200); padding: var(--cell-padding); gap: var(--cell-spacing); - background: var(--background); + background: var(--spectrum-global-color-gray-100); z-index: 2; } .controls-left, diff --git a/packages/frontend-core/src/components/grid/layout/NewRow.svelte b/packages/frontend-core/src/components/grid/layout/NewRow.svelte index 85b430f79b..4581e37746 100644 --- a/packages/frontend-core/src/components/grid/layout/NewRow.svelte +++ b/packages/frontend-core/src/components/grid/layout/NewRow.svelte @@ -141,6 +141,17 @@ }) + +{#if !visible} +
dispatch("add-row-inline")} + transition:fade|local={{ duration: 130 }} + > + +
+{/if} + {#if visible}
+ /* New row FAB */ + .new-row-fab { + position: absolute; + top: var(--default-row-height); + left: calc(var(--gutter-width) / 2); + transform: translateX(8px) translateY(-50%); + background: var(--cell-background); + padding: 4px; + border-radius: 50%; + border: var(--cell-border); + z-index: 10; + } + .new-row-fab:hover { + background: var(--cell-background-hover); + cursor: pointer; + } + .container { position: absolute; top: var(--default-row-height); From f56bd3ad13257fbede01e1a1d9004941c526da33 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 13 Jun 2023 17:19:12 +0100 Subject: [PATCH 06/46] Fix grid loading overlay color in client apps --- packages/frontend-core/src/components/grid/layout/Grid.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/frontend-core/src/components/grid/layout/Grid.svelte b/packages/frontend-core/src/components/grid/layout/Grid.svelte index e6550fa5a5..c4828e2791 100644 --- a/packages/frontend-core/src/components/grid/layout/Grid.svelte +++ b/packages/frontend-core/src/components/grid/layout/Grid.svelte @@ -268,7 +268,7 @@ left: 0; width: 100%; height: 100%; - background: var(--background); + background: var(--spectrum-global-color-gray-100); opacity: 0.6; } From 9991fd9558bbb877525ed8fe69ffce6120dfaca0 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 14 Jun 2023 09:09:59 +0100 Subject: [PATCH 07/46] Add grid block setting for striping row colours --- packages/client/manifest.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/client/manifest.json b/packages/client/manifest.json index 883d6fa0a6..327b05a320 100644 --- a/packages/client/manifest.json +++ b/packages/client/manifest.json @@ -5261,6 +5261,12 @@ "label": "Delete rows", "key": "allowDeleteRows", "defaultValue": true + }, + { + "type": "boolean", + "label": "Stripe rows", + "key": "stripeRows", + "defaultValue": false } ] } From ed9065aae3c76b33706d62fc84054aef7f9577e6 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 14 Jun 2023 09:10:09 +0100 Subject: [PATCH 08/46] Hide add row FAB when selecting rows --- packages/client/src/components/app/GridBlock.svelte | 8 +++++--- .../components/grid/controls/BulkDeleteHandler.svelte | 10 ++-------- .../src/components/grid/layout/Grid.svelte | 2 ++ .../src/components/grid/layout/NewRow.svelte | 7 +++++-- .../src/components/grid/layout/StickyColumn.svelte | 2 +- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/client/src/components/app/GridBlock.svelte b/packages/client/src/components/app/GridBlock.svelte index 7e69fcdcea..6fe436c0e2 100644 --- a/packages/client/src/components/app/GridBlock.svelte +++ b/packages/client/src/components/app/GridBlock.svelte @@ -5,9 +5,10 @@ import { Grid } from "@budibase/frontend-core" export let table - export let allowAddRows - export let allowEditRows - export let allowDeleteRows + export let allowAddRows = true + export let allowEditRows = true + export let allowDeleteRows = true + export let stripeRows = false const component = getContext("component") const { styleable, API, builderStore } = getContext("sdk") @@ -23,6 +24,7 @@ {allowAddRows} {allowEditRows} {allowDeleteRows} + {stripeRows} showControls={false} allowExpandRows={false} allowSchemaChanges={false} diff --git a/packages/frontend-core/src/components/grid/controls/BulkDeleteHandler.svelte b/packages/frontend-core/src/components/grid/controls/BulkDeleteHandler.svelte index f87b529390..3218ef9ffe 100644 --- a/packages/frontend-core/src/components/grid/controls/BulkDeleteHandler.svelte +++ b/packages/frontend-core/src/components/grid/controls/BulkDeleteHandler.svelte @@ -6,15 +6,9 @@ let modal - $: selectedRowCount = Object.values($selectedRows).filter(x => !!x).length + $: selectedRowCount = Object.values($selectedRows).length $: rowsToDelete = Object.entries($selectedRows) - .map(entry => { - if (entry[1] === true) { - return $rows.find(x => x._id === entry[0]) - } else { - return null - } - }) + .map(entry => $rows.find(x => x._id === entry[0])) .filter(x => x != null) // Deletion callback when confirmed diff --git a/packages/frontend-core/src/components/grid/layout/Grid.svelte b/packages/frontend-core/src/components/grid/layout/Grid.svelte index c4828e2791..8cf5803f23 100644 --- a/packages/frontend-core/src/components/grid/layout/Grid.svelte +++ b/packages/frontend-core/src/components/grid/layout/Grid.svelte @@ -57,6 +57,7 @@ allowEditRows, allowDeleteRows, stripeRows, + showControls, }) // Build up context @@ -91,6 +92,7 @@ allowEditRows, allowDeleteRows, stripeRows, + showControls, }) // Set context for children to consume diff --git a/packages/frontend-core/src/components/grid/layout/NewRow.svelte b/packages/frontend-core/src/components/grid/layout/NewRow.svelte index 4581e37746..06e4f0bfd6 100644 --- a/packages/frontend-core/src/components/grid/layout/NewRow.svelte +++ b/packages/frontend-core/src/components/grid/layout/NewRow.svelte @@ -26,6 +26,8 @@ maxScrollTop, rowVerticalInversionIndex, columnHorizontalInversionIndex, + config, + selectedRows, } = getContext("grid") let visible = false @@ -37,6 +39,7 @@ $: width = GutterWidth + ($stickyColumn?.width || 0) $: $tableId, (visible = false) $: invertY = shouldInvertY(offset, $rowVerticalInversionIndex, $renderedRows) + $: selectedRowCount = Object.values($selectedRows).length const shouldInvertY = (offset, inversionIndex, rows) => { if (offset === 0) { @@ -142,7 +145,7 @@ -{#if !visible} +{#if !visible && !$config.showControls && !selectedRowCount}
dispatch("add-row-inline")} @@ -243,7 +246,7 @@ position: absolute; top: var(--default-row-height); left: calc(var(--gutter-width) / 2); - transform: translateX(8px) translateY(-50%); + transform: translateX(6px) translateY(-50%); background: var(--cell-background); padding: 4px; border-radius: 50%; diff --git a/packages/frontend-core/src/components/grid/layout/StickyColumn.svelte b/packages/frontend-core/src/components/grid/layout/StickyColumn.svelte index 801772ed51..f8a65faadb 100644 --- a/packages/frontend-core/src/components/grid/layout/StickyColumn.svelte +++ b/packages/frontend-core/src/components/grid/layout/StickyColumn.svelte @@ -26,7 +26,7 @@ } = getContext("grid") $: rowCount = $rows.length - $: selectedRowCount = Object.values($selectedRows).filter(x => !!x).length + $: selectedRowCount = Object.values($selectedRows).length $: width = GutterWidth + ($stickyColumn?.width || 0) const selectAll = () => { From 328336463c1c47955bc37104e965737f783d08c3 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 14 Jun 2023 09:19:11 +0100 Subject: [PATCH 09/46] Standardise usage of CSS variables to work inside client and builder --- .../grid/cells/AttachmentCell.svelte | 2 +- .../components/grid/cells/HeaderCell.svelte | 2 +- .../components/grid/cells/OptionsCell.svelte | 2 +- .../grid/cells/RelationshipCell.svelte | 2 +- .../src/components/grid/layout/Grid.svelte | 28 ++++++++++--------- .../components/grid/layout/HeaderRow.svelte | 4 +-- .../grid/layout/StickyColumn.svelte | 2 +- 7 files changed, 22 insertions(+), 20 deletions(-) diff --git a/packages/frontend-core/src/components/grid/cells/AttachmentCell.svelte b/packages/frontend-core/src/components/grid/cells/AttachmentCell.svelte index 4d830723c2..c054c57498 100644 --- a/packages/frontend-core/src/components/grid/cells/AttachmentCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/AttachmentCell.svelte @@ -138,7 +138,7 @@ top: 100%; left: 0; width: 320px; - background: var(--background); + background: var(--grid-background-alt); border: var(--cell-border); padding: var(--cell-padding); box-shadow: 0 0 20px -4px rgba(0, 0, 0, 0.15); diff --git a/packages/frontend-core/src/components/grid/cells/HeaderCell.svelte b/packages/frontend-core/src/components/grid/cells/HeaderCell.svelte index db2e1a729b..e773af9e14 100644 --- a/packages/frontend-core/src/components/grid/cells/HeaderCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/HeaderCell.svelte @@ -218,7 +218,7 @@ .header-cell :global(.cell) { padding: 0 var(--cell-padding); gap: calc(2 * var(--cell-spacing)); - background: var(--spectrum-global-color-gray-100); + background: var(--grid-background-alt); } .name { diff --git a/packages/frontend-core/src/components/grid/cells/OptionsCell.svelte b/packages/frontend-core/src/components/grid/cells/OptionsCell.svelte index 9399617eb7..46ad048c20 100644 --- a/packages/frontend-core/src/components/grid/cells/OptionsCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/OptionsCell.svelte @@ -240,7 +240,7 @@ justify-content: space-between; align-items: center; gap: var(--cell-spacing); - background-color: var(--background); + background-color: var(--grid-background-alt); } .option:hover, .option.focused { diff --git a/packages/frontend-core/src/components/grid/cells/RelationshipCell.svelte b/packages/frontend-core/src/components/grid/cells/RelationshipCell.svelte index 40b6de5eaa..2bd0a17054 100644 --- a/packages/frontend-core/src/components/grid/cells/RelationshipCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/RelationshipCell.svelte @@ -453,7 +453,7 @@ var(--max-cell-render-height) + var(--row-height) - var(--max-relationship-height) ); - background: var(--background); + background: var(--grid-background-alt); border: var(--cell-border); box-shadow: 0 0 20px -4px rgba(0, 0, 0, 0.15); display: flex; diff --git a/packages/frontend-core/src/components/grid/layout/Grid.svelte b/packages/frontend-core/src/components/grid/layout/Grid.svelte index 8cf5803f23..39a67d44eb 100644 --- a/packages/frontend-core/src/components/grid/layout/Grid.svelte +++ b/packages/frontend-core/src/components/grid/layout/Grid.svelte @@ -168,6 +168,18 @@ diff --git a/packages/frontend-core/src/components/grid/layout/HeaderRow.svelte b/packages/frontend-core/src/components/grid/layout/HeaderRow.svelte index c22ee511a3..f31cc198fb 100644 --- a/packages/frontend-core/src/components/grid/layout/HeaderRow.svelte +++ b/packages/frontend-core/src/components/grid/layout/HeaderRow.svelte @@ -42,7 +42,7 @@ From b05eb5ad01c421b4feeee69c1ca1c2fb568a86bb Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 16 Jun 2023 12:09:44 +0100 Subject: [PATCH 15/46] Improve calculation of inversion indices, improve cell max sizes and grid padding for consitency --- .../src/components/app/GridBlock.svelte | 1 + .../components/grid/cells/LongFormCell.svelte | 2 +- .../src/components/grid/lib/constants.js | 7 ++++--- .../src/components/grid/stores/scroll.js | 12 +++++------- .../src/components/grid/stores/viewport.js | 19 ++++++++++++------- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/packages/client/src/components/app/GridBlock.svelte b/packages/client/src/components/app/GridBlock.svelte index da9ae74411..482721613d 100644 --- a/packages/client/src/components/app/GridBlock.svelte +++ b/packages/client/src/components/app/GridBlock.svelte @@ -39,6 +39,7 @@ border: 1px solid var(--spectrum-global-color-gray-300); border-radius: 4px; overflow: hidden; + min-height: 410px; } div.in-builder :global(*) { pointer-events: none; diff --git a/packages/frontend-core/src/components/grid/cells/LongFormCell.svelte b/packages/frontend-core/src/components/grid/cells/LongFormCell.svelte index 886d4ef8b0..233533c446 100644 --- a/packages/frontend-core/src/components/grid/cells/LongFormCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/LongFormCell.svelte @@ -102,7 +102,7 @@ top: 0; left: 0; width: calc(100% + var(--max-cell-render-width-overflow)); - height: var(--max-cell-render-height); + height: calc(var(--row-height) + var(--max-cell-render-height)); z-index: 1; border-radius: 2px; resize: none; diff --git a/packages/frontend-core/src/components/grid/lib/constants.js b/packages/frontend-core/src/components/grid/lib/constants.js index f078ef7274..a6e6723463 100644 --- a/packages/frontend-core/src/components/grid/lib/constants.js +++ b/packages/frontend-core/src/components/grid/lib/constants.js @@ -1,6 +1,5 @@ -export const Padding = 256 -export const MaxCellRenderHeight = 252 -export const MaxCellRenderWidthOverflow = 200 +export const Padding = 246 +export const MaxCellRenderHeight = 222 export const ScrollBarSize = 8 export const GutterWidth = 72 export const DefaultColumnWidth = 200 @@ -12,3 +11,5 @@ export const DefaultRowHeight = SmallRowHeight export const NewRowID = "new" export const BlankRowID = "blank" export const RowPageSize = 100 +export const FocusedCellMinOffset = 48 +export const MaxCellRenderWidthOverflow = Padding - 3 * ScrollBarSize diff --git a/packages/frontend-core/src/components/grid/stores/scroll.js b/packages/frontend-core/src/components/grid/stores/scroll.js index c1ca19633a..89e759854f 100644 --- a/packages/frontend-core/src/components/grid/stores/scroll.js +++ b/packages/frontend-core/src/components/grid/stores/scroll.js @@ -1,6 +1,6 @@ import { writable, derived, get } from "svelte/store" import { tick } from "svelte" -import { Padding, GutterWidth } from "../lib/constants" +import { Padding, GutterWidth, FocusedCellMinOffset } from "../lib/constants" export const createStores = () => { const scroll = writable({ @@ -138,14 +138,13 @@ export const initialise = context => { const $scroll = get(scroll) const $bounds = get(bounds) const $rowHeight = get(rowHeight) - const verticalOffset = 60 // Ensure vertical position is viewable if ($focusedRow) { // Ensure row is not below bottom of screen const rowYPos = $focusedRow.__idx * $rowHeight const bottomCutoff = - $scroll.top + $bounds.height - $rowHeight - verticalOffset + $scroll.top + $bounds.height - $rowHeight - FocusedCellMinOffset let delta = rowYPos - bottomCutoff if (delta > 0) { scroll.update(state => ({ @@ -156,7 +155,7 @@ export const initialise = context => { // Ensure row is not above top of screen else { - const delta = $scroll.top - rowYPos + verticalOffset + const delta = $scroll.top - rowYPos + FocusedCellMinOffset if (delta > 0) { scroll.update(state => ({ ...state, @@ -171,13 +170,12 @@ export const initialise = context => { const $visibleColumns = get(visibleColumns) const columnName = $focusedCellId?.split("-")[1] const column = $visibleColumns.find(col => col.name === columnName) - const horizontalOffset = 50 if (!column) { return } // Ensure column is not cutoff on left edge - let delta = $scroll.left - column.left + horizontalOffset + let delta = $scroll.left - column.left + FocusedCellMinOffset if (delta > 0) { scroll.update(state => ({ ...state, @@ -188,7 +186,7 @@ export const initialise = context => { // Ensure column is not cutoff on right edge else { const rightEdge = column.left + column.width - const rightBound = $bounds.width + $scroll.left - horizontalOffset + const rightBound = $bounds.width + $scroll.left - FocusedCellMinOffset delta = rightEdge - rightBound if (delta > 0) { scroll.update(state => ({ diff --git a/packages/frontend-core/src/components/grid/stores/viewport.js b/packages/frontend-core/src/components/grid/stores/viewport.js index f258b7daef..a363ffca00 100644 --- a/packages/frontend-core/src/components/grid/stores/viewport.js +++ b/packages/frontend-core/src/components/grid/stores/viewport.js @@ -108,12 +108,17 @@ export const deriveStores = context => { // Determine the row index at which we should start vertically inverting cell // dropdowns const rowVerticalInversionIndex = derived( - [visualRowCapacity, rowHeight], - ([$visualRowCapacity, $rowHeight]) => { - const maxCellRenderRows = Math.ceil(MaxCellRenderHeight / $rowHeight) - const topIdx = $visualRowCapacity - maxCellRenderRows - 2 - const bottomIdx = maxCellRenderRows + 1 - return Math.max(topIdx, bottomIdx) + [height, rowHeight, scrollTop], + ([$height, $rowHeight, $scrollTop]) => { + const offset = $scrollTop % $rowHeight + const minBottom = + $height - ScrollBarSize * 3 - MaxCellRenderHeight + offset + return Math.floor(minBottom / $rowHeight) + + // const maxCellRenderRows = Math.ceil(MaxCellRenderHeight / $rowHeight) + // const topIdx = $visualRowCapacity - maxCellRenderRows - 2 + // const bottomIdx = maxCellRenderRows + 1 + // return Math.max(topIdx, bottomIdx) } ) @@ -126,7 +131,7 @@ export const deriveStores = context => { let inversionIdx = $renderedColumns.length for (let i = $renderedColumns.length - 1; i >= 0; i--, inversionIdx--) { const rightEdge = $renderedColumns[i].left + $renderedColumns[i].width - if (rightEdge + MaxCellRenderWidthOverflow < cutoff) { + if (rightEdge + MaxCellRenderWidthOverflow <= cutoff) { break } } From 8fc29cb6dc3e27284505c08664c7c88d54259474 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 16 Jun 2023 14:54:50 +0100 Subject: [PATCH 16/46] Add slight border radius to cells which were missing it --- .../src/components/grid/cells/AttachmentCell.svelte | 2 ++ .../frontend-core/src/components/grid/cells/OptionsCell.svelte | 2 ++ .../src/components/grid/cells/RelationshipCell.svelte | 2 ++ 3 files changed, 6 insertions(+) diff --git a/packages/frontend-core/src/components/grid/cells/AttachmentCell.svelte b/packages/frontend-core/src/components/grid/cells/AttachmentCell.svelte index c054c57498..c80b12cf1a 100644 --- a/packages/frontend-core/src/components/grid/cells/AttachmentCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/AttachmentCell.svelte @@ -142,6 +142,8 @@ border: var(--cell-border); padding: var(--cell-padding); box-shadow: 0 0 20px -4px rgba(0, 0, 0, 0.15); + border-bottom-left-radius: 2px; + border-bottom-right-radius: 2px; } .dropzone.invertX { left: auto; diff --git a/packages/frontend-core/src/components/grid/cells/OptionsCell.svelte b/packages/frontend-core/src/components/grid/cells/OptionsCell.svelte index 46ad048c20..3969938012 100644 --- a/packages/frontend-core/src/components/grid/cells/OptionsCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/OptionsCell.svelte @@ -223,6 +223,8 @@ overflow-y: auto; border: var(--cell-border); box-shadow: 0 0 20px -4px rgba(0, 0, 0, 0.15); + border-bottom-left-radius: 2px; + border-bottom-right-radius: 2px; } .options.invertX { left: auto; diff --git a/packages/frontend-core/src/components/grid/cells/RelationshipCell.svelte b/packages/frontend-core/src/components/grid/cells/RelationshipCell.svelte index 2bd0a17054..689c9a8a92 100644 --- a/packages/frontend-core/src/components/grid/cells/RelationshipCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/RelationshipCell.svelte @@ -460,6 +460,8 @@ flex-direction: column; align-items: stretch; padding: 0 0 8px 0; + border-bottom-left-radius: 2px; + border-bottom-right-radius: 2px; } .dropdown.invertY { transform: translateY(-100%); From 68f21274edb39148a41e4b11571033f2379b8704 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 19 Jun 2023 09:54:24 +0100 Subject: [PATCH 17/46] Add settings to grid block for filtering and sorting, and refactor grid logic to allow external control of these stores --- .../buttons/grid/GridFilterButton.svelte | 3 ++ packages/client/manifest.json | 18 +++++++++ .../src/components/app/GridBlock.svelte | 6 +++ .../grid/cells/RelationshipCell.svelte | 7 +++- .../src/components/grid/layout/Grid.svelte | 38 ++++++++++++++----- .../src/components/grid/stores/rows.js | 25 +++++------- packages/frontend-core/src/fetch/DataFetch.js | 6 ++- packages/frontend-core/src/utils/index.js | 1 + packages/frontend-core/src/utils/memo.js | 35 +++++++++++++++++ 9 files changed, 111 insertions(+), 28 deletions(-) create mode 100644 packages/frontend-core/src/utils/memo.js diff --git a/packages/builder/src/components/backend/DataTable/buttons/grid/GridFilterButton.svelte b/packages/builder/src/components/backend/DataTable/buttons/grid/GridFilterButton.svelte index 2283862303..45e5d4e2b0 100644 --- a/packages/builder/src/components/backend/DataTable/buttons/grid/GridFilterButton.svelte +++ b/packages/builder/src/components/backend/DataTable/buttons/grid/GridFilterButton.svelte @@ -4,6 +4,9 @@ const { columns, tableId, filter, table } = getContext("grid") + // Wipe filter whenever table ID changes to avoid using stale filters + $: $tableId, filter.set([]) + const onFilter = e => { filter.set(e.detail || []) } diff --git a/packages/client/manifest.json b/packages/client/manifest.json index 327b05a320..3f36f2f666 100644 --- a/packages/client/manifest.json +++ b/packages/client/manifest.json @@ -5237,6 +5237,7 @@ "width": 600, "height": 400 }, + "info": "Grid Block is only compatible with internal or SQL tables", "settings": [ { "type": "table", @@ -5244,6 +5245,23 @@ "key": "table", "required": true }, + { + "type": "filter", + "label": "Filtering", + "key": "filter" + }, + { + "type": "field/sortable", + "label": "Sort column", + "key": "sortColumn" + }, + { + "type": "select", + "label": "Sort order", + "key": "sortOrder", + "options": ["Ascending", "Descending"], + "defaultValue": "Ascending" + }, { "type": "boolean", "label": "Add rows", diff --git a/packages/client/src/components/app/GridBlock.svelte b/packages/client/src/components/app/GridBlock.svelte index 482721613d..5267582bc8 100644 --- a/packages/client/src/components/app/GridBlock.svelte +++ b/packages/client/src/components/app/GridBlock.svelte @@ -9,6 +9,9 @@ export let allowEditRows = true export let allowDeleteRows = true export let stripeRows = false + export let filter = null + export let sortColumn = null + export let sortOrder = null const component = getContext("component") const { styleable, API, builderStore } = getContext("sdk") @@ -25,6 +28,9 @@ {allowEditRows} {allowDeleteRows} {stripeRows} + {filter} + {sortColumn} + {sortOrder} showControls={false} allowExpandRows={false} allowSchemaChanges={false} diff --git a/packages/frontend-core/src/components/grid/cells/RelationshipCell.svelte b/packages/frontend-core/src/components/grid/cells/RelationshipCell.svelte index 689c9a8a92..58aab8038b 100644 --- a/packages/frontend-core/src/components/grid/cells/RelationshipCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/RelationshipCell.svelte @@ -42,6 +42,8 @@ let candidateIndex let lastSearchId let searching = false + let valuesHeight = 0 + let container $: oneRowOnly = schema?.relationshipType === "one-to-many" $: editable = focused && !readonly @@ -138,6 +140,8 @@ const open = async () => { isOpen = true + valuesHeight = container.getBoundingClientRect().height + console.log(valuesHeight) // Find the primary display for the related table if (!primaryDisplay) { @@ -243,7 +247,7 @@
-
+
1} @@ -290,6 +294,7 @@ class:invertY on:wheel|stopPropagation use:clickOutside={close} + style="--values-height:{valuesHeight}px;" >