@@ -24,17 +24,18 @@ import OutsideClickHandler from 'sonar-ui-common/components/controls/OutsideClic | |||
import DropdownIcon from 'sonar-ui-common/components/icons/DropdownIcon'; | |||
import { PopupPlacement } from 'sonar-ui-common/components/ui/popups'; | |||
import { translate } from 'sonar-ui-common/helpers/l10n'; | |||
import { HotspotUpdateFields } from '../../../types/security-hotspots'; | |||
import { DetailedHotspot, HotspotUpdateFields } from '../../../types/security-hotspots'; | |||
import HotspotActionsForm from './HotspotActionsForm'; | |||
export interface HotspotActionsProps { | |||
hotspotKey: string; | |||
hotspot: DetailedHotspot; | |||
onSubmit: (hotspot: HotspotUpdateFields) => void; | |||
} | |||
const ESCAPE_KEY = 'Escape'; | |||
export default function HotspotActions(props: HotspotActionsProps) { | |||
const { hotspot } = props; | |||
const [open, setOpen] = React.useState(false); | |||
React.useEffect(() => { | |||
@@ -54,7 +55,7 @@ export default function HotspotActions(props: HotspotActionsProps) { | |||
return ( | |||
<div className="dropdown"> | |||
<Button onClick={() => setOpen(!open)}> | |||
{translate('hotspots.review_hotspot')} | |||
{translate('hotspot.change_status', hotspot.status)} | |||
<DropdownIcon className="little-spacer-left" /> | |||
</Button> | |||
@@ -62,7 +63,7 @@ export default function HotspotActions(props: HotspotActionsProps) { | |||
<OutsideClickHandler onClickOutside={() => setOpen(false)}> | |||
<DropdownOverlay placement={PopupPlacement.BottomRight}> | |||
<HotspotActionsForm | |||
hotspotKey={props.hotspotKey} | |||
hotspotKey={hotspot.key} | |||
onSubmit={data => { | |||
setOpen(false); | |||
props.onSubmit(data); |
@@ -48,7 +48,7 @@ export function HotspotViewerRenderer(props: HotspotViewerRendererProps) { | |||
<div className="display-flex-space-between"> | |||
<h1>{hotspot.message}</h1> | |||
{isLoggedIn(currentUser) && ( | |||
<HotspotActions hotspotKey={hotspot.key} onSubmit={props.onUpdateHotspot} /> | |||
<HotspotActions hotspot={hotspot} onSubmit={props.onUpdateHotspot} /> | |||
)} | |||
</div> | |||
<div className="text-muted"> |
@@ -21,6 +21,7 @@ import { shallow } from 'enzyme'; | |||
import * as React from 'react'; | |||
import { Button } from 'sonar-ui-common/components/controls/buttons'; | |||
import { waitAndUpdate } from 'sonar-ui-common/helpers/testUtils'; | |||
import { HotspotStatus } from '../../../../types/security-hotspots'; | |||
import HotspotActions, { HotspotActionsProps } from '../HotspotActions'; | |||
it('should render correctly', () => { | |||
@@ -66,5 +67,12 @@ it('should register an eventlistener', () => { | |||
}); | |||
function shallowRender(props: Partial<HotspotActionsProps> = {}) { | |||
return shallow(<HotspotActions hotspotKey="key" onSubmit={jest.fn()} {...props} />); | |||
return shallow( | |||
<HotspotActions | |||
hotspotKey="key" | |||
hotspotStatus={HotspotStatus.TO_REVIEW} | |||
onSubmit={jest.fn()} | |||
{...props} | |||
/> | |||
); | |||
} |
@@ -7,7 +7,7 @@ exports[`should open when clicked 1`] = ` | |||
<Button | |||
onClick={[Function]} | |||
> | |||
hotspots.review_hotspot | |||
hotspot.change_status.TO_REVIEW | |||
<DropdownIcon | |||
className="little-spacer-left" | |||
/> | |||
@@ -34,7 +34,7 @@ exports[`should register an eventlistener: Dropdown closed 1`] = ` | |||
<Button | |||
onClick={[Function]} | |||
> | |||
hotspots.review_hotspot | |||
hotspot.change_status.TO_REVIEW | |||
<DropdownIcon | |||
className="little-spacer-left" | |||
/> | |||
@@ -49,7 +49,7 @@ exports[`should register an eventlistener: Dropdown open 1`] = ` | |||
<Button | |||
onClick={[Function]} | |||
> | |||
hotspots.review_hotspot | |||
hotspot.change_status.TO_REVIEW | |||
<DropdownIcon | |||
className="little-spacer-left" | |||
/> | |||
@@ -76,7 +76,7 @@ exports[`should register an eventlistener: Dropdown still open 1`] = ` | |||
<Button | |||
onClick={[Function]} | |||
> | |||
hotspots.review_hotspot | |||
hotspot.change_status.TO_REVIEW | |||
<DropdownIcon | |||
className="little-spacer-left" | |||
/> | |||
@@ -103,7 +103,7 @@ exports[`should render correctly 1`] = ` | |||
<Button | |||
onClick={[Function]} | |||
> | |||
hotspots.review_hotspot | |||
hotspot.change_status.TO_REVIEW | |||
<DropdownIcon | |||
className="little-spacer-left" | |||
/> |
@@ -689,6 +689,7 @@ exports[`should render correctly: user logged in 1`] = ` | |||
</h1> | |||
<HotspotActions | |||
hotspotKey="01fc972e-2a3c-433e-bcae-0bd7f88f5123" | |||
hotspotStatus="RESOLVED" | |||
onSubmit={[MockFunction]} | |||
/> | |||
</div> |
@@ -659,7 +659,8 @@ hotspot.assigned_to=Assigned to: | |||
hotspot.tabs.risk_description=What's the risk? | |||
hotspot.tabs.vulnerability_description=Are you vulnerable? | |||
hotspot.tabs.fix_recommendations=How can you fix it? | |||
hotspots.review_hotspot=Review Hotspot | |||
hotspot.change_status.REVIEWED=Change status | |||
hotspot.change_status.TO_REVIEW=Review Hotspot | |||
hotspot.status.TO_REVIEW=To review | |||
hotspot.status.FIXED=Fixed |