Enable pagination on views
This commit is contained in:
parent
f6bbfe5e4e
commit
4db33b9d75
|
@ -22,9 +22,33 @@ export const buildViewV2Endpoints = API => ({
|
||||||
/**
|
/**
|
||||||
* 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 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 viewId => {
|
fetch: async ({
|
||||||
return await API.post({ url: `/api/v2/views/${viewId}/search` })
|
viewId,
|
||||||
|
paginate,
|
||||||
|
limit,
|
||||||
|
bookmark,
|
||||||
|
sort,
|
||||||
|
sortOrder,
|
||||||
|
sortType,
|
||||||
|
}) => {
|
||||||
|
return await API.post({
|
||||||
|
url: `/api/v2/views/${viewId}/search`,
|
||||||
|
body: {
|
||||||
|
paginate,
|
||||||
|
limit,
|
||||||
|
bookmark,
|
||||||
|
sort,
|
||||||
|
sortOrder,
|
||||||
|
sortType,
|
||||||
|
},
|
||||||
|
})
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Delete a view
|
* Delete a view
|
||||||
|
|
|
@ -116,7 +116,7 @@ export default class DataFetch {
|
||||||
async getInitialData() {
|
async getInitialData() {
|
||||||
const { datasource, filter, paginate } = this.options
|
const { datasource, filter, paginate } = this.options
|
||||||
|
|
||||||
// Fetch datasource definition and extract filter and sort if configured
|
// Fetch datasource definition and extract sort properties if configured
|
||||||
const definition = await this.getDefinition(datasource)
|
const definition = await this.getDefinition(datasource)
|
||||||
if (definition?.sort?.field) {
|
if (definition?.sort?.field) {
|
||||||
this.options.sortColumn = definition.sort.field
|
this.options.sortColumn = definition.sort.field
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
import DataFetch from "./DataFetch.js"
|
import DataFetch from "./DataFetch.js"
|
||||||
|
import { get } from "svelte/store"
|
||||||
|
|
||||||
export default class ViewV2Fetch extends DataFetch {
|
export default class ViewV2Fetch extends DataFetch {
|
||||||
determineFeatureFlags() {
|
determineFeatureFlags() {
|
||||||
return {
|
return {
|
||||||
|
// The API does not actually support dynamic filtering, but since views
|
||||||
|
// have filters built in we don't want to perform client side filtering
|
||||||
|
// which would happen if we marked this as false
|
||||||
supportsSearch: true,
|
supportsSearch: true,
|
||||||
supportsSort: true,
|
supportsSort: true,
|
||||||
supportsPagination: true,
|
supportsPagination: true,
|
||||||
|
@ -29,12 +33,30 @@ export default class ViewV2Fetch extends DataFetch {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getData() {
|
async getData() {
|
||||||
const { datasource } = this.options
|
const { datasource, limit, sortColumn, sortOrder, sortType, paginate } =
|
||||||
|
this.options
|
||||||
|
const { cursor } = get(this.store)
|
||||||
try {
|
try {
|
||||||
const res = await this.API.viewV2.fetch(datasource.id)
|
const res = await this.API.viewV2.fetch({
|
||||||
return { rows: res?.rows || [] }
|
viewId: datasource.id,
|
||||||
|
paginate,
|
||||||
|
limit,
|
||||||
|
bookmark: cursor,
|
||||||
|
sort: sortColumn,
|
||||||
|
sortOrder,
|
||||||
|
sortType,
|
||||||
|
})
|
||||||
|
return {
|
||||||
|
rows: res?.rows || [],
|
||||||
|
hasNextPage: res?.hasNextPage || false,
|
||||||
|
cursor: res?.bookmark || null,
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return { rows: [] }
|
return {
|
||||||
|
rows: [],
|
||||||
|
hasNextPage: false,
|
||||||
|
error,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue