Skip to content

Commit

Permalink
Refs #36738 - Return SelectAll option
Browse files Browse the repository at this point in the history
  • Loading branch information
ofedoren committed Mar 14, 2024
1 parent 44e5c16 commit d8ecf7a
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react';
import PropTypes from 'prop-types';

import { ExternalLinkSquareAltIcon } from '@patternfly/react-icons';
import { Button } from '@patternfly/react-core';

import { translate as __ } from 'foremanReact/common/I18n';
import { foremanUrl } from 'foremanReact/common/helpers';
import { getHostsPageUrl } from 'foremanReact/Root/Context/ForemanContext';

const ViewSelectedHostsLink = ({
hostIdsParam,
isAllHostsSelected,
defaultFailedHostsSearch,
}) => {
const search = isAllHostsSelected ? defaultFailedHostsSearch : hostIdsParam;
const url = foremanUrl(`${getHostsPageUrl(false)}?search=${search}`);
return (
<Button
component="a"
variant="link"
icon={<ExternalLinkSquareAltIcon />}
iconPosition="right"
target="_blank"
href={url}
>
{__('View selected hosts')}
</Button>
);
};

ViewSelectedHostsLink.propTypes = {
isAllHostsSelected: PropTypes.bool.isRequired,
defaultFailedHostsSearch: PropTypes.string.isRequired,
hostIdsParam: PropTypes.string.isRequired,
};

export default ViewSelectedHostsLink;
2 changes: 0 additions & 2 deletions webpack/components/OpenscapRemediationWizard/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,3 @@ export const supportedRemediationSnippets = (
)
);
};

export const reviewHostCount = hostIdsParam => hostIdsParam.split(',').length;
7 changes: 6 additions & 1 deletion webpack/components/OpenscapRemediationWizard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
selectLogError,
selectLogStatus,
} from './OpenscapRemediationSelectors';
import { REPORT_LOG_REQUEST_KEY } from './constants';
import { REPORT_LOG_REQUEST_KEY, FAIL_RULE_SEARCH } from './constants';
import { SnippetSelect, ReviewHosts, ReviewRemediation, Finish } from './steps';

