]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11036 Handle an error query parameter in the project creation page
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Fri, 3 Aug 2018 11:43:49 +0000 (13:43 +0200)
committerSonarTech <sonartech@sonarsource.com>
Fri, 10 Aug 2018 18:21:31 +0000 (20:21 +0200)
server/sonar-web/src/main/js/apps/projects/create/CreateProjectPage.tsx
server/sonar-web/src/main/js/apps/projects/create/__tests__/CreateProjectPage-test.tsx
server/sonar-web/src/main/js/apps/projects/create/utils.ts

index a3cdbb510a09dae1e1f0e8c1f48a6362bb3f23d5..f4ea23b49bb9667bbac77ba2ceb724977e995f00 100644 (file)
@@ -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
index 42f39b9fb616e1833042f96ef088020cebbb393f..c4dd1380821777f1299cab95a7f58d2bacaf3203 100644 (file)
@@ -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() }}
index f3528d0a633ecd45a1969b0b70fa97955fd026ac..4963cfc5ebc34c102d32ac18245c26478aca92c6 100644 (file)
@@ -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)
   };
 });