Skip to content

Commit c6a0951

Browse files
committed
feat: component stickible
1 parent 5d3ec4c commit c6a0951

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

packages/module/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableExpandableExample.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const expandableContents: ExpandableContent[] = [
1717
// Row 1 - Repository one
1818
{ row_id: 1, column_id: 2, content: <div><strong>Branch Details:</strong> 5 active branches, main, develop, feature/new-ui, hotfix/bug-123, release/v2.0</div> },
1919
{ row_id: 1, column_id: 3, content: <div><strong>PR Details:</strong> 3 open PRs, 45 merged this month, avg review time: 2 days</div> },
20-
{ row_id: 1, column_id: 4, content: <div><strong>Workspace Info:</strong> Production env, 5 active deployments, last updated 2 hours ago</div> },
2120
{ row_id: 1, column_id: 5, content: <div><strong>Commit Info:</strong> Author: John Doe, Message: "Fix critical authentication bug", SHA: a1b2c3d</div> },
2221

2322
// Row 2 - Repository two
@@ -110,7 +109,7 @@ const columns: DataViewTh[] = [
110109
'Repositories',
111110
{ cell: <>Branches<ExclamationCircleIcon className='pf-v6-u-ml-sm' color="var(--pf-t--global--color--status--danger--default)"/></> },
112111
'Pull requests',
113-
{ cell: 'Workspaces', props: { info: { tooltip: 'More information' } } },
112+
{ cell: 'Workspaces', props: { info: { tooltip: 'More information' }, isStickyColumn: true} },
114113
{ cell: 'Last commit', props: { sort: { sortBy: {}, columnIndex: 4 } } },
115114
];
116115

packages/module/src/DataViewTableBasic/DataViewTableBasic.tsx

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { FC, useMemo, useState } from 'react';
22
import {
33
expandable,
44
ExpandableRowContent,
5+
InnerScrollContainer,
6+
OuterScrollContainer,
57
Table,
68
TableProps,
79
Tbody,
@@ -37,6 +39,10 @@ export interface DataViewTableBasicProps extends Omit<TableProps, 'onSelect' | '
3739
hasResizableColumns?: boolean;
3840
/** Toggles expandable */
3941
isExpandable?: boolean;
42+
/** Toogles sticky colums and headder */
43+
isSticky?: boolean;
44+
/** Toogles draggable rows */
45+
isDraggable?: boolean;
4046
}
4147

4248
export const DataViewTableBasic: FC<DataViewTableBasicProps> = ({
@@ -48,6 +54,8 @@ export const DataViewTableBasic: FC<DataViewTableBasicProps> = ({
4854
bodyStates,
4955
hasResizableColumns,
5056
isExpandable,
57+
isSticky = false,
58+
isDraggable = true,
5159
...props
5260
}: DataViewTableBasicProps) => {
5361
const { selection, activeState, isSelectable } = useInternalContext();
@@ -70,13 +78,13 @@ export const DataViewTableBasic: FC<DataViewTableBasicProps> = ({
7078
const rowId = isDataViewTdObject(firstCell) ? (firstCell as any).id : undefined;
7179

7280
// Find the matching expanded content by row_id and column_id
73-
const expandedRowContent = expandedRows?.find(
81+
const expandedRowContent = isExpandable ? expandedRows?.find(
7482
(content) => content.row_id === rowId && content.column_id === expandedColIndex
75-
);
83+
) : undefined;
7684

7785
return (
7886
<Tbody key={rowIndex} isExpanded={isRowExpanded}>
79-
<Tr ouiaId={`${ouiaId}-tr-${rowIndex}`} {...(rowIsObject && row?.props)} isContentExpanded={isRowExpanded} isControlRow>
87+
<Tr ouiaId={`${ouiaId}-tr-${rowIndex}`} {...(rowIsObject && row?.props)} isContentExpanded={isRowExpanded} isControlRow draggable={isDraggable}>
8088
{isSelectable && (
8189
<Td
8290
key={`select-${rowIndex}`}
@@ -92,9 +100,9 @@ export const DataViewTableBasic: FC<DataViewTableBasicProps> = ({
92100
)}
93101
{(rowIsObject ? row.row : row).map((cell, colIndex) => {
94102
const cellIsObject = isDataViewTdObject(cell);
95-
const cellExpandableContent = expandedRows?.find(
103+
const cellExpandableContent = isExpandable ? expandedRows?.find(
96104
(content) => content.row_id === rowId && content.column_id === colIndex
97-
);
105+
) : undefined;
98106
return (
99107
<Td
100108
key={colIndex}
@@ -136,6 +144,20 @@ export const DataViewTableBasic: FC<DataViewTableBasicProps> = ({
136144
);
137145
}), [ rows, isSelectable, isSelected, isSelectDisabled, onSelect, ouiaId, expandedRowsState, expandedColumnIndex, expandedRows, columns.length ]);
138146

147+
if(isSticky)
148+
{
149+
return(
150+
<OuterScrollContainer>
151+
<InnerScrollContainer>
152+
<Table aria-label="Data table" ouiaId={ouiaId} isExpandable={isExpandable} {...props} isStickyHeader>
153+
{ activeHeadState || <DataViewTableHead columns={columns} ouiaId={ouiaId} hasResizableColumns={hasResizableColumns} /> }
154+
{ activeBodyState || renderedRows }
155+
</Table>
156+
</InnerScrollContainer>
157+
</OuterScrollContainer>
158+
)
159+
}
160+
else
139161
return (
140162
<Table aria-label="Data table" ouiaId={ouiaId} isExpandable={isExpandable} {...props}>
141163
{ activeHeadState || <DataViewTableHead columns={columns} ouiaId={ouiaId} hasResizableColumns={hasResizableColumns} /> }

0 commit comments

Comments
 (0)