Skip to content

Commit 04ea047

Browse files
authored
Merge pull request #3903 from dlabrecq/table
Replace deprecated PatternFly table components
2 parents 0c080e1 + 3ab83c7 commit 04ea047

File tree

20 files changed

+52
-130
lines changed

20 files changed

+52
-130
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}

src/routes/components/dataTable/expandableTable.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface ExpandableTableOwnProps {
2929
isActionsCell?: boolean;
3030
isAllExpanded?: boolean;
3131
isLoading?: boolean;
32-
onSort(value: string, isSortAscending: boolean);
32+
onSort(sortType: string, isSortAscending: boolean);
3333
orderBy: any;
3434
rows?: any[];
3535
selectedItems?: ComputedReportItem[];

src/routes/components/dataTable/selectableTable.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ interface SelectableTableOwnProps {
2424
emptyState?: ReactNode;
2525
filterBy: any;
2626
isLoading?: boolean;
27-
onSort(value: string, isSortAscending: boolean);
27+
onSort(sortType: string, isSortAscending: boolean);
2828
onRowClick(rowIndex: number);
2929
orderBy: any;
3030
rows?: any[];

src/routes/details/awsBreakdown/instances/instancesTable.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface InstancesTableOwnProps {
2121
isAllSelected?: boolean;
2222
isLoading?: boolean;
2323
onSelect(items: ComputedReportItem[], isSelected: boolean);
24-
onSort(value: string, isSortAscending: boolean);
24+
onSort(sortType: string, isSortAscending: boolean);
2525
orderBy?: any;
2626
query?: Query;
2727
report?: Report;
@@ -203,9 +203,9 @@ const InstancesTable: React.FC<InstancesTableProps> = ({
203203
);
204204
};
205205

206-
const handleOnSort = (value: string, isSortAscending: boolean) => {
206+
const handleOnSort = (sortType: string, isSortAscending: boolean) => {
207207
if (onSort) {
208-
onSort(value, isSortAscending);
208+
onSort(sortType, isSortAscending);
209209
}
210210
};
211211

src/routes/details/awsDetails/detailsTable.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ interface DetailsTableOwnProps extends RouterComponentProps, WrappedComponentPro
3333
isAllSelected?: boolean;
3434
isLoading?: boolean;
3535
onSelect(items: ComputedReportItem[], isSelected: boolean);
36-
onSort(value: string, isSortAscending: boolean);
36+
onSort(sortType: string, isSortAscending: boolean);
3737
orderBy?: any;
3838
query?: Query;
3939
report: AwsReport;

src/routes/details/azureDetails/detailsTable.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ interface DetailsTableOwnProps extends RouterComponentProps, WrappedComponentPro
3131
groupByTagKey?: string;
3232
isLoading?: boolean;
3333
onSelect(items: ComputedReportItem[], isSelected: boolean);
34-
onSort(value: string, isSortAscending: boolean);
34+
onSort(sortType: string, isSortAscending: boolean);
3535
orderBy?: any;
3636
query?: Query;
3737
report: AzureReport;

src/routes/details/components/pvcChart/modal/pvcTable.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { formatUsage, unitsLookupKey } from 'utils/format';
1313
interface PvcTableOwnProps {
1414
filterBy?: any;
1515
isLoading?: boolean;
16-
onSort(value: string, isSortAscending: boolean);
16+
onSort(sortType: string, isSortAscending: boolean);
1717
orderBy?: any;
1818
report: OcpReport;
1919
reportQueryString: string;
@@ -115,9 +115,9 @@ const PvcTable: React.FC<PvcTableProps> = ({ filterBy, isLoading, onSort, orderB
115115
setRows(filteredRows);
116116
};
117117

118-
const handleOnSort = (value: string, isSortAscending: boolean) => {
118+
const handleOnSort = (sortType: string, isSortAscending: boolean) => {
119119
if (onSort) {
120-
onSort(value, isSortAscending);
120+
onSort(sortType, isSortAscending);
121121
}
122122
};
123123

src/routes/details/gcpDetails/detailsTable.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ interface DetailsTableOwnProps extends RouterComponentProps, WrappedComponentPro
3131
isAllSelected?: boolean;
3232
isLoading?: boolean;
3333
onSelect(items: ComputedReportItem[], isSelected: boolean);
34-
onSort(value: string, isSortAscending: boolean);
34+
onSort(sortType: string, isSortAscending: boolean);
3535
orderBy?: any;
3636
query?: Query;
3737
report: GcpReport;

src/routes/details/ibmDetails/detailsTable.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ interface DetailsTableOwnProps extends RouterComponentProps, WrappedComponentPro
3131
isAllSelected?: boolean;
3232
isLoading?: boolean;
3333
onSelect(items: ComputedReportItem[], isSelected: boolean);
34-
onSort(value: string, isSortAscending: boolean);
34+
onSort(sortType: string, isSortAscending: boolean);
3535
orderBy?: any;
3636
query?: Query;
3737
report: IbmReport;

src/routes/details/ociDetails/detailsTable.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ interface DetailsTableOwnProps extends RouterComponentProps, WrappedComponentPro
3131
groupByTagKey?: string;
3232
isLoading?: boolean;
3333
onSelect(items: ComputedReportItem[], isSelected: boolean);
34-
onSort(value: string, isSortAscending: boolean);
34+
onSort(sortType: string, isSortAscending: boolean);
3535
orderBy?: any;
3636
query?: Query;
3737
report: OciReport;

src/routes/details/ocpDetails/detailsTable.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ interface DetailsTableOwnProps extends RouterComponentProps, WrappedComponentPro
4242
isLoading?: boolean;
4343
isRosToggleEnabled?: boolean;
4444
onSelect(items: ComputedReportItem[], isSelected: boolean);
45-
onSort(value: string, isSortAscending: boolean);
45+
onSort(sortType: string, isSortAscending: boolean);
4646
orderBy?: any;
4747
query?: Query;
4848
report: OcpReport;

src/routes/details/rhelDetails/detailsTable.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ interface DetailsTableOwnProps extends RouterComponentProps, WrappedComponentPro
3333
isAllSelected?: boolean;
3434
isLoading?: boolean;
3535
onSelect(items: ComputedReportItem[], isSelected: boolean);
36-
onSort(value: string, isSortAscending: boolean);
36+
onSort(sortType: string, isSortAscending: boolean);
3737
orderBy?: any;
3838
query?: Query;
3939
report: RhelReport;

src/routes/explorer/explorerTable.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ interface ExplorerTableOwnProps extends RouterComponentProps, WrappedComponentPr
5555
isAllSelected?: boolean;
5656
isLoading?: boolean;
5757
onSelect(items: ComputedReportItem[], isSelected: boolean);
58-
onSort(value: string, isSortAscending: boolean, date: string);
58+
onSort(sortType: string, isSortAscending: boolean, date: string);
5959
perspective: PerspectiveType;
6060
query: Query;
6161
report: Report;

0 commit comments

Comments
 (0)