Skip to content

Commit 792914b

Browse files
ianhifcollonval
andauthored
improve error dialogs (#619)
* make filenames more noticeable in error dialogs Emphasized the filenames in these dialogs to make it more immediately obvious what files have conflicts/are being discarded. * don't prematurely close new branch dialog if a name wasn't entered or an invalid branch name was entered then the new branch dialog would close once you hit new branch. This makes it so the create branch button is disabled when no name has been entered, and keeps the dialog open until it is clear that branch creation was successful. I also removed the 'fatal' from the git error message as it was redundant with the title of the dialog. * Use same styling than commit button when disabled Co-authored-by: Frederic Collonval <[email protected]>
1 parent dad4ee1 commit 792914b

File tree

4 files changed

+66
-17
lines changed

4 files changed

+66
-17
lines changed

src/components/BranchMenu.tsx

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { classes } from 'typestyle';
33
import List from '@material-ui/core/List';
44
import ListItem from '@material-ui/core/ListItem';
55
import ClearIcon from '@material-ui/icons/Clear';
6-
import { showErrorMessage } from '@jupyterlab/apputils';
6+
import { Dialog, showDialog, showErrorMessage } from '@jupyterlab/apputils';
77
import { Git, IGitExtension } from '../tokens';
88
import {
99
activeListItemClass,
@@ -314,7 +314,41 @@ export class BranchMenu extends React.Component<
314314
* @param err - error
315315
*/
316316
function onError(err: any): void {
317-
showErrorMessage('Error switching branch', err.message);
317+
if (err.message.includes('following files would be overwritten')) {
318+
showDialog({
319+
title: 'Unable to switch branch',
320+
body: (
321+
<React.Fragment>
322+
<p>
323+
Your changes to the follow files would be overwritten by
324+
switching:
325+
</p>
326+
<List>
327+
{err.message
328+
.split('\n')
329+
.slice(1, -3)
330+
.map(renderFileName)}
331+
</List>
332+
<span>
333+
Please commit, stash, or discard your changes before you switch
334+
branches.
335+
</span>
336+
</React.Fragment>
337+
),
338+
buttons: [Dialog.okButton({ label: 'Dismiss' })]
339+
});
340+
} else {
341+
showErrorMessage('Error switching branch', err.message);
342+
}
343+
}
344+
345+
/**
346+
* Render a filename into a list
347+
* @param filename
348+
* @returns ReactElement
349+
*/
350+
function renderFileName(filename: string): React.ReactElement {
351+
return <ListItem key={filename}>{filename}</ListItem>;
318352
}
319353
}
320354
}

src/components/FileList.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,12 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
237237
discardChanges = async (file: string) => {
238238
const result = await showDialog({
239239
title: 'Discard changes',
240-
body: `Are you sure you want to permanently discard changes to ${file}? This action cannot be undone.`,
240+
body: (
241+
<span>
242+
Are you sure you want to permanently discard changes to <b>{file}</b>?
243+
This action cannot be undone.
244+
</span>
245+
),
241246
buttons: [Dialog.cancelButton(), Dialog.warnButton({ label: 'Discard' })]
242247
});
243248
if (result.button.accept) {

src/components/NewBranchDialog.tsx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ export class NewBranchDialog extends React.Component<
204204
title="Create a new branch"
205205
value="Create Branch"
206206
onClick={this._onCreate}
207+
disabled={this.state.name === ''}
207208
/>
208209
</DialogActions>
209210
</Dialog>
@@ -397,19 +398,8 @@ export class NewBranchDialog extends React.Component<
397398
* @param event - event object
398399
*/
399400
private _onCreate = (): void => {
400-
const branch = this.state.name;
401-
402-
// Close the branch dialog:
403-
this.props.onClose();
404-
405-
// Reset the branch name and filter:
406-
this.setState({
407-
name: '',
408-
filter: ''
409-
});
410-
411401
// Create the branch:
412-
this._createBranch(branch);
402+
this._createBranch(this.state.name);
413403
};
414404

415405
/**
@@ -418,6 +408,7 @@ export class NewBranchDialog extends React.Component<
418408
* @param branch - branch name
419409
*/
420410
private _createBranch(branch: string): void {
411+
const self = this;
421412
const opts = {
422413
newBranch: true,
423414
branchname: branch
@@ -436,6 +427,15 @@ export class NewBranchDialog extends React.Component<
436427
function onResolve(result: any): void {
437428
if (result.code !== 0) {
438429
showErrorMessage('Error creating branch', result.message);
430+
} else {
431+
// Close the branch dialog:
432+
self.props.onClose();
433+
434+
// Reset the branch name and filter:
435+
self.setState({
436+
name: '',
437+
filter: ''
438+
});
439439
}
440440
}
441441

@@ -446,7 +446,10 @@ export class NewBranchDialog extends React.Component<
446446
* @param err - error
447447
*/
448448
function onError(err: any): void {
449-
showErrorMessage('Error creating branch', err.message);
449+
showErrorMessage(
450+
'Error creating branch',
451+
err.message.replace(/^fatal:/, '')
452+
);
450453
}
451454
}
452455
}

src/style/NewBranchDialog.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,5 +257,12 @@ export const cancelButtonClass = style({
257257
});
258258

259259
export const createButtonClass = style({
260-
backgroundColor: 'var(--jp-brand-color1)'
260+
backgroundColor: 'var(--jp-brand-color1)',
261+
$nest: {
262+
'&:disabled': {
263+
cursor: 'default',
264+
color: 'var(--jp-ui-inverse-font-color0)',
265+
backgroundColor: 'var(--jp-layout-color3)'
266+
}
267+
}
261268
});

0 commit comments

Comments
 (0)