diff --git a/packages/frontend-core/src/api/types.ts b/packages/frontend-core/src/api/types.ts index 08820f750c..0db1049591 100644 --- a/packages/frontend-core/src/api/types.ts +++ b/packages/frontend-core/src/api/types.ts @@ -31,6 +31,7 @@ import { TableEndpoints } from "./tables" import { TemplateEndpoints } from "./templates" import { UserEndpoints } from "./user" import { ViewEndpoints } from "./views" +import { ViewV2Endpoints } from "./viewsV2" export enum HTTPMethod { POST = "POST", @@ -132,4 +133,4 @@ export type APIClient = BaseAPIClient & TableEndpoints & TemplateEndpoints & UserEndpoints & - ViewEndpoints & { rowActions: RowActionEndpoints; [key: string]: any } + ViewEndpoints & { rowActions: RowActionEndpoints; viewV2: ViewV2Endpoints } diff --git a/packages/frontend-core/src/api/viewsV2.js b/packages/frontend-core/src/api/viewsV2.ts similarity index 57% rename from packages/frontend-core/src/api/viewsV2.js rename to packages/frontend-core/src/api/viewsV2.ts index d1cb07c6b0..11b3358f4c 100644 --- a/packages/frontend-core/src/api/viewsV2.js +++ b/packages/frontend-core/src/api/viewsV2.ts @@ -1,4 +1,25 @@ -export const buildViewV2Endpoints = API => ({ +import { + CreateViewRequest, + SearchRowResponse, + SearchViewRowRequest, + UpdateViewRequest, + ViewResponse, + ViewResponseEnriched, +} from "@budibase/types" +import { BaseAPIClient } from "./types" + +export interface ViewV2Endpoints { + fetchDefinition: (viewId: string) => Promise + create: (view: CreateViewRequest) => Promise + update: (view: UpdateViewRequest) => Promise + fetch: ( + viewId: string, + opts: SearchViewRowRequest + ) => Promise + delete: (viewId: string) => Promise +} + +export const buildViewV2Endpoints = (API: BaseAPIClient): ViewV2Endpoints => ({ /** * Fetches the definition of a view * @param viewId the ID of the view to fetch @@ -9,6 +30,7 @@ export const buildViewV2Endpoints = API => ({ cache: true, }) }, + /** * Create a new view * @param view the view object @@ -19,6 +41,7 @@ export const buildViewV2Endpoints = API => ({ body: view, }) }, + /** * Updates a view * @param view the view object @@ -29,40 +52,19 @@ export const buildViewV2Endpoints = API => ({ body: view, }) }, + /** * Fetches all rows in a view * @param viewId the id of the view - * @param query the search query - * @param paginate whether to paginate or not - * @param limit page size - * @param bookmark pagination cursor - * @param sort sort column - * @param sortOrder sort order - * @param sortType sort type (text or numeric) + * @param opts the search options */ - fetch: async ({ - viewId, - query, - paginate, - limit, - bookmark, - sort, - sortOrder, - sortType, - }) => { + fetch: async (viewId, opts) => { return await API.post({ url: `/api/v2/views/${encodeURIComponent(viewId)}/search`, - body: { - query, - paginate, - limit, - bookmark, - sort, - sortOrder, - sortType, - }, + body: opts, }) }, + /** * Delete a view * @param viewId the id of the view diff --git a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.js b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.js index 4df707d1c8..b9f4851a60 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.js +++ b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.js @@ -28,8 +28,7 @@ export const createActions = context => { } const getRow = async id => { - const res = await API.viewV2.fetch({ - viewId: get(datasource).id, + const res = await API.viewV2.fetch(get(datasource).id, { limit: 1, query: { equal: { diff --git a/packages/frontend-core/src/fetch/ViewV2Fetch.js b/packages/frontend-core/src/fetch/ViewV2Fetch.js index 6bfef0927f..8436646077 100644 --- a/packages/frontend-core/src/fetch/ViewV2Fetch.js +++ b/packages/frontend-core/src/fetch/ViewV2Fetch.js @@ -62,8 +62,7 @@ export default class ViewV2Fetch extends DataFetch { } try { - const res = await this.API.viewV2.fetch({ - viewId: datasource.id, + const res = await this.API.viewV2.fetch(datasource.id, { ...(query ? { query } : {}), paginate, limit,