Added extra 'Table' component without tbody and used for transactions
This commit is contained in:
parent
74377a4697
commit
ee66bea4f4
@ -3,7 +3,7 @@ import { BlockMeta } from '../../routes/blocks/tendermint-blockchain-response';
|
|||||||
import { Routes } from '../../routes/router-config';
|
import { Routes } from '../../routes/router-config';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { SecondsAgo } from '../seconds-ago';
|
import { SecondsAgo } from '../seconds-ago';
|
||||||
import { Table, TableRow, TableCell } from '../table';
|
import { TableWithTbody, TableRow, TableCell } from '../table';
|
||||||
|
|
||||||
interface BlockProps {
|
interface BlockProps {
|
||||||
block: BlockMeta;
|
block: BlockMeta;
|
||||||
@ -12,7 +12,7 @@ interface BlockProps {
|
|||||||
|
|
||||||
export const BlockData = ({ block, className }: BlockProps) => {
|
export const BlockData = ({ block, className }: BlockProps) => {
|
||||||
return (
|
return (
|
||||||
<Table
|
<TableWithTbody
|
||||||
aria-label={`Data for block ${block.header?.height}`}
|
aria-label={`Data for block ${block.header?.height}`}
|
||||||
className={className}
|
className={className}
|
||||||
>
|
>
|
||||||
@ -55,6 +55,6 @@ export const BlockData = ({ block, className }: BlockProps) => {
|
|||||||
<SecondsAgo date={block.header?.time} />
|
<SecondsAgo date={block.header?.time} />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</Table>
|
</TableWithTbody>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -25,6 +25,21 @@ interface TableCellProps extends ThHTMLAttributes<HTMLTableCellElement> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const Table = ({ children, className, ...props }: TableProps) => {
|
export const Table = ({ children, className, ...props }: TableProps) => {
|
||||||
|
const classes = classnames(className, 'overflow-x-auto whitespace-nowrap');
|
||||||
|
return (
|
||||||
|
<div className={classes}>
|
||||||
|
<table className="w-full" {...props}>
|
||||||
|
{children}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const TableWithTbody = ({
|
||||||
|
children,
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: TableProps) => {
|
||||||
const classes = classnames(className, 'overflow-x-auto whitespace-nowrap');
|
const classes = classnames(className, 'overflow-x-auto whitespace-nowrap');
|
||||||
return (
|
return (
|
||||||
<div className={classes}>
|
<div className={classes}>
|
||||||
@ -57,8 +72,7 @@ export const TableRow = ({
|
|||||||
...props
|
...props
|
||||||
}: TableRowProps) => {
|
}: TableRowProps) => {
|
||||||
const cellClasses = classnames(className, {
|
const cellClasses = classnames(className, {
|
||||||
'border-b bg-black-40 border-black-40 dark:border-white-40':
|
'border-b border-black-40 dark:border-white-40': modifier === 'bordered',
|
||||||
modifier === 'bordered',
|
|
||||||
'border-b-4 bg-black-40 border-b-white dark:bg-white-25 dark:border-b-black':
|
'border-b-4 bg-black-40 border-b-white dark:bg-white-25 dark:border-b-black':
|
||||||
modifier === 'background',
|
modifier === 'background',
|
||||||
});
|
});
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import { render, screen } from '@testing-library/react';
|
import { render, screen } from '@testing-library/react';
|
||||||
|
|
||||||
import { Table, TableRow, TableHeader, TableCell } from './index';
|
import { TableWithTbody, TableRow, TableHeader, TableCell } from './index';
|
||||||
|
|
||||||
describe('Renders all table components', () => {
|
describe('Renders all table components', () => {
|
||||||
render(
|
render(
|
||||||
<Table data-testid="test-table">
|
<TableWithTbody data-testid="test-table">
|
||||||
<TableRow data-testid="test-tr">
|
<TableRow data-testid="test-tr">
|
||||||
<TableHeader data-testid="test-th">Title</TableHeader>
|
<TableHeader data-testid="test-th">Title</TableHeader>
|
||||||
<TableCell data-testid="test-td">Content</TableCell>
|
<TableCell data-testid="test-td">Content</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</Table>
|
</TableWithTbody>
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(screen.getByTestId('test-table')).toBeInTheDocument();
|
expect(screen.getByTestId('test-table')).toBeInTheDocument();
|
||||||
@ -21,11 +21,11 @@ describe('Renders all table components', () => {
|
|||||||
describe('Table row', () => {
|
describe('Table row', () => {
|
||||||
it('should include classes based on custom "modifier" prop', () => {
|
it('should include classes based on custom "modifier" prop', () => {
|
||||||
render(
|
render(
|
||||||
<Table>
|
<TableWithTbody>
|
||||||
<TableRow data-testid="modifier-test" modifier="bordered">
|
<TableRow data-testid="modifier-test" modifier="bordered">
|
||||||
<TableCell>With modifier</TableCell>
|
<TableCell>With modifier</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</Table>
|
</TableWithTbody>
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(screen.getByTestId('modifier-test')).toHaveClass('border-b');
|
expect(screen.getByTestId('modifier-test')).toHaveClass('border-b');
|
||||||
@ -35,13 +35,13 @@ describe('Table row', () => {
|
|||||||
describe('Table header', () => {
|
describe('Table header', () => {
|
||||||
it('should accept props i.e. scope="row"', () => {
|
it('should accept props i.e. scope="row"', () => {
|
||||||
render(
|
render(
|
||||||
<Table>
|
<TableWithTbody>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHeader data-testid="props-test" scope="row">
|
<TableHeader data-testid="props-test" scope="row">
|
||||||
Test
|
Test
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</Table>
|
</TableWithTbody>
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(screen.getByTestId('props-test')).toHaveAttribute('scope');
|
expect(screen.getByTestId('props-test')).toHaveAttribute('scope');
|
||||||
@ -49,13 +49,13 @@ describe('Table header', () => {
|
|||||||
|
|
||||||
it('should include custom class based on scope="row"', () => {
|
it('should include custom class based on scope="row"', () => {
|
||||||
render(
|
render(
|
||||||
<Table>
|
<TableWithTbody>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHeader data-testid="scope-class-test" scope="row">
|
<TableHeader data-testid="scope-class-test" scope="row">
|
||||||
With scope attribute
|
With scope attribute
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</Table>
|
</TableWithTbody>
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(screen.getByTestId('scope-class-test')).toHaveClass('text-left');
|
expect(screen.getByTestId('scope-class-test')).toHaveClass('text-left');
|
||||||
@ -65,13 +65,13 @@ describe('Table header', () => {
|
|||||||
describe('Table cell', () => {
|
describe('Table cell', () => {
|
||||||
it('should include class based on custom "modifier" prop', () => {
|
it('should include class based on custom "modifier" prop', () => {
|
||||||
render(
|
render(
|
||||||
<Table>
|
<TableWithTbody>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell data-testid="modifier-class-test" modifier="bordered">
|
<TableCell data-testid="modifier-class-test" modifier="bordered">
|
||||||
With modifier
|
With modifier
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</Table>
|
</TableWithTbody>
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(screen.getByTestId('modifier-class-test')).toHaveClass('py-4');
|
expect(screen.getByTestId('modifier-class-test')).toHaveClass('py-4');
|
||||||
|
@ -2,10 +2,10 @@ import useFetch from '../../hooks/use-fetch';
|
|||||||
import { ChainExplorerTxResponse } from '../../routes/types/chain-explorer-response';
|
import { ChainExplorerTxResponse } from '../../routes/types/chain-explorer-response';
|
||||||
import { Routes } from '../../routes/router-config';
|
import { Routes } from '../../routes/router-config';
|
||||||
import { DATA_SOURCES } from '../../config';
|
import { DATA_SOURCES } from '../../config';
|
||||||
import { Link } from 'react-router-dom';
|
|
||||||
import { RenderFetched } from '../render-fetched';
|
import { RenderFetched } from '../render-fetched';
|
||||||
import { TruncateInline } from '../truncate/truncate';
|
import { TruncatedLink } from '../truncate/truncated-link';
|
||||||
import { TxOrderType } from './tx-order-type';
|
import { TxOrderType } from './tx-order-type';
|
||||||
|
import { Table, TableRow, TableCell } from '../table';
|
||||||
|
|
||||||
interface TxsPerBlockProps {
|
interface TxsPerBlockProps {
|
||||||
blockHeight: string | undefined;
|
blockHeight: string | undefined;
|
||||||
@ -33,50 +33,46 @@ export const TxsPerBlock = ({ blockHeight }: TxsPerBlockProps) => {
|
|||||||
<RenderFetched error={error} loading={loading} className="text-body-large">
|
<RenderFetched error={error} loading={loading} className="text-body-large">
|
||||||
{decodedBlockData && decodedBlockData.length ? (
|
{decodedBlockData && decodedBlockData.length ? (
|
||||||
<div className="overflow-x-auto whitespace-nowrap mb-28">
|
<div className="overflow-x-auto whitespace-nowrap mb-28">
|
||||||
<table className="w-full">
|
<Table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr className="font-mono">
|
<TableRow modifier="bordered" className="font-mono">
|
||||||
<td>Transaction</td>
|
<td>Transaction</td>
|
||||||
<td>From</td>
|
<td>From</td>
|
||||||
<td>Type</td>
|
<td>Type</td>
|
||||||
</tr>
|
</TableRow>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{decodedBlockData.map(({ TxHash, PubKey, Type }) => {
|
{decodedBlockData.map(({ TxHash, PubKey, Type }) => {
|
||||||
return (
|
return (
|
||||||
<tr
|
<TableRow
|
||||||
|
modifier="bordered"
|
||||||
key={TxHash}
|
key={TxHash}
|
||||||
data-testid="transaction-row"
|
data-testid="transaction-row"
|
||||||
className="bg-black-40 dark:bg-transparent"
|
|
||||||
>
|
>
|
||||||
<td className="pl-4 dark:pl-0">
|
<TableCell modifier="bordered">
|
||||||
<Link to={`/${Routes.TX}/${TxHash}`}>
|
<TruncatedLink
|
||||||
<TruncateInline
|
to={`/${Routes.TX}/${TxHash}`}
|
||||||
text={TxHash}
|
text={TxHash}
|
||||||
startChars={truncateLength}
|
startChars={truncateLength}
|
||||||
endChars={truncateLength}
|
endChars={truncateLength}
|
||||||
className="text-vega-yellow font-mono"
|
/>
|
||||||
/>
|
</TableCell>
|
||||||
</Link>
|
<TableCell modifier="bordered">
|
||||||
</td>
|
<TruncatedLink
|
||||||
<td>
|
to={`/${Routes.PARTIES}/${PubKey}`}
|
||||||
<Link to={`/${Routes.PARTIES}/${PubKey}`}>
|
text={PubKey}
|
||||||
<TruncateInline
|
startChars={truncateLength}
|
||||||
text={PubKey}
|
endChars={truncateLength}
|
||||||
startChars={truncateLength}
|
/>
|
||||||
endChars={truncateLength}
|
</TableCell>
|
||||||
className="text-vega-yellow font-mono"
|
<TableCell modifier="bordered">
|
||||||
/>
|
<TxOrderType orderType={Type} />
|
||||||
</Link>
|
</TableCell>
|
||||||
</td>
|
</TableRow>
|
||||||
<td>
|
|
||||||
<TxOrderType className="my-2" orderType={Type} />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="font-mono mb-28">
|
<div className="font-mono mb-28">
|
||||||
|
@ -6,7 +6,7 @@ import { TendermintBlocksResponse } from '../tendermint-blocks-response';
|
|||||||
import { RouteTitle } from '../../../components/route-title';
|
import { RouteTitle } from '../../../components/route-title';
|
||||||
import { SecondsAgo } from '../../../components/seconds-ago';
|
import { SecondsAgo } from '../../../components/seconds-ago';
|
||||||
import {
|
import {
|
||||||
Table,
|
TableWithTbody,
|
||||||
TableRow,
|
TableRow,
|
||||||
TableHeader,
|
TableHeader,
|
||||||
TableCell,
|
TableCell,
|
||||||
@ -56,13 +56,13 @@ const Block = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
<Table className="mb-28">
|
<TableWithTbody className="mb-28">
|
||||||
<TableRow modifier="bordered">
|
<TableRow modifier="bordered">
|
||||||
<TableHeader scope="row">Mined by</TableHeader>
|
<TableHeader scope="row">Mined by</TableHeader>
|
||||||
<TableCell modifier="bordered">
|
<TableCell modifier="bordered">
|
||||||
<Link
|
<Link
|
||||||
data-testid="block-validator"
|
data-testid="block-validator"
|
||||||
className="text-vega-yellow font-mono"
|
className="font-mono font-bold underline dark:text-vega-yellow dark:font-normal dark:no-underline"
|
||||||
to={`/${Routes.VALIDATORS}`}
|
to={`/${Routes.VALIDATORS}`}
|
||||||
>
|
>
|
||||||
{header.proposer_address}
|
{header.proposer_address}
|
||||||
@ -75,7 +75,7 @@ const Block = () => {
|
|||||||
<SecondsAgo data-testid="block-time" date={header.time} />
|
<SecondsAgo data-testid="block-time" date={header.time} />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</Table>
|
</TableWithTbody>
|
||||||
{blockData && blockData.result.block.data.txs.length > 0 ? (
|
{blockData && blockData.result.block.data.txs.length > 0 ? (
|
||||||
<TxsPerBlock blockHeight={block} />
|
<TxsPerBlock blockHeight={block} />
|
||||||
) : null}
|
) : null}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
import { StatusMessage } from '../../../components/status-message';
|
import { StatusMessage } from '../../../components/status-message';
|
||||||
import { SyntaxHighlighter } from '../../../components/syntax-highlighter';
|
import { SyntaxHighlighter } from '../../../components/syntax-highlighter';
|
||||||
import {
|
import {
|
||||||
Table,
|
TableWithTbody,
|
||||||
TableCell,
|
TableCell,
|
||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow,
|
TableRow,
|
||||||
} from '../../../components/table';
|
} from '../../../components/table';
|
||||||
import { TxOrderType } from '../../../components/txs';
|
import { TxOrderType } from '../../../components/txs';
|
||||||
import { ChainExplorerTxResponse } from '../../../routes/types/chain-explorer-response';
|
import { ChainExplorerTxResponse } from '../../types/chain-explorer-response';
|
||||||
|
|
||||||
interface TxContentProps {
|
interface TxContentProps {
|
||||||
data: ChainExplorerTxResponse | undefined;
|
data: ChainExplorerTxResponse | undefined;
|
||||||
@ -22,7 +22,7 @@ export const TxContent = ({ data }: TxContentProps) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Table className="mb-12">
|
<TableWithTbody className="mb-12">
|
||||||
<TableRow modifier="bordered">
|
<TableRow modifier="bordered">
|
||||||
<TableHeader scope="row" className="w-[160px]">
|
<TableHeader scope="row" className="w-[160px]">
|
||||||
Type
|
Type
|
||||||
@ -31,7 +31,7 @@ export const TxContent = ({ data }: TxContentProps) => {
|
|||||||
<TxOrderType orderType={data.Type} />
|
<TxOrderType orderType={data.Type} />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</Table>
|
</TableWithTbody>
|
||||||
|
|
||||||
<h3 className="font-mono mb-8">Decoded transaction content</h3>
|
<h3 className="font-mono mb-8">Decoded transaction content</h3>
|
||||||
<SyntaxHighlighter data={JSON.parse(data.Command)} />
|
<SyntaxHighlighter data={JSON.parse(data.Command)} />
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import {
|
import {
|
||||||
Table,
|
TableWithTbody,
|
||||||
TableCell,
|
TableCell,
|
||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow,
|
TableRow,
|
||||||
} from '../../../components/table';
|
} from '../../../components/table';
|
||||||
import { TruncateInline } from '../../../components/truncate/truncate';
|
import { TruncateInline } from '../../../components/truncate/truncate';
|
||||||
import { Routes } from '../../../routes/router-config';
|
import { Routes } from '../../router-config';
|
||||||
import { Result } from '../../../routes/txs/tendermint-transaction-response.d';
|
import { Result } from '../tendermint-transaction-response.d';
|
||||||
|
|
||||||
interface TxDetailsProps {
|
interface TxDetailsProps {
|
||||||
txData: Result | undefined;
|
txData: Result | undefined;
|
||||||
@ -23,7 +23,7 @@ export const TxDetails = ({ txData, pubKey, className }: TxDetailsProps) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Table className={className}>
|
<TableWithTbody className={className}>
|
||||||
<TableRow modifier="bordered">
|
<TableRow modifier="bordered">
|
||||||
<TableCell>Hash</TableCell>
|
<TableCell>Hash</TableCell>
|
||||||
<TableCell modifier="bordered" data-testid="hash">
|
<TableCell modifier="bordered" data-testid="hash">
|
||||||
@ -64,6 +64,6 @@ export const TxDetails = ({ txData, pubKey, className }: TxDetailsProps) => {
|
|||||||
/>
|
/>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</Table>
|
</TableWithTbody>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user