diff --git a/frontend/.eslintrc.json b/frontend/.eslintrc.json index 4d524ef20..ae5968839 100644 --- a/frontend/.eslintrc.json +++ b/frontend/.eslintrc.json @@ -82,7 +82,7 @@ "react/function-component-definition": [ 2, { - "namedComponents": "arrow-function", + "namedComponents": ["arrow-function", "function-declaration"], "unnamedComponents": "arrow-function" } ], diff --git a/frontend/src/components/ACLPage/List/List.tsx b/frontend/src/components/ACLPage/List/List.tsx index 499f255c3..2d4af3463 100644 --- a/frontend/src/components/ACLPage/List/List.tsx +++ b/frontend/src/components/ACLPage/List/List.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { ColumnDef } from '@tanstack/react-table'; +import { ColumnDef, Row } from '@tanstack/react-table'; import { useTheme } from 'styled-components'; import PageHeading from 'components/common/PageHeading/PageHeading'; import Table from 'components/common/NewTable'; @@ -130,9 +130,9 @@ const ACList: React.FC = () => { [rowId] ); - const onRowHover = (value: unknown) => { - if (value && typeof value === 'object' && 'id' in value) { - setRowId(value.id as string); + const onRowHover = (value: Row) => { + if (value) { + setRowId(value.id); } }; diff --git a/frontend/src/components/Connect/Details/Tasks/Tasks.tsx b/frontend/src/components/Connect/Details/Tasks/Tasks.tsx index bb21e8953..58bac45fb 100644 --- a/frontend/src/components/Connect/Details/Tasks/Tasks.tsx +++ b/frontend/src/components/Connect/Details/Tasks/Tasks.tsx @@ -50,7 +50,11 @@ const Tasks: React.FC = () => { data={data} emptyMessage="No tasks found" enableSorting - getRowCanExpand={(row) => row.original.status.trace?.length > 0} + getRowCanExpand={(row) => { + const { trace } = row.original.status; + if (trace === undefined) return false; + return trace.length > 0; + }} renderSubComponent={ExpandedTaskRow} /> ); diff --git a/frontend/src/components/ConsumerGroups/List.tsx b/frontend/src/components/ConsumerGroups/List.tsx index da35c6bba..54d3ebf4b 100644 --- a/frontend/src/components/ConsumerGroups/List.tsx +++ b/frontend/src/components/ConsumerGroups/List.tsx @@ -3,7 +3,7 @@ import PageHeading from 'components/common/PageHeading/PageHeading'; import Search from 'components/common/Search/Search'; import { ControlPanelWrapper } from 'components/common/ControlPanel/ControlPanel.styled'; import { - ConsumerGroupDetails, + ConsumerGroup, ConsumerGroupOrdering, ConsumerGroupState, SortOrder, @@ -33,7 +33,7 @@ const List = () => { search: searchParams.get('q') || '', }); - const columns = React.useMemo[]>( + const columns = React.useMemo[]>( () => [ { id: ConsumerGroupOrdering.NAME, diff --git a/frontend/src/components/common/NewTable/ExpanderCell.tsx b/frontend/src/components/common/NewTable/ExpanderCell.tsx index d5b78c383..e9375683b 100644 --- a/frontend/src/components/common/NewTable/ExpanderCell.tsx +++ b/frontend/src/components/common/NewTable/ExpanderCell.tsx @@ -3,7 +3,7 @@ import React from 'react'; import * as S from './Table.styled'; -const ExpanderCell: React.FC> = ({ row }) => { +function ExpanderCell({ row }: CellContext) { return ( > = ({ row }) => { )} ); -}; +} export default ExpanderCell; diff --git a/frontend/src/components/common/NewTable/SelectRowCell.tsx b/frontend/src/components/common/NewTable/SelectRowCell.tsx index 5c212e1d5..8d66260fe 100644 --- a/frontend/src/components/common/NewTable/SelectRowCell.tsx +++ b/frontend/src/components/common/NewTable/SelectRowCell.tsx @@ -2,13 +2,15 @@ import { CellContext } from '@tanstack/react-table'; import React from 'react'; import IndeterminateCheckbox from 'components/common/IndeterminateCheckbox/IndeterminateCheckbox'; -const SelectRowCell: React.FC> = ({ row }) => ( - -); +function SelectRowCell({ row }: CellContext) { + return ( + + ); +} export default SelectRowCell; diff --git a/frontend/src/components/common/NewTable/SelectRowHeader.tsx b/frontend/src/components/common/NewTable/SelectRowHeader.tsx index d33282f28..c7d735dfa 100644 --- a/frontend/src/components/common/NewTable/SelectRowHeader.tsx +++ b/frontend/src/components/common/NewTable/SelectRowHeader.tsx @@ -1,15 +1,15 @@ -import { HeaderContext } from '@tanstack/react-table'; import React from 'react'; import IndeterminateCheckbox from 'components/common/IndeterminateCheckbox/IndeterminateCheckbox'; +import { HeaderContext } from '@tanstack/react-table'; -const SelectRowHeader: React.FC> = ({ - table, -}) => ( - -); +function SelectRowHeader({ table }: HeaderContext) { + return ( + + ); +} export default SelectRowHeader; diff --git a/frontend/src/components/common/NewTable/Table.tsx b/frontend/src/components/common/NewTable/Table.tsx index ee1bba2aa..42d406b4f 100644 --- a/frontend/src/components/common/NewTable/Table.tsx +++ b/frontend/src/components/common/NewTable/Table.tsx @@ -26,15 +26,15 @@ import ExpanderCell from './ExpanderCell'; import SelectRowCell from './SelectRowCell'; import SelectRowHeader from './SelectRowHeader'; -export interface TableProps { +export interface TableProps { data: TData[]; pageCount?: number; - columns: ColumnDef[]; + columns: ColumnDef[]; // Server-side processing: sorting, pagination serverSideProcessing?: boolean; - // Expandeble rows + // Expandable rows getRowCanExpand?: (row: Row) => boolean; // Enables the ability to expand row. Use `() => true` when want to expand all rows. renderSubComponent?: React.FC<{ row: Row }>; // Component to render expanded row. @@ -56,7 +56,7 @@ export interface TableProps { onRowHover?: (row: Row) => void; onMouseLeave?: () => void; - setRowId?: (originalRow: Row) => string; + setRowId?: (originalRow: TData) => string; } type UpdaterFn = (previousState: T) => T; @@ -118,8 +118,7 @@ const getSortingFromSearchParams = (searchParams: URLSearchParams) => { * - use URLSearchParams to get the pagination and sorting state from the url for your server side processing. */ -// eslint-disable-next-line @typescript-eslint/no-explicit-any -const Table: React.FC> = ({ +function Table({ data, pageCount, columns, @@ -135,7 +134,7 @@ const Table: React.FC> = ({ onRowHover, onMouseLeave, setRowId, -}) => { +}: TableProps) { const [searchParams, setSearchParams] = useSearchParams(); const location = useLocation(); const [rowSelection, setRowSelection] = React.useState({}); @@ -157,7 +156,7 @@ const Table: React.FC> = ({ [searchParams, location] ); - const table = useReactTable({ + const table = useReactTable({ data, pageCount, columns, @@ -167,10 +166,16 @@ const Table: React.FC> = ({ rowSelection, }, getRowId: (originalRow, index) => { - return ( - setRowId?.(originalRow) || - (originalRow.name ? originalRow.name : `${index}`) - ); + if (setRowId) { + return setRowId(originalRow); + } + + // eslint-disable-next-line @typescript-eslint/ban-types + if ('name' in (originalRow as {})) { + return (originalRow as unknown as { name: string }).name; + } + + return index.toString(); }, onSortingChange: onSortingChange as OnChangeFn, onPaginationChange: onPaginationChange as OnChangeFn, @@ -187,7 +192,7 @@ const Table: React.FC> = ({ enableRowSelection, }); - const handleRowClick = (row: Row) => (e: React.MouseEvent) => { + const handleRowClick = (row: Row) => (e: React.MouseEvent) => { // If row selection is enabled do not handle row click. if (enableRowSelection) return undefined; @@ -205,7 +210,7 @@ const Table: React.FC> = ({ return undefined; }; - const handleRowHover = (row: Row) => (e: React.MouseEvent) => { + const handleRowHover = (row: Row) => (e: React.MouseEvent) => { if (onRowHover) { e.stopPropagation(); return onRowHover(row); @@ -238,7 +243,7 @@ const Table: React.FC> = ({ {!!enableRowSelection && ( {flexRender( - SelectRowHeader, + SelectRowHeader, headerGroup.headers[0].getContext() )} @@ -287,7 +292,7 @@ const Table: React.FC> = ({ {!!enableRowSelection && ( {flexRender( - SelectRowCell, + SelectRowCell, row.getVisibleCells()[0].getContext() )} @@ -295,7 +300,7 @@ const Table: React.FC> = ({ {table.getCanSomeRowsExpand() && ( {flexRender( - ExpanderCell, + ExpanderCell, row.getVisibleCells()[0].getContext() )} @@ -397,6 +402,6 @@ const Table: React.FC> = ({ )} ); -}; +} export default Table;