Convert fieldFetch
This commit is contained in:
parent
2b863cca61
commit
543660dc2e
|
@ -1,9 +1,29 @@
|
|||
import { Row, TableSchema } from "@budibase/types"
|
||||
import DataFetch from "./DataFetch"
|
||||
|
||||
export default class FieldFetch extends DataFetch {
|
||||
async getDefinition(datasource) {
|
||||
interface FieldDatasource {
|
||||
fieldType: "attachment" | "array"
|
||||
value: string[] | Row[]
|
||||
}
|
||||
|
||||
function isArrayOfStrings(value: string[] | Row[]): value is string[] {
|
||||
return Array.isArray(value) && !!value[0] && typeof value[0] !== "object"
|
||||
}
|
||||
|
||||
export default class FieldFetch extends DataFetch<
|
||||
FieldDatasource,
|
||||
{ schema?: Record<string, { type: string }> }
|
||||
> {
|
||||
getSchema(
|
||||
_datasource: FieldDatasource,
|
||||
definition: { schema?: TableSchema }
|
||||
) {
|
||||
return definition?.schema
|
||||
}
|
||||
|
||||
async getDefinition(datasource: FieldDatasource) {
|
||||
// Field sources have their schema statically defined
|
||||
let schema
|
||||
let schema: Record<string, { type: string }> | undefined
|
||||
if (datasource.fieldType === "attachment") {
|
||||
schema = {
|
||||
url: {
|
||||
|
@ -28,8 +48,8 @@ export default class FieldFetch extends DataFetch {
|
|||
|
||||
// These sources will be available directly from context
|
||||
const data = datasource?.value || []
|
||||
let rows
|
||||
if (Array.isArray(data) && data[0] && typeof data[0] !== "object") {
|
||||
let rows: Row[]
|
||||
if (isArrayOfStrings(data)) {
|
||||
rows = data.map(value => ({ value }))
|
||||
} else {
|
||||
rows = data
|
|
@ -1,4 +1,4 @@
|
|||
import FieldFetch from "./FieldFetch.js"
|
||||
import FieldFetch from "./FieldFetch"
|
||||
import { getJSONArrayDatasourceSchema } from "../utils/json"
|
||||
|
||||
export default class JSONArrayFetch extends FieldFetch {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import FieldFetch from "./FieldFetch.js"
|
||||
import FieldFetch from "./FieldFetch"
|
||||
import {
|
||||
getJSONArrayDatasourceSchema,
|
||||
generateQueryArraySchemas,
|
||||
|
|
|
@ -4,7 +4,7 @@ import ViewV2Fetch from "./ViewV2Fetch.js"
|
|||
import QueryFetch from "./QueryFetch.js"
|
||||
import RelationshipFetch from "./RelationshipFetch.js"
|
||||
import NestedProviderFetch from "./NestedProviderFetch.js"
|
||||
import FieldFetch from "./FieldFetch.js"
|
||||
import FieldFetch from "./FieldFetch"
|
||||
import JSONArrayFetch from "./JSONArrayFetch.js"
|
||||
import UserFetch from "./UserFetch.js"
|
||||
import GroupUserFetch from "./GroupUserFetch.js"
|
||||
|
|
Loading…
Reference in New Issue