diff options
author | Jeremy Davis <jeremy.davis@sonarsource.com> | 2022-02-25 09:58:58 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-02-25 20:02:55 +0000 |
commit | f87f174aa6c07d0d5f39f427f4a07978e7e6a53b (patch) | |
tree | b03243636477241cff69dac683dbc29c07b045fd | |
parent | c3602fdcd7063f15fedf56dea5f13756ae0aa7f1 (diff) | |
download | sonarqube-f87f174aa6c07d0d5f39f427f4a07978e7e6a53b.tar.gz sonarqube-f87f174aa6c07d0d5f39f427f4a07978e7e6a53b.zip |
SONAR-16007 Preserve category expansion state
-rw-r--r-- | server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotList.tsx | 9 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotList-test.tsx | 7 |
2 files changed, 7 insertions, 9 deletions
diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotList.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotList.tsx index 610aa769544..3bac3c57ebe 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotList.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotList.tsx @@ -87,11 +87,12 @@ export default class HotspotList extends React.Component<Props, State> { this.setState({ groupedHotspots }); } - if (this.props.selectedHotspotLocation !== prevProps.selectedHotspotLocation) { + if ( + this.props.selectedHotspotLocation !== undefined && + this.props.selectedHotspotLocation !== prevProps.selectedHotspotLocation + ) { const { selectedHotspot } = this.props; - this.setState({ - expandedCategories: { [selectedHotspot.securityCategory]: true } - }); + this.handleToggleCategory(selectedHotspot.securityCategory, true); } } diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotList-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotList-test.tsx index 2d9aa8ea056..574d0d4df6c 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotList-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotList-test.tsx @@ -101,14 +101,11 @@ it('should update grouped hotspots when the list changes', () => { it('should expand the categories for which the location is selected', () => { const wrapper = shallowRender({ hotspots, selectedHotspot: hotspots[0] }); - expect(wrapper.state().expandedCategories).toEqual({ cat2: true }); - - wrapper.instance().handleToggleCategory('cat2', false); - expect(wrapper.state().expandedCategories).toEqual({ cat2: false }); + wrapper.setState({ expandedCategories: { cat1: true, cat2: false } }); wrapper.setProps({ selectedHotspotLocation: 1 }); - expect(wrapper.state().expandedCategories).toEqual({ cat2: true }); + expect(wrapper.state().expandedCategories).toEqual({ cat1: true, cat2: true }); }); function shallowRender(props: Partial<HotspotList['props']> = {}) { |