Skip to content

Commit db16087

Browse files
authored
chore(Table): Update sticky header demo to use latest Table component (#9185)
1 parent 0f4a1d0 commit db16087

File tree

8 files changed

+94
-83
lines changed

8 files changed

+94
-83
lines changed

packages/react-table/src/docs/demos/Table.md

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import AttentionBellIcon from '@patternfly/react-icons/dist/esm/icons/attention-
5050
import DashboardWrapper from '@patternfly/react-core/src/demos/examples/DashboardWrapper';
5151
import BlueprintIcon from '@patternfly/react-icons/dist/esm/icons/blueprint-icon';
5252
import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon';
53-
import { rows, columns } from '../examples/Data.jsx';
53+
import { rows, columns } from './table-demos/sampleData';
5454

5555
## Demos
5656

@@ -855,7 +855,7 @@ import {
855855
import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon';
856856
import FilterIcon from '@patternfly/react-icons/dist/esm/icons/filter-icon';
857857
import { Table, TableText, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
858-
import { rows, columns } from '../../examples/Data.jsx';
858+
import { rows, columns } from '';
859859

860860
class FilterTableDemo extends React.Component {
861861
constructor(props) {
@@ -1426,70 +1426,8 @@ class ComplexPaginationTableDemo extends React.Component {
14261426

14271427
### Sticky header
14281428

1429-
```js isFullscreen
1430-
import React from 'react';
1431-
import { Label, PageSection } from '@patternfly/react-core';
1432-
import { Table as TableDeprecated, TableHeader, TableBody } from '@patternfly/react-table/deprecated';
1433-
import { rows } from '../examples/Data.jsx';
1434-
1435-
class StickyHeaderTableDemo extends React.Component {
1436-
render() {
1437-
const renderLabel = (labelText) => {
1438-
switch (labelText) {
1439-
case 'Running':
1440-
return <Label color="green">{labelText}</Label>;
1441-
case 'Stopped':
1442-
return <Label color="orange">{labelText}</Label>;
1443-
case 'Needs maintenance':
1444-
return <Label color="blue">{labelText}</Label>;
1445-
case 'Down':
1446-
return <Label color="red">{labelText}</Label>;
1447-
}
1448-
};
1429+
```js isFullscreen file="./table-demos/StickyHeader.jsx"
14491430

1450-
return (
1451-
<DashboardWrapper hasPageTemplateTitle>
1452-
<PageSection padding={{ default: 'noPadding', xl: 'padding' }}>
1453-
<Card component="div">
1454-
<TableDeprecated
1455-
cells={[
1456-
{ title: 'Servers', transforms: [cellWidth(15)] },
1457-
{ title: 'Threads', transforms: [cellWidth(10)] },
1458-
{ title: 'Applications', transforms: [cellWidth(10)] },
1459-
{ title: 'Workspaces', transforms: [cellWidth(10)] },
1460-
{ title: 'Status', transforms: [cellWidth(10)] },
1461-
{ title: 'Location', transforms: [cellWidth(15)] },
1462-
{ title: 'Last Modified', transforms: [cellWidth(15)] },
1463-
{ title: 'URL', transforms: [cellWidth(10)] }
1464-
]}
1465-
rows={rows.map((row) => [
1466-
row.name,
1467-
row.threads,
1468-
row.applications,
1469-
row.workspaces,
1470-
{ title: renderLabel(row.status) },
1471-
row.location,
1472-
row.lastModified,
1473-
{
1474-
title: (
1475-
<a href="#">
1476-
<TableText wrapModifier="truncate">{row.url} </TableText>
1477-
</a>
1478-
)
1479-
}
1480-
])}
1481-
aria-label="Sticky Header Table Demo"
1482-
isStickyHeader
1483-
>
1484-
<TableHeader />
1485-
<TableBody />
1486-
</TableDeprecated>
1487-
</Card>
1488-
</PageSection>
1489-
</DashboardWrapper>
1490-
);
1491-
}
1492-
}
14931431
```
14941432

14951433
### Sticky first column

packages/react-table/src/docs/demos/table-demos/BulkSelect.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
23
import {
34
Dropdown,
45
DropdownList,
@@ -14,7 +15,8 @@ import {
1415
} from '@patternfly/react-core';
1516
import { Table, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
1617
import DashboardWrapper from '@patternfly/react-core/src/demos/examples/DashboardWrapper';
17-
import { rows, columns } from '../../examples/Data.jsx';
18+
19+
import { rows, columns } from './sampleData';
1820

1921
export const BulkSelectTableDemo = () => {
2022
const [isBulkSelectDropdownOpen, setIsBulkSelectDropdownOpen] = React.useState(false);

packages/react-table/src/docs/demos/table-demos/ColumnManagement.jsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import * as React from 'react';
1+
import React from 'react';
2+
23
import {
34
Button,
45
DataList,
@@ -26,10 +27,11 @@ import {
2627
import { Table, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
2728
import FilterIcon from '@patternfly/react-icons/dist/esm/icons/filter-icon';
2829
import SortAmountDownIcon from '@patternfly/react-icons/dist/esm/icons/sort-amount-down-icon';
29-
import { rows, columns } from '../../examples/Data.jsx';
3030
import DashboardWrapper from '@patternfly/react-core/src/demos/examples/DashboardWrapper.js';
3131
import { capitalize } from '@patternfly/react-table/src/components/Table/utils/utils';
3232

33+
import { rows, columns } from './sampleData';
34+
3335
export const ColumnManagementAction = () => {
3436
const defaultColumns = columns;
3537
const defaultRows = rows;
@@ -389,10 +391,14 @@ export const ColumnManagementAction = () => {
389391
<ToolbarItem variant="overflow-menu">
390392
<OverflowMenu breakpoint="md">
391393
<OverflowMenuItem>
392-
<MenuToggle><FilterIcon /> Name</MenuToggle>
394+
<MenuToggle>
395+
<FilterIcon /> Name
396+
</MenuToggle>
393397
</OverflowMenuItem>
394398
<OverflowMenuItem>
395-
<MenuToggle variant="plain" aria-label="Sort columns"><SortAmountDownIcon aria-hidden="true" /></MenuToggle>
399+
<MenuToggle variant="plain" aria-label="Sort columns">
400+
<SortAmountDownIcon aria-hidden="true" />
401+
</MenuToggle>
396402
</OverflowMenuItem>
397403
<OverflowMenuGroup groupType="button" isPersistent>
398404
<OverflowMenuItem>

packages/react-table/src/docs/demos/table-demos/Compact.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
23
import {
34
Button,
45
Card,
@@ -14,10 +15,10 @@ import {
1415
ToolbarItem
1516
} from '@patternfly/react-core';
1617
import { Table, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
17-
1818
import FilterIcon from '@patternfly/react-icons/dist/esm/icons/filter-icon';
1919
import DashboardWrapper from '@patternfly/react-core/src/demos/examples/DashboardWrapper';
20-
import { rows, columns } from '../../examples/Data.jsx';
20+
21+
import { rows, columns } from './sampleData';
2122

2223
export const CompactTable = () => {
2324
const [isSelectOpen, setIsSelectOpen] = React.useState(false);

packages/react-table/src/docs/demos/table-demos/SortableResponsive.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
23
import {
34
Button,
45
Card,
@@ -21,7 +22,6 @@ import {
2122
ToolbarItem
2223
} from '@patternfly/react-core';
2324
import { Table, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
24-
import { rows, columns } from '../../examples/Data.jsx';
2525
import CloneIcon from '@patternfly/react-icons/dist/esm/icons/clone-icon';
2626
import EditIcon from '@patternfly/react-icons/dist/esm/icons/edit-icon';
2727
import SyncIcon from '@patternfly/react-icons/dist/esm/icons/sync-icon';
@@ -32,6 +32,8 @@ import CubeIcon from '@patternfly/react-icons/dist/esm/icons/cube-icon';
3232
import DashboardWrapper from '@patternfly/react-core/src/demos/examples/DashboardWrapper';
3333
import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon';
3434

35+
import { rows, columns } from './sampleData';
36+
3537
export const ComposableTableSortable = () => {
3638
const [isKebabDropdownOpen, setIsKebabDropdownOpen] = React.useState(false);
3739

packages/react-table/src/docs/demos/table-demos/StaticBottomPagination.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
23
import {
34
Button,
45
Card,
@@ -15,11 +16,11 @@ import {
1516
SelectOption
1617
} from '@patternfly/react-core';
1718
import { Table, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
18-
import { rows, columns } from '../../examples/Data.jsx';
19-
2019
import FilterIcon from '@patternfly/react-icons/dist/esm/icons/filter-icon';
2120
import DashboardWrapper from '@patternfly/react-core/src/demos/examples/DashboardWrapper';
2221

22+
import { rows, columns } from './sampleData';
23+
2324
export const StaticBottomPagination = () => {
2425
const [isSelectOpen, setIsSelectOpen] = React.useState(false);
2526
const [page, setPage] = React.useState(1);
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React from 'react';
2+
3+
import { Card, Label, PageSection } from '@patternfly/react-core';
4+
import { Table, Thead, Tr, Th, Tbody, Td, TableText } from '@patternfly/react-table';
5+
import DashboardWrapper from '@patternfly/react-core/src/demos/examples/DashboardWrapper';
6+
7+
import { rows, columns } from '../examples/Data';
8+
9+
export const StickyHeader: React.FunctionComponent = () => {
10+
const renderLabel = (labelText: string) => {
11+
switch (labelText) {
12+
case 'Running':
13+
return <Label color="green">{labelText}</Label>;
14+
case 'Stopped':
15+
return <Label color="orange">{labelText}</Label>;
16+
case 'Needs Maintenance':
17+
return <Label color="blue">{labelText}</Label>;
18+
case 'Down':
19+
return <Label color="red">{labelText}</Label>;
20+
}
21+
};
22+
23+
return (
24+
<DashboardWrapper hasPageTemplateTitle>
25+
<PageSection padding={{ default: 'noPadding', xl: 'padding' }}>
26+
<Card component="div">
27+
<Table aria-label="Sticky Header Table Demo" isStickyHeader>
28+
<Thead>
29+
<Tr>
30+
<Th width={15}>{columns[0]}</Th>
31+
<Th width={10}>{columns[1]}</Th>
32+
<Th width={10}>{columns[2]}</Th>
33+
<Th width={10}>{columns[3]}</Th>
34+
<Th width={10}>{columns[4]}</Th>
35+
<Th width={15}>{columns[5]}</Th>
36+
<Th width={15}>{columns[6]}</Th>
37+
<Th width={10}>{columns[7]}</Th>
38+
</Tr>
39+
</Thead>
40+
<Tbody>
41+
{rows.map((row) => (
42+
<Tr key={row.name}>
43+
<Td dataLabel={columns[0]}>{row.name}</Td>
44+
<Td dataLabel={columns[1]}>{row.threads}</Td>
45+
<Td dataLabel={columns[2]}>{row.applications}</Td>
46+
<Td dataLabel={columns[3]}>{row.workspaces}</Td>
47+
<Td dataLabel={columns[4]}>{renderLabel(row.status)}</Td>
48+
<Td dataLabel={columns[5]}>{row.location}</Td>
49+
<Td dataLabel={columns[6]}>{row.lastModified}</Td>
50+
<Td dataLabel={columns[7]}>
51+
<a href="#">
52+
<TableText wrapModifier="truncate">{row.url} </TableText>
53+
</a>
54+
</Td>
55+
</Tr>
56+
))}
57+
</Tbody>
58+
</Table>
59+
</Card>
60+
</PageSection>
61+
</DashboardWrapper>
62+
);
63+
};

packages/react-table/src/docs/examples/Data.jsx renamed to packages/react-table/src/docs/demos/table-demos/sampleData.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
const getRandomInteger = (min, max) => (
2-
Math.floor(Math.random() * (max - min + 1)) + min
3-
);
1+
const getRandomInteger = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
42

53
export const columns = [
64
'Servers',
@@ -14,7 +12,7 @@ export const columns = [
1412
];
1513

1614
export const rows = [
17-
{
15+
{
1816
name: 'US-Node 1',
1917
threads: getRandomInteger(1, 20),
2018
applications: getRandomInteger(1, 50),
@@ -24,7 +22,7 @@ export const rows = [
2422
lastModified: '2 hours ago',
2523
url: 'http://www.redhat.com/en/office-locations/US-node1'
2624
},
27-
{
25+
{
2826
name: 'US-Node 2',
2927
threads: getRandomInteger(1, 20),
3028
applications: getRandomInteger(1, 50),
@@ -34,7 +32,7 @@ export const rows = [
3432
lastModified: '5 hours ago',
3533
url: 'http://www.redhat.com/en/office-locations/US-node2'
3634
},
37-
{
35+
{
3836
name: 'US-Node 3',
3937
threads: getRandomInteger(1, 20),
4038
applications: getRandomInteger(1, 50),
@@ -734,7 +732,7 @@ export const rows = [
734732
lastModified: '20 minutes ago',
735733
url: 'http://www.redhat.com/en/office-locations/Bangalore-node13'
736734
},
737-
{
735+
{
738736
name: 'Bangalore-Node 14',
739737
threads: getRandomInteger(1, 20),
740738
applications: getRandomInteger(1, 50),
@@ -744,7 +742,7 @@ export const rows = [
744742
lastModified: '4 hours ago',
745743
url: 'http://www.redhat.com/en/office-locations/Bangalore-node14'
746744
},
747-
{
745+
{
748746
name: 'Bangalore-Node 15',
749747
threads: getRandomInteger(1, 20),
750748
applications: getRandomInteger(1, 50),

0 commit comments

Comments
 (0)