From cc26f2f76379066d93d58fa90288d7d6a2a3334c Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Thu, 9 Jan 2020 17:31:53 +0100 Subject: [PATCH] SONAR-12753 Refresh status when commenting --- .../SecurityHotspotsAppRenderer-test.tsx.snap | 8 +++--- .../components/HotspotActions.tsx | 8 +++--- .../components/HotspotActionsForm.tsx | 7 +++--- .../components/HotspotViewer.tsx | 25 +++++++++++++------ .../components/HotspotViewerRenderer.tsx | 4 +-- 5 files changed, 30 insertions(+), 22 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/__tests__/__snapshots__/SecurityHotspotsAppRenderer-test.tsx.snap b/server/sonar-web/src/main/js/apps/securityHotspots/__tests__/__snapshots__/SecurityHotspotsAppRenderer-test.tsx.snap index a99469f0413..5af2220ac69 100644 --- a/server/sonar-web/src/main/js/apps/securityHotspots/__tests__/__snapshots__/SecurityHotspotsAppRenderer-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/securityHotspots/__tests__/__snapshots__/SecurityHotspotsAppRenderer-test.tsx.snap @@ -36,7 +36,7 @@ exports[`should render correctly with hotspots 1`] = ` - - - - void; + onSubmit: () => void; } const ESCAPE_KEY = 'Escape'; @@ -64,9 +64,9 @@ export default function HotspotActions(props: HotspotActionsProps) { { + onSubmit={() => { setOpen(false); - props.onSubmit(data); + props.onSubmit(); }} /> diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotActionsForm.tsx b/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotActionsForm.tsx index 86dd3113604..c5564548006 100644 --- a/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotActionsForm.tsx +++ b/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotActionsForm.tsx @@ -27,14 +27,13 @@ import { Hotspot, HotspotResolution, HotspotStatus, - HotspotStatusOption, - HotspotUpdateFields + HotspotStatusOption } from '../../../types/security-hotspots'; import HotspotActionsFormRenderer from './HotspotActionsFormRenderer'; interface Props { hotspot: Hotspot; - onSubmit: (data: HotspotUpdateFields) => void; + onSubmit: () => void; } interface State { @@ -100,7 +99,7 @@ export default class HotspotActionsForm extends React.Component { .then(() => this.updateAssignee(hotspot, selectedOption, selectedUser)) .then(() => this.addComment(hotspot, comment)) .then(() => { - this.props.onSubmit({ status, resolution }); + this.props.onSubmit(); // No need to set "submitting", we are closing the window }) .catch(() => { diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotViewer.tsx b/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotViewer.tsx index c3b2036255f..480b3001dd0 100644 --- a/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotViewer.tsx +++ b/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotViewer.tsx @@ -21,7 +21,7 @@ import * as React from 'react'; import { getSecurityHotspotDetails } from '../../../api/security-hotspots'; import { BranchLike } from '../../../types/branch-like'; -import { Hotspot, HotspotUpdate, HotspotUpdateFields } from '../../../types/security-hotspots'; +import { Hotspot, HotspotUpdate } from '../../../types/security-hotspots'; import HotspotViewerRenderer from './HotspotViewerRenderer'; interface Props { @@ -58,16 +58,25 @@ export default class HotspotViewer extends React.PureComponent { fetchHotspot() { this.setState({ loading: true }); return getSecurityHotspotDetails(this.props.hotspotKey) - .then(hotspot => this.mounted && this.setState({ hotspot, loading: false })) + .then(hotspot => { + if (this.mounted) { + this.setState({ hotspot, loading: false }); + } + return hotspot; + }) .catch(() => this.mounted && this.setState({ loading: false })); } - handleHotspotUpdate = (data?: HotspotUpdateFields) => { - if (data) { - this.props.onUpdateHotspot({ key: this.props.hotspotKey, ...data }); - } - - this.fetchHotspot(); + handleHotspotUpdate = () => { + return this.fetchHotspot().then((hotspot?: Hotspot) => { + if (hotspot) { + this.props.onUpdateHotspot({ + key: hotspot.key, + status: hotspot.status, + resolution: hotspot.resolution + }); + } + }); }; render() { diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotViewerRenderer.tsx b/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotViewerRenderer.tsx index 9359659c5e7..a12ae55ffe6 100644 --- a/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotViewerRenderer.tsx +++ b/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotViewerRenderer.tsx @@ -23,7 +23,7 @@ import { translate, translateWithParameters } from 'sonar-ui-common/helpers/l10n import { withCurrentUser } from '../../../components/hoc/withCurrentUser'; import { isLoggedIn } from '../../../helpers/users'; import { BranchLike } from '../../../types/branch-like'; -import { Hotspot, HotspotUpdateFields } from '../../../types/security-hotspots'; +import { Hotspot } from '../../../types/security-hotspots'; import HotspotActions from './HotspotActions'; import HotspotSnippetContainer from './HotspotSnippetContainer'; import HotspotViewerTabs from './HotspotViewerTabs'; @@ -33,7 +33,7 @@ export interface HotspotViewerRendererProps { currentUser: T.CurrentUser; hotspot?: Hotspot; loading: boolean; - onUpdateHotspot: (data?: HotspotUpdateFields) => void; + onUpdateHotspot: () => void; securityCategories: T.StandardSecurityCategories; } -- 2.39.5