Преглед изворни кода

SONAR-12753 Conditional display for the action button

tags/8.2.0.32929
Jeremy Davis пре 4 година
родитељ
комит
4b17d6b79e

+ 5
- 4
server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotActions.tsx Прегледај датотеку

@@ -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);

+ 1
- 1
server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotViewerRenderer.tsx Прегледај датотеку

@@ -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">

+ 9
- 1
server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/HotspotActions-test.tsx Прегледај датотеку

@@ -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}
/>
);
}

+ 5
- 5
server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/HotspotActions-test.tsx.snap Прегледај датотеку

@@ -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"
/>

+ 1
- 0
server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/HotspotViewerRenderer-test.tsx.snap Прегледај датотеку

@@ -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>

+ 2
- 1
sonar-core/src/main/resources/org/sonar/l10n/core.properties Прегледај датотеку

@@ -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

Loading…
Откажи
Сачувај