diff --git a/awx/ui_next/src/components/PaginatedTable/HeaderRow.jsx b/awx/ui_next/src/components/PaginatedTable/HeaderRow.jsx index 8fd0fef003..51c92e6de8 100644 --- a/awx/ui_next/src/components/PaginatedTable/HeaderRow.jsx +++ b/awx/ui_next/src/components/PaginatedTable/HeaderRow.jsx @@ -23,7 +23,7 @@ export default function HeaderRow({ const onSort = (key, order) => { console.log({ key, order }); const newParams = replaceParams(params, { - order_by: order === 'desc' ? key : `-${key}`, + order_by: order === 'asc' ? key : `-${key}`, page: null, }); const encodedParams = encodeNonDefaultQueryString(qsConfig, newParams); @@ -37,7 +37,7 @@ export default function HeaderRow({ const sortKey = params.order_by?.replace('-', ''); const sortBy = { index: sortKey || defaultSortKey, - direction: params.order_by?.startsWith('-') ? 'asc' : 'desc', + direction: params.order_by?.startsWith('-') ? 'desc' : 'asc', }; return ( diff --git a/awx/ui_next/src/components/PaginatedTable/PaginatedTable.jsx b/awx/ui_next/src/components/PaginatedTable/PaginatedTable.jsx index d797fde02b..b78f1afb1d 100644 --- a/awx/ui_next/src/components/PaginatedTable/PaginatedTable.jsx +++ b/awx/ui_next/src/components/PaginatedTable/PaginatedTable.jsx @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; import { TableComposable, Tbody } from '@patternfly/react-table'; import { withI18n } from '@lingui/react'; import { t } from '@lingui/macro'; -import { withRouter } from 'react-router-dom'; +import { useHistory } from 'react-router-dom'; import ListHeader from '../ListHeader'; import ContentEmpty from '../ContentEmpty'; @@ -17,173 +17,155 @@ import { parseQueryString, replaceParams, } from '../../util/qs'; - +import PaginatedTableRow from './PaginatedTableRow'; import { QSConfig, SearchColumns, SortColumns } from '../../types'; -import PaginatedTableRow from './PaginatedTableRow'; +function PaginatedTable({ + contentError, + hasContentLoading, + emptyStateControls, + items, + itemCount, + qsConfig, + headerRow, + renderRow, + toolbarSearchColumns, + toolbarSearchableKeys, + toolbarRelatedSearchableKeys, + toolbarSortColumns, + pluralizedItemName, + showPageSizeOptions, + i18n, + renderToolbar, + // onRowClick, +}) { + const history = useHistory(); -class PaginatedTable 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); - } + // const handleListItemSelect = (id = 0) => { + // const match = items.find(item => item.id === Number(id)); + // onRowClick(match); + // }; - handleListItemSelect = (id = 0) => { - const { items, onRowClick } = this.props; - const match = items.find(item => item.id === Number(id)); - onRowClick(match); - }; - - handleSetPage(event, pageNumber) { - const { history, qsConfig } = this.props; - const { search } = history.location; - const oldParams = parseQueryString(qsConfig, search); - this.pushHistoryState(replaceParams(oldParams, { page: pageNumber })); - } - - handleSetPageSize(event, pageSize, page) { - const { history, qsConfig } = this.props; - const { search } = history.location; - const oldParams = parseQueryString(qsConfig, search); - this.pushHistoryState( - replaceParams(oldParams, { page_size: pageSize, page }) - ); - } - - pushHistoryState(params) { - const { history, qsConfig } = this.props; + const pushHistoryState = params => { const { pathname } = history.location; const encodedParams = encodeNonDefaultQueryString(qsConfig, params); history.push(encodedParams ? `${pathname}?${encodedParams}` : pathname); + }; + + const handleSetPage = (event, pageNumber) => { + const oldParams = parseQueryString(qsConfig, history.location.search); + pushHistoryState(replaceParams(oldParams, { page: pageNumber })); + }; + + const handleSetPageSize = (event, pageSize, page) => { + const oldParams = parseQueryString(qsConfig, history.location.search); + pushHistoryState(replaceParams(oldParams, { page_size: pageSize, page })); + }; + + 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, history.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 = ( + + {headerRow} + {items.map(renderRow)} + + ); } - render() { - const { - contentError, - hasContentLoading, - emptyStateControls, - items, - itemCount, - qsConfig, - headerRow, - renderRow, - 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 = ( - this.handleListItemSelect(id)} - > - {headerRow} - {items.map(renderRow)} - - ); - } - - const ToolbarPagination = ( - + - ); - - return ( - - - {Content} - {items.length ? ( - - ) : null} - - ); - } + ) : null} + + ); } const Item = PropTypes.shape({ @@ -206,7 +188,7 @@ PaginatedTable.propTypes = { renderToolbar: PropTypes.func, hasContentLoading: PropTypes.bool, contentError: PropTypes.shape(), - onRowClick: PropTypes.func, + // onRowClick: PropTypes.func, }; PaginatedTable.defaultProps = { @@ -220,8 +202,8 @@ PaginatedTable.defaultProps = { showPageSizeOptions: true, renderRow: item => , renderToolbar: props => , - onRowClick: () => null, + // onRowClick: () => null, }; export { PaginatedTable as _PaginatedTable }; -export default withI18n()(withRouter(PaginatedTable)); +export default withI18n()(PaginatedTable); diff --git a/awx/ui_next/src/screens/Organization/OrganizationList/OrganizationList.jsx b/awx/ui_next/src/screens/Organization/OrganizationList/OrganizationList.jsx index 2f647be8fc..05512fc04e 100644 --- a/awx/ui_next/src/screens/Organization/OrganizationList/OrganizationList.jsx +++ b/awx/ui_next/src/screens/Organization/OrganizationList/OrganizationList.jsx @@ -3,7 +3,6 @@ import { useLocation, useRouteMatch } from 'react-router-dom'; import { withI18n } from '@lingui/react'; import { t } from '@lingui/macro'; import { Card, PageSection } from '@patternfly/react-core'; -import { Thead, Tr, Th } from '@patternfly/react-table'; import { OrganizationsAPI } from '../../../api'; import useRequest, { useDeleteItems } from '../../../util/useRequest'; @@ -118,10 +117,6 @@ function OrganizationsList({ i18n }) { } }; - const onSort = (e, index, direction) => { - console.log(index, direction); - }; - return ( <> @@ -174,55 +169,6 @@ function OrganizationsList({ i18n }) { {i18n._(t`Teams`)} } - _headerRow={ - // TODO: move sorting into w/ friendly API - - - - - {i18n._(t`Name`)} - - - {i18n._(t`Members`)} - - - {i18n._(t`Teams`)} - - - - } renderToolbar={props => (