import withIndexationGuard from '../../components/hoc/withIndexationGuard';
import { Location, Router, withRouter } from '../../components/hoc/withRouter';
import { getLeakValue } from '../../components/measure/utils';
-import { getBranchLikeQuery, isPullRequest } from '../../helpers/branch-like';
+import { getBranchLikeQuery, isPullRequest, isSameBranchLike } from '../../helpers/branch-like';
import { isInput } from '../../helpers/keyboardEventHelpers';
import { KeyboardKeys } from '../../helpers/keycodes';
import { getStandards } from '../../helpers/security-standard';
branchLike?: BranchLike;
currentUser: CurrentUser;
component: Component;
- isFetchingBranch?: boolean;
location: Location;
router: Router;
}
componentDidMount() {
this.mounted = true;
- if (!this.props.isFetchingBranch) {
- this.fetchInitialData();
- }
+ this.fetchInitialData();
this.registerKeyboardEvents();
}
componentDidUpdate(previous: Props) {
- const wasBranchJustFetched = !!previous.isFetchingBranch && !this.props.isFetchingBranch;
-
if (
- wasBranchJustFetched ||
+ !isSameBranchLike(previous.branchLike, this.props.branchLike) ||
this.props.component.key !== previous.component.key ||
this.props.location.query.hotspots !== previous.location.query.hotspots ||
SECURITY_STANDARDS.some((s) => this.props.location.query[s] !== previous.location.query[s]) ||
}
if (
- wasBranchJustFetched ||
+ !isSameBranchLike(previous.branchLike, this.props.branchLike) ||
isLoggedIn(this.props.currentUser) !== isLoggedIn(previous.currentUser) ||
this.props.location.query.assignedToMe !== previous.location.query.assignedToMe ||
this.props.location.query.inNewCodePeriod !== previous.location.query.inNewCodePeriod
};
fetchInitialData() {
+ const { branchLike: previousBranch } = this.props;
return Promise.all([
getStandards(),
this.fetchSecurityHotspots(),
return;
}
- const selectedHotspot = hotspots.length > 0 ? hotspots[0] : undefined;
+ const { branchLike } = this.props;
- this.setState({
- hotspots,
- hotspotsTotal: paging.total,
- loading: false,
- selectedHotspot,
- standards,
- });
+ if (isSameBranchLike(previousBranch, branchLike)) {
+ const selectedHotspot = hotspots.length > 0 ? hotspots[0] : undefined;
+
+ this.setState({
+ hotspots,
+ hotspotsTotal: paging.total,
+ loading: false,
+ selectedHotspot,
+ standards,
+ });
+ }
})
.catch(this.handleCallFailure);
}
fetchSecurityHotspotsReviewed = () => {
- const { branchLike, component } = this.props;
+ const { branchLike: previousBranch, component } = this.props;
const { filters } = this.state;
const reviewedHotspotsMetricKey = filters.inNewCodePeriod
return getMeasures({
component: component.key,
metricKeys: reviewedHotspotsMetricKey,
- ...getBranchLikeQuery(branchLike),
+ ...getBranchLikeQuery(previousBranch),
})
.then((measures) => {
+ const { branchLike } = this.props;
if (!this.mounted) {
return;
}
- const measure = measures && measures.length > 0 ? measures[0] : undefined;
+ if (isSameBranchLike(previousBranch, branchLike)) {
+ const measure = measures && measures.length > 0 ? measures[0] : undefined;
- const hotspotsReviewedMeasure = filters.inNewCodePeriod
- ? getLeakValue(measure)
- : measure?.value;
+ const hotspotsReviewedMeasure = filters.inNewCodePeriod
+ ? getLeakValue(measure)
+ : measure?.value;
- this.setState({ hotspotsReviewedMeasure, loadingMeasure: false });
+ this.setState({ hotspotsReviewedMeasure, loadingMeasure: false });
+ }
})
.catch(() => {
if (this.mounted) {