Skip to content

Commit ffb065b

Browse files
committed
Replace deprecated PatternFly table components
https://issues.redhat.com/browse/COST-5184
1 parent 0c080e1 commit ffb065b

File tree

2 files changed

+30
-108
lines changed

2 files changed

+30
-108
lines changed

src/components/drawers/exports/exportsTable.tsx

+26-105
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
Bullseye,
32
Button,
43
ButtonVariant,
54
EmptyState,
@@ -9,22 +8,20 @@ import {
98
EmptyStateIcon,
109
Label,
1110
Popover,
12-
Spinner,
1311
} from '@patternfly/react-core';
1412
import { DownloadIcon } from '@patternfly/react-icons/dist/esm/icons/download-icon';
1513
import { ExclamationCircleIcon } from '@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon';
1614
import { OutlinedClockIcon } from '@patternfly/react-icons/dist/esm/icons/outlined-clock-icon';
1715
import { PlusCircleIcon } from '@patternfly/react-icons/dist/esm/icons/plus-circle-icon';
1816
import { SyncIcon } from '@patternfly/react-icons/dist/esm/icons/sync-icon';
19-
import { sortable, SortByDirection, TableVariant } from '@patternfly/react-table';
20-
import { Table, TableBody, TableHeader } from '@patternfly/react-table/deprecated';
2117
import type { Query } from 'api/queries/query';
2218
import { getQuery } from 'api/queries/query';
2319
import type { Report } from 'api/reports/report';
2420
import messages from 'locales/messages';
2521
import React from 'react';
2622
import type { WrappedComponentProps } from 'react-intl';
2723
import { injectIntl } from 'react-intl';
24+
import { DataTable } from 'routes/components/dataTable';
2825
import type { DropdownWrapperItem } from 'routes/components/dropdownWrapper';
2926
import { DropdownWrapper } from 'routes/components/dropdownWrapper';
3027
import { EmptyFilterState } from 'routes/components/state/emptyFilterState';
@@ -34,38 +31,24 @@ import { styles } from './exportsTable.styles';
3431
interface ExportsTableOwnProps {
3532
isLoading?: boolean;
3633
onClose();
37-
onSort(value: string, isSortAscending: boolean);
34+
onSort(sortType: string, isSortAscending: boolean);
3835
query: Query;
3936
report: Report;
4037
}
4138

4239
interface ExportsTableState {
4340
columns?: any[];
44-
loadingRows?: any[];
4541
rows?: any[];
4642
}
4743

4844
type ExportsTableProps = ExportsTableOwnProps & WrappedComponentProps;
4945

50-
export const ExportsTableColumnIds = {
51-
actions: 'actions',
52-
created: 'created',
53-
expires: 'expires',
54-
names: 'names',
55-
status: 'status',
56-
};
57-
5846
class ExportsTableBase extends React.Component<ExportsTableProps, ExportsTableState> {
5947
public state: ExportsTableState = {
6048
columns: [],
6149
rows: [],
6250
};
6351

64-
constructor(props: ExportsTableProps) {
65-
super(props);
66-
this.handleOnSort = this.handleOnSort.bind(this);
67-
}
68-
6952
public componentDidMount() {
7053
this.initDatum();
7154
}
@@ -91,69 +74,44 @@ class ExportsTableBase extends React.Component<ExportsTableProps, ExportsTableSt
9174

9275
const columns = [
9376
{
94-
id: ExportsTableColumnIds.names,
77+
name: intl.formatMessage(messages.names, { count: 1 }),
9578
orderBy: 'name',
96-
title: intl.formatMessage(messages.names, { count: 1 }),
97-
...(isSortable && { transforms: [sortable] }),
79+
isSortable,
9880
},
9981
{
100-
id: ExportsTableColumnIds.created,
82+
name: intl.formatMessage(messages.timeOfExport),
10183
orderBy: 'created',
102-
title: intl.formatMessage(messages.timeOfExport),
103-
...(isSortable && { transforms: [sortable] }),
84+
isSortable,
10485
},
10586
{
106-
id: ExportsTableColumnIds.expires,
87+
name: intl.formatMessage(messages.expiresOn),
10788
orderBy: 'expires',
108-
title: intl.formatMessage(messages.expiresOn),
109-
...(isSortable && { transforms: [sortable] }),
89+
isSortable,
11090
},
11191
{
112-
id: ExportsTableColumnIds.status,
113-
title: intl.formatMessage(messages.statusActions),
92+
name: intl.formatMessage(messages.statusActions),
11493
},
11594
{
116-
id: ExportsTableColumnIds.actions,
117-
title: '',
95+
name: '',
11896
},
11997
];
12098

12199
if (report.data.length) {
122100
report.data.map((item: any) => {
123101
rows.push({
124102
cells: [
125-
{ title: <div>{item.name}</div>, id: ExportsTableColumnIds.names },
126-
{ title: <div>{item.created}</div>, id: ExportsTableColumnIds.created },
127-
{ title: <div>{item.expires}</div>, id: ExportsTableColumnIds.expires },
128-
{ title: this.getStatus(item.status), id: ExportsTableColumnIds.status },
129-
{ title: this.getActions(), id: ExportsTableColumnIds.actions },
103+
{ value: item.name },
104+
{ value: item.created },
105+
{ value: item.expires },
106+
{ value: this.getStatus(item.status) },
107+
{ value: this.getActions() },
130108
],
131109
item,
132110
});
133111
});
134112
}
135-
136-
const loadingRows = [
137-
{
138-
heightAuto: true,
139-
cells: [
140-
{
141-
props: { colSpan: 7 },
142-
title: (
143-
<Bullseye>
144-
<div style={{ textAlign: 'center' }}>
145-
<Spinner size="xl" />
146-
</div>
147-
</Bullseye>
148-
),
149-
},
150-
],
151-
},
152-
];
153-
154113
this.setState({
155114
columns,
156-
loadingRows,
157115
rows,
158116
});
159117
};
@@ -198,27 +156,6 @@ class ExportsTableBase extends React.Component<ExportsTableProps, ExportsTableSt
198156
);
199157
};
200158

