Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve error dialogs #619

Merged
merged 3 commits into from
May 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 36 additions & 2 deletions src/components/BranchMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { classes } from 'typestyle';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import ClearIcon from '@material-ui/icons/Clear';
import { showErrorMessage } from '@jupyterlab/apputils';
import { Dialog, showDialog, showErrorMessage } from '@jupyterlab/apputils';
import { Git, IGitExtension } from '../tokens';
import {
activeListItemClass,
Expand Down Expand Up @@ -314,7 +314,41 @@ export class BranchMenu extends React.Component<
* @param err - error
*/
function onError(err: any): void {
showErrorMessage('Error switching branch', err.message);
if (err.message.includes('following files would be overwritten')) {
showDialog({
title: 'Unable to switch branch',
body: (
<React.Fragment>
<p>
Your changes to the follow files would be overwritten by
fcollonval marked this conversation as resolved.
Show resolved Hide resolved
switching:
</p>
<List>
{err.message
.split('\n')
.slice(1, -3)
.map(renderFileName)}
</List>
<span>
Please commit, stash, or discard your changes before you switch
branches.
</span>
</React.Fragment>
),
buttons: [Dialog.okButton({ label: 'Dismiss' })]
});
} else {
showErrorMessage('Error switching branch', err.message);
}
}

/**
* Render a filename into a list
* @param filename
* @returns ReactElement
*/
function renderFileName(filename: string): React.ReactElement {
return <ListItem key={filename}>{filename}</ListItem>;
}
}
}
7 changes: 6 additions & 1 deletion src/components/FileList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,12 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
discardChanges = async (file: string) => {
const result = await showDialog({
title: 'Discard changes',
body: `Are you sure you want to permanently discard changes to ${file}? This action cannot be undone.`,
body: (
<span>
Are you sure you want to permanently discard changes to <b>{file}</b>?
This action cannot be undone.
</span>
),
buttons: [Dialog.cancelButton(), Dialog.warnButton({ label: 'Discard' })]
});
if (result.button.accept) {
Expand Down
29 changes: 16 additions & 13 deletions src/components/NewBranchDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export class NewBranchDialog extends React.Component<
title="Create a new branch"
value="Create Branch"
onClick={this._onCreate}
disabled={this.state.name === ''}
/>
</DialogActions>
</Dialog>
Expand Down Expand Up @@ -397,19 +398,8 @@ export class NewBranchDialog extends React.Component<
* @param event - event object
*/
private _onCreate = (): void => {
const branch = this.state.name;

// Close the branch dialog:
this.props.onClose();

// Reset the branch name and filter:
this.setState({
name: '',
filter: ''
});

// Create the branch:
this._createBranch(branch);
this._createBranch(this.state.name);
};

/**
Expand All @@ -418,6 +408,7 @@ export class NewBranchDialog extends React.Component<
* @param branch - branch name
*/
private _createBranch(branch: string): void {
const self = this;
const opts = {
newBranch: true,
branchname: branch
Expand All @@ -436,6 +427,15 @@ export class NewBranchDialog extends React.Component<
function onResolve(result: any): void {
if (result.code !== 0) {
showErrorMessage('Error creating branch', result.message);
} else {
// Close the branch dialog:
self.props.onClose();

// Reset the branch name and filter:
self.setState({
name: '',
filter: ''
});
}
}

Expand All @@ -446,7 +446,10 @@ export class NewBranchDialog extends React.Component<
* @param err - error
*/
function onError(err: any): void {
showErrorMessage('Error creating branch', err.message);
showErrorMessage(
'Error creating branch',
err.message.replace(/^fatal:/, '')
);
}
}
}
9 changes: 8 additions & 1 deletion src/style/NewBranchDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,12 @@ export const cancelButtonClass = style({
});

export const createButtonClass = style({
backgroundColor: 'var(--jp-brand-color1)'
backgroundColor: 'var(--jp-brand-color1)',
$nest: {
'&:disabled': {
cursor: 'default',
color: 'var(--jp-ui-inverse-font-color0)',
backgroundColor: 'var(--jp-layout-color3)'
}
}
});