Skip to content

Commit 546bfc9

Browse files
authored
Paginate the table row data (#100)
To prevent excessive network calls, this commit caches the retrieved table rows into a `Map` of pages. It will fetch the total cache factor, which is the amount of pages a user wishes to retrieve per request. The cache is not currently limited to a max size, and is busted with every new query. The user now has 3 options for navigating the table forwards or backwards. 1. next/previous page 2. first/last page 3. direct page number input The page navigation click events are debounced. This prevents having the user wait on the results of fetching new results when they reach a page that is not cached. Closes: #99 Squashed commits: * Display row count information * Start a cache from the initial table row results * Navigate forward if page exists in the cache * Navigate backwards if page exists in the cache * Fetch next set of rows when navigating forward and page not cached * Reset the page number when updating the query * Enable changing pages by inputting a number * Display total number of pages * Add buttons to skip to 1st and last page * Fetch next set of rows when navigating backward and page not cached * Bust the cache when fetching new queries * Debounce successive page navigation click events
1 parent 9abbe33 commit 546bfc9

11 files changed

+552
-64
lines changed

.babelrc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
// This file is only used from the command line for packages that require it
22
// like stylelint. It must be kept in sync with craco's modifications of create-react-app
33
{
4-
"presets": ["react-app"]
4+
"presets": ["react-app"],
5+
"plugins": [
6+
[
7+
"import",
8+
{
9+
"libraryName": "react-use",
10+
"libraryDirectory": "lib",
11+
"camel2DashComponentName": false
12+
}
13+
]
14+
]
515
}

craco.config.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@ const emotionBabelPreset = require('@emotion/babel-preset-css-prop').default(
1414

1515
module.exports = {
1616
babel: {
17-
plugins: [...emotionBabelPreset.plugins],
17+
plugins: [
18+
...emotionBabelPreset.plugins,
19+
[
20+
'import',
21+
{
22+
libraryName: 'react-use',
23+
libraryDirectory: 'lib',
24+
camel2DashComponentName: false,
25+
},
26+
],
27+
],
1828
},
1929
typescript: {
2030
enableTypeChecking: false,

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"nanoid-dictionary": "^3.0.0",
5050
"react": "^16.13.1",
5151
"react-dom": "^16.13.1",
52+
"react-use": "^15.3.2",
5253
"react-window": "^1.8.5",
5354
"recharts": "^1.8.5",
5455
"underscore.string": "^3.3.5",
@@ -73,6 +74,7 @@
7374
"@typescript-eslint/parser": "2.x",
7475
"@xstate/test": "^0.4.0",
7576
"babel-eslint": "10.x",
77+
"babel-plugin-import": "^1.13.0",
7678
"babel-preset-react-app": "^9.1.2",
7779
"concurrently": "^5.2.0",
7880
"cross-env": "^7.0.2",

src/actionConstants.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ export const SET_INITIAL_ORGANISMS = 'pieChart/fetch/initial'
3838
*/
3939
export const CHANGE_MINE = 'supervisor/mine/change'
4040
export const CHANGE_CLASS = 'supervisor/class/change'
41+
42+
/**
43+
* Table
44+
*/
45+
export const CHANGE_PAGE = 'table/page/change'

src/blueprintIcons.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ exports.usedIcons = [
1616
IconNames.ARCHIVE,
1717
IconNames.CHEVRON_BACKWARD,
1818
IconNames.CHEVRON_FORWARD,
19+
IconNames.CHEVRON_LEFT,
20+
IconNames.CHEVRON_RIGHT,
1921
IconNames.WARNING_SIGN,
2022
IconNames.REMOVE,
2123
IconNames.DELETE,

src/components/App.jsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import '@emotion/core'
33

44
import { assign } from '@xstate/immer'
5+
import { enableMapSet } from 'immer'
56
import React, { useEffect } from 'react'
67
import { CHANGE_CLASS, CHANGE_MINE, FETCH_INITIAL_SUMMARY } from 'src/actionConstants'
78
import { fetchClasses, fetchInstances } from 'src/fetchSummary'
@@ -12,6 +13,10 @@ import { ConstraintSection } from './Layout/ConstraintSection'
1213
import { ChartSection, TableSection } from './Layout/DataVizSection'
1314
import { Header } from './Layout/Header'
1415

16+
enableMapSet()
17+
18+
const isProduction = process.env.NODE_ENV === 'production'
19+
1520
const supervisorMachine = Machine(
1621
{
1722
id: 'Supervisor',
@@ -21,8 +26,10 @@ const supervisorMachine = Machine(
2126
intermines: [],
2227
modelClasses: [],
2328
selectedMine: {
24-
rootUrl: 'https://www.humanmine.org/humanmine',
25-
name: 'HumanMine',
29+
name: isProduction ? 'HumanMine' : 'biotestmine',
30+
rootUrl: isProduction
31+
? 'https://www.humanmine.org/humanmine'
32+
: 'http://localhost:9999/biotestmine',
2633
},
2734
},
2835
states: {

src/components/DataViz/DataViz.story.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ PieChart.parameters = {
6565
},
6666
}
6767

68+
// @ts-ignore
6869
const tableMockMachine = TableChartMachine.withContext({
70+
// @ts-ignore
6971
rows: humanMine25,
7072
mineUrl,
7173
})

0 commit comments

Comments
 (0)