Handle undefined attributes in records resolver #61

Merged
nabarun merged 3 commits from deep-stack/laconic-console:pm-handle-attributes into main 2024-10-23 08:00:13 +00:00
2 changed files with 70 additions and 78 deletions

View File

@ -11,8 +11,8 @@ import Button from '@material-ui/core/Button';
import TableHead from '@material-ui/core/TableHead'; import TableHead from '@material-ui/core/TableHead';
import TableRow from '@material-ui/core/TableRow'; import TableRow from '@material-ui/core/TableRow';
import TableBody from '@material-ui/core/TableBody'; import TableBody from '@material-ui/core/TableBody';
import TableFooter from '@material-ui/core/TableFooter';
import TablePagination from '@material-ui/core/TablePagination'; import TablePagination from '@material-ui/core/TablePagination';
import { Paper, TableContainer, } from '@material-ui/core';
import WNS_RECORDS from '../../../gql/wns_records.graphql'; import WNS_RECORDS from '../../../gql/wns_records.graphql';
@ -108,86 +108,78 @@ const RegistryRecords = ({ type }) => {
}; };
return ( return (
<Table> <Paper style={{
<TableHead> width: '100%',
<TableRow> }}>
<TableCell onClick={sortBy('attributes.type')} size='medium'>Type</TableCell> <TableContainer>
<TableCell onClick={sortBy('names[0]')}>Registered Names</TableCell> <Table>
<TableCell onClick={sortBy('attributes.version')} size='small'>Version</TableCell> <TableHead>
<TableCell onClick={sortBy('attributes.name')}>Display Name</TableCell> <TableRow>
<TableCell onClick={sortBy('createTime')} size='small'>Created</TableCell> <TableCell onClick={sortBy('attributes.type')} size='medium'>Type</TableCell>
<TableCell onClick={sortBy('attributes.package')}>Package</TableCell> <TableCell onClick={sortBy('names[0]')}>Registered Names</TableCell>
<TableCell size='icon' /> <TableCell onClick={sortBy('attributes.version')} size='small'>Version</TableCell>
</TableRow> <TableCell onClick={sortBy('attributes.name')}>Display Name</TableCell>
</TableHead> <TableCell onClick={sortBy('createTime')} size='small'>Created</TableCell>
<TableBody> <TableCell onClick={sortBy('attributes.package')}>Package</TableCell>
{records.sort(sorter) <TableCell size='icon' />
.map((record) => { </TableRow>
const { id, names, createTime, attributes: { type, name: displayName, fileName, version, description, service, package: pkg } } = record; </TableHead>
<TableBody>
{records.sort(sorter).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>
); );
} })}
</TableBody>
return ( </Table>
<TableRow key={id} size='small'> </TableContainer>
<TableCell monospace>{type}</TableCell> <TablePagination
<TableCell monospace> component="td"
{appLinks || (names || []).map(name => <div key={name}>{name}</div>)} rowsPerPageOptions={[5, 10, 25]}
</TableCell> count={-1}
<TableCell monospace> rowsPerPage={rowsPerPage}
{version} page={page}
</TableCell> onPageChange={handleChangePage}
<TableCell> onRowsPerPageChange={handleChangeRowsPerPage}
{displayName || service || fileName || description} labelDisplayedRows={labelDisplayedRows}
</TableCell> nextIconButtonProps={{
<TableCell> disabled: records.length < rowsPerPage,
{moment.utc(createTime).fromNow()} }}
</TableCell> />
<TableCell monospace> </Paper>
{pkgLink}
</TableCell>
<TableCell>
<QueryLink config={config} id={id} icon />
</TableCell>
</TableRow>
);
}
)}
</TableBody>
<TableFooter>
<TableRow>
<TablePagination
component="td"
rowsPerPageOptions={[5, 10, 25]}
count={-1}
rowsPerPage={rowsPerPage}
page={page}
onPageChange={handleChangePage}
onRowsPerPageChange={handleChangeRowsPerPage}
labelDisplayedRows={labelDisplayedRows}
nextIconButtonProps={{
disabled: records.length < rowsPerPage,
}}
/>
</TableRow>
</TableFooter>
</Table>
); );
}; };

View File

@ -46,7 +46,7 @@ export const createResolvers = config => {
wns_records: async (_, { attributes }) => { wns_records: async (_, { attributes }) => {
log('WNS records...'); log('WNS records...');
const {limit, offset, ...queryAttributes } = attributes; const {limit, offset, ...queryAttributes } = attributes || {};
const data = await registry.queryRecords(queryAttributes, false, false, limit, offset); const data = await registry.queryRecords(queryAttributes, false, false, limit, offset);
return { return {