201-
private getSortBy = () => {
202-
const { query } = this.props;
203-
const { columns } = this.state;
204-
205-
let index = -1;
206-
let direction: any = SortByDirection.asc;
207-
208-
for (const key of Object.keys(query.order_by)) {
209-
let c = 0;
210-
for (const column of columns) {
211-
if (column.orderBy === key) {
212-
direction = query.order_by[key] === 'asc' ? SortByDirection.asc : SortByDirection.desc;
213-
index = c;
214-
break;
215-
}
216-
c++;
217-
}
218-
}
219-
return index > -1 ? { index, direction } : {};
220-
};
221-
222159
private getStatus = (status: string) => {
223160
const { intl } = this.props;
224161

@@ -288,36 +225,20 @@ class ExportsTableBase extends React.Component<ExportsTableProps, ExportsTableSt
288225
console.log('handleOnDownload clicked');
289226
};
290227

291-
private handleOnSort = (event, index, direction) => {
292-
const { onSort } = this.props;
293-
const { columns } = this.state;
294-
295-
if (onSort) {
296-
const orderBy = columns[index - 1].orderBy;
297-
const isSortAscending = direction === SortByDirection.asc;
298-
onSort(orderBy, isSortAscending);
299-
}
300-
};
301-
302228
public render() {
303-
const { intl, isLoading } = this.props;
304-
const { columns, loadingRows, rows } = this.state;
229+
const { intl, isLoading, onSort, query } = this.props;
230+
const { columns, rows } = this.state;
305231

306232
return (
307-
<>
308-
<Table
309-
aria-label={intl.formatMessage(messages.exportsTableAriaLabel)}
310-
cells={columns}
311-
rows={isLoading ? loadingRows : rows}
312-
sortBy={this.getSortBy()}
313-
onSort={this.handleOnSort}
314-
variant={TableVariant.compact}
315-
>
316-
<TableHeader />
317-
<TableBody />
318-
</Table>
319-
{rows.length === 0 && <div style={styles.emptyState}>{this.getEmptyState()}</div>}
320-
</>
233+
<DataTable
234+
ariaLabel={intl.formatMessage(messages.exportsTableAriaLabel)}
235+
columns={columns}
236+
emptyState={this.getEmptyState()}
237+
isLoading={isLoading}
238+
onSort={onSort}
239+
rows={rows}
240+
orderBy={query.order_by}
241+
/>
321242
);
322243
}
323244
}

src/routes/components/dataTable/dataTable.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ import { withRouter } from 'utils/router';
2323
import { styles } from './dataTable.styles';
2424

2525
interface DataTableOwnProps {
26+
ariaLabel?: string;
2627
columns?: any[];
2728
emptyState?: React.ReactNode;
2829
filterBy: any;
2930
isActionsCell?: boolean;
3031
isLoading?: boolean;
3132
isSelectable?: boolean;
3233
onSelect(items: any[], isSelected: boolean);
33-
onSort(value: string, isSortAscending: boolean);
34+
onSort(sortType: string, isSortAscending: boolean);
3435
orderBy: any;
3536
rows?: any[];
3637
selectedItems?: ComputedReportItem[];
@@ -114,12 +115,12 @@ class DataTable extends React.Component<DataTableProps, any> {
114115
};
115116

116117
public render() {
117-
const { columns, intl, isActionsCell, isLoading, isSelectable, rows, variant } = this.props;
118+
const { ariaLabel, columns, intl, isActionsCell, isLoading, isSelectable, rows, variant } = this.props;
118119

119120
return (
120121
<>
121122
<Table
122-
aria-label={intl.formatMessage(messages.dataTableAriaLabel)}
123+
aria-label={ariaLabel ? ariaLabel : intl.formatMessage(messages.dataTableAriaLabel)}
123124
className="tableOverride"
124125
gridBreakPoint="grid-2xl"
125126
variant={TableVariant.compact}

0 commit comments

Comments
 (0)