Use APIClient

This commit is contained in:
Adria Navarro 2025-01-02 15:36:27 +01:00
parent 54d5047b34
commit 65fa3e0434
3 changed files with 13 additions and 15 deletions

View File

@ -5,19 +5,19 @@ import { convertJSONSchemaToTableSchema } from "../utils/json"
import {
FieldType,
LegacyFilter,
Row,
SearchFilters,
SortOrder,
SortType,
TableSchema,
UIFetchAPI,
UIRow,
UISearchFilter,
} from "@budibase/types"
import { APIClient } from "../api/types"
const { buildQuery, limit: queryLimit, runQuery, sort } = QueryUtils
interface DataFetchStore<T> {
rows: UIRow[]
rows: Row[]
info: null
schema: TableSchema | null
loading: boolean
@ -48,7 +48,7 @@ export default abstract class DataFetch<
TDatasource extends {},
TDefinition extends {}
> {
API: UIFetchAPI
API: APIClient
features: {
supportsSearch: boolean
supportsSort: boolean
@ -78,11 +78,7 @@ export default abstract class DataFetch<
* Constructs a new DataFetch instance.
* @param opts the fetch options
*/
constructor(opts: {
API: UIFetchAPI
datasource: TDatasource
options?: {}
}) {
constructor(opts: { API: APIClient; datasource: TDatasource; options?: {} }) {
// Feature flags
this.features = {
supportsSearch: false,
@ -323,7 +319,7 @@ export default abstract class DataFetch<
}
abstract getData(): Promise<{
rows: UIRow[]
rows: Row[]
info?: any
hasNextPage: boolean
cursor?: any

View File

@ -39,10 +39,10 @@ export default class TableFetch extends DataFetch<UITable, Table> {
// Search table
try {
const res = await this.API.searchTable(tableId, {
query,
query: query ?? undefined,
limit,
sort: sortColumn,
sortOrder: sortOrder?.toLowerCase() ?? SortOrder.ASCENDING,
sortOrder: sortOrder ?? SortOrder.ASCENDING,
sortType,
paginate,
bookmark: cursor,

View File

@ -1,7 +1,7 @@
import { SortOrder, UIView, ViewV2, ViewV2Type } from "@budibase/types"
import DataFetch from "./DataFetch.js"
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> {
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 (
definition?.type === ViewV2Type.CALCULATION &&
!Object.values(definition.schema || {}).some(isCalculationField)
!Object.values(definition.schema || {}).some(
helpers.views.isCalculationField
)
) {
return {
rows: [],
@ -72,7 +74,7 @@ export default class ViewV2Fetch extends DataFetch<UIView, ViewV2> {
limit,
bookmark: cursor,
sort: sortColumn,
sortOrder: sortOrder?.toLowerCase(),
sortOrder: sortOrder,
sortType,
})
return {