Skip to content

Commit

Permalink
Merge pull request #1306 from katerinapat/system-cves-pre-selected
Browse files Browse the repository at this point in the history
fix(VULN-1793): Introduce prevLoadedRows in system details page
  • Loading branch information
kpatticha authored Oct 26, 2021
2 parents 9cb58a8 + e8cb04d commit 8db5dcf
Show file tree
Hide file tree
Showing 13 changed files with 255 additions and 179 deletions.
13 changes: 6 additions & 7 deletions src/Components/SmartComponents/CVEs/CVEs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
changeCveListParameters,
fetchCveListByAccount,
selectCve,
deselectAllCves,
expandCve,
clearCVEsStore
} from '../../../Store/Actions/Actions';
Expand All @@ -37,7 +36,7 @@ export const CVEs = () => {
const [isColumnModalOpen, setColumnModalOpen] = useState(false);

const cveList = useSelector(
({ CVEsStore }) => CVEsStore.cveList
({ CVEsStore }) => CVEsStore.cveList
);
const parameters = useSelector(
({ CVEsStore }) => CVEsStore.parameters
Expand Down Expand Up @@ -94,25 +93,25 @@ export const CVEs = () => {
};

const showBusinessRiskModal = (cvesList, goToFirstPage) => {
const { meta } = cves;
const { meta } = cves;
setBusinessRiskModal(() => () =>
<BusinessRiskModal
cves={cvesList}
updateRef={() => {
dispatch(deselectAllCves());
dispatch(clearCVEsStore());
updateRef(goToFirstPage ? { ...meta, page: 1 } : meta, apply);
}}
/>
);
};

const showStatusModal = (cvesList, goToFirstPage) => {
const { meta } = cves;
const { meta } = cves;
setStatusModal(() => () =>
<StatusModal
cves={cvesList}
updateRef={() => {
dispatch(deselectAllCves());
dispatch(clearCVEsStore());
updateRef(goToFirstPage ? { ...meta, page: 1 } : meta, apply);
}}
/>
Expand Down Expand Up @@ -164,7 +163,7 @@ export const CVEs = () => {
</CVETableContext.Provider>
);
} else {
return <ErrorHandler code={parseInt(cves.errors.status)}/>;
return <ErrorHandler code={parseInt(cves.errors.status)} />;
}

};
Expand Down
28 changes: 14 additions & 14 deletions src/Components/SmartComponents/Modals/CvePairStatusModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const CvePairStatusModal = ({ cveList, updateRef, inventoryList, intl, ty
switch (type) {
case 'systemsExposed': {
const sameAsOverall = inventoryList.every(item =>
item.status_id === cveList[0].status_id && item.justification === cveList[0].justification
item.status_id === cveList[0]?.status_id && item.justification === cveList[0]?.justification
);

if (sameAsOverall) { // overall is only one therefore they are also same to each other
Expand All @@ -56,7 +56,7 @@ export const CvePairStatusModal = ({ cveList, updateRef, inventoryList, intl, ty

case 'systemDetail': {
const sameAsEachOther = cveList.every((item, _, arr) =>
item.status_id === arr[0].status_id && item.justification === arr[0].justification
item.status_id === arr[0]?.status_id && item.justification === arr[0]?.justification
);

const sameAsOverall = cveList.every(item =>
Expand All @@ -83,20 +83,20 @@ export const CvePairStatusModal = ({ cveList, updateRef, inventoryList, intl, ty
else {
const sameAsEachOther = inventoryList.every((item, _, arr) => item.status_id === arr[0].status_id);

return sameAsEachOther ? inventoryList[0].status_id : '0';
return sameAsEachOther ? inventoryList[0]?.status_id : '0';
}
}

case 'systemDetail': {
if (isOverallChecked) {
const sameOverallAsEachOther = cveList.every((item, _, arr) => item.cve_status_id === arr[0].cve_status_id);

return sameOverallAsEachOther ? cveList[0].cve_status_id : '0';
return sameOverallAsEachOther ? cveList[0]?.cve_status_id : '0';
}
else {
const sameAsEachOther = cveList.every((item, _, arr) => item.status_id === arr[0].status_id);

return sameAsEachOther ? cveList[0].status_id : '0';
return sameAsEachOther ? cveList[0]?.status_id : '0';
}
}
}
Expand All @@ -110,24 +110,24 @@ export const CvePairStatusModal = ({ cveList, updateRef, inventoryList, intl, ty
}
else {
const sameAsEachOther = inventoryList.every((item, _, arr) =>
item.justification === arr[0].justification);
item.justification === arr[0]?.justification);

return sameAsEachOther ? inventoryList[0].justification || '' : '';
return sameAsEachOther ? inventoryList[0]?.justification || '' : '';
}
}

case 'systemDetail': {
if (isOverallChecked) {
const sameOverallAsEachOther = cveList.every((item, _, arr) =>
item.cve_justification === arr[0].cve_justification);
item.cve_justification === arr[0]?.cve_justification);

return sameOverallAsEachOther ? cveList[0].cve_justification || '' : '';
return sameOverallAsEachOther ? cveList[0]?.cve_justification || '' : '';
}
else {
const sameAsEachOther = cveList.every((item, _, arr) =>
item.justification === arr[0].justification);
item.justification === arr[0]?.justification);

return sameAsEachOther ? cveList[0].justification || '' : '';
return sameAsEachOther ? cveList[0]?.justification || '' : '';
}
}
}
Expand All @@ -136,11 +136,11 @@ export const CvePairStatusModal = ({ cveList, updateRef, inventoryList, intl, ty
const showDifferentStatusesWarning = () => {
switch (type) {
case 'systemsExposed': {
return inventoryList.some((item, _, arr) => item.status_id !== arr[0].status_id);
return inventoryList.some((item, _, arr) => item.status_id !== arr[0]?.status_id);
}

case 'systemDetail': {
return cveList.some((item, _, arr) => item.status_id !== arr[0].status_id);
return cveList.some((item, _, arr) => item.status_id !== arr[0]?.status_id);
}
}
};
Expand Down Expand Up @@ -186,7 +186,7 @@ export const CvePairStatusModal = ({ cveList, updateRef, inventoryList, intl, ty
messages.cvePairStatusModalSelected,
{
cveCount: cveList.length || 0,
cveId: cveList[0].id, // only used when length is 1
cveId: cveList[0]?.id, // only used when length is 1
systemCount: inventoryList.length || 0,
systemName: inventoryNames[0], // only used when length is 1
b: (...chunks) => <b>{chunks}</b> // explicitly specifying what is wrapped <b> should be bold
Expand Down
6 changes: 3 additions & 3 deletions src/Components/SmartComponents/Remediation/Remediation.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ const Remediation = ({ cves, systems, manyRules, addNotification: dispatchNotifi
if (!manyRules && systems?.length === 1) {
const [systemID] = systems;

issues = cves.reduce((acc, { id: cveID, rules }) => {
issues = cves.reduce((acc, { id: cveID, attributes: { rule } }) => {
let issue = baseIssueTemplate(cveID, systemID);

if (rules?.rule_id) {
issue.id = `${issue.id}:${rules.rule_id}`;
if (rule?.rule_id) {
issue.id = `${issue.id}:${rule.rule_id}`;
}

return [...acc, issue];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const SystemCveToolbarWithContext = ({ entity, intl, context }) => {
methods.openCves(isOpen, expandedRows, !isAllExpanded);
};

const { cves, parameters, methods, selectedCves, isAllExpanded, canEditStatus, canRemediate } = context;
const { cves, parameters, methods, selectedCves, selectedRowsRawData, isAllExpanded, canEditStatus, canRemediate } = context;
const { filter, advisory } = parameters;
const selectedCvesCount = canRemediate && ((selectedCves && selectedCves.length) || 0);

Expand Down Expand Up @@ -67,8 +67,6 @@ const SystemCveToolbarWithContext = ({ entity, intl, context }) => {
}
];

const selectedCvesData = selectedCves.flatMap(item => cves.data.filter(cve => item === cve.id));

return (
<PrimaryToolbar
pagination={{
Expand All @@ -79,7 +77,11 @@ const SystemCveToolbarWithContext = ({ entity, intl, context }) => {
onSetPage: (_event, page) => handleChangePage(_event, page, methods.apply),
onPerPageSelect: (_event, perPage) => handleSetPageSize(_event, perPage, methods.apply)
}}
dedicatedAction={(canRemediate && entity && <Remediation systems={entity} cves={selectedCvesData} />)}
dedicatedAction={(canRemediate && entity &&
<Remediation
systems={entity}
cves={selectedRowsRawData}
/>)}
actionsConfig={{
actions,
dropdownProps: { ouiaId: 'toolbar-actions' }
Expand Down
60 changes: 42 additions & 18 deletions src/Components/SmartComponents/SystemCves/SystemCves.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ export const SystemCVEs = ({ entity, intl, allowedCveActions, showHeaderLabel, s
const selectedCves = useSelector(
({ SystemCvesStore }) => SystemCvesStore.selectedCves
);

const selectedRowsRawData = useSelector(
({ SystemCvesStore }) => SystemCvesStore.selectedRowsRawData || []
);

const expandedRows = useSelector(
({ SystemCvesStore }) => SystemCvesStore.expandedRows
);
Expand All @@ -61,8 +66,13 @@ export const SystemCVEs = ({ entity, intl, allowedCveActions, showHeaderLabel, s

const downloadReport = format => {
const params = { ...parameters, system: entity.id };
DownloadReport.exec(fetchCveListBySystem, params, format, 'system-cves', notification => dispatch(
addNotification(notification)), () => dispatch(clearNotifications()));
DownloadReport.exec(
fetchCveListBySystem,
params,
format,
'system-cves',
notification => dispatch(addNotification(notification)), () => dispatch(clearNotifications())
);
};

const processError = error => {
Expand All @@ -76,7 +86,7 @@ export const SystemCVEs = ({ entity, intl, allowedCveActions, showHeaderLabel, s
/>;
}
else {
return <ErrorHandler code={statusCode}/>;
return <ErrorHandler code={statusCode} />;
}
};

Expand All @@ -92,7 +102,7 @@ export const SystemCVEs = ({ entity, intl, allowedCveActions, showHeaderLabel, s
}

if (isFirstLoad) {
apply({ sort: '-public_date', ...urlParameters });
apply({ sort: '-public_date', ...urlParameters });
setIsFirstLoad(false);
}
else {
Expand All @@ -110,20 +120,33 @@ export const SystemCVEs = ({ entity, intl, allowedCveActions, showHeaderLabel, s
}, [dispatch]);

const showStatusModal = (cvesList, goToFirstPage) => {
let selectedCves = Array.from(cves.data.filter(cve => cvesList.some(element => element.id === cve.id)));
selectedCves = selectedCves.map((
// eslint-disable-next-line camelcase
{ id, cve_status_id, status_id, status_justification: justification, cve_status_justification: cve_justification }) =>
({ id, cve_status_id, status_id, justification, cve_justification })); // omit properties we don't need

setStatusModal(() => () =>
(<CvePairStatusModal
cveList={selectedCves}
updateRef={() => updateRef(goToFirstPage ? { ...cves.meta, page: 1 } : cves.meta, apply)}
let cveList = selectedRowsRawData.map((
{
id,
attributes:
{
// eslint-disable-next-line camelcase
cve_status_id,
// eslint-disable-next-line camelcase
status_id,
status_text: justification,
// eslint-disable-next-line camelcase
cve_status_text: cve_justification
}
}) => ({ id, cve_status_id, status_id, justification, cve_justification }));

setStatusModal(() => () => (
<CvePairStatusModal
cveList={cveList}
updateRef={() => {
dispatch(clearSystemCvesStore());
updateRef(goToFirstPage ? { ...cves.meta, page: 1 } : cves.meta, apply);
}}

inventoryList={[{ id: entity.id, display_name: entity.display_name }]}
type={'systemDetail'}
/>)
);
/>
));
};

const handleCveSelect = (iSelected, payload) => {
Expand All @@ -141,6 +164,7 @@ export const SystemCVEs = ({ entity, intl, allowedCveActions, showHeaderLabel, s
cves,
parameters,
selectedCves,
selectedRowsRawData,
expandedRows,
isAllExpanded,
canRemediate,
Expand Down Expand Up @@ -215,8 +239,8 @@ const TranslateSystemCves = ({ customItnlProvider, ...props }) => {
return <Wrapper {...customItnlProvider && {
locale: navigator.language.slice(0, 2),
messages
} } >
<ConnectedSystemCves { ...props } />
}} >
<ConnectedSystemCves {...props} />
</Wrapper>;
};

Expand Down
Loading

0 comments on commit 8db5dcf

Please sign in to comment.