From afca35a22907f6d708bb85200feda15554315762 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 12 Apr 2021 14:45:41 +0100 Subject: [PATCH] Improve table props and update table to work with views --- packages/bbui/src/Table/Table.svelte | 13 ++++++------- .../src/components/backend/DataTable/Table.svelte | 12 +++++++++--- .../backend/DataTable/ViewDataTable.svelte | 1 + 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/bbui/src/Table/Table.svelte b/packages/bbui/src/Table/Table.svelte index 973756bf4a..d4731e84aa 100644 --- a/packages/bbui/src/Table/Table.svelte +++ b/packages/bbui/src/Table/Table.svelte @@ -14,8 +14,7 @@ export let allowEditRows = true export let allowEditColumns = true export let selectedRows = [] - export let customColumnRenderer = SelectEditRenderer - export let customColumnTitle = null + export let editColumnTitle = "Edit" export let customRenderers = [] const dispatch = createEventDispatcher() @@ -41,6 +40,7 @@ $: contentStyle = getContentStyle(visibleRowCount, scroll || !loaded) $: sortedRows = sortRows(rows, sortColumn, sortOrder) $: fields = getFields(schema, showAutoColumns) + $: showEditColumn = allowEditRows || allowSelectRows // Scrolling state let timeout @@ -155,10 +155,10 @@ - {#if customColumnRenderer} + {#if showEditColumn} {/if} @@ -208,12 +208,11 @@ class="spectrum-Table-row" class:hidden={idx < firstVisibleRow || idx > lastVisibleRow}> {#if idx >= firstVisibleRow && idx <= lastVisibleRow} - {#if customColumnRenderer} + {#if showEditColumn}
- {customColumnTitle || ''} + {editColumnTitle || ''}
- toggleSelectRow(row)} diff --git a/packages/builder/src/components/backend/DataTable/Table.svelte b/packages/builder/src/components/backend/DataTable/Table.svelte index 8f99088e4a..562a2ecdc8 100644 --- a/packages/builder/src/components/backend/DataTable/Table.svelte +++ b/packages/builder/src/components/backend/DataTable/Table.svelte @@ -23,7 +23,6 @@ export let theme = "alpine" export let hideAutocolumns - let columnDefs = [] let selectedRows = [] let editableColumn let editableRow @@ -32,6 +31,7 @@ let customRenderers = [] $: isUsersTable = tableId === TableNames.USERS + $: data && resetSelectedRows() $: editRowComponent = isUsersTable ? CreateEditUser : CreateEditRow $: { if (isUsersTable) { @@ -54,7 +54,11 @@ } } - function selectRelationship(row, fieldName) { + const resetSelectedRows = () => { + selectedRows = [] + } + + const selectRelationship = (row, fieldName) => { if (!row?.[fieldName]?.length) { return } @@ -110,8 +114,10 @@ {schema} {loading} {customRenderers} - customColumnTitle="Edit" bind:selectedRows + allowSelectRows={allowEditing} + allowEditRows={allowEditing} + allowEditColumns={allowEditing} showAutoColumns={!hideAutocolumns} on:editcolumn={e => editColumn(e.detail)} on:editrow={e => editRow(e.detail)} /> diff --git a/packages/builder/src/components/backend/DataTable/ViewDataTable.svelte b/packages/builder/src/components/backend/DataTable/ViewDataTable.svelte index 092796b3b5..1001e98ed3 100644 --- a/packages/builder/src/components/backend/DataTable/ViewDataTable.svelte +++ b/packages/builder/src/components/backend/DataTable/ViewDataTable.svelte @@ -57,6 +57,7 @@ tableId={view.tableId} {data} {loading} + allowEditing={!view?.calculation} bind:hideAutocolumns>