-
Notifications
You must be signed in to change notification settings - Fork 9.3k
/
tutorial-panel.tsx
316 lines (301 loc) · 11 KB
/
tutorial-panel.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
import * as React from 'react'
import { join } from 'path'
import { LinkButton } from '../lib/link-button'
import { Button } from '../lib/button'
import { Repository } from '../../models/repository'
import { Dispatcher } from '../dispatcher'
import { Octicon } from '../octicons'
import * as OcticonSymbol from '../octicons/octicons.generated'
import {
ValidTutorialStep,
TutorialStep,
orderedTutorialSteps,
} from '../../models/tutorial-step'
import { encodePathAsUrl } from '../../lib/path'
import { PopupType } from '../../models/popup'
import { PreferencesTab } from '../../models/preferences'
import { Ref } from '../lib/ref'
import { suggestedExternalEditor } from '../../lib/editors/shared'
import { TutorialStepInstructions } from './tutorial-step-instruction'
const TutorialPanelImage = encodePathAsUrl(
__dirname,
'static/required-status-check.svg'
)
interface ITutorialPanelProps {
readonly dispatcher: Dispatcher
readonly repository: Repository
/** name of the configured external editor
* (`undefined` if none is configured.)
*/
readonly resolvedExternalEditor: string | null
readonly currentTutorialStep: ValidTutorialStep
readonly onExitTutorial: () => void
}
interface ITutorialPanelState {
/** ID of the currently expanded tutorial step */
readonly currentlyOpenSectionId: ValidTutorialStep
}
/** The Onboarding Tutorial Panel
* Renders a list of expandable tutorial steps (`TutorialListItem`).
* Enforces only having one step expanded at a time through
* event callbacks and local state.
*/
export class TutorialPanel extends React.Component<
ITutorialPanelProps,
ITutorialPanelState
> {
public constructor(props: ITutorialPanelProps) {
super(props)
this.state = { currentlyOpenSectionId: this.props.currentTutorialStep }
}
private openTutorialFileInEditor = () => {
this.props.dispatcher.openInExternalEditor(
// TODO: tie this filename to a shared constant
// for tutorial repos
join(this.props.repository.path, 'README.md')
)
}
private openPullRequest = () => {
this.props.dispatcher.createPullRequest(this.props.repository)
}
private skipEditorInstall = () => {
this.props.dispatcher.skipPickEditorTutorialStep(this.props.repository)
}
private skipCreatePR = () => {
this.props.dispatcher.markPullRequestTutorialStepAsComplete(
this.props.repository
)
}
private isStepComplete = (step: ValidTutorialStep) => {
return (
orderedTutorialSteps.indexOf(step) <
orderedTutorialSteps.indexOf(this.props.currentTutorialStep)
)
}
private isStepNextTodo = (step: ValidTutorialStep) => {
return step === this.props.currentTutorialStep
}
public componentWillReceiveProps(nextProps: ITutorialPanelProps) {
if (this.props.currentTutorialStep !== nextProps.currentTutorialStep) {
this.setState({
currentlyOpenSectionId: nextProps.currentTutorialStep,
})
}
}
public render() {
return (
<div className="tutorial-panel-component panel">
<div className="titleArea">
<h3>Get started</h3>
<img src={TutorialPanelImage} />
</div>
<ol>
<TutorialStepInstructions
summaryText="Install a text editor"
isComplete={this.isStepComplete}
isNextStepTodo={this.isStepNextTodo}
sectionId={TutorialStep.PickEditor}
currentlyOpenSectionId={this.state.currentlyOpenSectionId}
skipLinkButton={<SkipLinkButton onClick={this.skipEditorInstall} />}
onSummaryClick={this.onStepSummaryClick}
>
{!this.isStepComplete(TutorialStep.PickEditor) ? (
<>
<p className="description">
It doesn’t look like you have a text editor installed. We can
recommend{' '}
<LinkButton
uri={suggestedExternalEditor.url}
title={`Open the ${suggestedExternalEditor.name} website`}
>
{suggestedExternalEditor.name}
</LinkButton>
{` or `}
<LinkButton
uri="https://atom.io"
title="Open the Atom website"
>
Atom
</LinkButton>
, but feel free to use any.
</p>
<div className="action">
<LinkButton onClick={this.skipEditorInstall}>
I have an editor
</LinkButton>
</div>
</>
) : (
<p className="description">
Your default editor is{' '}
<strong>{this.props.resolvedExternalEditor}</strong>. You can
change your preferred editor in{' '}
<LinkButton onClick={this.onPreferencesClick}>
{__DARWIN__ ? 'Preferences' : 'options'}
</LinkButton>
</p>
)}
</TutorialStepInstructions>
<TutorialStepInstructions
summaryText="Create a branch"
isComplete={this.isStepComplete}
isNextStepTodo={this.isStepNextTodo}
sectionId={TutorialStep.CreateBranch}
currentlyOpenSectionId={this.state.currentlyOpenSectionId}
onSummaryClick={this.onStepSummaryClick}
>
<p className="description">
{`A branch allows you to work on different versions of a repository at one time. Create a
branch by going into the branch menu in the top bar and
clicking "${__DARWIN__ ? 'New Branch' : 'New branch'}".`}
</p>
<div className="action">
{__DARWIN__ ? (
<>
<kbd>⌘</kbd>
<kbd>⇧</kbd>
<kbd>N</kbd>
</>
) : (
<>
<kbd>Ctrl</kbd>
<kbd>Shift</kbd>
<kbd>N</kbd>
</>
)}
</div>
</TutorialStepInstructions>
<TutorialStepInstructions
summaryText="Edit a file"
isComplete={this.isStepComplete}
isNextStepTodo={this.isStepNextTodo}
sectionId={TutorialStep.EditFile}
currentlyOpenSectionId={this.state.currentlyOpenSectionId}
onSummaryClick={this.onStepSummaryClick}
>
<p className="description">
Open this repository in your preferred text editor. Edit the
{` `}
<Ref>README.md</Ref>
{` `}
file, save it, and come back.
</p>
{this.props.resolvedExternalEditor && (
<div className="action">
<Button onClick={this.openTutorialFileInEditor}>
{__DARWIN__ ? 'Open Editor' : 'Open editor'}
</Button>
{__DARWIN__ ? (
<>
<kbd>⌘</kbd>
<kbd>⇧</kbd>
<kbd>A</kbd>
</>
) : (
<>
<kbd>Ctrl</kbd>
<kbd>Shift</kbd>
<kbd>A</kbd>
</>
)}
</div>
)}
</TutorialStepInstructions>
<TutorialStepInstructions
summaryText="Make a commit"
isComplete={this.isStepComplete}
isNextStepTodo={this.isStepNextTodo}
sectionId={TutorialStep.MakeCommit}
currentlyOpenSectionId={this.state.currentlyOpenSectionId}
onSummaryClick={this.onStepSummaryClick}
>
<p className="description">
A commit allows you to save sets of changes. In the “summary“
field in the bottom left, write a short message that describes the
changes you made. When you’re done, click the blue Commit button
to finish.
</p>
</TutorialStepInstructions>
<TutorialStepInstructions
summaryText="Publish to GitHub"
isComplete={this.isStepComplete}
isNextStepTodo={this.isStepNextTodo}
sectionId={TutorialStep.PushBranch}
currentlyOpenSectionId={this.state.currentlyOpenSectionId}
onSummaryClick={this.onStepSummaryClick}
>
<p className="description">
Publishing will “push”, or upload, your commits to this branch of
your repository on GitHub. Publish using the third button in the
top bar.
</p>
<div className="action">
{__DARWIN__ ? (
<>
<kbd>⌘</kbd>
<kbd>P</kbd>
</>
) : (
<>
<kbd>Ctrl</kbd>
<kbd>P</kbd>
</>
)}
</div>
</TutorialStepInstructions>
<TutorialStepInstructions
summaryText="Open a pull request"
isComplete={this.isStepComplete}
isNextStepTodo={this.isStepNextTodo}
sectionId={TutorialStep.OpenPullRequest}
currentlyOpenSectionId={this.state.currentlyOpenSectionId}
skipLinkButton={<SkipLinkButton onClick={this.skipCreatePR} />}
onSummaryClick={this.onStepSummaryClick}
>
<p className="description">
A pull request allows you to propose changes to the code. By
opening one, you’re requesting that someone review and merge them.
Since this is a demo repository, this pull request will be
private.
</p>
<div className="action">
<Button onClick={this.openPullRequest}>
{__DARWIN__ ? 'Open Pull Request' : 'Open pull request'}
<Octicon symbol={OcticonSymbol.linkExternal} />
</Button>
{__DARWIN__ ? (
<>
<kbd>⌘</kbd>
<kbd>R</kbd>
</>
) : (
<>
<kbd>Ctrl</kbd>
<kbd>R</kbd>
</>
)}
</div>
</TutorialStepInstructions>
</ol>
<div className="footer">
<Button onClick={this.props.onExitTutorial}>
{__DARWIN__ ? 'Exit Tutorial' : 'Exit tutorial'}
</Button>
</div>
</div>
)
}
/** this makes sure we only have one `TutorialListItem` open at a time */
public onStepSummaryClick = (id: ValidTutorialStep) => {
this.setState({ currentlyOpenSectionId: id })
}
private onPreferencesClick = () => {
this.props.dispatcher.showPopup({
type: PopupType.Preferences,
initialSelectedTab: PreferencesTab.Advanced,
})
}
}
const SkipLinkButton: React.FunctionComponent<{
onClick: () => void
}> = props => <LinkButton onClick={props.onClick}>Skip</LinkButton>