-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement dashbar in the ui (#1544)
* 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
Showing
8 changed files
with
732 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}) | ||
}) |
Oops, something went wrong.