Skip to content

Commit 87d94f7

Browse files
committed
fix: removing the draggable functionality, implementing requested changes and addign test
1 parent 2fbf5b1 commit 87d94f7

File tree

12 files changed

+132
-483
lines changed

12 files changed

+132
-483
lines changed

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

Lines changed: 0 additions & 72 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@ const columns: DataViewTh[] = [
6363
const ouiaId = 'TableExample';
6464

6565
export const BasicExample: FunctionComponent = () => (
66-
<DataViewTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={rows} isExpandable={true}/>
66+
<DataViewTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={rows} />
6767
);

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { FunctionComponent, useState } from 'react';
2-
import { DataViewTable, DataViewTr, DataViewTh, ExpandableContent } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
2+
import { DataViewTable, DataViewTr, DataViewTh } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
3+
import { ExpandableContent } from '@patternfly/react-data-view/dist/dynamic/DataViewTableBasic';
34
import { ExclamationCircleIcon } from '@patternfly/react-icons';
45
import { Button, Toolbar, ToolbarContent, ToolbarItem, Switch } from '@patternfly/react-core';
56

@@ -75,7 +76,6 @@ const ouiaId = 'TableInteractiveExample';
7576
export const InteractiveExample: FunctionComponent = () => {
7677
const [isExpandable, setIsExpandable] = useState(true);
7778
const [isSticky, setIsSticky] = useState(true);
78-
const [isDraggable, setIsDraggable] = useState(true);
7979

8080
// Generate rows based on current settings
8181
const rows: DataViewTr[] = repositories.map(({ id, name, branches, prs, workspaces, lastCommit, contributors, stars, forks }) => [
@@ -130,15 +130,6 @@ export const InteractiveExample: FunctionComponent = () => {
130130
aria-label="Toggle sticky header and columns"
131131
/>
132132
</ToolbarItem>
133-
<ToolbarItem>
134-
<Switch
135-
id="draggable-switch"
136-
label="Draggable rows"
137-
isChecked={isDraggable}
138-
onChange={(_event, checked) => setIsDraggable(checked)}
139-
aria-label="Toggle draggable rows"
140-
/>
141-
</ToolbarItem>
142133
</ToolbarContent>
143134
</Toolbar>
144135
<div style={{ height: '400px', overflow: 'auto' }}>
@@ -150,7 +141,6 @@ export const InteractiveExample: FunctionComponent = () => {
150141
expandedRows={isExpandable ? expandableContents : undefined}
151142
isExpandable={isExpandable}
152143
isSticky={isSticky}
153-
isDraggable={isDraggable}
154144
/>
155145
</div>
156146
</>

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

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -111,27 +111,9 @@ When sticky headers and columns are enabled:
111111

112112
```
113113

114-
## Draggable rows
115-
116-
To enable drag-and-drop functionality for table rows, set the `isDraggable` prop to `true` on the `<DataViewTable>` component. This allows users to reorder rows by dragging them to a new position.
117-
118-
When draggable rows are enabled:
119-
- A drag handle icon appears at the beginning of each row
120-
- Users can click and drag the handle or anywhere on the row to reorder rows
121-
- Visual feedback is provided during the drag operation with a ghost row effect
122-
- The new order is maintained after the drop
123-
124-
The draggable functionality is built using the `useDraggableRows` hook internally, which manages the drag-and-drop state and DOM manipulation.
125-
126-
### Draggable rows example
127-
128-
```js file="./DataViewTableDraggableExample.tsx"
129-
130-
```
131-
132114
### Interactive example
133115
- Interactive example show how the different composable options work together.
134-
- By toggling the toggles you can switch between them and observe the bahaviour
116+
- By toggling the toggles you can switch between them and observe the behaviour
135117

136118
```js file="./DataViewTableInteractiveExample.tsx"
137119

packages/module/patternfly-docs/generated/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ module.exports = {
1414
'/extensions/data-view/table/react': {
1515
id: "Table",
1616
title: "Data view table",
17-
toc: [{"text":"Configuring rows and columns"},[{"text":"Table example"}],{"text":"Expandable rows"},[{"text":"Expandable rows example"}],{"text":"Sticky header and columns"},[{"text":"Sticky header and columns example"}],{"text":"Draggable rows"},[{"text":"Draggable rows example"},{"text":"Interactive example"},{"text":"Resizable columns"}],{"text":"Tree table"},[{"text":"Tree table example"}],{"text":"Sorting"},[{"text":"Sorting example"},{"text":"Sorting state"}],{"text":"States"},[{"text":"Empty"},{"text":"Error"},{"text":"Loading"}]],
18-
examples: ["Table example","Expandable rows example","Sticky header and columns example","Draggable rows example","Interactive example","Resizable columns","Tree table example","Sorting example","Empty","Error","Loading"],
17+
toc: [{"text":"Configuring rows and columns"},[{"text":"Table example"}],{"text":"Expandable rows"},[{"text":"Expandable rows example"}],{"text":"Sticky header and columns"},[{"text":"Sticky header and columns example"},{"text":"Interactive example"},{"text":"Resizable columns"}],{"text":"Tree table"},[{"text":"Tree table example"}],{"text":"Sorting"},[{"text":"Sorting example"},{"text":"Sorting state"}],{"text":"States"},[{"text":"Empty"},{"text":"Error"},{"text":"Loading"}]],
18+
examples: ["Table example","Expandable rows example","Sticky header and columns example","Interactive example","Resizable columns","Tree table example","Sorting example","Empty","Error","Loading"],
1919
section: "extensions",
2020
subsection: "Data view",
2121
source: "react",

packages/module/src/DataViewTable/__snapshots__/DataViewTable.test.tsx.snap

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ exports[`DataViewTable component should render a basic table correctly 1`] = `
7171
data-ouia-component-id="TableExample-tr-0"
7272
data-ouia-component-type="PF6/TableRow"
7373
data-ouia-safe="true"
74-
draggable="false"
75-
id="row-0"
7674
>
7775
<td
7876
class="pf-v6-c-table__td"
@@ -110,18 +108,11 @@ exports[`DataViewTable component should render a basic table correctly 1`] = `
110108
Timestamp one
111109
</td>
112110
</tr>
113-
</tbody>
114-
<tbody
115-
class="pf-v6-c-table__tbody"
116-
role="rowgroup"
117-
>
118111
<tr
119112
class="pf-v6-c-table__tr pf-v6-c-table__control-row"
120113
data-ouia-component-id="TableExample-tr-1"
121114
data-ouia-component-type="PF6/TableRow"
122115
data-ouia-safe="true"
123-
draggable="false"
124-
id="row-1"
125116
>
126117
<td
127118
class="pf-v6-c-table__td"
@@ -159,18 +150,11 @@ exports[`DataViewTable component should render a basic table correctly 1`] = `
159150
Timestamp two
160151
</td>
161152
</tr>
162-
</tbody>
163-
<tbody
164-
class="pf-v6-c-table__tbody"
165-
role="rowgroup"
166-
>
167153
<tr
168154
class="pf-v6-c-table__tr pf-v6-c-table__control-row"
169155
data-ouia-component-id="TableExample-tr-2"
170156
data-ouia-component-type="PF6/TableRow"
171157
data-ouia-safe="true"
172-
draggable="false"
173-
id="row-2"
174158
>
175159
<td
176160
class="pf-v6-c-table__td"
@@ -208,18 +192,11 @@ exports[`DataViewTable component should render a basic table correctly 1`] = `
208192
Timestamp three
209193
</td>
210194
</tr>
211-
</tbody>
212-
<tbody
213-
class="pf-v6-c-table__tbody"
214-
role="rowgroup"
215-
>
216195
<tr
217196
class="pf-v6-c-table__tr pf-v6-c-table__control-row"
218197
data-ouia-component-id="TableExample-tr-3"
219198
data-ouia-component-type="PF6/TableRow"
220199
data-ouia-safe="true"
221-
draggable="false"
222-
id="row-3"
223200
>
224201
<td
225202
class="pf-v6-c-table__td"
@@ -257,18 +234,11 @@ exports[`DataViewTable component should render a basic table correctly 1`] = `
257234
Timestamp four
258235
</td>
259236
</tr>
260-
</tbody>
261-
<tbody
262-
class="pf-v6-c-table__tbody"
263-
role="rowgroup"
264-
>
265237
<tr
266238
class="pf-v6-c-table__tr pf-v6-c-table__control-row"
267239
data-ouia-component-id="TableExample-tr-4"
268240
data-ouia-component-type="PF6/TableRow"
269241
data-ouia-safe="true"
270-
draggable="false"
271-
id="row-4"
272242
>
273243
<td
274244
class="pf-v6-c-table__td"
@@ -306,18 +276,11 @@ exports[`DataViewTable component should render a basic table correctly 1`] = `
306276
Timestamp five
307277
</td>
308278
</tr>
309-
</tbody>
310-
<tbody
311-
class="pf-v6-c-table__tbody"
312-
role="rowgroup"
313-
>
314279
<tr
315280
class="pf-v6-c-table__tr pf-v6-c-table__control-row"
316281
data-ouia-component-id="TableExample-tr-5"
317282
data-ouia-component-type="PF6/TableRow"
318283
data-ouia-safe="true"
319-
draggable="false"
320-
id="row-5"
321284
>
322285
<td
323286
class="pf-v6-c-table__td"

packages/module/src/DataViewTableBasic/DataViewTableBasic.test.tsx

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { render } from '@testing-library/react';
1+
import { render, screen } from '@testing-library/react';
2+
import userEvent from '@testing-library/user-event';
23
import { DataView } from '../DataView';
3-
import { DataViewTableBasic } from './DataViewTableBasic';
4+
import { DataViewTableBasic, ExpandableContent } from './DataViewTableBasic';
45

56
interface Repository {
7+
id: number;
68
name: string;
79
branches: string | null;
810
prs: string | null;
@@ -11,20 +13,28 @@ interface Repository {
1113
}
1214

1315
const repositories: Repository[] = [
14-
{ name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
15-
{ name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
16-
{ name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
17-
{ name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
18-
{ name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
19-
{ name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
16+
{ id: 1, name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
17+
{ id: 2, name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
18+
{ id: 3, name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
19+
{ id: 4, name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
20+
{ id: 5, name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
21+
{ id: 6, name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
2022
];
2123

22-
const rows = repositories.map(repo => ({
23-
row: Object.values(repo),
24-
}));
24+
const rows = repositories.map(({ id, name, branches, prs, workspaces, lastCommit }) => [
25+
{ id, cell: name },
26+
branches,
27+
prs,
28+
workspaces,
29+
lastCommit
30+
]);
2531

2632
const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
2733

34+
const expandableContents: ExpandableContent[] = [
35+
{ rowId: 1, columnId: 1, content: <div>Branch details for Repository one</div> },
36+
];
37+
2838
const ouiaId = 'TableExample';
2939

3040
describe('DataViewTable component', () => {
@@ -57,8 +67,40 @@ describe('DataViewTable component', () => {
5767
const { container } = render(
5868
<DataView activeState="loading">
5969
<DataViewTableBasic aria-label='Repositories table' ouiaId={ouiaId} columns={columns} bodyStates={{ loading: "Data is loading" }} rows={[]} />
60-
</DataView>
70+
</DataView>
6171
);
6272
expect(container).toMatchSnapshot();
6373
});
74+
75+
test('when isExpandable cell should be clickable and expandable', async () => {
76+
const user = userEvent.setup();
77+
78+
render(
79+
<DataViewTableBasic
80+
aria-label='Repositories table'
81+
ouiaId={ouiaId}
82+
columns={columns}
83+
rows={rows}
84+
isExpandable={true}
85+
expandedRows={expandableContents}
86+
/>
87+
);
88+
89+
// Initially, expandable content is rendered but should be hidden (not visible)
90+
const initialBranchContent = screen.getByText('Branch details for Repository one');
91+
expect(initialBranchContent.closest('tr')?.classList.contains('pf-m-expanded')).toBeFalsy();
92+
93+
// Find the first expandable button by ID
94+
const branchExpandButton = document.getElementById('expandable-0-0-1');
95+
expect(branchExpandButton).toBeTruthy();
96+
// Verify the button is in the cell with "Branch one" text
97+
expect(branchExpandButton?.closest('td')?.textContent).toContain('Branch one');
98+
99+
// Click the expand button for Branches column
100+
await user.click(branchExpandButton!);
101+
102+
// After clicking, the expandable content should be visible
103+
const branchContent = screen.getByText('Branch details for Repository one');
104+
expect(branchContent.closest('tr')?.classList.contains('pf-m-expanded')).toBeTruthy();
105+
});
64106
});

0 commit comments

Comments
 (0)