Skip to content

Commit

Permalink
feat: implement dashbar in the ui (#1544)
Browse files Browse the repository at this point in the history
* Added Dashbar with hardcoded data

* Dashbar is displayed if dashbar = true in url

* updated snap

Co-authored-by: Alexandr Čelakovský <[email protected]>
  • Loading branch information
AsToNlele and AsToNlele authored Feb 16, 2022
1 parent 45a06ad commit 6a92ec1
Show file tree
Hide file tree
Showing 8 changed files with 732 additions and 1 deletion.
8 changes: 8 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@
"cvssVector.popoverTitle": "vector breakdown",
"cvssVector.value": "Value",
"cvssVector.vector": "base score",
"dashbarCriticalVulnerabilitiesFilterText": "Filter by CVEs with critical severity",
"dashbarCriticalVulnerabilitiesTitle": "Critical vulnerabilities",
"dashbarImportantVulnerabilitiesFilterText": "Filter by CVEs with important severity",
"dashbarImportantVulnerabilitiesTitle": "Important vulnerabilities",
"dashbarKnownExploitsFilterText": "Filter by CVEs with known exploits",
"dashbarKnownExploitsTitle": "Known exploits",
"dashbarSecurityRulesFilterText": "Filter by CVEs with security rules",
"dashbarSecurityRulesTitle": "Security Rules",
"description": "CVE description",
"emptyPage.body": "Connect your systems to keep your Red Hat environment running efficiently, with security and compliance with various standards.",
"emptyPage.button": "Learn more about connecting your systems",
Expand Down
129 changes: 129 additions & 0 deletions src/Components/SmartComponents/Dashbar/Dashbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import React from 'react';
import { Card, Grid, GridItem, Split, SplitItem, StackItem, Stack, Alert, CardBody, Text } from '@patternfly/react-core';
import { Main } from '@redhat-cloud-services/frontend-components/Main';
import { SecurityIcon } from '@patternfly/react-icons';
import { CVES_ALLOWED_PARAMS } from '../../../Helpers/constants';
import { constructFilterParameters, useUrlParams } from '../../../Helpers/MiscHelper';
import { useDispatch } from 'react-redux';
import { changeCveListParameters } from '../../../Store/Actions/Actions';
import { FormattedMessage } from 'react-intl';
import messages from '../../../Messages';

const Dashbar = () => {
const dispatch = useDispatch();
const [urlParameters, setUrlParams] = useUrlParams([CVES_ALLOWED_PARAMS]);

const apply = (filterParams = {}) => {
setUrlParams(filterParams);
const params = constructFilterParameters(filterParams);
dispatch(changeCveListParameters(params));
};

return (urlParameters?.dashbar === 'true' &&
<Main style={{ paddingBottom: 0 }}>
<Stack hasGutter>
<StackItem>
<Grid hasGutter>
<GridItem span={12} md={3}>
<Card isFullHeight className="card-box">
<CardBody>
<Text>
<span className="pf-u-font-size-2xl pf-u-font-weight-bold">
5
</span>
<span className="pf-u-font-size-md pf-u-font-weight-light pf-u-ml-sm">
<FormattedMessage {...messages.dashbarKnownExploitsTitle} />
</span>
</Text>
<Text>
<a onClick={() => apply({ ...urlParameters, known_exploit: 'true' })}>
<FormattedMessage {...messages.dashbarKnownExploitsFilterText} />
</a>
</Text>
</CardBody>
</Card>
</GridItem>
<GridItem span={12} md={3}>
<Card isFullHeight>
<CardBody>
<Text>
<span className="pf-u-font-size-2xl pf-u-font-weight-bold">
2
</span>
<span className="pf-u-font-size-md pf-u-font-weight-light pf-u-ml-sm">
<FormattedMessage {...messages.dashbarSecurityRulesTitle} />
</span>
</Text>
<Text>
<a onClick={() => apply({ ...urlParameters, rule_presence: 'true' })}>
<FormattedMessage {...messages.dashbarSecurityRulesFilterText} />
</a>
</Text>
</CardBody>
</Card>
</GridItem>
<GridItem span={12} md={6}>
<Card isFullHeight>
<CardBody>
<Split hasGutter>
<SplitItem isFilled>
<Text>
<SecurityIcon
color="var(--pf-global--danger-color--200)"
size="sm"
noVerticalAlign
/>
<span className="pf-u-ml-sm pf-u-font-size-2xl pf-u-font-weight-bold">
2
</span>
<span className="pf-u-font-size-md pf-u-font-weight-light pf-u-ml-sm">
<FormattedMessage {...messages.dashbarCriticalVulnerabilitiesTitle} />
</span>
</Text>
<Text>
<a onClick={() => apply({ ...urlParameters, impact: '7' })}>
<FormattedMessage {...messages.dashbarCriticalVulnerabilitiesFilterText} />
</a>
</Text>
</SplitItem>
<SplitItem isFilled>
<Text>
<SecurityIcon
color="var(--pf-global--warning-color--100)"
size="sm"
noVerticalAlign
/>
<span className="pf-u-ml-sm pf-u-font-size-2xl pf-u-font-weight-bold">
3
</span>
<span className="pf-u-font-size-md pf-u-font-weight-light pf-u-ml-sm">
<FormattedMessage {...messages.dashbarImportantVulnerabilitiesTitle} />
</span>
</Text>
<Text>
<a onClick={() => apply({ ...urlParameters, impact: '5' })}>
<FormattedMessage {...messages.dashbarImportantVulnerabilitiesFilterText} />
</a>
</Text>
</SplitItem>
</Split>
</CardBody>
</Card>
</GridItem>
</Grid>
</StackItem>
<StackItem>
<Alert
variant="warning"
isInline
title="This is an announcement"
>
Lorem ipsum
</Alert>
</StackItem>
</Stack>
</Main>
);
};

export default Dashbar;
55 changes: 55 additions & 0 deletions src/Components/SmartComponents/Dashbar/Dashbar.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import Dashbar from './Dashbar';
import { Card, Grid } from '@patternfly/react-core';
import toJson from 'enzyme-to-json';
import { mountWithIntl } from '../../../Helpers/MiscHelper';
import { Provider } from 'react-redux';
import configureStore from 'redux-mock-store';
import { BrowserRouter as Router } from 'react-router-dom';
window.insights = {};

jest.mock("react-redux", () => ({
...jest.requireActual("react-redux"),
useSelector: jest.fn(),
useDispatch: jest.fn()
}));

const mockStore = configureStore([store => next => action => { }]);
let store = mockStore({});

jest.mock('../../../Helpers/MiscHelper', () => ({
...jest.requireActual('../../../Helpers/MiscHelper'),
useUrlParams: () => [{ dashbar: "true" }, jest.fn()]
}))

describe('Dashbar', () => {
it('Should match the snapshot', () => {
const wrapper = mountWithIntl(
<Provider store={store}>
<Router>
<Dashbar />
</Router>
</Provider>);
expect(toJson(wrapper)).toMatchSnapshot();
})
it('Should render Grid with props hasGutter = true', () => {
const wrapper = mountWithIntl(
<Provider store={store}>
<Router>
<Dashbar />
</Router>
</Provider>
);
expect(wrapper.find(Grid)).toHaveLength(1);
expect(wrapper.find(Grid).prop('hasGutter')).toBeTruthy();
});
it('Should have 3 card items', () => {
const wrapper = mountWithIntl(
<Provider store={store}>
<Router>
<Dashbar />
</Router>
</Provider>
);
expect(wrapper.find(Card)).toHaveLength(3);
})
})
Loading

0 comments on commit 6a92ec1

Please sign in to comment.