Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #38154 - Allow generic table children outside of tbody #10419

Merged
merged 1 commit into from
Jan 24, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const Table = ({
idColumn,
children,
bottomPagination,
childrenOutsideTbody, // Expendable table rows are each a Tbody so they cant be inside the Tbody
}) => {
const onPagination = newPagination => {
setParams({ ...params, ...newPagination });
Expand Down Expand Up @@ -123,6 +124,7 @@ export const Table = ({
))}
</Tr>
</Thead>
{childrenOutsideTbody ? children : null}
<Tbody>
{isPending && results.length === 0 && (
<Tr ouiaId="table-loading">
Expand Down Expand Up @@ -160,34 +162,39 @@ export const Table = ({
</Td>
</Tr>
)}
{children ||
results.map((result, rowIndex) => {
const rowActions = actions(result);
return (
<Tr key={rowIndex} ouiaId={`table-row-${rowIndex}`} isHoverable>
{showCheckboxes && (
<RowSelectTd
rowData={result}
selectOne={selectOne}
isSelected={isSelected}
idColumnName={idColumn}
/>
)}
{columnNamesKeys.map(k => (
<Td key={k} dataLabel={keysToColumnNames[k]}>
{columns[k].wrapper
? columns[k].wrapper(result)
: result[k]}
{!childrenOutsideTbody &&
(children ||
adamruzicka marked this conversation as resolved.
Show resolved Hide resolved
results.map((result, rowIndex) => {
const rowActions = actions(result);
return (
<Tr
key={rowIndex}
ouiaId={`table-row-${rowIndex}`}
isHoverable
>
{showCheckboxes && (
<RowSelectTd
rowData={result}
selectOne={selectOne}
isSelected={isSelected}
idColumnName={idColumn}
/>
)}
{columnNamesKeys.map(k => (
<Td key={k} dataLabel={keysToColumnNames[k]}>
{columns[k].wrapper
? columns[k].wrapper(result)
: result[k]}
</Td>
))}
<Td isActionCell>
{rowActions.length ? (
<ActionsColumn items={rowActions} />
) : null}
</Td>
))}
<Td isActionCell>
{rowActions.length ? (
<ActionsColumn items={rowActions} />
) : null}
</Td>
</Tr>
);
})}
</Tr>
);
}))}
</Tbody>
</TableComposable>
{results.length > 0 && !errorMessage && !emptyMessage && bottomPagination}
Expand Down Expand Up @@ -222,6 +229,7 @@ Table.propTypes = {
isSelected: PropTypes.func,
showCheckboxes: PropTypes.bool,
bottomPagination: PropTypes.node,
childrenOutsideTbody: PropTypes.bool,
};

Table.defaultProps = {
Expand All @@ -241,4 +249,5 @@ Table.defaultProps = {
isSelected: noop,
showCheckboxes: false,
bottomPagination: null,
childrenOutsideTbody: false,
};
Loading