@@ -2,7 +2,8 @@ import * as React from 'react'
2
2
import { UncommittedChangesStrategy } from '../../models/uncommitted-changes-strategy'
3
3
import { DialogContent } from '../dialog'
4
4
import { Checkbox , CheckboxValue } from '../lib/checkbox'
5
- import { RadioButton } from '../lib/radio-button'
5
+ import { RadioGroup } from '../lib/radio-group'
6
+ import { assertNever } from '../../lib/fatal-error'
6
7
7
8
interface IPromptsPreferencesProps {
8
9
readonly confirmRepositoryRemoval : boolean
@@ -134,106 +135,121 @@ export class Prompts extends React.Component<
134
135
this . props . onShowCommitLengthWarningChanged ( event . currentTarget . checked )
135
136
}
136
137
138
+ private renderSwitchBranchOptionLabel = ( key : UncommittedChangesStrategy ) => {
139
+ switch ( key ) {
140
+ case UncommittedChangesStrategy . AskForConfirmation :
141
+ return 'Ask me where I want the changes to go'
142
+ case UncommittedChangesStrategy . MoveToNewBranch :
143
+ return 'Always bring my changes to my new branch'
144
+ case UncommittedChangesStrategy . StashOnCurrentBranch :
145
+ return 'Always stash and leave my changes on the current branch'
146
+ default :
147
+ return assertNever ( key , `Unknown uncommitted changes strategy: ${ key } ` )
148
+ }
149
+ }
150
+
151
+ private renderSwitchBranchOptions = ( ) => {
152
+ const options = [
153
+ UncommittedChangesStrategy . AskForConfirmation ,
154
+ UncommittedChangesStrategy . MoveToNewBranch ,
155
+ UncommittedChangesStrategy . StashOnCurrentBranch ,
156
+ ]
157
+
158
+ const selectedKey =
159
+ options . find ( o => o === this . state . uncommittedChangesStrategy ) ??
160
+ UncommittedChangesStrategy . AskForConfirmation
161
+
162
+ return (
163
+ < div className = "advanced-section" >
164
+ < h2 id = "switch-branch-heading" >
165
+ If I have changes and I switch branches...
166
+ </ h2 >
167
+
168
+ < RadioGroup < UncommittedChangesStrategy >
169
+ ariaLabelledBy = "switch-branch-heading"
170
+ selectedKey = { selectedKey }
171
+ radioButtonKeys = { options }
172
+ onSelectionChanged = { this . onUncommittedChangesStrategyChanged }
173
+ renderRadioButtonLabelContents = { this . renderSwitchBranchOptionLabel }
174
+ />
175
+ </ div >
176
+ )
177
+ }
178
+
137
179
public render ( ) {
138
180
return (
139
181
< DialogContent >
140
182
< div className = "advanced-section" >
141
- < h2 > Show a confirmation dialog before...</ h2 >
142
- < Checkbox
143
- label = "Removing repositories"
144
- value = {
145
- this . state . confirmRepositoryRemoval
146
- ? CheckboxValue . On
147
- : CheckboxValue . Off
148
- }
149
- onChange = { this . onConfirmRepositoryRemovalChanged }
150
- />
151
- < Checkbox
152
- label = "Discarding changes"
153
- value = {
154
- this . state . confirmDiscardChanges
155
- ? CheckboxValue . On
156
- : CheckboxValue . Off
157
- }
158
- onChange = { this . onConfirmDiscardChangesChanged }
159
- />
160
- < Checkbox
161
- label = "Discarding changes permanently"
162
- value = {
163
- this . state . confirmDiscardChangesPermanently
164
- ? CheckboxValue . On
165
- : CheckboxValue . Off
166
- }
167
- onChange = { this . onConfirmDiscardChangesPermanentlyChanged }
168
- />
169
- < Checkbox
170
- label = "Discarding stash"
171
- value = {
172
- this . state . confirmDiscardStash
173
- ? CheckboxValue . On
174
- : CheckboxValue . Off
175
- }
176
- onChange = { this . onConfirmDiscardStashChanged }
177
- />
178
- < Checkbox
179
- label = "Checking out a commit"
180
- value = {
181
- this . state . confirmCheckoutCommit
182
- ? CheckboxValue . On
183
- : CheckboxValue . Off
184
- }
185
- onChange = { this . onConfirmCheckoutCommitChanged }
186
- />
187
- < Checkbox
188
- label = "Force pushing"
189
- value = {
190
- this . state . confirmForcePush ? CheckboxValue . On : CheckboxValue . Off
191
- }
192
- onChange = { this . onConfirmForcePushChanged }
193
- />
194
- < Checkbox
195
- label = "Undo commit"
196
- value = {
197
- this . state . confirmUndoCommit
198
- ? CheckboxValue . On
199
- : CheckboxValue . Off
200
- }
201
- onChange = { this . onConfirmUndoCommitChanged }
202
- />
203
- </ div >
204
- < div className = "advanced-section" >
205
- < h2 > If I have changes and I switch branches...</ h2 >
206
-
207
- < RadioButton
208
- value = { UncommittedChangesStrategy . AskForConfirmation }
209
- checked = {
210
- this . state . uncommittedChangesStrategy ===
211
- UncommittedChangesStrategy . AskForConfirmation
212
- }
213
- label = "Ask me where I want the changes to go"
214
- onSelected = { this . onUncommittedChangesStrategyChanged }
215
- />
216
-
217
- < RadioButton
218
- value = { UncommittedChangesStrategy . MoveToNewBranch }
219
- checked = {
220
- this . state . uncommittedChangesStrategy ===
221
- UncommittedChangesStrategy . MoveToNewBranch
222
- }
223
- label = "Always bring my changes to my new branch"
224
- onSelected = { this . onUncommittedChangesStrategyChanged }
225
- />
226
-
227
- < RadioButton
228
- value = { UncommittedChangesStrategy . StashOnCurrentBranch }
229
- checked = {
230
- this . state . uncommittedChangesStrategy ===
231
- UncommittedChangesStrategy . StashOnCurrentBranch
232
- }
233
- label = "Always stash and leave my changes on the current branch"
234
- onSelected = { this . onUncommittedChangesStrategyChanged }
235
- />
183
+ < h2 id = "show-confirm-dialog-heading" >
184
+ Show a confirmation dialog before...
185
+ </ h2 >
186
+ < div role = "group" aria-labelledby = "show-confirm-dialog-heading" >
187
+ < Checkbox
188
+ label = "Removing repositories"
189
+ value = {
190
+ this . state . confirmRepositoryRemoval
191
+ ? CheckboxValue . On
192
+ : CheckboxValue . Off
193
+ }
194
+ onChange = { this . onConfirmRepositoryRemovalChanged }
195
+ />
196
+ < Checkbox
197
+ label = "Discarding changes"
198
+ value = {
199
+ this . state . confirmDiscardChanges
200
+ ? CheckboxValue . On
201
+ : CheckboxValue . Off
202
+ }
203
+ onChange = { this . onConfirmDiscardChangesChanged }
204
+ />
205
+ < Checkbox
206
+ label = "Discarding changes permanently"
207
+ value = {
208
+ this . state . confirmDiscardChangesPermanently
209
+ ? CheckboxValue . On
210
+ : CheckboxValue . Off
211
+ }
212
+ onChange = { this . onConfirmDiscardChangesPermanentlyChanged }
213
+ />
214
+ < Checkbox
215
+ label = "Discarding stash"
216
+ value = {
217
+ this . state . confirmDiscardStash
218
+ ? CheckboxValue . On
219
+ : CheckboxValue . Off
220
+ }
221
+ onChange = { this . onConfirmDiscardStashChanged }
222
+ />
223
+ < Checkbox
224
+ label = "Checking out a commit"
225
+ value = {
226
+ this . state . confirmCheckoutCommit
227
+ ? CheckboxValue . On
228
+ : CheckboxValue . Off
229
+ }
230
+ onChange = { this . onConfirmCheckoutCommitChanged }
231
+ />
232
+ < Checkbox
233
+ label = "Force pushing"
234
+ value = {
235
+ this . state . confirmForcePush
236
+ ? CheckboxValue . On
237
+ : CheckboxValue . Off
238
+ }
239
+ onChange = { this . onConfirmForcePushChanged }
240
+ />
241
+ < Checkbox
242
+ label = "Undo commit"
243
+ value = {
244
+ this . state . confirmUndoCommit
245
+ ? CheckboxValue . On
246
+ : CheckboxValue . Off
247
+ }
248
+ onChange = { this . onConfirmUndoCommitChanged }
249
+ />
250
+ </ div >
236
251
</ div >
252
+ { this . renderSwitchBranchOptions ( ) }
237
253
< div className = "advanced-section" >
238
254
< h2 > Commit Length</ h2 >
239
255
< Checkbox
0 commit comments