diff --git a/awx/ui_next/src/components/PaginatedDataList/PaginatedDataList.jsx b/awx/ui_next/src/components/PaginatedDataList/PaginatedDataList.jsx
index 8bd449e851..ab60173e75 100644
--- a/awx/ui_next/src/components/PaginatedDataList/PaginatedDataList.jsx
+++ b/awx/ui_next/src/components/PaginatedDataList/PaginatedDataList.jsx
@@ -1,9 +1,10 @@
import React, { Fragment } from 'react';
+
import PropTypes from 'prop-types';
import { DataList } from '@patternfly/react-core';
import { withI18n } from '@lingui/react';
import { t } from '@lingui/macro';
-import { withRouter } from 'react-router-dom';
+import { withRouter, useHistory, useLocation } from 'react-router-dom';
import ListHeader from '../ListHeader';
import ContentEmpty from '../ContentEmpty';
@@ -22,166 +23,150 @@ import { QSConfig, SearchColumns, SortColumns } from '../../types';
import PaginatedDataListItem from './PaginatedDataListItem';
-class PaginatedDataList extends React.Component {
- constructor(props) {
- super(props);
- this.handleSetPage = this.handleSetPage.bind(this);
- this.handleSetPageSize = this.handleSetPageSize.bind(this);
- this.handleListItemSelect = this.handleListItemSelect.bind(this);
- }
-
- handleListItemSelect = (id = 0) => {
- const { items, onRowClick } = this.props;
+function PaginatedDataList({
+ items,
+ onRowClick,
+ contentError,
+ hasContentLoading,
+ emptyStateControls,
+ itemCount,
+ qsConfig,
+ renderItem,
+ toolbarSearchColumns,
+ toolbarSearchableKeys,
+ toolbarRelatedSearchableKeys,
+ toolbarSortColumns,
+ pluralizedItemName,
+ showPageSizeOptions,
+ location,
+ i18n,
+ renderToolbar,
+}) {
+ const { search, pathname } = useLocation();
+ const history = useHistory();
+ const handleListItemSelect = (id = 0) => {
const match = items.find(item => item.id === Number(id));
onRowClick(match);
};
- handleSetPage(event, pageNumber) {
- const { history, qsConfig } = this.props;
- const { search } = history.location;
+ const handleSetPage = (event, pageNumber) => {
const oldParams = parseQueryString(qsConfig, search);
- this.pushHistoryState(replaceParams(oldParams, { page: pageNumber }));
- }
+ pushHistoryState(replaceParams(oldParams, { page: pageNumber }));
+ };
- handleSetPageSize(event, pageSize, page) {
- const { history, qsConfig } = this.props;
- const { search } = history.location;
+ const handleSetPageSize = (event, pageSize, page) => {
const oldParams = parseQueryString(qsConfig, search);
- this.pushHistoryState(
- replaceParams(oldParams, { page_size: pageSize, page })
- );
- }
+ pushHistoryState(replaceParams(oldParams, { page_size: pageSize, page }));
+ };
- pushHistoryState(params) {
- const { history, qsConfig } = this.props;
- const { pathname } = history.location;
+ const pushHistoryState = params => {
const encodedParams = encodeNonDefaultQueryString(qsConfig, params);
history.push(encodedParams ? `${pathname}?${encodedParams}` : pathname);
+ };
+
+ const searchColumns = toolbarSearchColumns.length
+ ? toolbarSearchColumns
+ : [
+ {
+ name: i18n._(t`Name`),
+ key: 'name',
+ isDefault: true,
+ },
+ ];
+ const sortColumns = toolbarSortColumns.length
+ ? toolbarSortColumns
+ : [
+ {
+ name: i18n._(t`Name`),
+ key: 'name',
+ },
+ ];
+ const queryParams = parseQueryString(qsConfig, location.search);
+
+ const dataListLabel = i18n._(t`${pluralizedItemName} List`);
+ const emptyContentMessage = i18n._(
+ t`Please add ${pluralizedItemName} to populate this list `
+ );
+ const emptyContentTitle = i18n._(t`No ${pluralizedItemName} Found `);
+
+ let Content;
+ if (hasContentLoading && items.length <= 0) {
+ Content = ;
+ } else if (contentError) {
+ Content = ;
+ } else if (items.length <= 0) {
+ Content = (
+
+ );
+ } else {
+ Content = (
+
+ );
}
- render() {
- const {
- contentError,
- hasContentLoading,
- emptyStateControls,
- items,
- itemCount,
- qsConfig,
- renderItem,
- toolbarSearchColumns,
- toolbarSearchableKeys,
- toolbarRelatedSearchableKeys,
- toolbarSortColumns,
- pluralizedItemName,
- showPageSizeOptions,
- location,
- i18n,
- renderToolbar,
- } = this.props;
- const searchColumns = toolbarSearchColumns.length
- ? toolbarSearchColumns
- : [
- {
- name: i18n._(t`Name`),
- key: 'name',
- isDefault: true,
- },
- ];
- const sortColumns = toolbarSortColumns.length
- ? toolbarSortColumns
- : [
- {
- name: i18n._(t`Name`),
- key: 'name',
- },
- ];
- const queryParams = parseQueryString(qsConfig, location.search);
+ const ToolbarPagination = (
+
+ );
- const dataListLabel = i18n._(t`${pluralizedItemName} List`);
- const emptyContentMessage = i18n._(
- t`Please add ${pluralizedItemName} to populate this list `
- );
- const emptyContentTitle = i18n._(t`No ${pluralizedItemName} Found `);
-
- let Content;
- if (hasContentLoading && items.length <= 0) {
- Content = ;
- } else if (contentError) {
- Content = ;
- } else if (items.length <= 0) {
- Content = (
-
- );
- } else {
- Content = (
-
- );
- }
-
- const ToolbarPagination = (
-
+
- );
-
- return (
-
-
- {Content}
- {items.length ? (
-
- ) : null}
-
- );
- }
+ ) : null}
+
+ );
}
const Item = PropTypes.shape({