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)
|
return getAPI()?.actions.canUseColumn(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the default number of rows for a single page
|
|
||||||
const getFeatures = () => {
|
|
||||||
return getAPI()?.actions.getFeatures()
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
datasource: {
|
datasource: {
|
||||||
...datasource,
|
...datasource,
|
||||||
|
@ -177,7 +172,6 @@ export const createActions = context => {
|
||||||
getRow,
|
getRow,
|
||||||
isDatasourceValid,
|
isDatasourceValid,
|
||||||
canUseColumn,
|
canUseColumn,
|
||||||
getFeatures,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,11 +35,6 @@ export const createActions = context => {
|
||||||
return $columns.some(col => col.name === name) || $sticky?.name === name
|
return $columns.some(col => col.name === name) || $sticky?.name === name
|
||||||
}
|
}
|
||||||
|
|
||||||
const getFeatures = () => {
|
|
||||||
// We don't support any features
|
|
||||||
return {}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
nonPlus: {
|
nonPlus: {
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -50,7 +45,6 @@ export const createActions = context => {
|
||||||
getRow,
|
getRow,
|
||||||
isDatasourceValid,
|
isDatasourceValid,
|
||||||
canUseColumn,
|
canUseColumn,
|
||||||
getFeatures,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { get } from "svelte/store"
|
import { get } from "svelte/store"
|
||||||
import TableFetch from "../../../../fetch/TableFetch"
|
|
||||||
|
|
||||||
const SuppressErrors = true
|
const SuppressErrors = true
|
||||||
|
|
||||||
|
@ -46,10 +45,6 @@ export const createActions = context => {
|
||||||
return $columns.some(col => col.name === name) || $sticky?.name === name
|
return $columns.some(col => col.name === name) || $sticky?.name === name
|
||||||
}
|
}
|
||||||
|
|
||||||
const getFeatures = () => {
|
|
||||||
return new TableFetch({ API }).determineFeatureFlags()
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
table: {
|
table: {
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -60,7 +55,6 @@ export const createActions = context => {
|
||||||
getRow,
|
getRow,
|
||||||
isDatasourceValid,
|
isDatasourceValid,
|
||||||
canUseColumn,
|
canUseColumn,
|
||||||
getFeatures,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { get } from "svelte/store"
|
import { get } from "svelte/store"
|
||||||
import ViewV2Fetch from "../../../../fetch/ViewV2Fetch"
|
|
||||||
|
|
||||||
const SuppressErrors = true
|
const SuppressErrors = true
|
||||||
|
|
||||||
|
@ -46,10 +45,6 @@ export const createActions = context => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const getFeatures = () => {
|
|
||||||
return new ViewV2Fetch({ API }).determineFeatureFlags()
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
viewV2: {
|
viewV2: {
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -60,7 +55,6 @@ export const createActions = context => {
|
||||||
getRow,
|
getRow,
|
||||||
isDatasourceValid,
|
isDatasourceValid,
|
||||||
canUseColumn,
|
canUseColumn,
|
||||||
getFeatures,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,10 +114,6 @@ export const createActions = context => {
|
||||||
const $allFilters = get(allFilters)
|
const $allFilters = get(allFilters)
|
||||||
const $sort = get(sort)
|
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
|
// Create new fetch model
|
||||||
const newFetch = fetchData({
|
const newFetch = fetchData({
|
||||||
API,
|
API,
|
||||||
|
@ -126,8 +122,12 @@ export const createActions = context => {
|
||||||
filter: $allFilters,
|
filter: $allFilters,
|
||||||
sortColumn: $sort.column,
|
sortColumn: $sort.column,
|
||||||
sortOrder: $sort.order,
|
sortOrder: $sort.order,
|
||||||
limit,
|
limit: RowPageSize,
|
||||||
paginate: true,
|
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
|
// Pagination config
|
||||||
paginate: true,
|
paginate: true,
|
||||||
|
|
||||||
|
// Client side feature customisation
|
||||||
|
clientSideSearching: true,
|
||||||
|
clientSideSorting: true,
|
||||||
|
clientSideLimiting: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
// State of the fetch
|
// State of the fetch
|
||||||
|
@ -208,24 +213,32 @@ export default class DataFetch {
|
||||||
* Fetches some filtered, sorted and paginated data
|
* Fetches some filtered, sorted and paginated data
|
||||||
*/
|
*/
|
||||||
async getPage() {
|
async getPage() {
|
||||||
const { sortColumn, sortOrder, sortType, limit } = this.options
|
const {
|
||||||
|
sortColumn,
|
||||||
|
sortOrder,
|
||||||
|
sortType,
|
||||||
|
limit,
|
||||||
|
clientSideSearching,
|
||||||
|
clientSideSorting,
|
||||||
|
clientSideLimiting,
|
||||||
|
} = this.options
|
||||||
const { query } = get(this.store)
|
const { query } = get(this.store)
|
||||||
|
|
||||||
// Get the actual data
|
// Get the actual data
|
||||||
let { rows, info, hasNextPage, cursor, error } = await this.getData()
|
let { rows, info, hasNextPage, cursor, error } = await this.getData()
|
||||||
|
|
||||||
// If we don't support searching, do a client search
|
// If we don't support searching, do a client search
|
||||||
if (!this.features.supportsSearch) {
|
if (!this.features.supportsSearch && clientSideSearching) {
|
||||||
rows = runLuceneQuery(rows, query)
|
rows = runLuceneQuery(rows, query)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we don't support sorting, do a client-side sort
|
// 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)
|
rows = luceneSort(rows, sortColumn, sortOrder, sortType)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we don't support pagination, do a client-side limit
|
// If we don't support pagination, do a client-side limit
|
||||||
if (!this.features.supportsPagination) {
|
if (!this.features.supportsPagination && clientSideLimiting) {
|
||||||
rows = luceneLimit(rows, limit)
|
rows = luceneLimit(rows, limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue