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 { TemplateEndpoints } from "./templates"
|
||||||
import { UserEndpoints } from "./user"
|
import { UserEndpoints } from "./user"
|
||||||
import { ViewEndpoints } from "./views"
|
import { ViewEndpoints } from "./views"
|
||||||
|
import { ViewV2Endpoints } from "./viewsV2"
|
||||||
|
|
||||||
export enum HTTPMethod {
|
export enum HTTPMethod {
|
||||||
POST = "POST",
|
POST = "POST",
|
||||||
|
@ -132,4 +133,4 @@ export type APIClient = BaseAPIClient &
|
||||||
TableEndpoints &
|
TableEndpoints &
|
||||||
TemplateEndpoints &
|
TemplateEndpoints &
|
||||||
UserEndpoints &
|
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
|
* Fetches the definition of a view
|
||||||
* @param viewId the ID of the view to fetch
|
* @param viewId the ID of the view to fetch
|
||||||
|
@ -9,6 +30,7 @@ export const buildViewV2Endpoints = API => ({
|
||||||
cache: true,
|
cache: true,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new view
|
* Create a new view
|
||||||
* @param view the view object
|
* @param view the view object
|
||||||
|
@ -19,6 +41,7 @@ export const buildViewV2Endpoints = API => ({
|
||||||
body: view,
|
body: view,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates a view
|
* Updates a view
|
||||||
* @param view the view object
|
* @param view the view object
|
||||||
|
@ -29,40 +52,19 @@ export const buildViewV2Endpoints = API => ({
|
||||||
body: view,
|
body: view,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches all rows in a view
|
* Fetches all rows in a view
|
||||||
* @param viewId the id of the view
|
* @param viewId the id of the view
|
||||||
* @param query the search query
|
* @param opts the search options
|
||||||
* @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)
|
|
||||||
*/
|
*/
|
||||||
fetch: async ({
|
fetch: async (viewId, opts) => {
|
||||||
viewId,
|
|
||||||
query,
|
|
||||||
paginate,
|
|
||||||
limit,
|
|
||||||
bookmark,
|
|
||||||
sort,
|
|
||||||
sortOrder,
|
|
||||||
sortType,
|
|
||||||
}) => {
|
|
||||||
return await API.post({
|
return await API.post({
|
||||||
url: `/api/v2/views/${encodeURIComponent(viewId)}/search`,
|
url: `/api/v2/views/${encodeURIComponent(viewId)}/search`,
|
||||||
body: {
|
body: opts,
|
||||||
query,
|
|
||||||
paginate,
|
|
||||||
limit,
|
|
||||||
bookmark,
|
|
||||||
sort,
|
|
||||||
sortOrder,
|
|
||||||
sortType,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a view
|
* Delete a view
|
||||||
* @param viewId the id of the view
|
* @param viewId the id of the view
|
|
@ -28,8 +28,7 @@ export const createActions = context => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const getRow = async id => {
|
const getRow = async id => {
|
||||||
const res = await API.viewV2.fetch({
|
const res = await API.viewV2.fetch(get(datasource).id, {
|
||||||
viewId: get(datasource).id,
|
|
||||||
limit: 1,
|
limit: 1,
|
||||||
query: {
|
query: {
|
||||||
equal: {
|
equal: {
|
||||||
|
|
|
@ -62,8 +62,7 @@ export default class ViewV2Fetch extends DataFetch {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await this.API.viewV2.fetch({
|
const res = await this.API.viewV2.fetch(datasource.id, {
|
||||||
viewId: datasource.id,
|
|
||||||
...(query ? { query } : {}),
|
...(query ? { query } : {}),
|
||||||
paginate,
|
paginate,
|
||||||
limit,
|
limit,
|
||||||
|
|
Loading…
Reference in New Issue