mirror of https://github.com/Budibase/budibase.git
7 changed files with 69 additions and 47 deletions
@ -1,46 +1,57 @@ |
|||||
<script> |
<script> |
||||
import { onMount, getContext } from "svelte" |
import { onMount, getContext } from "svelte" |
||||
|
|
||||
const { API, screenStore, routeStore, Provider, styleable } = getContext( |
|
||||
"sdk" |
|
||||
) |
|
||||
const component = getContext("component") |
|
||||
|
|
||||
export let table |
export let table |
||||
|
|
||||
|
const { |
||||
|
API, |
||||
|
screenStore, |
||||
|
routeStore, |
||||
|
Provider, |
||||
|
styleable, |
||||
|
ActionTypes, |
||||
|
} = getContext("sdk") |
||||
|
const component = getContext("component") |
||||
let headers = [] |
let headers = [] |
||||
let row |
let row |
||||
|
|
||||
async function fetchFirstRow() { |
const fetchFirstRow = async tableId => { |
||||
const rows = await API.fetchTableData(table) |
const rows = await API.fetchTableData(tableId) |
||||
return Array.isArray(rows) && rows.length ? rows[0] : { tableId: table } |
return Array.isArray(rows) && rows.length ? rows[0] : { tableId } |
||||
} |
} |
||||
|
|
||||
async function fetchData() { |
const fetchData = async (rowId, tableId) => { |
||||
if (!table) { |
if (!tableId) { |
||||
return |
return |
||||
} |
} |
||||
|
|
||||
const pathParts = window.location.pathname.split("/") |
const pathParts = window.location.pathname.split("/") |
||||
const routeParamId = $routeStore.routeParams.id |
|
||||
|
|
||||
// if srcdoc, then we assume this is the builder preview |
// if srcdoc, then we assume this is the builder preview |
||||
if ((pathParts.length === 0 || pathParts[0] === "srcdoc") && table) { |
if ((pathParts.length === 0 || pathParts[0] === "srcdoc") && tableId) { |
||||
row = await fetchFirstRow() |
row = await fetchFirstRow(tableId) |
||||
} else if (routeParamId) { |
} else if (rowId) { |
||||
row = await API.fetchRow({ tableId: table, rowId: routeParamId }) |
row = await API.fetchRow({ tableId, rowId }) |
||||
} else { |
} else { |
||||
throw new Error("Row ID was not supplied to RowDetail") |
throw new Error("Row ID was not supplied to RowDetail") |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
onMount(fetchData) |
$: actions = [ |
||||
|
{ |
||||
|
type: ActionTypes.RefreshDatasource, |
||||
|
callback: () => fetchData($routeStore.routeParams.id, table), |
||||
|
metadata: { datasource: { type: "table", tableId: table } }, |
||||
|
}, |
||||
|
] |
||||
|
|
||||
|
onMount(() => fetchData($routeStore.routeParams.id, table)) |
||||
</script> |
</script> |
||||
|
|
||||
{#if row} |
{#if row} |
||||
<div use:styleable={$component.styles}> |
<Provider data={row} {actions}> |
||||
<Provider data={row}> |
<div use:styleable={$component.styles}> |
||||
<slot /> |
<slot /> |
||||
</Provider> |
</div> |
||||
</div> |
</Provider> |
||||
{/if} |
{/if} |
||||
|
|||||
Loading…
Reference in new issue