Use APIClient
This commit is contained in:
parent
54d5047b34
commit
65fa3e0434
|
@ -5,19 +5,19 @@ import { convertJSONSchemaToTableSchema } from "../utils/json"
|
||||||
import {
|
import {
|
||||||
FieldType,
|
FieldType,
|
||||||
LegacyFilter,
|
LegacyFilter,
|
||||||
|
Row,
|
||||||
SearchFilters,
|
SearchFilters,
|
||||||
SortOrder,
|
SortOrder,
|
||||||
SortType,
|
SortType,
|
||||||
TableSchema,
|
TableSchema,
|
||||||
UIFetchAPI,
|
|
||||||
UIRow,
|
|
||||||
UISearchFilter,
|
UISearchFilter,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
import { APIClient } from "../api/types"
|
||||||
|
|
||||||
const { buildQuery, limit: queryLimit, runQuery, sort } = QueryUtils
|
const { buildQuery, limit: queryLimit, runQuery, sort } = QueryUtils
|
||||||
|
|
||||||
interface DataFetchStore<T> {
|
interface DataFetchStore<T> {
|
||||||
rows: UIRow[]
|
rows: Row[]
|
||||||
info: null
|
info: null
|
||||||
schema: TableSchema | null
|
schema: TableSchema | null
|
||||||
loading: boolean
|
loading: boolean
|
||||||
|
@ -48,7 +48,7 @@ export default abstract class DataFetch<
|
||||||
TDatasource extends {},
|
TDatasource extends {},
|
||||||
TDefinition extends {}
|
TDefinition extends {}
|
||||||
> {
|
> {
|
||||||
API: UIFetchAPI
|
API: APIClient
|
||||||
features: {
|
features: {
|
||||||
supportsSearch: boolean
|
supportsSearch: boolean
|
||||||
supportsSort: boolean
|
supportsSort: boolean
|
||||||
|
@ -78,11 +78,7 @@ export default abstract class DataFetch<
|
||||||
* Constructs a new DataFetch instance.
|
* Constructs a new DataFetch instance.
|
||||||
* @param opts the fetch options
|
* @param opts the fetch options
|
||||||
*/
|
*/
|
||||||
constructor(opts: {
|
constructor(opts: { API: APIClient; datasource: TDatasource; options?: {} }) {
|
||||||
API: UIFetchAPI
|
|
||||||
datasource: TDatasource
|
|
||||||
options?: {}
|
|
||||||
}) {
|
|
||||||
// Feature flags
|
// Feature flags
|
||||||
this.features = {
|
this.features = {
|
||||||
supportsSearch: false,
|
supportsSearch: false,
|
||||||
|
@ -323,7 +319,7 @@ export default abstract class DataFetch<
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract getData(): Promise<{
|
abstract getData(): Promise<{
|
||||||
rows: UIRow[]
|
rows: Row[]
|
||||||
info?: any
|
info?: any
|
||||||
hasNextPage: boolean
|
hasNextPage: boolean
|
||||||
cursor?: any
|
cursor?: any
|
||||||
|
|
|
@ -39,10 +39,10 @@ export default class TableFetch extends DataFetch<UITable, Table> {
|
||||||
// Search table
|
// Search table
|
||||||
try {
|
try {
|
||||||
const res = await this.API.searchTable(tableId, {
|
const res = await this.API.searchTable(tableId, {
|
||||||
query,
|
query: query ?? undefined,
|
||||||
limit,
|
limit,
|
||||||
sort: sortColumn,
|
sort: sortColumn,
|
||||||
sortOrder: sortOrder?.toLowerCase() ?? SortOrder.ASCENDING,
|
sortOrder: sortOrder ?? SortOrder.ASCENDING,
|
||||||
sortType,
|
sortType,
|
||||||
paginate,
|
paginate,
|
||||||
bookmark: cursor,
|
bookmark: cursor,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { SortOrder, UIView, ViewV2, ViewV2Type } from "@budibase/types"
|
import { SortOrder, UIView, ViewV2, ViewV2Type } from "@budibase/types"
|
||||||
import DataFetch from "./DataFetch.js"
|
import DataFetch from "./DataFetch.js"
|
||||||
import { get } from "svelte/store"
|
import { get } from "svelte/store"
|
||||||
import { isCalculationField } from "packages/shared-core/src/helpers/views.js"
|
import { helpers } from "@budibase/shared-core"
|
||||||
|
|
||||||
export default class ViewV2Fetch extends DataFetch<UIView, ViewV2> {
|
export default class ViewV2Fetch extends DataFetch<UIView, ViewV2> {
|
||||||
determineFeatureFlags() {
|
determineFeatureFlags() {
|
||||||
|
@ -47,7 +47,9 @@ export default class ViewV2Fetch extends DataFetch<UIView, ViewV2> {
|
||||||
// If this is a calculation view and we have no calculations, return nothing
|
// If this is a calculation view and we have no calculations, return nothing
|
||||||
if (
|
if (
|
||||||
definition?.type === ViewV2Type.CALCULATION &&
|
definition?.type === ViewV2Type.CALCULATION &&
|
||||||
!Object.values(definition.schema || {}).some(isCalculationField)
|
!Object.values(definition.schema || {}).some(
|
||||||
|
helpers.views.isCalculationField
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
rows: [],
|
rows: [],
|
||||||
|
@ -72,7 +74,7 @@ export default class ViewV2Fetch extends DataFetch<UIView, ViewV2> {
|
||||||
limit,
|
limit,
|
||||||
bookmark: cursor,
|
bookmark: cursor,
|
||||||
sort: sortColumn,
|
sort: sortColumn,
|
||||||
sortOrder: sortOrder?.toLowerCase(),
|
sortOrder: sortOrder,
|
||||||
sortType,
|
sortType,
|
||||||
})
|
})
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue