Merge pull request #11632 from Budibase/dean-bug-fixes

View bug fixes
This commit is contained in:
Andrew Kingston 2023-09-04 11:03:06 +01:00 committed by GitHub
commit ffb9a63b1b
7 changed files with 51 additions and 22 deletions

View File

@ -10,6 +10,7 @@
import ManageAccessButton from "./buttons/ManageAccessButton.svelte" import ManageAccessButton from "./buttons/ManageAccessButton.svelte"
import HideAutocolumnButton from "./buttons/HideAutocolumnButton.svelte" import HideAutocolumnButton from "./buttons/HideAutocolumnButton.svelte"
import { notifications } from "@budibase/bbui" import { notifications } from "@budibase/bbui"
import { ROW_EXPORT_FORMATS } from "constants/backend"
export let view = {} export let view = {}
@ -19,6 +20,14 @@
let type = "internal" let type = "internal"
$: name = view.name $: name = view.name
$: calculation = view.calculation
$: supportedFormats = Object.values(ROW_EXPORT_FORMATS).filter(key => {
if (calculation && key === ROW_EXPORT_FORMATS.JSON_WITH_SCHEMA) {
return false
}
return true
})
// Fetch rows for specified view // Fetch rows for specified view
$: fetchViewData(name, view.field, view.groupBy, view.calculation) $: fetchViewData(name, view.field, view.groupBy, view.calculation)
@ -68,5 +77,5 @@
{/if} {/if}
<ManageAccessButton resourceId={decodeURI(name)} /> <ManageAccessButton resourceId={decodeURI(name)} />
<HideAutocolumnButton bind:hideAutocolumns /> <HideAutocolumnButton bind:hideAutocolumns />
<ExportButton view={view.name} /> <ExportButton view={view.name} formats={supportedFormats} />
</Table> </Table>

View File

@ -7,6 +7,7 @@
export let sorting export let sorting
export let disabled = false export let disabled = false
export let selectedRows export let selectedRows
export let formats
let modal let modal
</script> </script>
@ -15,5 +16,5 @@
Export Export
</ActionButton> </ActionButton>
<Modal bind:this={modal}> <Modal bind:this={modal}>
<ExportModal {view} {filters} {sorting} {selectedRows} /> <ExportModal {view} {filters} {sorting} {selectedRows} {formats} />
</Modal> </Modal>

View File

@ -9,30 +9,43 @@
import download from "downloadjs" import download from "downloadjs"
import { API } from "api" import { API } from "api"
import { Constants, LuceneUtils } from "@budibase/frontend-core" import { Constants, LuceneUtils } from "@budibase/frontend-core"
import { ROW_EXPORT_FORMATS } from "constants/backend"
const FORMATS = [
{
name: "CSV",
key: "csv",
},
{
name: "JSON",
key: "json",
},
{
name: "JSON with Schema",
key: "jsonWithSchema",
},
]
export let view export let view
export let filters export let filters
export let sorting export let sorting
export let selectedRows = [] export let selectedRows = []
export let formats
let exportFormat = FORMATS[0].key const FORMATS = [
{
name: "CSV",
key: ROW_EXPORT_FORMATS.CSV,
},
{
name: "JSON",
key: ROW_EXPORT_FORMATS.JSON,
},
{
name: "JSON with Schema",
key: ROW_EXPORT_FORMATS.JSON_WITH_SCHEMA,
},
]
$: options = FORMATS.filter(format => {
if (formats && !formats.includes(format.key)) {
return false
}
return true
})
let exportFormat
let filterLookup let filterLookup
$: if (options && !exportFormat) {
exportFormat = Array.isArray(options) ? options[0]?.key : []
}
$: luceneFilter = LuceneUtils.buildLuceneQuery(filters) $: luceneFilter = LuceneUtils.buildLuceneQuery(filters)
$: exportOpDisplay = buildExportOpDisplay(sorting, filterDisplay, filters) $: exportOpDisplay = buildExportOpDisplay(sorting, filterDisplay, filters)
@ -190,7 +203,7 @@
<Select <Select
label="Format" label="Format"
bind:value={exportFormat} bind:value={exportFormat}
options={FORMATS} {options}
placeholder={null} placeholder={null}
getOptionLabel={x => x.name} getOptionLabel={x => x.name}
getOptionValue={x => x.key} getOptionValue={x => x.key}

View File

@ -287,3 +287,9 @@ export const DatasourceTypes = {
GRAPH: "Graph", GRAPH: "Graph",
API: "API", API: "API",
} }
export const ROW_EXPORT_FORMATS = {
CSV: "csv",
JSON: "json",
JSON_WITH_SCHEMA: "jsonWithSchema",
}

View File

@ -136,7 +136,7 @@
// Check arrays - remove any values not present in the field schema and // Check arrays - remove any values not present in the field schema and
// convert any values supplied to strings // convert any values supplied to strings
if (Array.isArray(value) && type === "array" && schema) { if (Array.isArray(value) && type === "array" && schema) {
const options = schema?.constraints.inclusion || [] const options = schema?.constraints?.inclusion || []
return value.map(opt => String(opt)).filter(opt => options.includes(opt)) return value.map(opt => String(opt)).filter(opt => options.includes(opt))
} }
return value return value

View File

@ -92,7 +92,7 @@ export async function fetchView(ctx: any) {
() => () =>
sdk.rows.fetchView(tableId, viewName, { sdk.rows.fetchView(tableId, viewName, {
calculation, calculation,
group, group: calculation ? group : null,
field, field,
}), }),
{ {

View File

@ -27,7 +27,7 @@ export function json(rows: Row[]) {
export function jsonWithSchema(schema: TableSchema, rows: Row[]) { export function jsonWithSchema(schema: TableSchema, rows: Row[]) {
const newSchema: TableSchema = {} const newSchema: TableSchema = {}
Object.values(schema).forEach(column => { Object.values(schema).forEach(column => {
if (!column.autocolumn) { if (!column.autocolumn && column.name) {
newSchema[column.name] = column newSchema[column.name] = column
} }
}) })