From f747edca0cad7467b88216ac4009907ac7888ed8 Mon Sep 17 00:00:00 2001 From: Keith Grant Date: Tue, 26 Jan 2021 15:32:41 -0800 Subject: [PATCH] convert HostList to PaginatedTable --- .../src/screens/Host/HostList/HostList.jsx | 23 ++-- .../screens/Host/HostList/HostList.test.jsx | 10 +- .../screens/Host/HostList/HostListItem.jsx | 128 +++++++----------- .../Host/HostList/HostListItem.test.jsx | 32 +++-- 4 files changed, 92 insertions(+), 101 deletions(-) diff --git a/awx/ui_next/src/screens/Host/HostList/HostList.jsx b/awx/ui_next/src/screens/Host/HostList/HostList.jsx index 0fabce1b60..9aa8d36d36 100644 --- a/awx/ui_next/src/screens/Host/HostList/HostList.jsx +++ b/awx/ui_next/src/screens/Host/HostList/HostList.jsx @@ -8,10 +8,14 @@ import { HostsAPI } from '../../../api'; import AlertModal from '../../../components/AlertModal'; import DataListToolbar from '../../../components/DataListToolbar'; import ErrorDetail from '../../../components/ErrorDetail'; -import PaginatedDataList, { +import { ToolbarAddButton, ToolbarDeleteButton, } from '../../../components/PaginatedDataList'; +import PaginatedTable, { + HeaderRow, + HeaderCell, +} from '../../../components/PaginatedTable'; import useRequest, { useDeleteItems } from '../../../util/useRequest'; import { encodeQueryString, @@ -130,7 +134,7 @@ function HostList({ i18n }) { return ( - + {i18n._(t`Name`)} + {i18n._(t`Inventory`)} + + } renderToolbar={props => ( )} - renderItem={host => ( + renderRow={(host, index) => ( row.id === host.id)} onSelect={() => handleSelect(host)} + rowIndex={index} /> )} emptyStateControls={ diff --git a/awx/ui_next/src/screens/Host/HostList/HostList.test.jsx b/awx/ui_next/src/screens/Host/HostList/HostList.test.jsx index 5b502979e1..4212a08ff5 100644 --- a/awx/ui_next/src/screens/Host/HostList/HostList.test.jsx +++ b/awx/ui_next/src/screens/Host/HostList/HostList.test.jsx @@ -134,8 +134,9 @@ describe('', () => { act(() => { wrapper - .find('input#select-host-1') - .closest('DataListCheck') + .find('.pf-c-table__check') + .first() + .find('input') .invoke('onChange')(); }); wrapper.update(); @@ -147,8 +148,9 @@ describe('', () => { ).toEqual(true); act(() => { wrapper - .find('input#select-host-1') - .closest('DataListCheck') + .find('.pf-c-table__check') + .first() + .find('input') .invoke('onChange')(); }); wrapper.update(); diff --git a/awx/ui_next/src/screens/Host/HostList/HostListItem.jsx b/awx/ui_next/src/screens/Host/HostList/HostListItem.jsx index d920568f96..87c4d4eff6 100644 --- a/awx/ui_next/src/screens/Host/HostList/HostListItem.jsx +++ b/awx/ui_next/src/screens/Host/HostList/HostListItem.jsx @@ -1,91 +1,67 @@ import 'styled-components/macro'; -import React, { Fragment } from 'react'; +import React from 'react'; import { string, bool, func } from 'prop-types'; import { withI18n } from '@lingui/react'; import { t } from '@lingui/macro'; -import { - Button, - DataListAction as _DataListAction, - DataListCheck, - DataListItem, - DataListItemRow, - DataListItemCells, - Tooltip, -} from '@patternfly/react-core'; +import { Button } from '@patternfly/react-core'; +import { Tr, Td } from '@patternfly/react-table'; import { Link } from 'react-router-dom'; import { PencilAltIcon } from '@patternfly/react-icons'; -import styled from 'styled-components'; -import DataListCell from '../../../components/DataListCell'; - -import Sparkline from '../../../components/Sparkline'; +import { ActionsTd, ActionItem } from '../../../components/PaginatedTable'; import { Host } from '../../../types'; import HostToggle from '../../../components/HostToggle'; -const DataListAction = styled(_DataListAction)` - align-items: center; - display: grid; - grid-gap: 24px; - grid-template-columns: 92px 40px; -`; - -function HostListItem({ i18n, host, isSelected, onSelect, detailUrl }) { +function HostListItem({ + i18n, + host, + isSelected, + onSelect, + detailUrl, + rowIndex, +}) { const labelId = `check-action-${host.id}`; + return ( - - - - - - {host.name} - - , - - - , - - {host.summary_fields.inventory && ( - - {i18n._(t`Inventory`)} - - {host.summary_fields.inventory.name} - - - )} - , - ]} - /> - + + + + {host.name} + + + + {host.summary_fields.inventory && ( + + {host.summary_fields.inventory.name} + + )} + + + + - - {host.summary_fields.user_capabilities.edit ? ( - - - - ) : ( - '' - )} - - - + + + + ); } diff --git a/awx/ui_next/src/screens/Host/HostList/HostListItem.test.jsx b/awx/ui_next/src/screens/Host/HostList/HostListItem.test.jsx index aee5b91127..15d6db5ab1 100644 --- a/awx/ui_next/src/screens/Host/HostList/HostListItem.test.jsx +++ b/awx/ui_next/src/screens/Host/HostList/HostListItem.test.jsx @@ -25,12 +25,16 @@ describe('', () => { beforeEach(() => { wrapper = mountWithContexts( - {}} - host={mockHost} - /> + + + {}} + host={mockHost} + /> + +
); }); @@ -46,12 +50,16 @@ describe('', () => { const copyMockHost = Object.assign({}, mockHost); copyMockHost.summary_fields.user_capabilities.edit = false; wrapper = mountWithContexts( - {}} - host={copyMockHost} - /> + + + {}} + host={copyMockHost} + /> + +
); expect(wrapper.find('PencilAltIcon').exists()).toBeFalsy(); });