Pass page limit and offset for fetching records
This commit is contained in:
parent
1edff74f48
commit
e81ad6009c
@ -72,9 +72,12 @@ const RegistryRecords = ({ type }) => {
|
|||||||
const [sorter, sortBy] = useSorter('createTime', false);
|
const [sorter, sortBy] = useSorter('createTime', false);
|
||||||
const [page, setPage] = useState(0);
|
const [page, setPage] = useState(0);
|
||||||
const [rowsPerPage, setRowsPerPage] = useState(5);
|
const [rowsPerPage, setRowsPerPage] = useState(5);
|
||||||
const { data } = useQueryStatusReducer(useQuery(WNS_RECORDS, {
|
|
||||||
|
const offset = page * rowsPerPage;
|
||||||
|
|
||||||
|
const { data, refetch } = useQueryStatusReducer(useQuery(WNS_RECORDS, {
|
||||||
pollInterval: config.api.intervalQuery,
|
pollInterval: config.api.intervalQuery,
|
||||||
variables: { attributes: { type } }
|
variables: { attributes: { type, limit: rowsPerPage, offset: offset } }
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
@ -85,14 +88,24 @@ const RegistryRecords = ({ type }) => {
|
|||||||
|
|
||||||
const handleChangePage = (event, newPage) => {
|
const handleChangePage = (event, newPage) => {
|
||||||
setPage(newPage);
|
setPage(newPage);
|
||||||
|
const offset = newPage * rowsPerPage;
|
||||||
|
refetch({ attributes: { type, limit: rowsPerPage, offset } });
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleChangeRowsPerPage = (event) => {
|
const handleChangeRowsPerPage = (event) => {
|
||||||
setRowsPerPage(parseInt(event.target.value, 10));
|
const newRowsPerPage = parseInt(event.target.value, 10);
|
||||||
|
setRowsPerPage(newRowsPerPage);
|
||||||
setPage(0);
|
setPage(0);
|
||||||
|
refetch({ attributes: { type, limit: newRowsPerPage, offset: 0 } });
|
||||||
};
|
};
|
||||||
|
|
||||||
const paginatedRecords = records.sort(sorter).slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage);
|
const labelDisplayedRows = ({ from, to }) => {
|
||||||
|
if(to > from) {
|
||||||
|
return `${from}-${to}`;
|
||||||
|
} else {
|
||||||
|
return `${from}-${from + records.length - 1}`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Table>
|
<Table>
|
||||||
@ -108,63 +121,66 @@ const RegistryRecords = ({ type }) => {
|
|||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{paginatedRecords.map((record) => {
|
{records.sort(sorter)
|
||||||
const { id, names, createTime, attributes: { type, name: displayName, fileName, version, description, service, package: pkg } } = record;
|
.map((record) => {
|
||||||
|
const { id, names, createTime, attributes: { type, name: displayName, fileName, version, description, service, package: pkg } } = record;
|
||||||
|
|
||||||
let pkgLink;
|
let pkgLink;
|
||||||
let appLinks;
|
let appLinks;
|
||||||
|
|
||||||
if (pkg) {
|
if (pkg) {
|
||||||
pkgLink = (<PackageLink config={config} type={type} pkg={pkg} />);
|
pkgLink = (<PackageLink config={config} type={type} pkg={pkg} />);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'lrn:app') {
|
if (type === 'lrn:app') {
|
||||||
appLinks = (
|
appLinks = (
|
||||||
<>
|
<>
|
||||||
{(names || []).map(lrn =>
|
{(names || []).map(lrn =>
|
||||||
<div key={lrn}>
|
<div key={lrn}>
|
||||||
<AppLink config={config} lrn={lrn} />
|
<AppLink config={config} lrn={lrn} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TableRow key={id} size='small'>
|
||||||
|
<TableCell monospace>{type}</TableCell>
|
||||||
|
<TableCell monospace>
|
||||||
|
{appLinks || (names || []).map(name => <div key={name}>{name}</div>)}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell monospace>
|
||||||
|
{version}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
{displayName || service || fileName || description}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
{moment.utc(createTime).fromNow()}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell monospace>
|
||||||
|
{pkgLink}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<QueryLink config={config} id={id} icon />
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
)}
|
||||||
return (
|
|
||||||
<TableRow key={id} size='small'>
|
|
||||||
<TableCell monospace>{type}</TableCell>
|
|
||||||
<TableCell monospace>
|
|
||||||
{appLinks || (names || []).map(name => <div key={name}>{name}</div>)}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell monospace>
|
|
||||||
{version}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>
|
|
||||||
{displayName || service || fileName || description}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>
|
|
||||||
{moment.utc(createTime).fromNow()}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell monospace>
|
|
||||||
{pkgLink}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>
|
|
||||||
<QueryLink config={config} id={id} icon />
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</TableBody>
|
</TableBody>
|
||||||
<TableFooter>
|
<TableFooter>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TablePagination
|
<TablePagination
|
||||||
component="td"
|
component="td"
|
||||||
rowsPerPageOptions={[5, 10, 25]}
|
rowsPerPageOptions={[5, 10, 25]}
|
||||||
count={records.length}
|
count={records.length >= rowsPerPage ? -1 : rowsPerPage}
|
||||||
rowsPerPage={rowsPerPage}
|
rowsPerPage={rowsPerPage}
|
||||||
page={page}
|
page={page}
|
||||||
onPageChange={handleChangePage}
|
onPageChange={handleChangePage}
|
||||||
onRowsPerPageChange={handleChangeRowsPerPage}
|
onRowsPerPageChange={handleChangeRowsPerPage}
|
||||||
|
labelDisplayedRows={labelDisplayedRows}
|
||||||
/>
|
/>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableFooter>
|
</TableFooter>
|
||||||
|
@ -45,7 +45,9 @@ export const createResolvers = config => {
|
|||||||
|
|
||||||
wns_records: async (_, { attributes }) => {
|
wns_records: async (_, { attributes }) => {
|
||||||
log('WNS records...');
|
log('WNS records...');
|
||||||
const data = await registry.queryRecords(attributes);
|
|
||||||
|
const {limit, offset, ...queryAttributes } = attributes;
|
||||||
|
const data = await registry.queryRecords(queryAttributes, false, false, limit, offset);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
__typename: 'JSONResult',
|
__typename: 'JSONResult',
|
||||||
|
Loading…
Reference in New Issue
Block a user