From c5ad5ce1ae73742cb8e2910a5760c5ca3026dc7e Mon Sep 17 00:00:00 2001 From: Georgy Karataev Date: Mon, 3 Apr 2023 16:05:36 +0200 Subject: [PATCH 1/3] Remove prepareColumns duplicate, use correct links --- .../GroupSystems/GroupSystems.cy.js | 2 +- src/components/GroupSystems/GroupSystems.js | 33 ++++++++++------- .../Modals/AddSystemsToGroupModal.js | 36 ++----------------- 3 files changed, 25 insertions(+), 46 deletions(-) diff --git a/src/components/GroupSystems/GroupSystems.cy.js b/src/components/GroupSystems/GroupSystems.cy.js index 40cb696a7..15c1022ab 100644 --- a/src/components/GroupSystems/GroupSystems.cy.js +++ b/src/components/GroupSystems/GroupSystems.cy.js @@ -39,7 +39,7 @@ import _ from 'lodash'; const GROUP_NAME = 'foobar'; const ROOT = 'div[id="group-systems-table"]'; -const TABLE_HEADERS = ['Name', 'Tags', 'OS', 'Update method', 'Last seen']; +const TABLE_HEADERS = ['Name', 'OS', 'Tags', 'Update method', 'Last seen']; const SORTABLE_HEADERS = ['Name', 'OS', 'Last seen']; const DEFAULT_ROW_COUNT = 50; diff --git a/src/components/GroupSystems/GroupSystems.js b/src/components/GroupSystems/GroupSystems.js index e59737e32..f66f3e657 100644 --- a/src/components/GroupSystems/GroupSystems.js +++ b/src/components/GroupSystems/GroupSystems.js @@ -33,12 +33,12 @@ export const bulkSelectConfig = (dispatch, selectedNumber, noneSelected, pageSel checked: selectedNumber > 0 && pageSelected // TODO: support partial selection (dash sign) in FEC BulkSelect }); -const prepareColumns = (initialColumns) => { +export const prepareColumns = (initialColumns, hideGroupColumn) => { // hides the "groups" column - const columns = initialColumns.filter(({ key }) => key !== 'groups'); + const columns = hideGroupColumn ? initialColumns.filter(({ key }) => key !== 'groups') : initialColumns; // additionally insert the "update method" column - columns.splice(columns.length - 1 /* must be penultimate */, 0, { + columns.splice(columns.length - 2 /* must be the 3rd col from the end */, 0, { key: 'update_method', title: 'Update method', sortKey: 'update_method', @@ -53,15 +53,24 @@ const prepareColumns = (initialColumns) => { }); columns[columns.findIndex(({ key }) => key === 'display_name')].renderFunc = - (value, hostId) => ( -
- - {value} - -
- ); + (value, hostId) => ( +
+ + {value} + +
+ ); - return columns; + // map columns to the speicifc order + return [ + 'display_name', + 'system_profile', + 'tags', + 'update_method', + 'groups', + 'updated' + ].map((colKey) => columns.find(({ key }) => key === colKey)) + .filter(Boolean); // eliminate possible undefined's }; const GroupSystems = ({ groupName, groupId }) => { @@ -107,7 +116,7 @@ const GroupSystems = ({ groupName, groupId }) => { { !isModalOpen && prepareColumns(columns, true)} getEntities={async (items, config, showTags, defaultGetEntities) => await defaultGetEntities( items, diff --git a/src/components/InventoryGroups/Modals/AddSystemsToGroupModal.js b/src/components/InventoryGroups/Modals/AddSystemsToGroupModal.js index d239d2b74..950760cf9 100644 --- a/src/components/InventoryGroups/Modals/AddSystemsToGroupModal.js +++ b/src/components/InventoryGroups/Modals/AddSystemsToGroupModal.js @@ -5,49 +5,19 @@ import { FlexItem, Modal } from '@patternfly/react-core'; -import { fitContent, TableVariant } from '@patternfly/react-table'; +import { TableVariant } from '@patternfly/react-table'; import difference from 'lodash/difference'; import map from 'lodash/map'; import PropTypes from 'prop-types'; import React, { useCallback, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { fetchGroupDetail } from '../../../store/inventory-actions'; -import { bulkSelectConfig } from '../../GroupSystems/GroupSystems'; +import { bulkSelectConfig, prepareColumns } from '../../GroupSystems/GroupSystems'; import InventoryTable from '../../InventoryTable/InventoryTable'; import { addHostsToGroupById } from '../utils/api'; import apiWithToast from '../utils/apiWithToast'; import ConfirmSystemsAddModal from './ConfirmSystemsAddModal'; -export const prepareColumns = (initialColumns) => { - const columns = initialColumns; - - // additionally insert the "update method" column - columns.splice(columns.length - 2 /* must be the 3rd col from the end */, 0, { - key: 'update_method', - title: 'Update method', - sortKey: 'update_method', - transforms: [fitContent], - renderFunc: (value, hostId, systemData) => - systemData?.system_profile?.system_update_method || 'N/A', - props: { - // TODO: remove isStatic when the sorting is supported by API - isStatic: true, - width: 10 - } - }); - - // map columns to the speicifc order - return [ - 'display_name', - 'system_profile', - 'tags', - 'update_method', - 'groups', - 'updated' - ].map((colKey) => columns.find(({ key }) => key === colKey)) - .filter(Boolean); // eliminate possible undefined's -}; - const AddSystemsToGroupModal = ({ isModalOpen, setIsModalOpen, @@ -172,7 +142,7 @@ const AddSystemsToGroupModal = ({ variant="large" // required to accomodate the systems table > prepareColumns(columns, false)} variant={TableVariant.compact} // TODO: this doesn't affect the table variant tableProps={{ isStickyHeader: false, From 840e5f1eacd5747e4ee1abb0bf03ead0645f2b49 Mon Sep 17 00:00:00 2001 From: Georgy Karataev Date: Mon, 3 Apr 2023 16:17:37 +0200 Subject: [PATCH 2/3] Show Tags filter in the filters dropdown --- .../Modals/AddSystemsToGroupModal.cy.js | 25 +++++++++++++++++++ .../Modals/AddSystemsToGroupModal.js | 1 + 2 files changed, 26 insertions(+) diff --git a/src/components/InventoryGroups/Modals/AddSystemsToGroupModal.cy.js b/src/components/InventoryGroups/Modals/AddSystemsToGroupModal.cy.js index bc7220c5f..8714c4510 100644 --- a/src/components/InventoryGroups/Modals/AddSystemsToGroupModal.cy.js +++ b/src/components/InventoryGroups/Modals/AddSystemsToGroupModal.cy.js @@ -1,6 +1,7 @@ import { mount } from '@cypress/react'; import { checkTableHeaders, + DROPDOWN_ITEM, MODAL, ouiaId, TABLE @@ -32,6 +33,17 @@ const TABLE_HEADERS = [ 'Last seen' ]; +const AVAILABLE_FILTER_NAMES = [ + 'Name', + 'Status', + 'Operating System', + 'Data Collector', + 'RHC status', + 'Last seen', + 'Group', + 'Tags' +]; + const ALERT = '[data-ouia-component-type="PF4/Alert"]'; before(() => { @@ -156,4 +168,17 @@ describe('AddSystemsToGroupModal', () => { host_ids: ['host-1', 'host-2', 'anim commodo'] // sends the merged list of hosts }); }); + + describe('filters', () => { + it('has correct list of filters', () => { + groupDetailInterceptors['successful with hosts'](); + mountModal(); + + cy.wait('@getHosts'); + cy.get('button[data-ouia-component-id="ConditionalFilter"]').click(); + cy.get(DROPDOWN_ITEM).each(($item, i) => { + expect($item.text()).to.equal(AVAILABLE_FILTER_NAMES[i]); + }); + }); + }); }); diff --git a/src/components/InventoryGroups/Modals/AddSystemsToGroupModal.js b/src/components/InventoryGroups/Modals/AddSystemsToGroupModal.js index 950760cf9..5d092d2a6 100644 --- a/src/components/InventoryGroups/Modals/AddSystemsToGroupModal.js +++ b/src/components/InventoryGroups/Modals/AddSystemsToGroupModal.js @@ -150,6 +150,7 @@ const AddSystemsToGroupModal = ({ }} bulkSelect={bulkSelectConfig(dispatch, selected.size, noneSelected, pageSelected, rows.length)} initialLoading={true} + showTags /> From 47f845630ba87153650a2f6fdc445339916ca074 Mon Sep 17 00:00:00 2001 From: Georgy Karataev Date: Mon, 3 Apr 2023 16:47:53 +0200 Subject: [PATCH 3/3] Fix AddSystemsToGroupModal tests --- .../InventoryGroups/Modals/AddSystemsToGroupModal.cy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/InventoryGroups/Modals/AddSystemsToGroupModal.cy.js b/src/components/InventoryGroups/Modals/AddSystemsToGroupModal.cy.js index 8714c4510..8b6c8cd3b 100644 --- a/src/components/InventoryGroups/Modals/AddSystemsToGroupModal.cy.js +++ b/src/components/InventoryGroups/Modals/AddSystemsToGroupModal.cy.js @@ -127,7 +127,7 @@ describe('AddSystemsToGroupModal', () => { groupDetailInterceptors['successful with hosts'](); mountModal(); - cy.wait('@getHosts'); + cy.get('table[aria-label="Host inventory"]').should('have.attr', 'data-ouia-safe', 'true'); cy.get('button').contains('Add systems').should('be.disabled'); selectRowN(1); cy.get('button').contains('Add systems').click(); @@ -145,7 +145,7 @@ describe('AddSystemsToGroupModal', () => { groupDetailInterceptors['successful with hosts'](); mountModal(); - cy.wait('@getHosts'); + cy.get('table[aria-label="Host inventory"]').should('have.attr', 'data-ouia-safe', 'true'); const i = hostsFixtures.results.findIndex( // eslint-disable-next-line camelcase