Simplify code
This commit is contained in:
parent
23f9e3f3fe
commit
eb6a2434b6
|
@ -11,7 +11,6 @@ import {
|
||||||
SortType,
|
SortType,
|
||||||
TableSchema,
|
TableSchema,
|
||||||
UISearchFilter,
|
UISearchFilter,
|
||||||
ViewSchema,
|
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { APIClient } from "../api/types"
|
import { APIClient } from "../api/types"
|
||||||
|
|
||||||
|
@ -224,12 +223,12 @@ export default abstract class DataFetch<
|
||||||
supportsPagination: paginate && !!features?.supportsPagination,
|
supportsPagination: paginate && !!features?.supportsPagination,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!definition?.schema) {
|
// Fetch and enrich schema
|
||||||
|
let schema = this.getSchema(definition)
|
||||||
|
if (!schema) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
schema = this.enrichSchema(schema)
|
||||||
// Fetch and enrich schema
|
|
||||||
const schema = this.enrichSchema(definition.schema)
|
|
||||||
|
|
||||||
// If an invalid sort column is specified, delete it
|
// If an invalid sort column is specified, delete it
|
||||||
if (this.options.sortColumn && !schema[this.options.sortColumn]) {
|
if (this.options.sortColumn && !schema[this.options.sortColumn]) {
|
||||||
|
@ -362,9 +361,7 @@ export default abstract class DataFetch<
|
||||||
* @param definition the datasource definition
|
* @param definition the datasource definition
|
||||||
* @return {object} the schema
|
* @return {object} the schema
|
||||||
*/
|
*/
|
||||||
getSchema(
|
getSchema(definition: TDefinition | null): Record<string, any> | undefined {
|
||||||
definition: TDefinition | null
|
|
||||||
): ViewSchema | Record<string, any> | undefined {
|
|
||||||
return definition?.schema ?? undefined
|
return definition?.schema ?? undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,7 +376,7 @@ export default abstract class DataFetch<
|
||||||
let jsonAdditions: Record<string, { type: string; nestedJSON: true }> = {}
|
let jsonAdditions: Record<string, { type: string; nestedJSON: true }> = {}
|
||||||
for (const fieldKey of Object.keys(schema)) {
|
for (const fieldKey of Object.keys(schema)) {
|
||||||
const fieldSchema = schema[fieldKey]
|
const fieldSchema = schema[fieldKey]
|
||||||
if (fieldSchema?.type === FieldType.JSON) {
|
if (fieldSchema.type === FieldType.JSON) {
|
||||||
const jsonSchema = convertJSONSchemaToTableSchema(fieldSchema, {
|
const jsonSchema = convertJSONSchemaToTableSchema(fieldSchema, {
|
||||||
squashObjects: true,
|
squashObjects: true,
|
||||||
}) as Record<string, { type: string }> | null // TODO: remove when convertJSONSchemaToTableSchema is typed
|
}) as Record<string, { type: string }> | null // TODO: remove when convertJSONSchemaToTableSchema is typed
|
||||||
|
|
Loading…
Reference in New Issue