|
|
@ -13,9 +13,10 @@ import { fetchTableDefinition } from "api" |
|
|
* For other types of datasource, this class is overridden and extended. |
|
|
* For other types of datasource, this class is overridden and extended. |
|
|
*/ |
|
|
*/ |
|
|
export default class TableFetch { |
|
|
export default class TableFetch { |
|
|
SupportsSearch = false |
|
|
// Feature flags
|
|
|
SupportsSort = false |
|
|
supportsSearch = false |
|
|
SupportsPagination = false |
|
|
supportsSort = false |
|
|
|
|
|
supportsPagination = false |
|
|
|
|
|
|
|
|
// Config
|
|
|
// Config
|
|
|
options = { |
|
|
options = { |
|
|
@ -51,13 +52,20 @@ export default class TableFetch { |
|
|
/** |
|
|
/** |
|
|
* Constructs a new DataFetch instance. |
|
|
* Constructs a new DataFetch instance. |
|
|
* @param opts the fetch options |
|
|
* @param opts the fetch options |
|
|
|
|
|
* @param flags the datasource feature flags |
|
|
*/ |
|
|
*/ |
|
|
constructor(opts) { |
|
|
constructor(opts, flags) { |
|
|
|
|
|
// Merge options with their default values
|
|
|
this.options = { |
|
|
this.options = { |
|
|
...this.options, |
|
|
...this.options, |
|
|
...opts, |
|
|
...opts, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Update feature flags
|
|
|
|
|
|
this.supportsSearch = flags?.supportsSearch || false |
|
|
|
|
|
this.supportsSort = flags?.supportsSort || false |
|
|
|
|
|
this.supportsPagination = flags?.supportsPagination || false |
|
|
|
|
|
|
|
|
// Bind all functions to properly scope "this"
|
|
|
// Bind all functions to properly scope "this"
|
|
|
this.getData = this.getData.bind(this) |
|
|
this.getData = this.getData.bind(this) |
|
|
this.getInitialData = this.getInitialData.bind(this) |
|
|
this.getInitialData = this.getInitialData.bind(this) |
|
|
@ -158,17 +166,17 @@ export default class TableFetch { |
|
|
let { rows, hasNextPage, cursor } = await this.getData() |
|
|
let { rows, hasNextPage, cursor } = 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.SupportsSearch) { |
|
|
if (!this.supportsSearch) { |
|
|
rows = luceneQuery(rows, query) |
|
|
rows = luceneQuery(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.SupportsSort) { |
|
|
if (!this.supportsSort) { |
|
|
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.SupportsPagination) { |
|
|
if (!this.supportsPagination) { |
|
|
rows = luceneLimit(rows, limit) |
|
|
rows = luceneLimit(rows, limit) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|