Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 12 additions & 38 deletions src/components/TableToolsTable/TableToolsTable.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import React from 'react';
import React, { useContext } from 'react';

Check failure on line 1 in src/components/TableToolsTable/TableToolsTable.js

View workflow job for this annotation

GitHub Actions / build (21.x)

'useContext' is defined but never used

Check failure on line 1 in src/components/TableToolsTable/TableToolsTable.js

View workflow job for this annotation

GitHub Actions / build (21.x)

'useContext' is defined but never used

Check failure on line 1 in src/components/TableToolsTable/TableToolsTable.js

View workflow job for this annotation

GitHub Actions / build (22.x)

'useContext' is defined but never used

Check failure on line 1 in src/components/TableToolsTable/TableToolsTable.js

View workflow job for this annotation

GitHub Actions / build (22.x)

'useContext' is defined but never used

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 2 issues:

1. 'useContext' is defined but never used. [eslint:@typescript-eslint/no-unused-vars]


2. 'useContext' is defined but never used. [eslint:no-unused-vars]

Suggested change
import React, { useContext } from 'react';
import React from 'react';

Remove unused variable 'useContext'.

import propTypes from 'prop-types';
import { Pagination, PaginationVariant } from '@patternfly/react-core';
import {
Table,
TableBody,
TableHeader,
} from '@patternfly/react-table/deprecated';
import {
SkeletonTable,
ColumnManagementModal,
} from '@patternfly/react-component-groups';

import PrimaryToolbar from '@redhat-cloud-services/frontend-components/PrimaryToolbar';
import { ColumnManagementModal } from '@patternfly/react-component-groups';
import TableToolbar from '@redhat-cloud-services/frontend-components/TableToolbar';

import useTableTools from '~/hooks/useTableTools';
import { TableStateProvider, FilterModal, TableViewToggle } from '~/components';
import { TableContext } from '~/hooks/useTableContext/constants';
import { TableStateProvider, FilterModal } from '~/components';

import { variants, queryClient } from './constants';

Check failure on line 11 in src/components/TableToolsTable/TableToolsTable.js

View workflow job for this annotation

GitHub Actions / build (21.x)

'queryClient' is defined but never used

Check failure on line 11 in src/components/TableToolsTable/TableToolsTable.js

View workflow job for this annotation

GitHub Actions / build (21.x)

'queryClient' is defined but never used

Check failure on line 11 in src/components/TableToolsTable/TableToolsTable.js

View workflow job for this annotation

GitHub Actions / build (22.x)

'queryClient' is defined but never used

Check failure on line 11 in src/components/TableToolsTable/TableToolsTable.js

View workflow job for this annotation

GitHub Actions / build (22.x)

'queryClient' is defined but never used

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 2 issues:

1. 'queryClient' is defined but never used. [eslint:@typescript-eslint/no-unused-vars]


2. 'queryClient' is defined but never used. [eslint:no-unused-vars]

Suggested change
import { variants, queryClient } from './constants';
import { variants } from './constants';

Remove unused variable 'queryClient'.


