aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js
diff options
context:
space:
mode:
authorStas Vilchik <stas.vilchik@sonarsource.com>2018-09-19 11:55:00 +0200
committerSonarTech <sonartech@sonarsource.com>2018-09-25 20:21:00 +0200
commit273dde50738358e27873507e6b4a332ea1ec5943 (patch)
tree0c7b9f7480162f5e56d719ab55553bca7d888e6f /server/sonar-web/src/main/js
parentabb68832ff18c47f502cd2ab097b5b4b9fc3a509 (diff)
downloadsonarqube-273dde50738358e27873507e6b4a332ea1ec5943.tar.gz
sonarqube-273dde50738358e27873507e6b4a332ea1ec5943.zip
SONARCLOUD-43 pass organization for manual project creation (#723)
Diffstat (limited to 'server/sonar-web/src/main/js')
-rw-r--r--server/sonar-web/src/main/js/app/components/StartupModal.tsx4
-rw-r--r--server/sonar-web/src/main/js/apps/projects/components/EmptyInstance.tsx8
-rw-r--r--server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/EmptyInstance-test.tsx.snap8
-rw-r--r--server/sonar-web/src/main/js/apps/projects/create/CreateProjectPage.tsx2
-rw-r--r--server/sonar-web/src/main/js/apps/projects/create/ManualProjectCreate.tsx14
-rw-r--r--server/sonar-web/src/main/js/apps/projects/create/utils.ts10
6 files changed, 36 insertions, 10 deletions
diff --git a/server/sonar-web/src/main/js/app/components/StartupModal.tsx b/server/sonar-web/src/main/js/app/components/StartupModal.tsx
index 49863fa9ffc..a5f0263139a 100644
--- a/server/sonar-web/src/main/js/app/components/StartupModal.tsx
+++ b/server/sonar-web/src/main/js/app/components/StartupModal.tsx
@@ -120,10 +120,10 @@ export class StartupModal extends React.PureComponent<Props, State> {
this.props.router.push({ pathname: '/create-organization', state: { paid: true } });
};
- openProjectOnboarding = () => {
+ openProjectOnboarding = (organization?: string) => {
if (isSonarCloud()) {
this.setState({ automatic: false, modal: undefined });
- this.props.router.push(`/projects/create`);
+ this.props.router.push({ pathname: `/projects/create`, query: { organization } });
} else {
this.setState({ modal: ModalKey.projectOnboarding });
}
diff --git a/server/sonar-web/src/main/js/apps/projects/components/EmptyInstance.tsx b/server/sonar-web/src/main/js/apps/projects/components/EmptyInstance.tsx
index a9f09ca7664..974d80815fb 100644
--- a/server/sonar-web/src/main/js/apps/projects/components/EmptyInstance.tsx
+++ b/server/sonar-web/src/main/js/apps/projects/components/EmptyInstance.tsx
@@ -34,6 +34,12 @@ export default class EmptyInstance extends React.PureComponent<Props> {
openProjectOnboarding: PropTypes.func
};
+ analyzeNewProject = () => {
+ const { organization } = this.props;
+ const organizationKey = organization && organization.key;
+ this.context.openProjectOnboarding(organizationKey);
+ };
+
render() {
const { currentUser, organization } = this.props;
const showNewProjectButton = isSonarCloud()
@@ -53,7 +59,7 @@ export default class EmptyInstance extends React.PureComponent<Props> {
{translate('projects.no_projects.empty_instance.how_to_add_projects')}
</p>
<p className="big-spacer-top">
- <Button onClick={this.context.openProjectOnboarding}>
+ <Button onClick={this.analyzeNewProject}>
{translate('embed_docs.analyze_new_project')}
</Button>
</p>
diff --git a/server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/EmptyInstance-test.tsx.snap b/server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/EmptyInstance-test.tsx.snap
index d903a5771aa..89bb1bcf659 100644
--- a/server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/EmptyInstance-test.tsx.snap
+++ b/server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/EmptyInstance-test.tsx.snap
@@ -26,7 +26,9 @@ exports[`renders correctly for SC 2`] = `
<p
className="big-spacer-top"
>
- <Button>
+ <Button
+ onClick={[Function]}
+ >
embed_docs.analyze_new_project
</Button>
</p>
@@ -60,7 +62,9 @@ exports[`renders correctly for SQ 2`] = `
<p
className="big-spacer-top"
>
- <Button>
+ <Button
+ onClick={[Function]}
+ >
embed_docs.analyze_new_project
</Button>
</p>
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 7e27c4accff..f3c9b4a961d 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
@@ -151,6 +151,7 @@ export class CreateProjectPage extends React.PureComponent<Props, State> {
const displayManual = parseQuery(this.props.location.query).manual;
const header = translate('onboarding.create_project.header');
const hasAutoProvisioning = this.canAutoCreate() && identityProvider;
+ const query = parseQuery(this.props.location.query);
return (
<>
<Helmet title={header} titleTemplate="%s" />
@@ -197,6 +198,7 @@ export class CreateProjectPage extends React.PureComponent<Props, State> {
<ManualProjectCreate
currentUser={currentUser}
onProjectCreate={this.handleProjectCreate}
+ organization={query.organization}
/>
) : (
<AutoProjectCreate
diff --git a/server/sonar-web/src/main/js/apps/projects/create/ManualProjectCreate.tsx b/server/sonar-web/src/main/js/apps/projects/create/ManualProjectCreate.tsx
index 9b6c21429de..1101f6484ef 100644
--- a/server/sonar-web/src/main/js/apps/projects/create/ManualProjectCreate.tsx
+++ b/server/sonar-web/src/main/js/apps/projects/create/ManualProjectCreate.tsx
@@ -41,6 +41,7 @@ interface DispatchProps {
interface OwnProps {
currentUser: LoggedInUser;
onProjectCreate: (projectKeys: string[]) => void;
+ organization?: string;
}
type Props = OwnProps & StateProps & DispatchProps;
@@ -60,8 +61,7 @@ export class ManualProjectCreate extends React.PureComponent<Props, State> {
this.state = {
projectName: '',
projectKey: '',
- selectedOrganization:
- props.userOrganizations.length === 1 ? props.userOrganizations[0].key : '',
+ selectedOrganization: this.getInitialSelectedOrganization(props),
submitting: false
};
}
@@ -74,6 +74,16 @@ export class ManualProjectCreate extends React.PureComponent<Props, State> {
this.mounted = false;
}
+ getInitialSelectedOrganization(props: Props) {
+ if (props.organization) {
+ return props.organization;
+ } else if (props.userOrganizations.length === 1) {
+ return props.userOrganizations[0].key;
+ } else {
+ return '';
+ }
+ }
+
handleFormSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
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 64a746fc61c..ed3f0b178fb 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
@@ -23,19 +23,22 @@ import {
RawQuery,
parseAsBoolean,
serializeOptionalBoolean,
- parseAsOptionalString
+ parseAsOptionalString,
+ serializeString
} from '../../../helpers/query';
export interface Query {
error?: string;
manual: boolean;
+ organization?: string;
}
export const parseQuery = memoize(
(urlQuery: RawQuery): Query => {
return {
error: parseAsOptionalString(urlQuery['error']),
- manual: parseAsBoolean(urlQuery['manual'], false)
+ manual: parseAsBoolean(urlQuery['manual'], false),
+ organization: parseAsOptionalString(urlQuery['organization'])
};
}
);
@@ -43,6 +46,7 @@ export const parseQuery = memoize(
export const serializeQuery = memoize(
(query: Query): RawQuery =>
cleanQuery({
- manual: serializeOptionalBoolean(query.manual || undefined)
+ manual: serializeOptionalBoolean(query.manual || undefined),
+ organization: serializeString(query.organization)
})
);