Skip to content

Commit 8e55f19

Browse files
authored
Add GH button on next-step modal (#1369)
1 parent 5834497 commit 8e55f19

File tree

5 files changed

+69
-24
lines changed

5 files changed

+69
-24
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ nb-configuration.xml
3737
*.orig
3838
*.rej
3939

40+
41+
.env

base/src/main/resources/web/lib/components/api/quarkus-project-utils.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export function getProjectShareUrl(api: Api, project: QuarkusProject, github = f
175175
return `${BASE_LOCATION}?${generateProjectQuery(api, project, github, false)}`;
176176
}
177177

178+
178179
export async function generateProject(api: Api, environment: string, project: QuarkusProject, target: Target): Promise<GenerateResult> {
179180
switch (target) {
180181
case Target.DOWNLOAD:
@@ -191,14 +192,19 @@ export async function generateProject(api: Api, environment: string, project: Qu
191192
}
192193
}
193194

194-
export const createOnGitHub = (api: Api, project: QuarkusProject, clientId: string) => {
195+
export const createOnGitHubUrl = (api: Api, project: QuarkusProject, clientId: string) => {
195196
const authParams = {
196197
redirect_uri: getProjectShareUrl(api, project, true),
197198
client_id: clientId,
198199
scope: 'public_repo,workflow',
199200
state: Math.random().toString(36)
200201
};
201-
window.location.href = `https://github.com/login/oauth/authorize?${stringify(authParams)}`;
202+
return `https://github.com/login/oauth/authorize?${stringify(authParams)}`;
203+
};
204+
205+
206+
export const createOnGitHub = (api: Api, project: QuarkusProject, clientId: string) => {
207+
window.location.href = createOnGitHubUrl(api, project, clientId)
202208
};
203209

204210
export function newDefaultProject(): QuarkusProject {

base/src/main/resources/web/lib/components/code-quarkus.scss

+20-5
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ button.btn, a.btn {
8888
}
8989

9090
h3 {
91-
margin-top: 20px;
91+
margin-top: 10px;
9292
}
9393

9494
}
@@ -99,21 +99,36 @@ button.btn, a.btn {
9999
border: none;
100100
}
101101

102-
a.download-button {
102+
a.action-button, button.action-button {
103+
cursor: pointer;
104+
display: inline-block;
103105
background-color: var(--nextStepsModalDownloadButtonBg);
104106
border: 1px solid var(--nextStepsModalDownloadButtonBg);
105107
color: var(--nextStepsModalDownloadButtonTextColor);
106108
border-radius: 0;
107109
text-transform: uppercase;
108-
width: 200px;
109-
padding: 5px;
110+
padding: 10px;
110111
text-decoration: none;
111-
112+
margin-bottom: 20px;
113+
line-height: 20px;
112114
&:hover {
113115
border: 1px solid var(--nextStepsModalDownloadButtonBorderColorOnHover);
114116
}
117+
svg {
118+
margin-right: 10px;
119+
vertical-align: middle;
120+
}
121+
122+
span {
123+
vertical-align: middle;
124+
}
125+
126+
&.github {
127+
background-color: transparent;
128+
}
115129
}
116130

131+
117132
.modal-footer {
118133
border: none;
119134
button.btn {

base/src/main/resources/web/lib/components/modals/next-steps-modal.tsx

+32-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import * as React from 'react';
22
import { useAnalytics, createLinkTracker } from '../../core/analytics';
33
import { CopyToClipboard, ExternalLink } from '../../core/components';
4-
import { GenerateResult, Target } from '../api/quarkus-project-utils';
5-
import { Extension } from '../api/model';
4+
import {GenerateResult, Target, createOnGitHub} from '../api/quarkus-project-utils';
5+
import {Extension, QuarkusProject} from '../api/model';
66
import { Button, Modal } from 'react-bootstrap';
7+
import { FaGithub, FaFileArchive } from 'react-icons/fa';
8+
import {Api} from "../api/code-quarkus-api";
79

810
interface NextStepsProps {
911
result: GenerateResult;
1012
buildTool: string;
1113
extensions: Extension[];
12-
14+
api: Api;
15+
project: QuarkusProject;
16+
githubClientId?: string;
1317
onClose?(reset?: boolean): void;
1418
}
1519

@@ -28,6 +32,12 @@ export function NextStepsModal(props: NextStepsProps) {
2832
const extensionsWithGuides = props.extensions.filter(e => !!e.guide);
2933
const devModeEventContext = { ...context, label: 'Dev mode command' }
3034
const zip = props.result.target === Target.DOWNLOAD || props.result.target === Target.GENERATE;
35+
36+
const githubClick = (e: any) => {
37+
linkTracker(e);
38+
createOnGitHub(props.api, props.project, props.githubClientId!);
39+
};
40+
3141
return (
3242
<Modal
3343
className="next-steps-modal code-quarkus-modal"
@@ -38,15 +48,22 @@ export function NextStepsModal(props: NextStepsProps) {
3848
<Modal.Header><h2>Your Supersonic Subatomic App is ready!</h2></Modal.Header>
3949
<Modal.Body>
4050
{zip && (
41-
<>
42-
{props.result.target === Target.DOWNLOAD ? (
43-
<p>Your download should start shortly. If it doesn't, please use the direct link:</p>
44-
) : (
45-
<p>It's time to download it:</p>
46-
)}
47-
<Button as="a" href={props.result.url} aria-label="Download the zip" className="download-button"
48-
onClick={linkTracker}>Download the zip</Button>
49-
</>
51+
<>
52+
{props.result.target === Target.DOWNLOAD ? (
53+
<p>Your download should start shortly. If it doesn't, please use the direct link:</p>
54+
) : (
55+
<p>Your download link is ready:</p>
56+
)}
57+
<Button as="a" href={props.result.url} aria-label="Download the zip" className="action-button"
58+
onClick={linkTracker}><FaFileArchive /><span>Download the zip</span></Button>
59+
{props.githubClientId && (
60+
<>
61+
<p>If you want to start collaborating:</p>
62+
<Button as="button" aria-label="Create on GitHub" className="action-button github"
63+
onClick={githubClick}><FaGithub/><span>Push to GitHub</span></Button>
64+
</>
65+
)}
66+
</>
5067
)}
5168
{props.result.target === Target.GITHUB && (
5269
<>
@@ -87,8 +104,9 @@ export function NextStepsModal(props: NextStepsProps) {
87104

88105
</div>
89106
{extensionsWithGuides.length === 1 && (
90-
<div>
91-
<b>Follow the <ExternalLink href={extensionsWithGuides[0].guide!} aria-label={`Open ${extensionsWithGuides[0].name} guide`} onClick={onClickGuide(extensionsWithGuides[0].id)}>{extensionsWithGuides[0].name} guide</ExternalLink> for your next steps!</b>
107+
<div>
108+
<b>Follow the <ExternalLink href={extensionsWithGuides[0].guide!}
109+
aria-label={`Open ${extensionsWithGuides[0].name} guide`} onClick={onClickGuide(extensionsWithGuides[0].id)}>{extensionsWithGuides[0].name} guide</ExternalLink> for your next steps!</b>
92110
</div>
93111
)}
94112
{extensionsWithGuides.length > 1 && (

base/src/main/resources/web/lib/components/quarkus-project/quarkus-project-flow.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ interface QuarkusProjectFlowProps extends ConfiguredCodeQuarkusProps {
3535
}
3636

3737
export function QuarkusProjectFlow(props: QuarkusProjectFlowProps) {
38+
const initialized = React.useRef(false);
3839
const [ run, setRun ] = React.useState<RunState>({ status: Status.EDITION });
3940
const [ missingExtensions, setMissingExtensions ] = React.useState<string[]>([]);
4041
const analytics = useAnalytics();
@@ -59,8 +60,11 @@ export function QuarkusProjectFlow(props: QuarkusProjectFlowProps) {
5960
};
6061

6162
React.useEffect(() => {
62-
if (props.project.github) {
63-
generate(Target.GITHUB);
63+
if (!initialized.current) {
64+
initialized.current = true;
65+
if (props.project.github) {
66+
generate(Target.GITHUB);
67+
}
6468
}
6569
// eslint-disable-next-line
6670
}, []);
@@ -88,7 +92,7 @@ export function QuarkusProjectFlow(props: QuarkusProjectFlowProps) {
8892
<LoadingModal/>
8993
)}
9094
{!run.error && run.status === Status.DOWNLOADED && (
91-
<NextStepsModal onClose={closeModal} result={run.result} buildTool={props.project.metadata.buildTool} extensions={mappedExtensions.mapped}/>
95+
<NextStepsModal api={props.api} project={props.project} githubClientId={props.config.gitHubClientId} onClose={closeModal} result={run.result} buildTool={props.project.metadata.buildTool} extensions={mappedExtensions.mapped}/>
9296
)}
9397
{run.error && (
9498
<ErrorModal onHide={() => closeModal(false)} error={run.error}/>

0 commit comments

Comments
 (0)