Automatically refresh data as needed when rows or columns are updated

This commit is contained in:
Andrew Kingston 2021-09-29 12:07:35 +01:00
parent e4a57253fa
commit f9c8cd8506
8 changed files with 47 additions and 10 deletions

View File

@ -49,6 +49,12 @@
filters: e.detail, filters: e.detail,
}) })
} }
const onUpdateColumns = () => {
search.update({
schema,
})
}
</script> </script>
<div> <div>
@ -63,9 +69,11 @@
on:sort={onSort} on:sort={onSort}
allowEditing allowEditing
disableSorting disableSorting
on:updatecolumns={onUpdateColumns}
on:updaterows={search.refresh}
> >
{#if isInternal} {#if isInternal}
<CreateColumnButton /> <CreateColumnButton on:updatecolumns={onUpdateColumns} />
{/if} {/if}
{#if schema && Object.keys(schema).length > 0} {#if schema && Object.keys(schema).length > 0}
{#if !isUsersTable} {#if !isUsersTable}

View File

@ -113,12 +113,12 @@
<div class="popovers"> <div class="popovers">
<slot /> <slot />
{#if !isUsersTable && selectedRows.length > 0} {#if !isUsersTable && selectedRows.length > 0}
<DeleteRowsButton {selectedRows} {deleteRows} /> <DeleteRowsButton on:updaterows {selectedRows} {deleteRows} />
{/if} {/if}
</div> </div>
</div> </div>
{#key tableId} {#key tableId}
<div in:fade={{ delay: 200, duration: 100 }}> <div class="table-wrapper" in:fade={{ delay: 200, duration: 100 }}>
<Table <Table
{data} {data}
{schema} {schema}
@ -141,10 +141,14 @@
</Layout> </Layout>
<Modal bind:this={editRowModal}> <Modal bind:this={editRowModal}>
<svelte:component this={editRowComponent} row={editableRow} /> <svelte:component this={editRowComponent} on:updaterows row={editableRow} />
</Modal> </Modal>
<Modal bind:this={editColumnModal}> <Modal bind:this={editColumnModal}>
<CreateEditColumn field={editableColumn} onClosed={editColumnModal.hide} /> <CreateEditColumn
field={editableColumn}
on:updatecolumns
onClosed={editColumnModal.hide}
/>
</Modal> </Modal>
<style> <style>
@ -158,6 +162,9 @@
.table-title > div { .table-title > div {
margin-left: var(--spacing-xs); margin-left: var(--spacing-xs);
} }
.table-wrapper {
overflow: hidden;
}
.popovers { .popovers {
display: flex; display: flex;

View File

@ -9,5 +9,5 @@
Create column Create column
</ActionButton> </ActionButton>
<Modal bind:this={modal}> <Modal bind:this={modal}>
<CreateEditColumn /> <CreateEditColumn on:updatecolumns />
</Modal> </Modal>

View File

@ -1,15 +1,18 @@
<script> <script>
import { createEventDispatcher } from "svelte"
import { Button } from "@budibase/bbui" import { Button } from "@budibase/bbui"
import ConfirmDialog from "components/common/ConfirmDialog.svelte" import ConfirmDialog from "components/common/ConfirmDialog.svelte"
export let selectedRows export let selectedRows
export let deleteRows export let deleteRows
const dispatch = createEventDispatcher()
let modal let modal
async function confirmDeletion() { async function confirmDeletion() {
await deleteRows() await deleteRows()
modal?.hide() modal?.hide()
dispatch("updaterows")
} }
</script> </script>

View File

@ -10,6 +10,7 @@
ModalContent, ModalContent,
Context, Context,
} from "@budibase/bbui" } from "@budibase/bbui"
import { createEventDispatcher } from "svelte"
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"
import { tables } from "stores/backend" import { tables } from "stores/backend"
import { TableNames, UNEDITABLE_USER_FIELDS } from "constants" import { TableNames, UNEDITABLE_USER_FIELDS } from "constants"
@ -30,8 +31,9 @@
const AUTO_TYPE = "auto" const AUTO_TYPE = "auto"
const FORMULA_TYPE = FIELDS.FORMULA.type const FORMULA_TYPE = FIELDS.FORMULA.type
const LINK_TYPE = FIELDS.LINK.type const LINK_TYPE = FIELDS.LINK.type
let fieldDefinitions = cloneDeep(FIELDS) const dispatch = createEventDispatcher()
const { hide } = getContext(Context.Modal) const { hide } = getContext(Context.Modal)
let fieldDefinitions = cloneDeep(FIELDS)
export let field = { export let field = {
type: "string", type: "string",
@ -81,12 +83,13 @@
if (field.type === AUTO_TYPE) { if (field.type === AUTO_TYPE) {
field = buildAutoColumn($tables.draft.name, field.name, field.subtype) field = buildAutoColumn($tables.draft.name, field.name, field.subtype)
} }
tables.saveField({ await tables.saveField({
originalName, originalName,
field, field,
primaryDisplay, primaryDisplay,
indexes, indexes,
}) })
dispatch("updatecolumns")
} }
function deleteColumn() { function deleteColumn() {
@ -99,6 +102,7 @@
hide() hide()
deletion = false deletion = false
} }
dispatch("updatecolumns")
} }
function handleTypeChange(event) { function handleTypeChange(event) {

View File

@ -1,4 +1,5 @@
<script> <script>
import { createEventDispatcher } from "svelte"
import { tables, rows } from "stores/backend" import { tables, rows } from "stores/backend"
import { notifications } from "@budibase/bbui" import { notifications } from "@budibase/bbui"
import RowFieldControl from "../RowFieldControl.svelte" import RowFieldControl from "../RowFieldControl.svelte"
@ -12,6 +13,7 @@
export let row = {} export let row = {}
let errors = [] let errors = []
const dispatch = createEventDispatcher()
$: creating = row?._id == null $: creating = row?._id == null
$: table = row.tableId $: table = row.tableId
@ -43,6 +45,7 @@
notifications.success("Row saved successfully.") notifications.success("Row saved successfully.")
rows.save(rowResponse) rows.save(rowResponse)
dispatch("updaterows")
} }
</script> </script>

View File

@ -1,4 +1,5 @@
<script> <script>
import { createEventDispatcher } from "svelte"
import { tables, rows } from "stores/backend" import { tables, rows } from "stores/backend"
import { roles } from "stores/backend" import { roles } from "stores/backend"
import { notifications } from "@budibase/bbui" import { notifications } from "@budibase/bbui"
@ -9,6 +10,7 @@
export let row = {} export let row = {}
const dispatch = createEventDispatcher()
let errors = [] let errors = []
$: creating = row?._id == null $: creating = row?._id == null
@ -71,6 +73,7 @@
notifications.success("User saved successfully") notifications.success("User saved successfully")
rows.save(rowResponse) rows.save(rowResponse)
dispatch("updaterows")
} }
</script> </script>

View File

@ -95,7 +95,13 @@ export function createTablesStore() {
selected: {}, selected: {},
})) }))
}, },
saveField: ({ originalName, field, primaryDisplay = false, indexes }) => { saveField: async ({
originalName,
field,
primaryDisplay = false,
indexes,
}) => {
let promise
update(state => { update(state => {
// delete the original if renaming // delete the original if renaming
// need to handle if the column had no name, empty string // need to handle if the column had no name, empty string
@ -126,9 +132,12 @@ export function createTablesStore() {
...state.draft.schema, ...state.draft.schema,
[field.name]: cloneDeep(field), [field.name]: cloneDeep(field),
} }
save(state.draft) promise = save(state.draft)
return state return state
}) })
if (promise) {
await promise
}
}, },
deleteField: field => { deleteField: field => {
update(state => { update(state => {