From c7903ab024f522208b44589a57b464294892d0ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Maro=C5=A1i?= Date: Thu, 3 Aug 2023 10:48:15 +0200 Subject: [PATCH] Remove deprecated table from skeleton loader. --- .../src/SkeletonTable/SkeletonTable.tsx | 115 +++++++----------- .../src/TagModal/TableWithFilter.tsx | 2 +- packages/components/src/index.ts | 1 - 3 files changed, 47 insertions(+), 71 deletions(-) diff --git a/packages/components/src/SkeletonTable/SkeletonTable.tsx b/packages/components/src/SkeletonTable/SkeletonTable.tsx index ec43c346f3..6a638bebcc 100644 --- a/packages/components/src/SkeletonTable/SkeletonTable.tsx +++ b/packages/components/src/SkeletonTable/SkeletonTable.tsx @@ -1,80 +1,57 @@ -import React from 'react'; -import { ICell, IRow, RowSelectVariant, TableVariant } from '@patternfly/react-table'; -import { Table, TableBody, TableHeader } from '@patternfly/react-table/deprecated'; -import { Skeleton, SkeletonSize } from '../Skeleton'; -import classNames from 'classnames'; +import React, { ReactNode } from 'react'; +import { Caption, Table, TableProps, TableVariant, Tbody, Td, Th, Thead, Tr } from '@patternfly/react-table'; +import { Skeleton } from '../Skeleton'; import './SkeletonTable.scss'; -export interface SkeletonTableProps { - colSize?: number; - rowSize?: number; - columns?: (ICell | string)[]; - paddingColumnSize?: number; - sortBy?: { - index?: number; - direction?: 'asc' | 'desc'; - }; - isSelectable?: boolean; - canSelectAll?: boolean; - hasRadio?: boolean; +export type SkeletonTableProps = TableProps & { variant?: TableVariant; - isDark?: boolean; -} - -const SkeletonTable: React.FunctionComponent = ({ - canSelectAll = false, - isSelectable = false, - sortBy, - variant, - isDark = false, - colSize = 0, - columns, - paddingColumnSize = 0, - hasRadio = false, - rowSize = 0, -}) => { - const newArray = (size: number) => [...Array(size)]; - const createColumns = () => { - return [...Array(colSize)].map(() => ({ title: })); - }; - - const getColumns = (): (ICell | string)[] => { - return newArray(paddingColumnSize) - .map(() => '') - .concat(columns || createColumns()); - }; + rows?: number; + caption?: ReactNode; +} & ( + | { + columns: ReactNode[]; + } + | { + numberOfColumns: number; + } + ); - const createRows = (): (IRow | string[])[] => { - const numberOfCols = columns ? columns.length : colSize; - return newArray(rowSize).map(() => ({ - disableSelection: true, - cells: newArray(paddingColumnSize) - .map<{ title: React.ReactNode } | string>(() => '') - .concat(newArray(numberOfCols).map(() => ({ title: }))), - })); - }; +function hasCustomColumns(props: Record): props is SkeletonTableProps & { + columns: ReactNode[]; +} { + return Array.isArray(props.columns); +} - const selectVariant = (): RowSelectVariant => { - return hasRadio ? RowSelectVariant?.radio || 'radio' : RowSelectVariant?.checkbox || 'checkbox'; - }; +const SkeletonTable: React.FunctionComponent = (props) => { + const { variant, rows = 5, caption } = props; + const rowCells = hasCustomColumns(props) ? props.columns.length : props.numberOfColumns; + const rowArray = [...new Array(rowCells)]; + const bodyRows = [...new Array(rows)].map((_, index) => ( + + {rowArray.map((_, index) => ( + + + + ))} + + )); return ( - undefined : undefined} - selectVariant={isSelectable ? selectVariant() : undefined} - canSelectAll={canSelectAll} - variant={variant} - > - - +
+ {caption && } + + + {hasCustomColumns(props) + ? props.columns.map((c, index) => ) + : rowArray.map((_, index) => ( + + ))} + + + {bodyRows}
{caption}
{c} + +
); }; diff --git a/packages/components/src/TagModal/TableWithFilter.tsx b/packages/components/src/TagModal/TableWithFilter.tsx index debcff6263..18221085f5 100644 --- a/packages/components/src/TagModal/TableWithFilter.tsx +++ b/packages/components/src/TagModal/TableWithFilter.tsx @@ -158,7 +158,7 @@ const TableWithFilter: React.FC = ({ ) : ( - + )} {onUpdateData && pagination && loaded && ( diff --git a/packages/components/src/index.ts b/packages/components/src/index.ts index a118faa161..eba5cd7279 100644 --- a/packages/components/src/index.ts +++ b/packages/components/src/index.ts @@ -4,7 +4,6 @@ export * from './Section'; export * from './Ansible'; export * from './Main'; export * from './SimpleTableFilter'; -export * from './Input'; export * from './InsightsLabel'; export * from './Battery'; export * from './Breadcrumbs';