Update grids to support pagination with REST queries and to simplify some logic
This commit is contained in:
parent
230dc169fa
commit
23cdac5906
|
@ -160,11 +160,6 @@ export const createActions = context => {
|
|||
return getAPI()?.actions.canUseColumn(name)
|
||||
}
|
||||
|
||||
// Gets the default number of rows for a single page
|
||||
const getFeatures = () => {
|
||||
return getAPI()?.actions.getFeatures()
|
||||
}
|
||||
|
||||
return {
|
||||
datasource: {
|
||||
...datasource,
|
||||
|
@ -177,7 +172,6 @@ export const createActions = context => {
|
|||
getRow,
|
||||
isDatasourceValid,
|
||||
canUseColumn,
|
||||
getFeatures,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -35,11 +35,6 @@ export const createActions = context => {
|
|||
return $columns.some(col => col.name === name) || $sticky?.name === name
|
||||
}
|
||||
|
||||
const getFeatures = () => {
|
||||
// We don't support any features
|
||||
return {}
|
||||
}
|
||||
|
||||
return {
|
||||
nonPlus: {
|
||||
actions: {
|
||||
|
@ -50,7 +45,6 @@ export const createActions = context => {
|
|||
getRow,
|
||||
isDatasourceValid,
|
||||
canUseColumn,
|
||||
getFeatures,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { get } from "svelte/store"
|
||||
import TableFetch from "../../../../fetch/TableFetch"
|
||||
|
||||
const SuppressErrors = true
|
||||
|
||||
|
@ -46,10 +45,6 @@ export const createActions = context => {
|
|||
return $columns.some(col => col.name === name) || $sticky?.name === name
|
||||
}
|
||||
|
||||
const getFeatures = () => {
|
||||
return new TableFetch({ API }).determineFeatureFlags()
|
||||
}
|
||||
|
||||
return {
|
||||
table: {
|
||||
actions: {
|
||||
|
@ -60,7 +55,6 @@ export const createActions = context => {
|
|||
getRow,
|
||||
isDatasourceValid,
|
||||
canUseColumn,
|
||||
getFeatures,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { get } from "svelte/store"
|
||||
import ViewV2Fetch from "../../../../fetch/ViewV2Fetch"
|
||||
|
||||
const SuppressErrors = true
|
||||
|
||||
|
@ -46,10 +45,6 @@ export const createActions = context => {
|
|||
)
|
||||
}
|
||||
|
||||
const getFeatures = () => {
|
||||
return new ViewV2Fetch({ API }).determineFeatureFlags()
|
||||
}
|
||||
|
||||
return {
|
||||
viewV2: {
|
||||
actions: {
|
||||
|
@ -60,7 +55,6 @@ export const createActions = context => {
|
|||
getRow,
|
||||
isDatasourceValid,
|
||||
canUseColumn,
|
||||
getFeatures,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -114,10 +114,6 @@ export const createActions = context => {
|
|||
const $allFilters = get(allFilters)
|
||||
const $sort = get(sort)
|
||||
|
||||
// Determine how many rows to fetch per page
|
||||
const features = datasource.actions.getFeatures()
|
||||
const limit = features?.supportsPagination ? RowPageSize : null
|
||||
|
||||
// Create new fetch model
|
||||
const newFetch = fetchData({
|
||||
API,
|
||||
|
@ -126,8 +122,12 @@ export const createActions = context => {
|
|||
filter: $allFilters,
|
||||
sortColumn: $sort.column,
|
||||
sortOrder: $sort.order,
|
||||
limit,
|
||||
limit: RowPageSize,
|
||||
paginate: true,
|
||||
|
||||
// Disable client side limiting, so that for queries and custom data
|
||||
// sources we don't impose fake row limits. We want all the data.
|
||||
clientSideLimiting: false,
|
||||
},
|
||||
})
|
||||
|
||||
|
|
|
@ -43,6 +43,11 @@ export default class DataFetch {
|
|||
|
||||
// Pagination config
|
||||
paginate: true,
|
||||
|
||||
// Client side feature customisation
|
||||
clientSideSearching: true,
|
||||
clientSideSorting: true,
|
||||
clientSideLimiting: true,
|
||||
}
|
||||
|
||||
// State of the fetch
|
||||
|
@ -208,24 +213,32 @@ export default class DataFetch {
|
|||
* Fetches some filtered, sorted and paginated data
|
||||
*/
|
||||
async getPage() {
|
||||
const { sortColumn, sortOrder, sortType, limit } = this.options
|
||||
const {
|
||||
sortColumn,
|
||||
sortOrder,
|
||||
sortType,
|
||||
limit,
|
||||
clientSideSearching,
|
||||
clientSideSorting,
|
||||
clientSideLimiting,
|
||||
} = this.options
|
||||
const { query } = get(this.store)
|
||||
|
||||
// Get the actual data
|
||||
let { rows, info, hasNextPage, cursor, error } = await this.getData()
|
||||
|
||||
// If we don't support searching, do a client search
|
||||
if (!this.features.supportsSearch) {
|
||||
if (!this.features.supportsSearch && clientSideSearching) {
|
||||
rows = runLuceneQuery(rows, query)
|
||||
}
|
||||
|
||||
// If we don't support sorting, do a client-side sort
|
||||
if (!this.features.supportsSort) {
|
||||
if (!this.features.supportsSort && clientSideSorting) {
|
||||
rows = luceneSort(rows, sortColumn, sortOrder, sortType)
|
||||
}
|
||||
|
||||
// If we don't support pagination, do a client-side limit
|
||||
if (!this.features.supportsPagination) {
|
||||
if (!this.features.supportsPagination && clientSideLimiting) {
|
||||
rows = luceneLimit(rows, limit)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue