Skip to content

Commit 139fb37

Browse files
prathamesh0IshaVenikar
authored andcommitted
Implement pagination for registry records table (#60)
Part of [Create a public laconicd testnet](https://www.notion.so/Create-a-public-laconicd-testnet-896a11bdd8094eff8f1b49c0be0ca3b8) Handles #59 Requires https://git.vdb.to/cerc-io/registry-sdk/pulls/27 ![image](/attachments/095cf131-19ef-4acc-9ffe-bcbe2f9dad77) ![image](/attachments/684722d3-b9df-44ae-8622-5bacd2dc2a3f) Co-authored-by: IshaVenikar <ishavenikar7@gmail.com> Reviewed-on: https://git.vdb.to/cerc-io/laconic-console/pulls/60 Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com> Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
1 parent 4c22335 commit 139fb37

File tree

4 files changed

+57
-10
lines changed

4 files changed

+57
-10
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cerc-io/console-app",
3-
"version": "0.2.4",
3+
"version": "0.2.5",
44
"description": "Laconic Console",
55
"repository": "https://github.com/cerc-io/laconic-console",
66
"main": "dist/es/index.js",
@@ -31,7 +31,7 @@
3131
"@apollo/react-components": "^4.0.0",
3232
"@apollo/react-hooks": "^4.0.0",
3333
"@babel/runtime": "^7.21.0",
34-
"@cerc-io/registry-sdk": "^0.2.2",
34+
"@cerc-io/registry-sdk": "^0.2.8",
3535
"@lirewine/debug": "1.0.0-beta.78",
3636
"@lirewine/gem-core": "1.0.0-beta.28",
3737
"@lirewine/react-ux": "1.1.0-beta.1",

src/containers/panels/registry/RegistryRecords.js

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
//
44

55
import moment from 'moment';
6-
import React, { useContext } from 'react';
6+
import React, { useContext, useState } from 'react';
77
import { useQuery } from '@apollo/react-hooks';
88
import { makeStyles } from '@material-ui/core';
99
import ButtonGroup from '@material-ui/core/ButtonGroup';
1010
import Button from '@material-ui/core/Button';
1111
import TableHead from '@material-ui/core/TableHead';
1212
import TableRow from '@material-ui/core/TableRow';
1313
import TableBody from '@material-ui/core/TableBody';
14+
import TableFooter from '@material-ui/core/TableFooter';
15+
import TablePagination from '@material-ui/core/TablePagination';
1416

1517
import WNS_RECORDS from '../../../gql/wns_records.graphql';
1618

@@ -68,9 +70,14 @@ export const RecordType = ({ type = types[0].key, onChange }) => {
6870
const RegistryRecords = ({ type }) => {
6971
const { config } = useContext(ConsoleContext);
7072
const [sorter, sortBy] = useSorter('createTime', false);
71-
const { data } = useQueryStatusReducer(useQuery(WNS_RECORDS, {
73+
const [page, setPage] = useState(0);
74+
const [rowsPerPage, setRowsPerPage] = useState(10);
75+
76+
const offset = page * rowsPerPage;
77+
78+
const { data, refetch } = useQueryStatusReducer(useQuery(WNS_RECORDS, {
7279
pollInterval: config.api.intervalQuery,
73-
variables: { attributes: { type } }
80+
variables: { attributes: { type, limit: rowsPerPage, offset: offset } }
7481
}));
7582

7683
if (!data) {
@@ -79,6 +86,27 @@ const RegistryRecords = ({ type }) => {
7986

8087
const records = JSON.parse(data.wns_records.json);
8188

89+
const handleChangePage = (event, newPage) => {
90+
setPage(newPage);
91+
const offset = newPage * rowsPerPage;
92+
refetch({ attributes: { type, limit: rowsPerPage, offset } });
93+
};
94+
95+
const handleChangeRowsPerPage = (event) => {
96+
const newRowsPerPage = parseInt(event.target.value, 10);
97+
setRowsPerPage(newRowsPerPage);
98+
setPage(0);
99+
refetch({ attributes: { type, limit: newRowsPerPage, offset: 0 } });
100+
};
101+
102+
const labelDisplayedRows = ({ from, to }) => {
103+
if (rowsPerPage > records.length) {
104+
return `${from}-${from + records.length - 1}`;
105+
} else {
106+
return `${from}-${to}`;
107+
}
108+
};
109+
82110
return (
83111
<Table>
84112
<TableHead>
@@ -142,6 +170,23 @@ const RegistryRecords = ({ type }) => {
142170
}
143171
)}
144172
</TableBody>
173+
<TableFooter>
174+
<TableRow>
175+
<TablePagination
176+
component="td"
177+
rowsPerPageOptions={[5, 10, 25]}
178+
count={-1}
179+
rowsPerPage={rowsPerPage}
180+
page={page}
181+
onPageChange={handleChangePage}
182+
onRowsPerPageChange={handleChangeRowsPerPage}
183+
labelDisplayedRows={labelDisplayedRows}
184+
nextIconButtonProps={{
185+
disabled: records.length < rowsPerPage,
186+
}}
187+
/>
188+
</TableRow>
189+
</TableFooter>
145190
</Table>
146191
);
147192
};

src/resolvers.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ export const createResolvers = config => {
4545

4646
wns_records: async (_, { attributes }) => {
4747
log('WNS records...');
48-
const data = await registry.queryRecords(attributes);
48+
49+
const {limit, offset, ...queryAttributes } = attributes;
50+
const data = await registry.queryRecords(queryAttributes, false, false, limit, offset);
4951

5052
return {
5153
__typename: 'JSONResult',

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,10 +1037,10 @@
10371037
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
10381038
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
10391039

1040-
"@cerc-io/registry-sdk@^0.2.2":
1041-
version "0.2.2"
1042-
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fregistry-sdk/-/0.2.2/registry-sdk-0.2.2.tgz#2e8a533f069b4bb9f4cd4798e783f52e29167d0d"
1043-
integrity sha512-ocRMbWtdewOg02ORfK1U+qbTqB46anHP4ApXokGkY4d+mFSApR3sdUEi2geHcs8oh+SG8YAp7LUJ9AAJneNY8g==
1040+
"@cerc-io/registry-sdk@^0.2.8":
1041+
version "0.2.8"
1042+
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fregistry-sdk/-/0.2.8/registry-sdk-0.2.8.tgz#d71837f735d998987055068457fdf8b2e94ca69c"
1043+
integrity sha512-utK3Rq5qZrEoRs/eOsOkowcsD740nlnBs6C3KKFRHgKIiR0XedD6t33KukUPLKbGp4mYZOYXRTA7/A04x58lKw==
10441044
dependencies:
10451045
"@cosmjs/amino" "^0.28.1"
10461046
"@cosmjs/crypto" "^0.28.1"

0 commit comments

Comments
 (0)