|
|
|
@ -1,37 +1,54 @@ |
|
|
|
<script> |
|
|
|
import { Label, Select, Body } from "@budibase/bbui" |
|
|
|
import { findAllMatchingComponents } from "builderStore/componentUtils" |
|
|
|
import { Label, Select, Body, Multiselect } from "@budibase/bbui" |
|
|
|
import { |
|
|
|
findAllMatchingComponents, |
|
|
|
findComponent, |
|
|
|
} from "builderStore/componentUtils" |
|
|
|
import { currentAsset } from "builderStore" |
|
|
|
import { onMount } from "svelte" |
|
|
|
import { |
|
|
|
getDatasourceForProvider, |
|
|
|
getSchemaForDatasource, |
|
|
|
} from "builderStore/dataBinding" |
|
|
|
|
|
|
|
export let parameters |
|
|
|
|
|
|
|
const FORMATS = [ |
|
|
|
{ |
|
|
|
label: "CSV", |
|
|
|
value: "csv", |
|
|
|
}, |
|
|
|
{ |
|
|
|
label: "JSON", |
|
|
|
value: "json", |
|
|
|
}, |
|
|
|
] |
|
|
|
|
|
|
|
$: tables = findAllMatchingComponents($currentAsset?.props, component => |
|
|
|
component._component.endsWith("table") |
|
|
|
).map(table => ({ |
|
|
|
label: table._instanceName, |
|
|
|
value: table._id, |
|
|
|
})) |
|
|
|
|
|
|
|
$: tableBlocks = findAllMatchingComponents($currentAsset?.props, component => |
|
|
|
component._component.endsWith("tableblock") |
|
|
|
).map(block => ({ |
|
|
|
label: block._instanceName, |
|
|
|
value: `${block._id}-table`, |
|
|
|
})) |
|
|
|
|
|
|
|
$: componentOptions = tables.concat(tableBlocks) |
|
|
|
$: columnOptions = getColumnOptions(parameters.tableComponentId) |
|
|
|
|
|
|
|
const FORMATS = [ |
|
|
|
{ |
|
|
|
label: "CSV", |
|
|
|
value: "csv", |
|
|
|
}, |
|
|
|
{ |
|
|
|
label: "JSON", |
|
|
|
value: "json", |
|
|
|
}, |
|
|
|
] |
|
|
|
const getColumnOptions = tableId => { |
|
|
|
// Strip block suffix if block component |
|
|
|
if (tableId?.includes("-")) { |
|
|
|
tableId = tableId.split("-")[0] |
|
|
|
} |
|
|
|
const selectedTable = findComponent($currentAsset?.props, tableId) |
|
|
|
const datasource = getDatasourceForProvider($currentAsset, selectedTable) |
|
|
|
const { schema } = getSchemaForDatasource($currentAsset, datasource) |
|
|
|
return Object.keys(schema || {}) |
|
|
|
} |
|
|
|
|
|
|
|
onMount(() => { |
|
|
|
if (!parameters.type) { |
|
|
|
@ -53,10 +70,16 @@ |
|
|
|
<Select |
|
|
|
bind:value={parameters.tableComponentId} |
|
|
|
options={componentOptions} |
|
|
|
on:change={() => (parameters.columns = [])} |
|
|
|
/> |
|
|
|
|
|
|
|
<Label small>Export as</Label> |
|
|
|
<Select bind:value={parameters.type} options={FORMATS} /> |
|
|
|
<Label small>Export columns</Label> |
|
|
|
<Multiselect |
|
|
|
placeholder="All columns" |
|
|
|
bind:value={parameters.columns} |
|
|
|
options={columnOptions} |
|
|
|
/> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
@ -80,7 +103,7 @@ |
|
|
|
display: grid; |
|
|
|
column-gap: var(--spacing-xs); |
|
|
|
row-gap: var(--spacing-s); |
|
|
|
grid-template-columns: 70px 1fr; |
|
|
|
grid-template-columns: 90px 1fr; |
|
|
|
align-items: center; |
|
|
|
} |
|
|
|
</style> |
|
|
|
|