From 0d0685cd48bd7169e743770cdfa03597a1ef493c Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 25 Mar 2020 10:59:47 +0000 Subject: [PATCH] bug fixes= --- .../builder/src/builderStore/store/backend.js | 4 +- .../ModelDataTable/ModelDataTable.svelte | 44 ++++++++++--------- .../ModelDataTable/TablePagination.svelte | 2 +- .../modals/CreateEditRecord.svelte | 10 +---- 4 files changed, 28 insertions(+), 32 deletions(-) diff --git a/packages/builder/src/builderStore/store/backend.js b/packages/builder/src/builderStore/store/backend.js index 0a3da2fb50..ded766e755 100644 --- a/packages/builder/src/builderStore/store/backend.js +++ b/packages/builder/src/builderStore/store/backend.js @@ -39,8 +39,8 @@ export const getBackendUiStore = () => { }) }, records: { - delete: record => store.update(state => { - state.selectedView.records = state.selectedView.records.filter(({ id }) => id !== record.id) + delete: () => store.update(state => { + state.selectedView = state.selectedView return state }), view: record => store.update(state => { diff --git a/packages/builder/src/database/ModelDataTable/ModelDataTable.svelte b/packages/builder/src/database/ModelDataTable/ModelDataTable.svelte index 4a59d11298..e4f87f35ed 100644 --- a/packages/builder/src/database/ModelDataTable/ModelDataTable.svelte +++ b/packages/builder/src/database/ModelDataTable/ModelDataTable.svelte @@ -13,7 +13,6 @@ const ITEMS_PER_PAGE = 10 - let selectedView = "" let modalOpen = false let data = [] let headers = [] @@ -28,21 +27,20 @@ appname: $store.appname, instanceId: $backendUiStore.selectedDatabase.id, } - // $: data = - // $backendUiStore.selectedDatabase && - // $backendUiStore.selectedView.records.slice( - // currentPage * ITEMS_PER_PAGE, - // currentPage * ITEMS_PER_PAGE + ITEMS_PER_PAGE - // ) $: fetchRecordsForView( $backendUiStore.selectedView, $backendUiStore.selectedDatabase ).then(records => { - data = records + data = records || [] headers = getSchema($backendUiStore.selectedView).map(get("name")) }) + $: paginatedData = data.slice( + currentPage * ITEMS_PER_PAGE, + currentPage * ITEMS_PER_PAGE + ITEMS_PER_PAGE + ) + const childViewsForRecord = compose( flatten, map("indexes"), @@ -52,10 +50,13 @@ const getSchema = getIndexSchema($store.hierarchy) async function fetchRecordsForView(view, instance) { + if (!view.name) return + const viewName = $backendUiStore.selectedRecord - ? `${$backendUiStore.selectedRecord.type}/` + ? `${$backendUiStore.selectedRecord.type}/${$backendUiStore.selectedRecord.id}/${view.name}` : view.name - return await api.fetchDataForView(view.name, { + + return await api.fetchDataForView(viewName, { appname: $store.appname, instanceId: instance.id, }) @@ -68,19 +69,20 @@ return state }) } + + onMount(() => { + if (views.length) { + backendUiStore.actions.views.select(views[0]) + } + })

{last($backendUiStore.breadcrumbs)}

- {#each views as view} - + {/each}
@@ -94,10 +96,10 @@ - {#if data.length === 0} + {#if paginatedData.length === 0}
No Data.
{/if} - {#each data as row} + {#each paginatedData as row}
@@ -135,9 +137,11 @@ + {ITEMS_PER_PAGE} + />