Type relationship fetch
This commit is contained in:
parent
1d661c6290
commit
af22eb30a6
|
@ -2,7 +2,7 @@ import { API } from "api"
|
|||
import TableFetch from "@budibase/frontend-core/src/fetch/TableFetch"
|
||||
import ViewFetch from "@budibase/frontend-core/src/fetch/ViewFetch"
|
||||
import QueryFetch from "@budibase/frontend-core/src/fetch/QueryFetch.js"
|
||||
import RelationshipFetch from "@budibase/frontend-core/src/fetch/RelationshipFetch.js"
|
||||
import RelationshipFetch from "@budibase/frontend-core/src/fetch/RelationshipFetch"
|
||||
import NestedProviderFetch from "@budibase/frontend-core/src/fetch/NestedProviderFetch.js"
|
||||
import FieldFetch from "@budibase/frontend-core/src/fetch/FieldFetch"
|
||||
import JSONArrayFetch from "@budibase/frontend-core/src/fetch/JSONArrayFetch.js"
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
import DataFetch from "./DataFetch"
|
||||
|
||||
export default class RelationshipFetch extends DataFetch {
|
||||
async getData() {
|
||||
const { datasource } = this.options
|
||||
if (!datasource?.rowId || !datasource?.rowTableId) {
|
||||
return { rows: [] }
|
||||
}
|
||||
try {
|
||||
const res = await this.API.fetchRelationshipData(
|
||||
datasource.rowTableId,
|
||||
datasource.rowId,
|
||||
datasource.fieldName
|
||||
)
|
||||
return { rows: res }
|
||||
} catch (error) {
|
||||
return { rows: [] }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
import { Table } from "@budibase/types"
|
||||
import DataFetch from "./DataFetch"
|
||||
|
||||
interface RelationshipDatasource {
|
||||
tableId: string
|
||||
rowId: string
|
||||
rowTableId: string
|
||||
fieldName: string
|
||||
}
|
||||
|
||||
export default class RelationshipFetch extends DataFetch<
|
||||
RelationshipDatasource,
|
||||
Table
|
||||
> {
|
||||
getSchema(_datasource: any, definition: any) {
|
||||
return definition?.schema
|
||||
}
|
||||
|
||||
async getDefinition(datasource: RelationshipDatasource) {
|
||||
if (!datasource?.tableId) {
|
||||
return null
|
||||
}
|
||||
try {
|
||||
return await this.API.fetchTableDefinition(datasource.tableId)
|
||||
} catch (error: any) {
|
||||
this.store.update(state => ({
|
||||
...state,
|
||||
error,
|
||||
}))
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async getData() {
|
||||
const { datasource } = this.options
|
||||
if (!datasource?.rowId || !datasource?.rowTableId) {
|
||||
return { rows: [] }
|
||||
}
|
||||
try {
|
||||
const res = await this.API.fetchRelationshipData(
|
||||
datasource.rowTableId,
|
||||
datasource.rowId,
|
||||
datasource.fieldName
|
||||
)
|
||||
return { rows: res }
|
||||
} catch (error) {
|
||||
return { rows: [] }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@ import TableFetch from "./TableFetch.js"
|
|||
import ViewFetch from "./ViewFetch.js"
|
||||
import ViewV2Fetch from "./ViewV2Fetch.js"
|
||||
import QueryFetch from "./QueryFetch.js"
|
||||
import RelationshipFetch from "./RelationshipFetch.js"
|
||||
import RelationshipFetch from "./RelationshipFetch"
|
||||
import NestedProviderFetch from "./NestedProviderFetch.js"
|
||||
import FieldFetch from "./FieldFetch"
|
||||
import JSONArrayFetch from "./JSONArrayFetch.js"
|
||||
|
|
Loading…
Reference in New Issue