Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ESSNTL-3728): Fix links, show missing tags filter #1824

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/GroupSystems/GroupSystems.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,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;

Expand Down
33 changes: 21 additions & 12 deletions src/components/GroupSystems/GroupSystems.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -53,15 +53,24 @@ const prepareColumns = (initialColumns) => {
});

columns[columns.findIndex(({ key }) => key === 'display_name')].renderFunc =
(value, hostId) => (
<div className="sentry-mask data-hj-suppress">
<Link to={`/${hostId}`}>
{value}
</Link>
</div>
);
(value, hostId) => (
<div className="sentry-mask data-hj-suppress">
<Link to={`/${hostId}`}>
{value}
</Link>
</div>
);

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 }) => {
Expand Down Expand Up @@ -107,8 +116,8 @@ const GroupSystems = ({ groupName, groupId }) => {
{
!isModalOpen &&
<InventoryTable
columns={(columns) => prepareColumns(columns, true)}
hideFilters={{ hostGroupFilter: true }}
columns={prepareColumns}
getEntities={async (items, config, showTags, defaultGetEntities) =>
await defaultGetEntities(
items,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { mount } from '@cypress/react';
import {
checkTableHeaders,
DROPDOWN_ITEM,
MODAL,
ouiaId,
TABLE
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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]);
});
});
});
});
37 changes: 4 additions & 33 deletions src/components/InventoryGroups/Modals/AddSystemsToGroupModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -172,14 +142,15 @@ const AddSystemsToGroupModal = ({
variant="large" // required to accomodate the systems table
>
<InventoryTable
columns={prepareColumns}
columns={(columns) => prepareColumns(columns, false)}
variant={TableVariant.compact} // TODO: this doesn't affect the table variant
tableProps={{
isStickyHeader: false,
canSelectAll: false
}}
bulkSelect={bulkSelectConfig(dispatch, selected.size, noneSelected, pageSelected, rows.length)}
initialLoading={true}
showTags
/>
</Modal>
</>
Expand Down