diff options
author | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2018-08-03 13:43:49 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-08-10 20:21:31 +0200 |
commit | 1433bb241ab3527ff4105481f2a597ae4b9c1ca6 (patch) | |
tree | d5462a975c41858a1293477f79b3158b3540a347 /server/sonar-web/src/main | |
parent | e01158776c6dddffa84ffaf5addc14c3b296cb8e (diff) | |
download | sonarqube-1433bb241ab3527ff4105481f2a597ae4b9c1ca6.tar.gz sonarqube-1433bb241ab3527ff4105481f2a597ae4b9c1ca6.zip |
SONAR-11036 Handle an error query parameter in the project creation page
Diffstat (limited to 'server/sonar-web/src/main')
3 files changed, 21 insertions, 2 deletions
diff --git a/server/sonar-web/src/main/js/apps/projects/create/CreateProjectPage.tsx b/server/sonar-web/src/main/js/apps/projects/create/CreateProjectPage.tsx index a3cdbb510a0..f4ea23b49bb 100644 --- a/server/sonar-web/src/main/js/apps/projects/create/CreateProjectPage.tsx +++ b/server/sonar-web/src/main/js/apps/projects/create/CreateProjectPage.tsx @@ -29,6 +29,7 @@ import { serializeQuery, Query, parseQuery } from './utils'; import DeferredSpinner from '../../../components/common/DeferredSpinner'; import handleRequiredAuthentication from '../../../app/utils/handleRequiredAuthentication'; import { getCurrentUser } from '../../../store/rootReducer'; +import { addGlobalErrorMessage } from '../../../store/globalMessages/duck'; import { skipOnboarding as skipOnboardingAction } from '../../../store/users/actions'; import { CurrentUser, IdentityProvider, isLoggedIn, LoggedInUser } from '../../../app/types'; import { skipOnboarding, getIdentityProviders } from '../../../api/users'; @@ -46,6 +47,7 @@ interface StateProps { } interface DispatchProps { + addGlobalErrorMessage: (message: string) => void; skipOnboardingAction: () => void; } @@ -64,6 +66,10 @@ export class CreateProjectPage extends React.PureComponent<Props, State> { constructor(props: Props) { super(props); this.state = { loading: true }; + const query = parseQuery(props.location.query); + if (query.error) { + this.props.addGlobalErrorMessage(query.error); + } if (!this.canAutoCreate(props)) { this.updateQuery({ manual: true }); } @@ -208,7 +214,7 @@ const mapStateToProps = (state: any): StateProps => { }; }; -const mapDispatchToProps: DispatchProps = { skipOnboardingAction }; +const mapDispatchToProps: DispatchProps = { addGlobalErrorMessage, skipOnboardingAction }; export default connect<StateProps, DispatchProps, OwnProps>(mapStateToProps, mapDispatchToProps)( CreateProjectPage diff --git a/server/sonar-web/src/main/js/apps/projects/create/__tests__/CreateProjectPage-test.tsx b/server/sonar-web/src/main/js/apps/projects/create/__tests__/CreateProjectPage-test.tsx index 42f39b9fb61..c4dd1380821 100644 --- a/server/sonar-web/src/main/js/apps/projects/create/__tests__/CreateProjectPage-test.tsx +++ b/server/sonar-web/src/main/js/apps/projects/create/__tests__/CreateProjectPage-test.tsx @@ -77,9 +77,19 @@ it('should switch tabs', async () => { expect(wrapper.find('AutoProjectCreate').exists()).toBeTruthy(); }); +it('should display an error message on load', () => { + const addGlobalErrorMessage = jest.fn(); + getWrapper({ + addGlobalErrorMessage, + location: { pathname: 'foo', query: { error: 'Foo error' } } + }); + expect(addGlobalErrorMessage).toHaveBeenCalledWith('Foo error'); +}); + function getWrapper(props = {}) { return shallow( <CreateProjectPage + addGlobalErrorMessage={jest.fn()} currentUser={user} location={{ pathname: 'foo', query: { manual: 'false' } } as Location} router={{ push: jest.fn(), replace: jest.fn() }} diff --git a/server/sonar-web/src/main/js/apps/projects/create/utils.ts b/server/sonar-web/src/main/js/apps/projects/create/utils.ts index f3528d0a633..4963cfc5ebc 100644 --- a/server/sonar-web/src/main/js/apps/projects/create/utils.ts +++ b/server/sonar-web/src/main/js/apps/projects/create/utils.ts @@ -22,15 +22,18 @@ import { cleanQuery, RawQuery, parseAsBoolean, - serializeOptionalBoolean + serializeOptionalBoolean, + parseAsOptionalString } from '../../../helpers/query'; export interface Query { + error?: string; manual: boolean; } export const parseQuery = memoize((urlQuery: RawQuery): Query => { return { + error: parseAsOptionalString(urlQuery['error']), manual: parseAsBoolean(urlQuery['manual'], false) }; }); |