From a8159273eb00e4d5e89d94c6e066c95736792990 Mon Sep 17 00:00:00 2001 From: Keith Grant Date: Tue, 1 Dec 2020 13:59:05 -0800 Subject: [PATCH] convert InventoryList to use PaginatedTable --- .../DataListToolbar/DataListToolbar.jsx | 8 +- .../components/PaginatedTable/HeaderRow.jsx | 17 +- .../PaginatedTable/PaginatedTable.jsx | 19 +- .../Inventory/InventoryList/InventoryList.jsx | 25 ++- .../InventoryList/InventoryListItem.jsx | 212 +++++++----------- .../OrganizationList/OrganizationList.jsx | 23 +- .../OrganizationList/OrganizationListItem.jsx | 2 +- 7 files changed, 114 insertions(+), 192 deletions(-) diff --git a/awx/ui_next/src/components/DataListToolbar/DataListToolbar.jsx b/awx/ui_next/src/components/DataListToolbar/DataListToolbar.jsx index 3fbf41679c..bcecf8a2bc 100644 --- a/awx/ui_next/src/components/DataListToolbar/DataListToolbar.jsx +++ b/awx/ui_next/src/components/DataListToolbar/DataListToolbar.jsx @@ -93,9 +93,11 @@ function DataListToolbar({ onRemove={onRemove} /> - - - + {sortColumns && ( + + + + )} {showExpandCollapse && ( diff --git a/awx/ui_next/src/components/PaginatedTable/HeaderRow.jsx b/awx/ui_next/src/components/PaginatedTable/HeaderRow.jsx index 51c92e6de8..906370c3b9 100644 --- a/awx/ui_next/src/components/PaginatedTable/HeaderRow.jsx +++ b/awx/ui_next/src/components/PaginatedTable/HeaderRow.jsx @@ -7,21 +7,13 @@ import { replaceParams, } from '../../util/qs'; -export default function HeaderRow({ - handleSelectAll, - isAllSelected, - qsConfig, - defaultSortKey, - children, -}) { +export default function HeaderRow({ qsConfig, defaultSortKey, children }) { const location = useLocation(); const history = useHistory(); const params = parseQueryString(qsConfig, location.search); - // TODO: asc vs desc -- correct for both alpha & numeric sorting? const onSort = (key, order) => { - console.log({ key, order }); const newParams = replaceParams(params, { order_by: order === 'asc' ? key : `-${key}`, page: null, @@ -43,12 +35,7 @@ export default function HeaderRow({ return ( - + {React.Children.map(children, child => React.cloneElement(child, { onSort, diff --git a/awx/ui_next/src/components/PaginatedTable/PaginatedTable.jsx b/awx/ui_next/src/components/PaginatedTable/PaginatedTable.jsx index b78f1afb1d..912773e573 100644 --- a/awx/ui_next/src/components/PaginatedTable/PaginatedTable.jsx +++ b/awx/ui_next/src/components/PaginatedTable/PaginatedTable.jsx @@ -18,7 +18,7 @@ import { replaceParams, } from '../../util/qs'; import PaginatedTableRow from './PaginatedTableRow'; -import { QSConfig, SearchColumns, SortColumns } from '../../types'; +import { QSConfig, SearchColumns } from '../../types'; function PaginatedTable({ contentError, @@ -32,7 +32,6 @@ function PaginatedTable({ toolbarSearchColumns, toolbarSearchableKeys, toolbarRelatedSearchableKeys, - toolbarSortColumns, pluralizedItemName, showPageSizeOptions, i18n, @@ -71,14 +70,6 @@ function PaginatedTable({ 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`); @@ -98,10 +89,7 @@ function PaginatedTable({ ); } else { Content = ( - + {headerRow} {items.map(renderRow)} @@ -137,7 +125,6 @@ function PaginatedTable({ renderToolbar={renderToolbar} emptyStateControls={emptyStateControls} searchColumns={searchColumns} - sortColumns={sortColumns} searchableKeys={toolbarSearchableKeys} relatedSearchableKeys={toolbarRelatedSearchableKeys} qsConfig={qsConfig} @@ -183,7 +170,6 @@ PaginatedTable.propTypes = { toolbarSearchColumns: SearchColumns, toolbarSearchableKeys: PropTypes.arrayOf(PropTypes.string), toolbarRelatedSearchableKeys: PropTypes.arrayOf(PropTypes.string), - toolbarSortColumns: SortColumns, showPageSizeOptions: PropTypes.bool, renderToolbar: PropTypes.func, hasContentLoading: PropTypes.bool, @@ -197,7 +183,6 @@ PaginatedTable.defaultProps = { toolbarSearchColumns: [], toolbarSearchableKeys: [], toolbarRelatedSearchableKeys: [], - toolbarSortColumns: [], pluralizedItemName: 'Items', showPageSizeOptions: true, renderRow: item => , diff --git a/awx/ui_next/src/screens/Inventory/InventoryList/InventoryList.jsx b/awx/ui_next/src/screens/Inventory/InventoryList/InventoryList.jsx index 6bb721a427..32e8ddd8ea 100644 --- a/awx/ui_next/src/screens/Inventory/InventoryList/InventoryList.jsx +++ b/awx/ui_next/src/screens/Inventory/InventoryList/InventoryList.jsx @@ -8,9 +8,11 @@ import useRequest, { useDeleteItems } from '../../../util/useRequest'; import AlertModal from '../../../components/AlertModal'; import DatalistToolbar from '../../../components/DataListToolbar'; import ErrorDetail from '../../../components/ErrorDetail'; -import PaginatedDataList, { - ToolbarDeleteButton, -} from '../../../components/PaginatedDataList'; +import { ToolbarDeleteButton } from '../../../components/PaginatedDataList'; +import PaginatedTable, { + HeaderRow, + HeaderCell, +} from '../../../components/PaginatedTable'; import { getQSConfig, parseQueryString } from '../../../util/qs'; import useWsInventories from './useWsInventories'; import AddDropDownButton from '../../../components/AddDropDownButton'; @@ -149,10 +151,11 @@ function InventoryList({ i18n }) { ]} /> ); + return ( - + {i18n._(t`Name`)} + {i18n._(t`Status`)} + {i18n._(t`Type`)} + {i18n._(t`Organization`)} + {i18n._(t`Groups`)} + {i18n._(t`Hosts`)} + {i18n._(t`Sources`)} + + } renderToolbar={props => ( )} - renderItem={inventory => ( + renderRow={(inventory, index) => ( - - - - {inventory.kind !== 'smart' && ( - - )} - , - - {inventory.pending_deletion ? ( - {inventory.name} - ) : ( - - {inventory.name} - - )} - , - - {inventory.kind === 'smart' - ? i18n._(t`Smart Inventory`) - : i18n._(t`Inventory`)} - , - - {i18n._(t`Organization`)} - - {inventory.summary_fields.organization.name} - - , - - - {i18n._(t`Groups`)} - {inventory.total_groups} - - - {i18n._(t`Hosts`)} - {inventory.total_hosts} - - - {i18n._(t`Sources`)} - {inventory.total_inventory_sources} - - , - inventory.pending_deletion && ( - - - - ), - ]} - /> - {!inventory.pending_deletion && ( - - {inventory.summary_fields.user_capabilities.edit ? ( - - - - ) : ( - '' - )} - {inventory.summary_fields.user_capabilities.copy && ( - - )} - + + + + {inventory.pending_deletion ? ( + {inventory.name} + ) : ( + + {inventory.name} + )} - - + + + {inventory.kind !== 'smart' && ( + + )} + + + {inventory.kind === 'smart' + ? i18n._(t`Smart Inventory`) + : i18n._(t`Inventory`)} + + + + {inventory.summary_fields.organization.name} + + + {inventory.total_groups} + {inventory.total_hosts} + {inventory.total_inventory_sources} + {inventory.pending_deletion ? ( + + + + ) : ( + + {inventory.summary_fields.user_capabilities.edit ? ( + + + + ) : ( +
+ )} + {inventory.summary_fields.user_capabilities.copy && ( + + )} + + )} + ); } export default withI18n()(InventoryListItem); diff --git a/awx/ui_next/src/screens/Organization/OrganizationList/OrganizationList.jsx b/awx/ui_next/src/screens/Organization/OrganizationList/OrganizationList.jsx index 05512fc04e..2d542fe3fe 100644 --- a/awx/ui_next/src/screens/Organization/OrganizationList/OrganizationList.jsx +++ b/awx/ui_next/src/screens/Organization/OrganizationList/OrganizationList.jsx @@ -122,12 +122,13 @@ function OrganizationsList({ i18n }) { + {i18n._(t`Name`)} {i18n._(t`Members`)} {i18n._(t`Teams`)} @@ -172,9 +161,9 @@ function OrganizationsList({ i18n }) { renderToolbar={props => ( {organization.summary_fields.related_field_counts.users} {organization.summary_fields.related_field_counts.teams} - + {organization.summary_fields.user_capabilities.edit ? (