mirror of https://github.com/Budibase/budibase.git
7 changed files with 125 additions and 91 deletions
@ -0,0 +1,14 @@ |
|||
<script> |
|||
import { getContext, setContext } from "svelte" |
|||
|
|||
const component = getContext("component") |
|||
const { styleable } = getContext("sdk") |
|||
|
|||
setContext("block", { |
|||
id: $component.id, |
|||
}) |
|||
</script> |
|||
|
|||
<div use:styleable={$component.styles}> |
|||
<slot /> |
|||
</div> |
|||
@ -0,0 +1,33 @@ |
|||
<script> |
|||
import { getContext } from "svelte" |
|||
import { generate } from "shortid" |
|||
import Component from "components/Component.svelte" |
|||
|
|||
export let type |
|||
export let props |
|||
export let styles |
|||
export let id |
|||
|
|||
const block = getContext("block") |
|||
const rand = generate() |
|||
|
|||
$: id = block.id + rand |
|||
$: instance = createInstance(type, props, id) |
|||
|
|||
const createInstance = (type, props, id) => { |
|||
return { |
|||
_component: `@budibase/standard-components/${type}`, |
|||
_id: id, |
|||
_styles: { |
|||
normal: { |
|||
...styles, |
|||
}, |
|||
}, |
|||
...props, |
|||
} |
|||
} |
|||
</script> |
|||
|
|||
<Component {instance}> |
|||
<slot /> |
|||
</Component> |
|||
@ -1,99 +1,89 @@ |
|||
<script> |
|||
import { getContext } from "svelte" |
|||
import { BlockBuilder } from "./block-builder" |
|||
import Component from "components/Component.svelte" |
|||
import Block from "./Block.svelte" |
|||
import BlockComponent from "./BlockComponent.svelte" |
|||
|
|||
// Common props |
|||
export let searchColumns |
|||
export let dataSource |
|||
|
|||
// Data provider props |
|||
export let searchColumns |
|||
export let filter |
|||
export let sortColumn |
|||
export let sortOrder |
|||
export let paginate |
|||
|
|||
// Table props |
|||
export let tableColumns |
|||
export let showAutoColumns |
|||
export let rowCount |
|||
export let quiet |
|||
export let size |
|||
|
|||
const { styleable } = getContext("sdk") |
|||
const component = getContext("component") |
|||
|
|||
let instance |
|||
$: { |
|||
const builder = new BlockBuilder($component) |
|||
|
|||
const form = builder.createComponent("form", { |
|||
dataSource, |
|||
}) |
|||
|
|||
let newFilter = [...(filter || [])] |
|||
|
|||
// Add search bar if required |
|||
if (searchColumns?.length) { |
|||
const searchContainer = builder |
|||
.createComponent("container", { |
|||
direction: "row", |
|||
hAlign: "right", |
|||
vAlign: "middle", |
|||
gap: "M", |
|||
wrap: true, |
|||
}) |
|||
.setStyles({ |
|||
"margin-bottom": "20px", |
|||
}) |
|||
let formId |
|||
let dataProviderId |
|||
|
|||
searchColumns?.forEach(column => { |
|||
const field = builder.createComponent("stringfield", { |
|||
field: column, |
|||
placeholder: column, |
|||
label: column, |
|||
}) |
|||
$: enrichedFilter = enrichFilter(filter, searchColumns, formId) |
|||
|
|||
searchContainer.addChild(field) |
|||
|
|||
newFilter.push({ |
|||
field: column, |
|||
operator: "equal", |
|||
type: "string", |
|||
valueType: "Binding", |
|||
value: `{{ [${form.id}].[${column}] }}`, |
|||
}) |
|||
const enrichFilter = (filter, searchColumns, formId) => { |
|||
let enrichedFilter = [...(filter || [])] |
|||
searchColumns?.forEach(column => { |
|||
enrichedFilter.push({ |
|||
field: column, |
|||
operator: "equal", |
|||
type: "string", |
|||
valueType: "Binding", |
|||
value: `{{ [${formId}].[${column}] }}`, |
|||
}) |
|||
|
|||
form.addChild(searchContainer) |
|||
} |
|||
|
|||
const dataProvider = builder.createComponent("dataprovider", { |
|||
dataSource, |
|||
filter: newFilter, |
|||
sortColumn, |
|||
sortOrder, |
|||
paginate, |
|||
limit: rowCount, |
|||
}) |
|||
|
|||
const table = builder.createComponent("table", { |
|||
dataProvider: `{{ literal [${dataProvider.id}] }}`, |
|||
columns: tableColumns, |
|||
showAutoColumns, |
|||
rowCount, |
|||
quiet, |
|||
size, |
|||
}) |
|||
|
|||
dataProvider.addChild(table) |
|||
|
|||
form.addChild(dataProvider) |
|||
instance = form.build() |
|||
console.log("new instance") |
|||
return enrichedFilter |
|||
} |
|||
</script> |
|||
|
|||
<div use:styleable={$component.styles}> |
|||
<Component {instance} /> |
|||
</div> |
|||
<Block> |
|||
<BlockComponent type="form" bind:id={formId} props={{ dataSource }}> |
|||
{#if searchColumns?.length} |
|||
<div class="search"> |
|||
{#each searchColumns as column} |
|||
<BlockComponent |
|||
type="stringfield" |
|||
props={{ |
|||
field: column, |
|||
placeholder: column, |
|||
label: column, |
|||
}} |
|||
/> |
|||
{/each} |
|||
</div> |
|||
{/if} |
|||
<BlockComponent |
|||
type="dataprovider" |
|||
bind:id={dataProviderId} |
|||
props={{ |
|||
dataSource, |
|||
filter: enrichedFilter, |
|||
sortColumn, |
|||
sortOrder, |
|||
paginate, |
|||
limit: rowCount, |
|||
}} |
|||
> |
|||
<BlockComponent |
|||
type="table" |
|||
props={{ |
|||
dataProvider: `{{ literal [${dataProviderId}] }}`, |
|||
columns: tableColumns, |
|||
showAutoColumns, |
|||
rowCount, |
|||
quiet, |
|||
size, |
|||
}} |
|||
/> |
|||
</BlockComponent> |
|||
</BlockComponent> |
|||
</Block> |
|||
|
|||
<style> |
|||
.search { |
|||
display: flex; |
|||
flex-direction: row; |
|||
justify-content: flex-end; |
|||
align-items: center; |
|||
margin-bottom: 20px; |
|||
gap: 10px; |
|||
} |
|||
</style> |
|||
|
|||
Loading…
Reference in new issue