Migrate Dashboard table (#2694)
* Migrate Dashboard table to the new version on table components #2682 * Added universal component to the column section and added part of test #2682 * Added universal component for the all new tables in project #2682 * deleted color argument on LinkCell component * deleted link on topic count Co-authored-by: davitbejanyan <dbejanyan@provectus.com>
This commit is contained in:
parent
7d5b7de992
commit
0939d6140f
8 changed files with 76 additions and 56 deletions
|
@ -42,10 +42,19 @@ const BrokersList: React.FC = () => {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}, [diskUsage, brokers]);
|
}, [diskUsage, brokers]);
|
||||||
|
|
||||||
const columns = React.useMemo<ColumnDef<typeof rows>[]>(
|
const columns = React.useMemo<ColumnDef<typeof rows>[]>(
|
||||||
() => [
|
() => [
|
||||||
{ header: 'Broker ID', accessorKey: 'brokerId', cell: LinkCell },
|
{
|
||||||
|
header: 'Broker ID',
|
||||||
|
accessorKey: 'brokerId',
|
||||||
|
// eslint-disable-next-line react/no-unstable-nested-components
|
||||||
|
cell: ({ getValue }) => (
|
||||||
|
<LinkCell
|
||||||
|
value={`${getValue<string | number>()}`}
|
||||||
|
to={encodeURIComponent(`${getValue<string | number>()}`)}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
{ header: 'Segment Size', accessorKey: 'size', cell: SizeCell },
|
{ header: 'Segment Size', accessorKey: 'size', cell: SizeCell },
|
||||||
{ header: 'Segment Count', accessorKey: 'count' },
|
{ header: 'Segment Count', accessorKey: 'count' },
|
||||||
{ header: 'Port', accessorKey: 'port' },
|
{ header: 'Port', accessorKey: 'port' },
|
||||||
|
|
|
@ -49,7 +49,13 @@ const List: React.FC<Props> = ({ consumerGroups, totalPages }) => {
|
||||||
id: ConsumerGroupOrdering.NAME,
|
id: ConsumerGroupOrdering.NAME,
|
||||||
header: 'Group ID',
|
header: 'Group ID',
|
||||||
accessorKey: 'groupId',
|
accessorKey: 'groupId',
|
||||||
cell: LinkCell,
|
// eslint-disable-next-line react/no-unstable-nested-components
|
||||||
|
cell: ({ getValue }) => (
|
||||||
|
<LinkCell
|
||||||
|
value={`${getValue<string | number>()}`}
|
||||||
|
to={encodeURIComponent(`${getValue<string | number>()}`)}
|
||||||
|
/>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: ConsumerGroupOrdering.MEMBERS,
|
id: ConsumerGroupOrdering.MEMBERS,
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
import React from 'react';
|
||||||
|
import { CellContext } from '@tanstack/react-table';
|
||||||
|
import { Tag } from 'components/common/Tag/Tag.styled';
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
const ClusterName: React.FC<CellContext<any, unknown>> = ({ row }) => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{row.original.readOnly && <Tag color="blue">readonly</Tag>}
|
||||||
|
{row.original.name}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ClusterName;
|
|
@ -1,16 +1,14 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import * as Metrics from 'components/common/Metrics';
|
import * as Metrics from 'components/common/Metrics';
|
||||||
import { Tag } from 'components/common/Tag/Tag.styled';
|
import { Tag } from 'components/common/Tag/Tag.styled';
|
||||||
import { Table } from 'components/common/table/Table/Table.styled';
|
|
||||||
import TableHeaderCell from 'components/common/table/TableHeaderCell/TableHeaderCell';
|
|
||||||
import BytesFormatted from 'components/common/BytesFormatted/BytesFormatted';
|
|
||||||
import { NavLink } from 'react-router-dom';
|
|
||||||
import { clusterTopicsPath } from 'lib/paths';
|
|
||||||
import Switch from 'components/common/Switch/Switch';
|
import Switch from 'components/common/Switch/Switch';
|
||||||
import { useClusters } from 'lib/hooks/api/clusters';
|
import { useClusters } from 'lib/hooks/api/clusters';
|
||||||
import { ServerStatus } from 'generated-sources';
|
import { Cluster, ServerStatus } from 'generated-sources';
|
||||||
|
import { ColumnDef } from '@tanstack/react-table';
|
||||||
|
import Table, { SizeCell } from 'components/common/NewTable';
|
||||||
|
|
||||||
import * as S from './ClustersWidget.styled';
|
import * as S from './ClustersWidget.styled';
|
||||||
|
import ClusterName from './ClusterName';
|
||||||
|
|
||||||
const ClustersWidget: React.FC = () => {
|
const ClustersWidget: React.FC = () => {
|
||||||
const { data } = useClusters();
|
const { data } = useClusters();
|
||||||
|
@ -28,6 +26,19 @@ const ClustersWidget: React.FC = () => {
|
||||||
};
|
};
|
||||||
}, [data, showOfflineOnly]);
|
}, [data, showOfflineOnly]);
|
||||||
|
|
||||||
|
const columns = React.useMemo<ColumnDef<Cluster>[]>(
|
||||||
|
() => [
|
||||||
|
{ header: 'Cluster name', accessorKey: 'name', cell: ClusterName },
|
||||||
|
{ header: 'Version', accessorKey: 'version' },
|
||||||
|
{ header: 'Brokers count', accessorKey: 'brokerCount' },
|
||||||
|
{ header: 'Partitions', accessorKey: 'onlinePartitionCount' },
|
||||||
|
{ header: 'Topics', accessorKey: 'topicCount' },
|
||||||
|
{ header: 'Production', accessorKey: 'bytesInPerSec', cell: SizeCell },
|
||||||
|
{ header: 'Consumption', accessorKey: 'bytesOutPerSec', cell: SizeCell },
|
||||||
|
],
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
const handleSwitch = () => setShowOfflineOnly(!showOfflineOnly);
|
const handleSwitch = () => setShowOfflineOnly(!showOfflineOnly);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -51,45 +62,12 @@ const ClustersWidget: React.FC = () => {
|
||||||
/>
|
/>
|
||||||
<label>Only offline clusters</label>
|
<label>Only offline clusters</label>
|
||||||
</S.SwitchWrapper>
|
</S.SwitchWrapper>
|
||||||
<Table isFullwidth>
|
<Table
|
||||||
<thead>
|
columns={columns}
|
||||||
<tr>
|
data={config?.list}
|
||||||
<TableHeaderCell title="Cluster name" />
|
enableSorting
|
||||||
<TableHeaderCell title="Version" />
|
emptyMessage="Disk usage data not available"
|
||||||
<TableHeaderCell title="Brokers count" />
|
/>
|
||||||
<TableHeaderCell title="Partitions" />
|
|
||||||
<TableHeaderCell title="Topics" />
|
|
||||||
<TableHeaderCell title="Production" />
|
|
||||||
<TableHeaderCell title="Consumption" />
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{config.list.map((cluster) => (
|
|
||||||
<tr key={cluster.name}>
|
|
||||||
<S.TableCell maxWidth="99px" width="350">
|
|
||||||
{cluster.readOnly && <Tag color="blue">readonly</Tag>}{' '}
|
|
||||||
{cluster.name}
|
|
||||||
</S.TableCell>
|
|
||||||
<S.TableCell maxWidth="99px">{cluster.version}</S.TableCell>
|
|
||||||
<S.TableCell maxWidth="99px">{cluster.brokerCount}</S.TableCell>
|
|
||||||
<S.TableCell maxWidth="78px">
|
|
||||||
{cluster.onlinePartitionCount}
|
|
||||||
</S.TableCell>
|
|
||||||
<S.TableCell maxWidth="60px">
|
|
||||||
<NavLink to={clusterTopicsPath(cluster.name)}>
|
|
||||||
{cluster.topicCount}
|
|
||||||
</NavLink>
|
|
||||||
</S.TableCell>
|
|
||||||
<S.TableCell maxWidth="85px">
|
|
||||||
<BytesFormatted value={cluster.bytesInPerSec} />
|
|
||||||
</S.TableCell>
|
|
||||||
<S.TableCell maxWidth="85px">
|
|
||||||
<BytesFormatted value={cluster.bytesOutPerSec} />
|
|
||||||
</S.TableCell>
|
|
||||||
</tr>
|
|
||||||
))}
|
|
||||||
</tbody>
|
|
||||||
</Table>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -36,8 +36,7 @@ describe('ClustersWidget', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('render clusterWidget cells', () => {
|
it('render clusterWidget cells', () => {
|
||||||
const cells = screen.getAllByRole('cells');
|
const cells = screen.getAllByRole('cell');
|
||||||
expect(cells.length).toBe(14);
|
expect(cells.length).toBe(14);
|
||||||
expect(cells[0]).toHaveStyle('max-width: 99px');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -54,7 +54,17 @@ const List: React.FC = () => {
|
||||||
|
|
||||||
const columns = React.useMemo<ColumnDef<SchemaSubject>[]>(
|
const columns = React.useMemo<ColumnDef<SchemaSubject>[]>(
|
||||||
() => [
|
() => [
|
||||||
{ header: 'Subject', accessorKey: 'subject', cell: LinkCell },
|
{
|
||||||
|
header: 'Subject',
|
||||||
|
accessorKey: 'subject',
|
||||||
|
// eslint-disable-next-line react/no-unstable-nested-components
|
||||||
|
cell: ({ getValue }) => (
|
||||||
|
<LinkCell
|
||||||
|
value={`${getValue<string | number>()}`}
|
||||||
|
to={encodeURIComponent(`${getValue<string | number>()}`)}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
{ header: 'Id', accessorKey: 'id' },
|
{ header: 'Id', accessorKey: 'id' },
|
||||||
{ header: 'Type', accessorKey: 'schemaType' },
|
{ header: 'Type', accessorKey: 'schemaType' },
|
||||||
{ header: 'Version', accessorKey: 'version' },
|
{ header: 'Version', accessorKey: 'version' },
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { CellContext } from '@tanstack/react-table';
|
|
||||||
import { NavLink } from 'react-router-dom';
|
import { NavLink } from 'react-router-dom';
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const LinkCell: React.FC<CellContext<any, unknown>> = ({ getValue }) => {
|
const LinkCell = ({ value, to = '' }: any) => {
|
||||||
const value = `${getValue<string | number>()}`;
|
|
||||||
const handleClick: React.MouseEventHandler = (e) => e.stopPropagation();
|
const handleClick: React.MouseEventHandler = (e) => e.stopPropagation();
|
||||||
return (
|
return (
|
||||||
<NavLink to={encodeURIComponent(value)} title={value} onClick={handleClick}>
|
<NavLink to={to} title={value} onClick={handleClick}>
|
||||||
{value}
|
{value}
|
||||||
</NavLink>
|
</NavLink>
|
||||||
);
|
);
|
||||||
|
|
|
@ -63,7 +63,12 @@ const columns: ColumnDef<Datum>[] = [
|
||||||
{
|
{
|
||||||
header: 'Text',
|
header: 'Text',
|
||||||
accessorKey: 'text',
|
accessorKey: 'text',
|
||||||
cell: LinkCell,
|
cell: ({ getValue }) => (
|
||||||
|
<LinkCell
|
||||||
|
value={`${getValue<string | number>()}`}
|
||||||
|
to={encodeURIComponent(`${getValue<string | number>()}`)}
|
||||||
|
/>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'Size',
|
header: 'Size',
|
||||||
|
|
Loading…
Add table
Reference in a new issue