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"
|
import DataFetch from "./DataFetch"
|
||||||
|
|
||||||
export default class FieldFetch extends DataFetch {
|
interface FieldDatasource {
|
||||||
async getDefinition(datasource) {
|
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
|
// Field sources have their schema statically defined
|
||||||
let schema
|
let schema: Record<string, { type: string }> | undefined
|
||||||
if (datasource.fieldType === "attachment") {
|
if (datasource.fieldType === "attachment") {
|
||||||
schema = {
|
schema = {
|
||||||
url: {
|
url: {
|
||||||
|
@ -28,8 +48,8 @@ export default class FieldFetch extends DataFetch {
|
||||||
|
|
||||||
// These sources will be available directly from context
|
// These sources will be available directly from context
|
||||||
const data = datasource?.value || []
|
const data = datasource?.value || []
|
||||||
let rows
|
let rows: Row[]
|
||||||
if (Array.isArray(data) && data[0] && typeof data[0] !== "object") {
|
if (isArrayOfStrings(data)) {
|
||||||
rows = data.map(value => ({ value }))
|
rows = data.map(value => ({ value }))
|
||||||
} else {
|
} else {
|
||||||
rows = data
|
rows = data
|
|
@ -1,4 +1,4 @@
|
||||||
import FieldFetch from "./FieldFetch.js"
|
import FieldFetch from "./FieldFetch"
|
||||||
import { getJSONArrayDatasourceSchema } from "../utils/json"
|
import { getJSONArrayDatasourceSchema } from "../utils/json"
|
||||||
|
|
||||||
export default class JSONArrayFetch extends FieldFetch {
|
export default class JSONArrayFetch extends FieldFetch {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import FieldFetch from "./FieldFetch.js"
|
import FieldFetch from "./FieldFetch"
|
||||||
import {
|
import {
|
||||||
getJSONArrayDatasourceSchema,
|
getJSONArrayDatasourceSchema,
|
||||||
generateQueryArraySchemas,
|
generateQueryArraySchemas,
|
||||||
|
|
|
@ -4,7 +4,7 @@ import ViewV2Fetch from "./ViewV2Fetch.js"
|
||||||
import QueryFetch from "./QueryFetch.js"
|
import QueryFetch from "./QueryFetch.js"
|
||||||
import RelationshipFetch from "./RelationshipFetch.js"
|
import RelationshipFetch from "./RelationshipFetch.js"
|
||||||
import NestedProviderFetch from "./NestedProviderFetch.js"
|
import NestedProviderFetch from "./NestedProviderFetch.js"
|
||||||
import FieldFetch from "./FieldFetch.js"
|
import FieldFetch from "./FieldFetch"
|
||||||
import JSONArrayFetch from "./JSONArrayFetch.js"
|
import JSONArrayFetch from "./JSONArrayFetch.js"
|
||||||
import UserFetch from "./UserFetch.js"
|
import UserFetch from "./UserFetch.js"
|
||||||
import GroupUserFetch from "./GroupUserFetch.js"
|
import GroupUserFetch from "./GroupUserFetch.js"
|
||||||
|
|
Loading…
Reference in New Issue