From: Stas Vilchik Date: Wed, 4 Oct 2017 16:16:08 +0000 (+0200) Subject: fix displaying organization name on project dashboard X-Git-Tag: 6.6-RC1~18 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c9b47ff7c654087fa47934f1e4e1424a09c6beca;p=sonarqube.git fix displaying organization name on project dashboard --- diff --git a/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx b/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx index 5c4287ae231..a20ec1d527c 100644 --- a/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx +++ b/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx @@ -18,6 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; +import { connect } from 'react-redux'; import ComponentContainerNotFound from './ComponentContainerNotFound'; import ComponentNav from './nav/component/ComponentNav'; import { Branch, Component } from '../types'; @@ -25,12 +26,16 @@ import handleRequiredAuthorization from '../utils/handleRequiredAuthorization'; import { getBranches } from '../../api/branches'; import { getComponentData } from '../../api/components'; import { getComponentNavigation } from '../../api/nav'; +import { fetchOrganizations } from '../../store/rootActions'; +import { areThereCustomOrganizations } from '../../store/rootReducer'; interface Props { children: any; + fetchOrganizations: (organizations: string[]) => void; location: { query: { branch?: string; id: string }; }; + organizationsEnabled?: boolean; } interface State { @@ -39,7 +44,7 @@ interface State { component: Component | null; } -export default class ComponentContainer extends React.PureComponent { +export class ComponentContainer extends React.PureComponent { mounted: boolean; constructor(props: Props) { @@ -86,6 +91,11 @@ export default class ComponentContainer extends React.PureComponent { const component = this.addQualifier({ ...nav, ...data }); + + if (this.props.organizationsEnabled) { + this.props.fetchOrganizations([component.organization]); + } + this.fetchBranches(component).then(branches => { if (this.mounted) { this.setState({ loading: false, branches, component }); @@ -156,3 +166,11 @@ export default class ComponentContainer extends React.PureComponent ({ + organizationsEnabled: areThereCustomOrganizations(state) +}); + +const mapDispatchToProps = { fetchOrganizations }; + +export default connect(mapStateToProps, mapDispatchToProps)(ComponentContainer); diff --git a/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx index 105931959f9..cd5be6f916c 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx +++ b/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx @@ -28,7 +28,7 @@ jest.mock('../nav/component/ComponentNav', () => ({ import * as React from 'react'; import { shallow, mount } from 'enzyme'; -import ComponentContainer from '../ComponentContainer'; +import { ComponentContainer } from '../ComponentContainer'; import { getBranches } from '../../../api/branches'; import { getComponentData } from '../../../api/components'; import { getComponentNavigation } from '../../../api/nav'; @@ -44,7 +44,7 @@ beforeEach(() => { it('changes component', () => { const wrapper = shallow( - + ); @@ -72,7 +72,7 @@ it("loads branches for module's project", () => { ); mount( - + ); @@ -94,7 +94,7 @@ it("doesn't load branches portfolio", () => { ); const wrapper = mount( - + ); @@ -110,7 +110,7 @@ it("doesn't load branches portfolio", () => { it('updates branches on change', () => { (getBranches as jest.Mock).mockImplementation(() => Promise.resolve([])); const wrapper = shallow( - + ); @@ -123,3 +123,23 @@ it('updates branches on change', () => { (wrapper.find(Inner).prop('onBranchesChange') as Function)(); expect(getBranches).toBeCalledWith('projectKey'); }); + +it('loads organization', () => { + (getComponentData as jest.Mock).mockImplementation(() => + Promise.resolve({ organization: 'org' }) + ); + + const fetchOrganizations = jest.fn(); + mount( + + + + ); + + return doAsync().then(() => { + expect(fetchOrganizations).toBeCalledWith(['org']); + }); +});