Type view V2 endpoints
This commit is contained in:
parent
1b467f2e74
commit
50fd530c4c
|
@ -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 }
|
||||
|
|
|
@ -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<ViewResponseEnriched>
|
||||
create: (view: CreateViewRequest) => Promise<ViewResponse>
|
||||
update: (view: UpdateViewRequest) => Promise<ViewResponse>
|
||||
fetch: (
|
||||
viewId: string,
|
||||
opts: SearchViewRowRequest
|
||||
) => Promise<SearchRowResponse>
|
||||
delete: (viewId: string) => Promise<void>
|
||||
}
|
||||
|
||||
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
|
|
@ -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: {
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue