]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12753 Conditional display for the action button
authorJeremy Davis <jeremy.davis@sonarsource.com>
Tue, 17 Dec 2019 15:50:50 +0000 (16:50 +0100)
committerSonarTech <sonartech@sonarsource.com>
Mon, 13 Jan 2020 19:46:31 +0000 (20:46 +0100)
server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotActions.tsx
server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotViewerRenderer.tsx
server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/HotspotActions-test.tsx
server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/HotspotActions-test.tsx.snap
server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/HotspotViewerRenderer-test.tsx.snap
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 2a59969b48f98e8505b64c9e35e15068583d5c4f..783129cf176e1dbb0f0647aa5fdce91e22344a3d 100644 (file)
@@ -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);
index 163693de895e2347d80687495d0421f229195c2c..21a550631385831fed53c6c3d7fb4599909e9e32 100644 (file)
@@ -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">
index aa92a0044880b796ea19c6000f2df220833c40b8..b1ce8cf1cbdb078c66c311938e7d064836e64cc2 100644 (file)
@@ -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}
+    />
+  );
 }
index efa3d92c629ceba9a246bbb1e078d7e913293537..4ba0565be9ad49616462dc265b22fd5e903f2541 100644 (file)
@@ -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"
     />
index eda423b8398ed876dc299dc8efc5a387f4741e2e..54b431acf164699c74c8fc312ae062e06e964b3d 100644 (file)
@@ -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>
index 9cebe11abfb007f5c099fe744a1fd6615612950c..e9a6699355cf4e1ea302f7f0c0b877270cb459b1 100644 (file)
@@ -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