const TableToolsTable = ({
tableToolsTableVariant = 'table',
loading: externalLoading,
items: externalItems,
error: externalError,
Expand All @@ -28,20 +22,16 @@
// TODO I'm not sure if we need this level of customisation.
// It might actually hurt in the long run. Consider removing until we really have the case where we need this
toolbarProps: toolbarPropsProp,
tableHeaderProps,
tableBodyProps,
tableToolbarProps,
paginationProps,
...tablePropsRest
}) => {
const { TableComponent, ToolbarComponent } = variants[tableToolsTableVariant];
const {
view,
loading,
toolbarProps,
tableProps,
filterModalProps,
columnManagerModalProps,
tableViewToggleProps,
...tableToolsProps
} = useTableTools(
externalLoading,
externalItems,
Expand All @@ -59,26 +49,9 @@

return (
<>
<PrimaryToolbar aria-label="Table toolbar" {...toolbarProps}>
{toolbarProps?.children}
{tableViewToggleProps && <TableViewToggle {...tableViewToggleProps} />}
</PrimaryToolbar>
<ToolbarComponent {...{ ...tableToolsProps, ...{ toolbarProps } }} />

{
// TODO This is a bit hackish. We should rather have an indicator if data necessary for the current view is loading.
(view === 'rows' || (view === 'tree' && !treeTable)) && loading ? (
<SkeletonTable
rowsCount={toolbarProps?.pagination?.perPage || 10}
// TODO use Th when migrating to PF composable tables
columns={columns.map(({ title }) => title)}
/>
) : (
<Table aria-label="Table" {...tableProps}>
<TableHeader {...tableHeaderProps} />
<TableBody {...tableBodyProps} />
</Table>
)
}
<TableComponent {...{ ...tableToolsProps, ...{ toolbarProps } }} />

<TableToolbar isFooter {...tableToolbarProps}>
{toolbarProps.pagination && (
Expand All @@ -101,6 +74,7 @@
};

TableToolsTable.propTypes = {
tableToolsTableVariant: propTypes.string,
items: propTypes.oneOfType([propTypes.array, propTypes.func]).isRequired,
columns: propTypes.arrayOf(
propTypes.shape({
Expand Down
8 changes: 8 additions & 0 deletions src/components/TableToolsTable/TableToolsTable.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const defaultOptions = {

const argProps = {
debug: propTypes.bool,
composable: propTypes.bool,
columns: propTypes.array,
filters: propTypes.array,
filtered: propTypes.bool,
Expand All @@ -62,6 +63,7 @@ const meta = {
title: 'TableToolsTable',
args: {
debug: true,
composable: false,
columns,
filters,
filtered: true,
Expand Down Expand Up @@ -105,6 +107,7 @@ const emptyRows = (_kind, colSpan) => [

const CommonExample = ({
debug,
composable,
columns,
filters,
filtered,
Expand Down Expand Up @@ -144,6 +147,11 @@ const CommonExample = ({

return (
<TableToolsTable
{...(composable
? {
tableToolsTableVariant: 'composable',
}
: {})}
loading={loading}
items={data}
total={total}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React, { useEffect } from 'react';
import { Table, Th } from '@patternfly/react-table';
import { SkeletonTable } from '@patternfly/react-component-groups';

import TableHead from './components/TableHead';
import TableBody from './components/TableBody';
import useTableToolsForComposable from './hooks/useTableToolsForComposable';

const ComposableTable = (props) => {
const composableTableProps = useTableToolsForComposable(props);
const {
columns,
rows,
view,
loading,
tableTree,
pagination,
bulkSelect,
expandable,
total,
} = composableTableProps;

useEffect(() => {
console.group('ComposableTable props');
console.warn(
'Note: The "composable" variant is considered experimental and not fully featured yet.',
);

console.log('props', props);
console.log('composableTableProps', composableTableProps);

console.groupEnd();
}, [composableTableProps, props]);

return (view === 'rows' || (view === 'tree' && !tableTree)) && loading ? (
<SkeletonTable
rowsCount={pagination?.perPage || 10}
columns={columns.map(({ title, sortable }) => (
<Th
key={title}
{...(sortable
? { sort: { columnIndex: 0, sortBy: { property: sortable } } }
: {})}
>
{title}
</Th>
))}
/>
) : (
<Table>
<TableHead
columns={columns}
hasBulkSelect={!!bulkSelect}
isExpandable={!!expandable}
/>
<TableBody
columns={columns}
rows={rows}
total={total}
bulkSelect={bulkSelect}
expandable={expandable}
/>
</Table>
);
};

export default ComposableTable;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import propTypes from 'prop-types';
import { Td } from '@patternfly/react-table';

const Cell = ({ row, column: { title, key, Component } }) => (
<Td>
{Component ? (
<Component {...row.item} />
) : (
row.item[key || title?.toLowerCase()]
)}
</Td>
);

Cell.propTypes = {
row: propTypes.object,
column: propTypes.object,
};

export default Cell;
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React from 'react';
import propTypes from 'prop-types';
import { Tbody, Td, Tr } from '@patternfly/react-table';

import NoResultsTable from '~/components/NoResultsTable';

import Cell from './Cell';

const TableBody = ({ total, columns, rows, bulkSelect, expandable }) => (

Check failure on line 9 in src/components/TableToolsTable/components/ComposableTable/components/TableBody.js

View workflow job for this annotation

GitHub Actions / build (21.x)

'expandable' is missing in props validation

Check failure on line 9 in src/components/TableToolsTable/components/ComposableTable/components/TableBody.js

View workflow job for this annotation

GitHub Actions / build (21.x)

'bulkSelect' is missing in props validation

Check failure on line 9 in src/components/TableToolsTable/components/ComposableTable/components/TableBody.js

View workflow job for this annotation

GitHub Actions / build (21.x)

'total' is missing in props validation

Check failure on line 9 in src/components/TableToolsTable/components/ComposableTable/components/TableBody.js

View workflow job for this annotation

GitHub Actions / build (22.x)

'expandable' is missing in props validation

Check failure on line 9 in src/components/TableToolsTable/components/ComposableTable/components/TableBody.js

View workflow job for this annotation

GitHub Actions / build (22.x)

'bulkSelect' is missing in props validation

Check failure on line 9 in src/components/TableToolsTable/components/ComposableTable/components/TableBody.js

View workflow job for this annotation

GitHub Actions / build (22.x)

'total' is missing in props validation

@qltysh qltysh Bot Jul 15, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 3 issues:

1. 'bulkSelect' is missing in props validation [eslint:react/prop-types]


2. 'expandable' is missing in props validation [eslint:react/prop-types]


3. 'total' is missing in props validation [eslint:react/prop-types]

<Tbody>
{total === 0 ? (
<Tr>
<Td colSpan={columns?.length + (bulkSelect ? 1 : 0)}>
<NoResultsTable />
</Td>
</Tr>
) : (
rows?.map((row, idx) => (
<Tr key={row?.item?.id || idx}>
{!!expandable && (
<Td
{...(expandable
? {
expand: {
rowIndex: idx,
isExpanded: expandable.isExpanded(row?.item?.itemId),

Check failure on line 26 in src/components/TableToolsTable/components/ComposableTable/components/TableBody.js

View workflow job for this annotation

GitHub Actions / build (21.x)

'expandable.isExpanded' is missing in props validation

Check failure on line 26 in src/components/TableToolsTable/components/ComposableTable/components/TableBody.js

View workflow job for this annotation

GitHub Actions / build (22.x)

'expandable.isExpanded' is missing in props validation

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'expandable.isExpanded' is missing in props validation [eslint:react/prop-types]

onToggle: () => expandable.onToggle(row?.item?.itemId),

Check failure on line 27 in src/components/TableToolsTable/components/ComposableTable/components/TableBody.js

View workflow job for this annotation

GitHub Actions / build (21.x)

'expandable.onToggle' is missing in props validation

Check failure on line 27 in src/components/TableToolsTable/components/ComposableTable/components/TableBody.js

View workflow job for this annotation

GitHub Actions / build (22.x)

'expandable.onToggle' is missing in props validation

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'expandable.onToggle' is missing in props validation [eslint:react/prop-types]

},
}
: {})}
/>
)}
{!!bulkSelect && (
<Td
{...(bulkSelect
? {
select: {
rowIndex: idx,
onSelect: () => bulkSelect.selectOne(row?.item),

Check failure on line 39 in src/components/TableToolsTable/components/ComposableTable/components/TableBody.js

View workflow job for this annotation

GitHub Actions / build (21.x)

'bulkSelect.selectOne' is missing in props validation

Check failure on line 39 in src/components/TableToolsTable/components/ComposableTable/components/TableBody.js

View workflow job for this annotation

GitHub Actions / build (22.x)

'bulkSelect.selectOne' is missing in props validation

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'bulkSelect.selectOne' is missing in props validation [eslint:react/prop-types]

isSelected: bulkSelect.isItemSelected(row?.item?.itemId),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'bulkSelect.isItemSelected' is missing in props validation [eslint:react/prop-types]

},
}
: {})}
/>
)}

{columns.map((column) => (
<Cell key={column.title + `-${idx}`} row={row} column={column} />
))}
</Tr>
))
)}
</Tbody>
);

TableBody.propTypes = {
rows: propTypes.array,
columns: propTypes.array,
};

export default TableBody;
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';
import propTypes from 'prop-types';
import { Thead, Tr, Th } from '@patternfly/react-table';

const TableHead = ({ columns, hasBulkSelect, isExpandable }) => (

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'isExpandable' is missing in props validation [eslint:react/prop-types]

<Thead>
<Tr>
{hasBulkSelect && <Th />}
{isExpandable && <Th />}
{columns.map(({ title, sortable }, idx) => (
<Th
key={title}
{...(sortable
? {
sort: {
columnIndex: idx,
sortBy: { property: sortable },
onSort: (_event, index, direction, ...args) => {
console.log(_event, index, direction, ...args);
},
},
}
: {})}
>
{title}
</Th>
))}
</Tr>
</Thead>
);

TableHead.propTypes = {
columns: propTypes.object,
hasBulkSelect: propTypes.bool,
};

export default TableHead;
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { useMemo } from 'react';

/**

Check warning on line 3 in src/components/TableToolsTable/components/ComposableTable/hooks/useTableToolsForComposable.js

View workflow job for this annotation

GitHub Actions / build (21.x)

Missing JSDoc @param "options.tableProps.rows" declaration

Check warning on line 3 in src/components/TableToolsTable/components/ComposableTable/hooks/useTableToolsForComposable.js

View workflow job for this annotation

GitHub Actions / build (21.x)

Missing JSDoc @param "options.tableProps.cells" declaration

Check warning on line 3 in src/components/TableToolsTable/components/ComposableTable/hooks/useTableToolsForComposable.js

View workflow job for this annotation

GitHub Actions / build (21.x)

Missing JSDoc @param "options.tableProps" declaration

Check warning on line 3 in src/components/TableToolsTable/components/ComposableTable/hooks/useTableToolsForComposable.js

View workflow job for this annotation

GitHub Actions / build (21.x)

Missing JSDoc @param "options.expandable" declaration

Check warning on line 3 in src/components/TableToolsTable/components/ComposableTable/hooks/useTableToolsForComposable.js

View workflow job for this annotation

GitHub Actions / build (21.x)

Missing JSDoc @param "options.bulkSelect" declaration

Check warning on line 3 in src/components/TableToolsTable/components/ComposableTable/hooks/useTableToolsForComposable.js

View workflow job for this annotation

GitHub Actions / build (21.x)

Missing JSDoc @param "options.total" declaration

Check warning on line 3 in src/components/TableToolsTable/components/ComposableTable/hooks/useTableToolsForComposable.js

View workflow job for this annotation

GitHub Actions / build (21.x)

Missing JSDoc @param "options.view" declaration

Check warning on line 3 in src/components/TableToolsTable/components/ComposableTable/hooks/useTableToolsForComposable.js

View workflow job for this annotation

GitHub Actions / build (21.x)

Missing JSDoc @param "options.loading" declaration

Check warning on line 3 in src/components/TableToolsTable/components/ComposableTable/hooks/useTableToolsForComposable.js

View workflow job for this annotation

GitHub Actions / build (22.x)

Missing JSDoc @param "options.tableProps.rows" declaration

Check warning on line 3 in src/components/TableToolsTable/components/ComposableTable/hooks/useTableToolsForComposable.js

View workflow job for this annotation

GitHub Actions / build (22.x)

Missing JSDoc @param "options.tableProps.cells" declaration

Check warning on line 3 in src/components/TableToolsTable/components/ComposableTable/hooks/useTableToolsForComposable.js

View workflow job for this annotation

GitHub Actions / build (22.x)

Missing JSDoc @param "options.tableProps" declaration

Check warning on line 3 in src/components/TableToolsTable/components/ComposableTable/hooks/useTableToolsForComposable.js

View workflow job for this annotation

GitHub Actions / build (22.x)

Missing JSDoc @param "options.expandable" declaration

Check warning on line 3 in src/components/TableToolsTable/components/ComposableTable/hooks/useTableToolsForComposable.js

View workflow job for this annotation

GitHub Actions / build (22.x)

Missing JSDoc @param "options.bulkSelect" declaration

Check warning on line 3 in src/components/TableToolsTable/components/ComposableTable/hooks/useTableToolsForComposable.js

View workflow job for this annotation

GitHub Actions / build (22.x)

Missing JSDoc @param "options.total" declaration

Check warning on line 3 in src/components/TableToolsTable/components/ComposableTable/hooks/useTableToolsForComposable.js

View workflow job for this annotation

GitHub Actions / build (22.x)

Missing JSDoc @param "options.view" declaration

Check warning on line 3 in src/components/TableToolsTable/components/ComposableTable/hooks/useTableToolsForComposable.js

View workflow job for this annotation

GitHub Actions / build (22.x)

Missing JSDoc @param "options.loading" declaration
* This hook is an adapter to put required props into the right place and
* form to be consumable by the ComposableTable components
*
* @param {object} [options] AsyncTableTools options

@qltysh qltysh Bot Jul 12, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 11 issues:

1. Missing @param "options.toolbarProps.pagination" [eslint:jsdoc/check-param-names]


2. Missing @param "options.loading" [eslint:jsdoc/check-param-names]


3. Missing @param "options.tableProps" [eslint:jsdoc/check-param-names]


4. Missing @param "options.tableProps.cells" [eslint:jsdoc/check-param-names]


5. Missing @param "options.tableProps.rows" [eslint:jsdoc/check-param-names]


6. Missing @param "options.tableProps.tableTree" [eslint:jsdoc/check-param-names]


7. Missing @param "options.toolbarProps" [eslint:jsdoc/check-param-names]


8. Missing @param "options.bulkSelect" [eslint:jsdoc/check-param-names]


9. Missing @param "options.total" [eslint:jsdoc/check-param-names]


10. Missing @param "options.view" [eslint:jsdoc/check-param-names]


11. Missing @param "options.expandable" [eslint:jsdoc/check-param-names]

*
* @returns {object}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing JSDoc @returns description. [eslint:jsdoc/require-returns-description]

*
* @group Hooks
*
Comment thread
qltysh[bot] marked this conversation as resolved.
Comment thread
qltysh[bot] marked this conversation as resolved.
Comment on lines +3 to +12

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 11 issues:

1. Missing JSDoc @param "options.bulkSelect" declaration. [eslint:jsdoc/require-param]


2. Missing JSDoc @param "options.expandable" declaration. [eslint:jsdoc/require-param]


3. Missing JSDoc @param "options.loading" declaration. [eslint:jsdoc/require-param]


4. Missing JSDoc @param "options.tableProps" declaration. [eslint:jsdoc/require-param]


5. Missing JSDoc @param "options.tableProps.cells" declaration. [eslint:jsdoc/require-param]


6. Missing JSDoc @param "options.tableProps.rows" declaration. [eslint:jsdoc/require-param]


7. Missing JSDoc @param "options.tableProps.tableTree" declaration. [eslint:jsdoc/require-param]


8. Missing JSDoc @param "options.toolbarProps" declaration. [eslint:jsdoc/require-param]


9. Missing JSDoc @param "options.toolbarProps.pagination" declaration. [eslint:jsdoc/require-param]


10. Missing JSDoc @param "options.total" declaration. [eslint:jsdoc/require-param]


11. Missing JSDoc @param "options.view" declaration. [eslint:jsdoc/require-param]

*/
const useTableToolsForComposable = ({
loading,
view,
total,
bulkSelect,
expandable,
tableProps: { cells: columns, rows, tableTree },
toolbarProps: { pagination },
}) => {
const composableReturn = useMemo(
() => ({
columns,
rows,
tableTree,
loading,
view,
pagination,
bulkSelect,
expandable,
total,
}),
[
columns,
rows,
tableTree,
loading,
view,
pagination,
bulkSelect,
total,
expandable,
],
);

return composableReturn;
};

export default useTableToolsForComposable;
Loading
Loading