Type views
This commit is contained in:
parent
65fa3e0434
commit
1f51489368
|
@ -1,6 +1,7 @@
|
|||
import {
|
||||
CreateViewRequest,
|
||||
CreateViewResponse,
|
||||
PaginatedSearchRowResponse,
|
||||
SearchRowResponse,
|
||||
SearchViewRowRequest,
|
||||
UpdateViewRequest,
|
||||
|
@ -13,10 +14,14 @@ export interface ViewV2Endpoints {
|
|||
fetchDefinition: (viewId: string) => Promise<ViewResponseEnriched>
|
||||
create: (view: CreateViewRequest) => Promise<CreateViewResponse>
|
||||
update: (view: UpdateViewRequest) => Promise<UpdateViewResponse>
|
||||
fetch: (
|
||||
fetch: <T extends SearchViewRowRequest>(
|
||||
viewId: string,
|
||||
opts: SearchViewRowRequest
|
||||
) => Promise<SearchRowResponse>
|
||||
opts: T
|
||||
) => Promise<
|
||||
T extends { paginate: true }
|
||||
? PaginatedSearchRowResponse
|
||||
: SearchRowResponse
|
||||
>
|
||||
delete: (viewId: string) => Promise<void>
|
||||
}
|
||||
|
||||
|
@ -59,7 +64,7 @@ export const buildViewV2Endpoints = (API: BaseAPIClient): ViewV2Endpoints => ({
|
|||
* @param viewId the id of the view
|
||||
* @param opts the search options
|
||||
*/
|
||||
fetch: async (viewId, opts) => {
|
||||
fetch: async (viewId, opts: SearchViewRowRequest) => {
|
||||
return await API.post({
|
||||
url: `/api/v2/views/${encodeURIComponent(viewId)}/search`,
|
||||
body: opts,
|
||||
|
|
|
@ -68,7 +68,7 @@ export default class ViewV2Fetch extends DataFetch<UIView, ViewV2> {
|
|||
}
|
||||
|
||||
try {
|
||||
const res = await this.API.viewV2.fetch(datasource.id, {
|
||||
const request = {
|
||||
...(query ? { query } : {}),
|
||||
paginate,
|
||||
limit,
|
||||
|
@ -76,11 +76,27 @@ export default class ViewV2Fetch extends DataFetch<UIView, ViewV2> {
|
|||
sort: sortColumn,
|
||||
sortOrder: sortOrder,
|
||||
sortType,
|
||||
})
|
||||
return {
|
||||
rows: res?.rows || [],
|
||||
hasNextPage: res?.hasNextPage || false,
|
||||
cursor: res?.bookmark || null,
|
||||
}
|
||||
if (paginate) {
|
||||
const res = await this.API.viewV2.fetch(datasource.id, {
|
||||
...request,
|
||||
paginate,
|
||||
})
|
||||
return {
|
||||
rows: res?.rows || [],
|
||||
hasNextPage: res?.hasNextPage || false,
|
||||
cursor: res?.bookmark || null,
|
||||
}
|
||||
} else {
|
||||
const res = await this.API.viewV2.fetch(datasource.id, {
|
||||
...request,
|
||||
paginate,
|
||||
})
|
||||
return {
|
||||
rows: res?.rows || [],
|
||||
hasNextPage: false,
|
||||
cursor: null,
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
import {
|
||||
UserCtx,
|
||||
ViewV2,
|
||||
SearchRowResponse,
|
||||
SearchViewRowRequest,
|
||||
RequiredKeys,
|
||||
RowSearchParams,
|
||||
PaginatedSearchRowResponse,
|
||||
} from "@budibase/types"
|
||||
import sdk from "../../../sdk"
|
||||
import { context } from "@budibase/backend-core"
|
||||
|
||||
export async function searchView(
|
||||
ctx: UserCtx<SearchViewRowRequest, SearchRowResponse>
|
||||
ctx: UserCtx<SearchViewRowRequest, PaginatedSearchRowResponse>
|
||||
) {
|
||||
const { viewId } = ctx.params
|
||||
|
||||
|
@ -49,7 +49,12 @@ export async function searchView(
|
|||
user: sdk.users.getUserContextBindings(ctx.user),
|
||||
})
|
||||
result.rows.forEach(r => (r._viewId = view.id))
|
||||
ctx.body = result
|
||||
|
||||
ctx.body = {
|
||||
rows: result.rows,
|
||||
bookmark: result.bookmark,
|
||||
hasNextPage: result.hasNextPage,
|
||||
}
|
||||
}
|
||||
|
||||
function getSortOptions(request: SearchViewRowRequest, view: ViewV2) {
|
||||
|
|
Loading…
Reference in New Issue