data now syncs in the grid

This commit is contained in:
kevmodrome 2020-10-02 10:12:18 +02:00
parent 193f536834
commit e501679813
No known key found for this signature in database
GPG Key ID: E8F9CD141E63BF38
3 changed files with 14 additions and 11 deletions

View File

@ -57,13 +57,11 @@
return false return false
} }
const handleSubmit = e => { const handleNewRecord = async () => {
// Send off data here and update to display in grid component data = await fetchData(datasource)
console.log("Submitting:", e.detail)
} }
const handleUpdate = ({ detail }) => { const handleUpdate = ({ detail }) => {
console.log(detail)
data[detail.row] = detail.data data[detail.row] = detail.data
updateRecord(detail.data) updateRecord(detail.data)
} }
@ -74,11 +72,9 @@
record record
) )
const json = await response.json() const json = await response.json()
console.log(json)
} }
const deleteRecords = async () => { const deleteRecords = async () => {
console.log(_bb.api)
const response = await _bb.api.post(`/api/${datasource.name}/records`, { const response = await _bb.api.post(`/api/${datasource.name}/records`, {
records: selectedRows, records: selectedRows,
type: "delete", type: "delete",
@ -91,7 +87,7 @@
<div class="container"> <div class="container">
{#if dataLoaded} {#if dataLoaded}
<div class="controls"> <div class="controls">
<CreateRowButton {_bb} {model} /> <CreateRowButton {_bb} {model} on:newRecord={handleNewRecord} />
{#if selectedRows.length > 0} {#if selectedRows.length > 0}
<DeleteButton text small on:click={deleteRecords}> <DeleteButton text small on:click={deleteRecords}>
<Icon name="addrow" /> <Icon name="addrow" />

View File

@ -1,7 +1,10 @@
<script> <script>
import { createEventDispatcher } from "svelte"
import { DropdownMenu, TextButton as Button, Icon } from "@budibase/bbui" import { DropdownMenu, TextButton as Button, Icon } from "@budibase/bbui"
import Modal from "./Modal.svelte" import Modal from "./Modal.svelte"
const dispatch = createEventDispatcher()
let anchor let anchor
let dropdown let dropdown
@ -16,7 +19,11 @@
</div> </div>
<DropdownMenu bind:this={dropdown} {anchor} align="left"> <DropdownMenu bind:this={dropdown} {anchor} align="left">
<h5>Add New Row</h5> <h5>Add New Row</h5>
<Modal {_bb} {model} onClosed={dropdown.hide} /> <Modal
{_bb}
{model}
onClosed={dropdown.hide}
on:newRecord={() => dispatch('newRecord')} />
</DropdownMenu> </DropdownMenu>
<style> <style>

View File

@ -1,9 +1,10 @@
<script> <script>
import { onMount } from "svelte" import { onMount, createEventDispatcher } from "svelte"
import { fade } from "svelte/transition" import { fade } from "svelte/transition"
import { Button, Label, DatePicker } from "@budibase/bbui" import { Button, Label, DatePicker } from "@budibase/bbui"
import Dropzone from "../../attachments/Dropzone.svelte" import Dropzone from "../../attachments/Dropzone.svelte"
import debounce from "lodash.debounce" import debounce from "lodash.debounce"
const dispatch = createEventDispatcher()
const DEFAULTS_FOR_TYPE = { const DEFAULTS_FOR_TYPE = {
string: "", string: "",
@ -43,8 +44,6 @@
const json = await response.json() const json = await response.json()
console.log(json)
if (response.status === 200) { if (response.status === 200) {
store.update(state => { store.update(state => {
state[model._id] = state[model._id] state[model._id] = state[model._id]
@ -60,6 +59,7 @@
record = isNew ? { modelId: model._id } : json record = isNew ? { modelId: model._id } : json
onClosed() onClosed()
dispatch("newRecord")
} }
if (response.status === 400) { if (response.status === 400) {