Skip to content

Commit 1e1149e

Browse files
prathamesh0IshaVenikar
authored andcommitted
Handle undefined attributes in records resolver (#61)
Part of [Create a public laconicd testnet](https://www.notion.so/Create-a-public-laconicd-testnet-896a11bdd8094eff8f1b49c0be0ca3b8) Handles the error in `LOOKUP` tab in the console: ```bash Error: Cannot destructure property 'limit' of 'attributes' as it is undefined. ``` Co-authored-by: IshaVenikar <ishavenikar7@gmail.com> Reviewed-on: https://git.vdb.to/cerc-io/laconic-console/pulls/61 Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com> Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
1 parent 139fb37 commit 1e1149e

File tree

2 files changed

+73
-81
lines changed

2 files changed

+73
-81
lines changed

src/containers/panels/registry/RegistryRecords.js

Lines changed: 72 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ 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';
1514
import TablePagination from '@material-ui/core/TablePagination';
15+
import { Paper, TableContainer, } from '@material-ui/core';
1616

1717
import WNS_RECORDS from '../../../gql/wns_records.graphql';
1818

@@ -108,86 +108,78 @@ const RegistryRecords = ({ type }) => {
108108
};
109109

110110
return (
111-
<Table>
112-
<TableHead>
113-
<TableRow>
114-
<TableCell onClick={sortBy('attributes.type')} size='medium'>Type</TableCell>
115-
<TableCell onClick={sortBy('names[0]')}>Registered Names</TableCell>
116-
<TableCell onClick={sortBy('attributes.version')} size='small'>Version</TableCell>
117-
<TableCell onClick={sortBy('attributes.name')}>Display Name</TableCell>
118-
<TableCell onClick={sortBy('createTime')} size='small'>Created</TableCell>
119-
<TableCell onClick={sortBy('attributes.package')}>Package</TableCell>
120-
<TableCell size='icon' />
121-
</TableRow>
122-
</TableHead>
123-
<TableBody>
124-
{records.sort(sorter)
125-
.map((record) => {
126-
const { id, names, createTime, attributes: { type, name: displayName, fileName, version, description, service, package: pkg } } = record;
127-
128-
let pkgLink;
129-
let appLinks;
130-
131-
if (pkg) {
132-
pkgLink = (<PackageLink config={config} type={type} pkg={pkg} />);
133-
}
134-
135-
if (type === 'lrn:app') {
136-
appLinks = (
137-
<>
138-
{(names || []).map(lrn =>
139-
<div key={lrn}>
140-
<AppLink config={config} lrn={lrn} />
141-
</div>
142-
)}
143-
</>
111+
<Paper style={{
112+
width: '100%',
113+
}}>
114+
<TableContainer>
115+
<Table>
116+
<TableHead>
117+
<TableRow>
118+
<TableCell onClick={sortBy('attributes.type')} size='medium'>Type</TableCell>
119+
<TableCell onClick={sortBy('names[0]')}>Registered Names</TableCell>
120+
<TableCell onClick={sortBy('attributes.version')} size='small'>Version</TableCell>
121+
<TableCell onClick={sortBy('attributes.name')}>Display Name</TableCell>
122+
<TableCell onClick={sortBy('createTime')} size='small'>Created</TableCell>
123+
<TableCell onClick={sortBy('attributes.package')}>Package</TableCell>
124+
<TableCell size='icon' />
125+
</TableRow>
126+
</TableHead>
127+
<TableBody>
128+
{records.sort(sorter).map((record) => {
129+
const { id, names, createTime, attributes: { type, name: displayName, fileName, version, description, service, package: pkg } } = record;
130+
131+
let pkgLink;
132+
let appLinks;
133+
134+
if (pkg) {
135+
pkgLink = (<PackageLink config={config} type={type} pkg={pkg} />);
136+
}
137+
138+
if (type === 'lrn:app') {
139+
appLinks = (
140+
<>
141+
{(names || []).map(lrn =>
142+
<div key={lrn}>
143+
<AppLink config={config} lrn={lrn} />
144+
</div>
145+
)}
146+
</>
147+
);
148+
}
149+
150+
return (
151+
<TableRow key={id} size='small'>
152+
<TableCell monospace>{type}</TableCell>
153+
<TableCell monospace>
154+
{appLinks || (names || []).map(name => <div key={name}>{name}</div>)}
155+
</TableCell>
156+
<TableCell monospace>{version}</TableCell>
157+
<TableCell>{displayName || service || fileName || description}</TableCell>
158+
<TableCell>{moment.utc(createTime).fromNow()}</TableCell>
159+
<TableCell monospace>{pkgLink}</TableCell>
160+
<TableCell>
161+
<QueryLink config={config} id={id} icon />
162+
</TableCell>
163+
</TableRow>
144164
);
145-
}
146-
147-
return (
148-
<TableRow key={id} size='small'>
149-
<TableCell monospace>{type}</TableCell>
150-
<TableCell monospace>
151-
{appLinks || (names || []).map(name => <div key={name}>{name}</div>)}
152-
</TableCell>
153-
<TableCell monospace>
154-
{version}
155-
</TableCell>
156-
<TableCell>
157-
{displayName || service || fileName || description}
158-
</TableCell>
159-
<TableCell>
160-
{moment.utc(createTime).fromNow()}
161-
</TableCell>
162-
<TableCell monospace>
163-
{pkgLink}
164-
</TableCell>
165-
<TableCell>
166-
<QueryLink config={config} id={id} icon />
167-
</TableCell>
168-
</TableRow>
169-
);
170-
}
171-
)}
172-
</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>
190-
</Table>
165+
})}
166+
</TableBody>
167+
</Table>
168+
</TableContainer>
169+
<TablePagination
170+
component="td"
171+
rowsPerPageOptions={[5, 10, 25]}
172+
count={-1}
173+
rowsPerPage={rowsPerPage}
174+
page={page}
175+
onPageChange={handleChangePage}
176+
onRowsPerPageChange={handleChangeRowsPerPage}
177+
labelDisplayedRows={labelDisplayedRows}
178+
nextIconButtonProps={{
179+
disabled: records.length < rowsPerPage,
180+
}}
181+
/>
182+
</Paper>
191183
);
192184
};
193185

src/resolvers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const createResolvers = config => {
4646
wns_records: async (_, { attributes }) => {
4747
log('WNS records...');
4848

49-
const {limit, offset, ...queryAttributes } = attributes;
49+
const {limit, offset, ...queryAttributes } = attributes || {};
5050
const data = await registry.queryRecords(queryAttributes, false, false, limit, offset);
5151

5252
return {

0 commit comments

Comments
 (0)