Merge branch 'new-backend' of github.com:Budibase/budibase into new-backend

This commit is contained in:
Michael Shanks 2020-03-25 11:14:04 +00:00
commit 6cbf2ce02b
4 changed files with 28 additions and 32 deletions

View File

@ -39,8 +39,8 @@ export const getBackendUiStore = () => {
}) })
}, },
records: { records: {
delete: record => store.update(state => { delete: () => store.update(state => {
state.selectedView.records = state.selectedView.records.filter(({ id }) => id !== record.id) state.selectedView = state.selectedView
return state return state
}), }),
view: record => store.update(state => { view: record => store.update(state => {

View File

@ -13,7 +13,6 @@
const ITEMS_PER_PAGE = 10 const ITEMS_PER_PAGE = 10
let selectedView = ""
let modalOpen = false let modalOpen = false
let data = [] let data = []
let headers = [] let headers = []
@ -28,21 +27,20 @@
appname: $store.appname, appname: $store.appname,
instanceId: $backendUiStore.selectedDatabase.id, instanceId: $backendUiStore.selectedDatabase.id,
} }
// $: data =
// $backendUiStore.selectedDatabase &&
// $backendUiStore.selectedView.records.slice(
// currentPage * ITEMS_PER_PAGE,
// currentPage * ITEMS_PER_PAGE + ITEMS_PER_PAGE
// )
$: fetchRecordsForView( $: fetchRecordsForView(
$backendUiStore.selectedView, $backendUiStore.selectedView,
$backendUiStore.selectedDatabase $backendUiStore.selectedDatabase
).then(records => { ).then(records => {
data = records data = records || []
headers = getSchema($backendUiStore.selectedView).map(get("name")) headers = getSchema($backendUiStore.selectedView).map(get("name"))
}) })
$: paginatedData = data.slice(
currentPage * ITEMS_PER_PAGE,
currentPage * ITEMS_PER_PAGE + ITEMS_PER_PAGE
)
const childViewsForRecord = compose( const childViewsForRecord = compose(
flatten, flatten,
map("indexes"), map("indexes"),
@ -52,10 +50,13 @@
const getSchema = getIndexSchema($store.hierarchy) const getSchema = getIndexSchema($store.hierarchy)
async function fetchRecordsForView(view, instance) { async function fetchRecordsForView(view, instance) {
if (!view.name) return
const viewName = $backendUiStore.selectedRecord const viewName = $backendUiStore.selectedRecord
? `${$backendUiStore.selectedRecord.type}/` ? `${$backendUiStore.selectedRecord.type}/${$backendUiStore.selectedRecord.id}/${view.name}`
: view.name : view.name
return await api.fetchDataForView(view.name, {
return await api.fetchDataForView(viewName, {
appname: $store.appname, appname: $store.appname,
instanceId: instance.id, instanceId: instance.id,
}) })
@ -68,19 +69,20 @@
return state return state
}) })
} }
onMount(() => {
if (views.length) {
backendUiStore.actions.views.select(views[0])
}
})
</script> </script>
<section> <section>
<div class="table-controls"> <div class="table-controls">
<h4 class="budibase__title--3">{last($backendUiStore.breadcrumbs)}</h4> <h4 class="budibase__title--3">{last($backendUiStore.breadcrumbs)}</h4>
<Select <Select icon="ri-eye-line" bind:value={$backendUiStore.selectedView}>
icon="ri-eye-line"
on:change={e => {
const view = e.target.value
backendUiStore.actions.views.select(view)
}}>
{#each views as view} {#each views as view}
<option value={view.name}>{view.name}</option> <option value={view}>{view.name}</option>
{/each} {/each}
</Select> </Select>
</div> </div>
@ -94,10 +96,10 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{#if data.length === 0} {#if paginatedData.length === 0}
<div class="no-data">No Data.</div> <div class="no-data">No Data.</div>
{/if} {/if}
{#each data as row} {#each paginatedData as row}
<tr class="hoverable"> <tr class="hoverable">
<td> <td>
<div class="uk-inline"> <div class="uk-inline">
@ -135,9 +137,11 @@
</tbody> </tbody>
</table> </table>
<TablePagination <TablePagination
{data}
bind:currentPage bind:currentPage
pageItemCount={data.length} pageItemCount={data.length}
{ITEMS_PER_PAGE} /> {ITEMS_PER_PAGE}
/>
</section> </section>
<style> <style>

View File

@ -1,13 +1,13 @@
<script> <script>
import { backendUiStore } from "../../builderStore" import { backendUiStore } from "../../builderStore"
export let data
export let currentPage export let currentPage
export let pageItemCount export let pageItemCount
export let ITEMS_PER_PAGE export let ITEMS_PER_PAGE
let numPages = 0 let numPages = 0
$: data = $backendUiStore.selectedView.records
$: numPages = Math.ceil(data.length / ITEMS_PER_PAGE) $: numPages = Math.ceil(data.length / ITEMS_PER_PAGE)
const next = () => { const next = () => {

View File

@ -29,15 +29,7 @@
currentAppInfo currentAppInfo
) )
backendUiStore.update(state => { backendUiStore.update(state => {
const idx = findIndex(state.selectedView.records, { state.selectedView = state.selectedView
id: recordResponse.id
})
if (idx > 0) {
state.selectedView.records.splice(idx, 1, recordResponse)
} else {
state.selectedView.records.push(recordResponse)
}
return state return state
}) })
onClosed() onClosed()