const OpenscapRemediationWizard = ({
Expand All @@ -29,12 +29,14 @@ const OpenscapRemediationWizard = ({
const source = log?.source?.value || '';
const title = log?.message?.value || '';
const defaultHostIdsParam = `id ^ (${hostId})`;
const defaultFailedHostsSearch = `${FAIL_RULE_SEARCH} = ${source}`;

const [isRemediationWizardOpen, setIsRemediationWizardOpen] = useState(false);
const [snippet, setSnippet] = useState('');
const [method, setMethod] = useState('job');
const [hostIdsParam, setHostIdsParam] = useState(defaultHostIdsParam);
const [isRebootSelected, setIsRebootSelected] = useState(false);
const [isAllHostsSelected, setIsAllHostsSelected] = useState(false);

const onModalButtonClick = e => {
e.preventDefault();
Expand Down Expand Up @@ -111,6 +113,9 @@ const OpenscapRemediationWizard = ({
hostId,
hostIdsParam,
setHostIdsParam,
isAllHostsSelected,
setIsAllHostsSelected,
defaultFailedHostsSearch,
}}
>
<Wizard
Expand Down
38 changes: 26 additions & 12 deletions webpack/components/OpenscapRemediationWizard/steps/Finish.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
import { Button, Bullseye } from '@patternfly/react-core';
import { ExternalLinkSquareAltIcon } from '@patternfly/react-icons';

import { sprintf, translate as __ } from 'foremanReact/common/I18n';
import { translate as __ } from 'foremanReact/common/I18n';
import { foremanUrl } from 'foremanReact/common/helpers';
import { STATUS } from 'foremanReact/constants';
import { useAPI } from 'foremanReact/common/hooks/API/APIHooks';
Expand All @@ -13,7 +13,8 @@ import PermissionDenied from 'foremanReact/components/PermissionDenied';

import OpenscapRemediationWizardContext from '../OpenscapRemediationWizardContext';
import EmptyState from '../../EmptyState';
import { errorMsg, findFixBySnippet, reviewHostCount } from '../helpers';
import ViewSelectedHostsLink from '../ViewSelectedHostsLink';
import { errorMsg, findFixBySnippet } from '../helpers';

import {
JOB_INVOCATION_PATH,
Expand All @@ -24,9 +25,14 @@ import {
} from '../constants';

const Finish = ({ onClose }) => {
const { fixes, snippet, isRebootSelected, hostIdsParam } = useContext(
OpenscapRemediationWizardContext
);
const {
fixes,
snippet,
isRebootSelected,
hostIdsParam,
isAllHostsSelected,
defaultFailedHostsSearch,
} = useContext(OpenscapRemediationWizardContext);

const snippetText = findFixBySnippet(fixes, snippet)?.full_text;

Expand All @@ -50,7 +56,9 @@ const Finish = ({ onClose }) => {
job_invocation: {
feature,
inputs,
search_query: hostIdsParam,
search_query: isAllHostsSelected
? defaultFailedHostsSearch
: hostIdsParam,
},
};
};
Expand Down Expand Up @@ -94,13 +102,19 @@ const Finish = ({ onClose }) => {
const body =
status === STATUS.RESOLVED ? (
<EmptyState
title={sprintf(
__(
'The job has started on %s host(s), you can check the status on the job details page.'
),
reviewHostCount(hostIdsParam)
title={__(
'The job has started on selected host(s), you can check the status on the job details page.'
)}
body={linkToJob}
body={
<>
{linkToJob}
<ViewSelectedHostsLink
isAllHostsSelected={isAllHostsSelected}
hostIdsParam={hostIdsParam}
defaultFailedHostsSearch={defaultFailedHostsSearch}
/>
</>
}
primaryButton={closeBtn}
/>
) : (
Expand Down
37 changes: 22 additions & 15 deletions webpack/components/OpenscapRemediationWizard/steps/ReviewHosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@patternfly/react-core';
import { Td } from '@patternfly/react-table';

import { foremanUrl, noop } from 'foremanReact/common/helpers';
import { foremanUrl } from 'foremanReact/common/helpers';
import { translate as __ } from 'foremanReact/common/I18n';
import SelectAllCheckbox from 'foremanReact/components/PF4/TableIndexPage/Table/SelectAllCheckbox';
import { Table } from 'foremanReact/components/PF4/TableIndexPage/Table/Table';
Expand All @@ -20,20 +20,18 @@ import { useAPI } from 'foremanReact/common/hooks/API/APIHooks';

import OpenscapRemediationWizardContext from '../OpenscapRemediationWizardContext';
import WizardHeader from '../WizardHeader';
import {
HOSTS_API_PATH,
HOSTS_API_REQUEST_KEY,
FAIL_RULE_SEARCH,
} from '../constants';
import { HOSTS_API_PATH, HOSTS_API_REQUEST_KEY } from '../constants';

const ReviewHosts = () => {
const { source, hostId, setHostIdsParam } = useContext(
OpenscapRemediationWizardContext
);
const {
hostId,
setHostIdsParam,
defaultFailedHostsSearch,
setIsAllHostsSelected,
} = useContext(OpenscapRemediationWizardContext);

const defaultSearch = `${FAIL_RULE_SEARCH} = ${source}`;
const defaultParams = {
search: defaultSearch,
search: defaultFailedHostsSearch,
};

const [params, setParams] = useState(defaultParams);
Expand Down Expand Up @@ -70,7 +68,7 @@ const ReviewHosts = () => {
const { fetchBulkParams, ...selectAllOptions } = useBulkSelect({
results,
metadata: { total: subtotalCount, page },
initialSearchQuery: apiSearchQuery || defaultSearch,
initialSearchQuery: apiSearchQuery || defaultFailedHostsSearch,
isSelectable: () => true,
initialArry: [hostId],
});
Expand All @@ -93,11 +91,18 @@ const ReviewHosts = () => {
<ToolbarItem key="selectAll">
<SelectAllCheckbox
{...{
selectAll, // I don't think it really can select all since ids from other pages are still need to be loaded/fetched
selectPage,
selectAll: () => {
selectAll(true);
setIsAllHostsSelected(true);
},
selectPage: () => {
selectPage();
setIsAllHostsSelected(false);
},
selectNone: () => {
selectNone();
selectOne(true, hostId);
setIsAllHostsSelected(false);
},
selectedCount,
pageRowCount,
Expand All @@ -115,6 +120,8 @@ const ReviewHosts = () => {
rowIndex: rowData.id,
onSelect: (_event, isSelecting) => {
selectOne(isSelecting, rowData.id);
// If at least one was unselected, then it's not all selected
if (!isSelecting) setIsAllHostsSelected(false);
},
isSelected: rowData.id === hostId || isSelected(rowData.id),
disable: rowData.id === hostId || false,
Expand Down Expand Up @@ -166,7 +173,7 @@ const ReviewHosts = () => {
refreshData={() =>
setAPIOptions({
key: HOSTS_API_REQUEST_KEY,
params: { defaultSearch },
params: { defaultFailedHostsSearch },
})
}
columns={columns}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ import {
} from '@patternfly/react-core';
import { ExternalLinkSquareAltIcon } from '@patternfly/react-icons';

import { sprintf, translate as __ } from 'foremanReact/common/I18n';
import { translate as __ } from 'foremanReact/common/I18n';
import { foremanUrl } from 'foremanReact/common/helpers';
import { getHostsPageUrl } from 'foremanReact/Root/Context/ForemanContext';

import OpenscapRemediationWizardContext from '../OpenscapRemediationWizardContext';
import WizardHeader from '../WizardHeader';
import ViewSelectedHostsLink from '../ViewSelectedHostsLink';
import { HOSTS_PATH, FAIL_RULE_SEARCH } from '../constants';
import { findFixBySnippet, reviewHostCount } from '../helpers';
import { findFixBySnippet } from '../helpers';

import './ReviewRemediation.scss';

Expand All @@ -34,7 +35,9 @@ const ReviewRemediation = () => {
source,
isRebootSelected,
setIsRebootSelected,
isAllHostsSelected,
hostIdsParam,
defaultFailedHostsSearch,
} = useContext(OpenscapRemediationWizardContext);
const [copied, setCopied] = useState(false);
const selectedFix = findFixBySnippet(fixes, snippet);
Expand All @@ -58,11 +61,8 @@ const ReviewRemediation = () => {
? __(
'Please review the remediation snippet and apply to the host manually.'
)
: sprintf(
__(
'Please review the remediation snippet that will be applied to %s host(s).'
),
reviewHostCount(hostIdsParam)
: __(
'Please review the remediation snippet that will be applied to selected host(s).'
);

const rebootAlertTitle = isRebootRequired()
Expand Down Expand Up @@ -108,6 +108,13 @@ const ReviewRemediation = () => {
${__('Remediation might render the system non-functional.')}`}
/>
</GridItem>
<GridItem md={12} span={4} rowSpan={1}>
<ViewSelectedHostsLink
isAllHostsSelected={isAllHostsSelected}
hostIdsParam={hostIdsParam}
defaultFailedHostsSearch={defaultFailedHostsSearch}
/>
</GridItem>
<GridItem md={12} span={4} rowSpan={1}>
<Button
variant="link"
Expand All @@ -120,7 +127,7 @@ const ReviewRemediation = () => {
{hostName}
</Button>{' '}
</GridItem>
<GridItem span={8} rowSpan={1}>
<GridItem md={12} span={8} rowSpan={1}>
<Button
variant="link"
icon={<ExternalLinkSquareAltIcon />}
Expand Down

0 comments on commit d8ecf7a

Please sign in to comment.