From fae24276f998afc48636bc1f66344886fd342f39 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Sun, 26 Feb 2023 21:29:46 +0000 Subject: [PATCH] Migrate sheet to data section, improve reordering and reszing --- .../backend/DataTable/DataTable.svelte | 218 ++++++++-------- .../app/spreadsheet/ReorderPlaceholder.svelte | 32 --- .../app/spreadsheet/ResizeSlider.svelte | 36 --- .../app/spreadsheet/SpacerCell.svelte | 13 - .../app/spreadsheet/SpreadsheetHeader.svelte | 108 -------- .../app/spreadsheet/VerticalSpacer.svelte | 17 -- .../src/components/app/spreadsheet/index.js | 1 - .../frontend-core/src/components/index.js | 1 + .../components/sheet/ResizeOverlay.svelte} | 82 +++--- .../src/components/sheet/Sheet.svelte} | 238 +++++++++--------- .../src/components/sheet/SheetBody.svelte} | 14 +- .../src/components/sheet/SheetCell.svelte} | 36 ++- .../src/components/sheet/SheetHeader.svelte | 112 +++++++++ .../src/components/sheet/SheetRow.svelte} | 2 +- .../components/sheet}/cells/DateCell.svelte | 0 .../sheet}/cells/MultiSelectCell.svelte | 0 .../components/sheet}/cells/NumberCell.svelte | 0 .../sheet}/cells/OptionsCell.svelte | 8 +- .../sheet}/cells/RelationshipCell.svelte | 0 .../components/sheet}/cells/TextCell.svelte | 0 .../src/components/sheet}/stores/reorder.js | 4 +- .../src/components/sheet}/utils.js | 0 packages/frontend-core/src/utils/utils.js | 21 ++ 23 files changed, 466 insertions(+), 477 deletions(-) delete mode 100644 packages/client/src/components/app/spreadsheet/ReorderPlaceholder.svelte delete mode 100644 packages/client/src/components/app/spreadsheet/ResizeSlider.svelte delete mode 100644 packages/client/src/components/app/spreadsheet/SpacerCell.svelte delete mode 100644 packages/client/src/components/app/spreadsheet/SpreadsheetHeader.svelte delete mode 100644 packages/client/src/components/app/spreadsheet/VerticalSpacer.svelte delete mode 100644 packages/client/src/components/app/spreadsheet/index.js rename packages/{client/src/components/app/spreadsheet/stores/resize.js => frontend-core/src/components/sheet/ResizeOverlay.svelte} (67%) rename packages/{client/src/components/app/spreadsheet/Spreadsheet.svelte => frontend-core/src/components/sheet/Sheet.svelte} (52%) rename packages/{client/src/components/app/spreadsheet/SpreadsheetBody.svelte => frontend-core/src/components/sheet/SheetBody.svelte} (94%) rename packages/{client/src/components/app/spreadsheet/SpreadsheetCell.svelte => frontend-core/src/components/sheet/SheetCell.svelte} (77%) create mode 100644 packages/frontend-core/src/components/sheet/SheetHeader.svelte rename packages/{client/src/components/app/spreadsheet/SpreadsheetRow.svelte => frontend-core/src/components/sheet/SheetRow.svelte} (98%) rename packages/{client/src/components/app/spreadsheet => frontend-core/src/components/sheet}/cells/DateCell.svelte (100%) rename packages/{client/src/components/app/spreadsheet => frontend-core/src/components/sheet}/cells/MultiSelectCell.svelte (100%) rename packages/{client/src/components/app/spreadsheet => frontend-core/src/components/sheet}/cells/NumberCell.svelte (100%) rename packages/{client/src/components/app/spreadsheet => frontend-core/src/components/sheet}/cells/OptionsCell.svelte (97%) rename packages/{client/src/components/app/spreadsheet => frontend-core/src/components/sheet}/cells/RelationshipCell.svelte (100%) rename packages/{client/src/components/app/spreadsheet => frontend-core/src/components/sheet}/cells/TextCell.svelte (100%) rename packages/{client/src/components/app/spreadsheet => frontend-core/src/components/sheet}/stores/reorder.js (94%) rename packages/{client/src/components/app/spreadsheet => frontend-core/src/components/sheet}/utils.js (100%) diff --git a/packages/builder/src/components/backend/DataTable/DataTable.svelte b/packages/builder/src/components/backend/DataTable/DataTable.svelte index 162240e12c..d921c94fb4 100644 --- a/packages/builder/src/components/backend/DataTable/DataTable.svelte +++ b/packages/builder/src/components/backend/DataTable/DataTable.svelte @@ -21,7 +21,7 @@ Layout, notifications, } from "@budibase/bbui" - import { fetchData } from "@budibase/frontend-core" + import { fetchData, Sheet } from "@budibase/frontend-core" import { API } from "api" let hideAutocolumns = true @@ -153,112 +153,122 @@
- { - selectedRows = e.detail - }} - customPlaceholder - > -
-
- - {#if !isUsersTable} - - {/if} - {#if isInternal} - - {/if} -
-
- - {#if isUsersTable} - - {/if} - {#if !isInternal} - - {/if} - - - - {#key id} - - {/key} -
-
-
- - {#if !hasCols} - Let's create some columns - - Start building out your table structure
- by adding some columns - - {:else} - Now let's add a row - - Add some data to your table
- by adding some rows - - {/if} -
-
-
- {#key id} -
- -
- {/key} +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/client/src/components/app/spreadsheet/ResizeSlider.svelte b/packages/client/src/components/app/spreadsheet/ResizeSlider.svelte deleted file mode 100644 index 7e4c4c9a12..0000000000 --- a/packages/client/src/components/app/spreadsheet/ResizeSlider.svelte +++ /dev/null @@ -1,36 +0,0 @@ - - -
resize.actions.startResizing(columnIdx, e)} /> - - diff --git a/packages/client/src/components/app/spreadsheet/SpacerCell.svelte b/packages/client/src/components/app/spreadsheet/SpacerCell.svelte deleted file mode 100644 index d4a9a87470..0000000000 --- a/packages/client/src/components/app/spreadsheet/SpacerCell.svelte +++ /dev/null @@ -1,13 +0,0 @@ - - - ($selectedCellId = null)} - on:mouseenter={() => ($hoveredRowId = null)} -/> diff --git a/packages/client/src/components/app/spreadsheet/SpreadsheetHeader.svelte b/packages/client/src/components/app/spreadsheet/SpreadsheetHeader.svelte deleted file mode 100644 index 35f81b950d..0000000000 --- a/packages/client/src/components/app/spreadsheet/SpreadsheetHeader.svelte +++ /dev/null @@ -1,108 +0,0 @@ - - -
-
- Filter - Group - Sort - Hide fields -
-
Sales Records
-
- {#if selectedRowCount} - - Delete {selectedRowCount} row{selectedRowCount === 1 ? "" : "s"} - - {:else} - {rowCount} row{rowCount === 1 ? "" : "s"} - {/if} -
-
- - diff --git a/packages/client/src/components/app/spreadsheet/VerticalSpacer.svelte b/packages/client/src/components/app/spreadsheet/VerticalSpacer.svelte deleted file mode 100644 index fcde0fcce9..0000000000 --- a/packages/client/src/components/app/spreadsheet/VerticalSpacer.svelte +++ /dev/null @@ -1,17 +0,0 @@ - - -
($selectedCellId = null)} - on:mouseenter={() => ($hoveredRowId = null)} -/> - - diff --git a/packages/client/src/components/app/spreadsheet/index.js b/packages/client/src/components/app/spreadsheet/index.js deleted file mode 100644 index 223ab462fa..0000000000 --- a/packages/client/src/components/app/spreadsheet/index.js +++ /dev/null @@ -1 +0,0 @@ -export { default as spreadsheet } from "./Spreadsheet.svelte" diff --git a/packages/frontend-core/src/components/index.js b/packages/frontend-core/src/components/index.js index 7ca21c4ff9..8e5959ef14 100644 --- a/packages/frontend-core/src/components/index.js +++ b/packages/frontend-core/src/components/index.js @@ -1,2 +1,3 @@ export { default as SplitPage } from "./SplitPage.svelte" export { default as TestimonialPage } from "./TestimonialPage.svelte" +export { default as Sheet } from "./sheet/Sheet.svelte" diff --git a/packages/client/src/components/app/spreadsheet/stores/resize.js b/packages/frontend-core/src/components/sheet/ResizeOverlay.svelte similarity index 67% rename from packages/client/src/components/app/spreadsheet/stores/resize.js rename to packages/frontend-core/src/components/sheet/ResizeOverlay.svelte index 8327f0e79d..aca8f59ac1 100644 --- a/packages/client/src/components/app/spreadsheet/stores/resize.js +++ b/packages/frontend-core/src/components/sheet/ResizeOverlay.svelte @@ -1,26 +1,16 @@ -import { writable, get } from "svelte/store" -import { domDebounce } from "../../../../utils/domDebounce.js" + + +{#each $columns as col} +
startResizing(col.idx, e)} + style="--left:{col.left + col.width}px;" + > +
+
+{/each} + + diff --git a/packages/client/src/components/app/spreadsheet/Spreadsheet.svelte b/packages/frontend-core/src/components/sheet/Sheet.svelte similarity index 52% rename from packages/client/src/components/app/spreadsheet/Spreadsheet.svelte rename to packages/frontend-core/src/components/sheet/Sheet.svelte index ee1d75d0af..4c3c58e5e1 100644 --- a/packages/client/src/components/app/spreadsheet/Spreadsheet.svelte +++ b/packages/frontend-core/src/components/sheet/Sheet.svelte @@ -1,27 +1,24 @@ -
-
- - -
- - - - - {#each $columns as field, fieldIdx} - reorder.actions.startReordering(fieldIdx, e)} - width={field.width} - left={field.left} - > - - - {field.name} - - - - {/each} -
- - - {#each renderedRows as row, rowIdx (row._id)} - - {/each} - - -
+
+ + +
+ + + + + {#each $columns as field, fieldIdx} ($hoveredRowId = "new")} - rowHovered={$hoveredRowId === "new"} - width="40" - left="0" + header + sticky={fieldIdx === 0} + reorderSource={$reorder.columnIdx === fieldIdx} + reorderTarget={$reorder.swapColumnIdx === fieldIdx} + on:mousedown={e => reorder.actions.startReordering(fieldIdx, e)} + width={field.width} + left={field.left} > - - - {#each $columns as field, fieldIdx} - addRow(field)} - on:mouseenter={() => ($hoveredRowId = "new")} - width={field.width} - left={field.left} + - {/each} -
-
+ + {field.name} + + + {/each} +
- - -
+ + {#each renderedRows as row, rowIdx (row._id)} + + {/each} + + +
+ ($hoveredRowId = "new")} + rowHovered={$hoveredRowId === "new"} + width="40" + left="0" + > + + + {#each $columns as field, fieldIdx} + addRow(field)} + on:mouseenter={() => ($hoveredRowId = "new")} + width={field.width} + left={field.left} + /> + {/each} +
+
+
diff --git a/packages/client/src/components/app/spreadsheet/SpreadsheetBody.svelte b/packages/frontend-core/src/components/sheet/SheetBody.svelte similarity index 94% rename from packages/client/src/components/app/spreadsheet/SpreadsheetBody.svelte rename to packages/frontend-core/src/components/sheet/SheetBody.svelte index b6fd5e94ae..12bd2dff70 100644 --- a/packages/client/src/components/app/spreadsheet/SpreadsheetBody.svelte +++ b/packages/frontend-core/src/components/sheet/SheetBody.svelte @@ -1,6 +1,6 @@
+ import { getContext } from "svelte" + import { ActionButton, Modal, ModalContent } from "@budibase/bbui" + + const { + selectedRows, + rows, + selectedCellId, + hoveredRowId, + tableId, + spreadsheetAPI, + API, + } = getContext("spreadsheet") + + let modal + + $: selectedRowCount = Object.values($selectedRows).filter(x => !!x).length + $: rowCount = $rows.length + $: rowsToDelete = Object.entries($selectedRows) + .map(entry => { + if (entry[1] === true) { + return $rows.find(x => x._id === entry[0]) + } else { + return null + } + }) + .filter(x => x != null) + + // Deletion callback when confirmed + const performDeletion = async () => { + await API.deleteRows({ + tableId, + rows: rowsToDelete, + }) + await spreadsheetAPI.refreshData() + + // Refresh state + $selectedCellId = null + $hoveredRowId = null + $selectedRows = {} + } + + +
+
+ Filter + Group + Sort + Hide fields +
+
+
+ {#if selectedRowCount} + + Delete {selectedRowCount} row{selectedRowCount === 1 ? "" : "s"} + + {:else} + {rowCount} row{rowCount === 1 ? "" : "s"} + {/if} +
+
+ + + + Are you sure you want to delete {selectedRowCount} + row{selectedRowCount === 1 ? "" : "s"}? + + + + diff --git a/packages/client/src/components/app/spreadsheet/SpreadsheetRow.svelte b/packages/frontend-core/src/components/sheet/SheetRow.svelte similarity index 98% rename from packages/client/src/components/app/spreadsheet/SpreadsheetRow.svelte rename to packages/frontend-core/src/components/sheet/SheetRow.svelte index 595f2d1742..0a174e1548 100644 --- a/packages/client/src/components/app/spreadsheet/SpreadsheetRow.svelte +++ b/packages/frontend-core/src/components/sheet/SheetRow.svelte @@ -1,6 +1,6 @@