@jupyterlab/git
Version:
A JupyterLab extension for version control using git
106 lines (105 loc) • 6.51 kB
JavaScript
import * as React from 'react';
import ClearIcon from '@mui/icons-material/Clear';
import Dialog from '@mui/material/Dialog';
import DialogActions from '@mui/material/DialogActions';
import { showErrorMessage } from '@jupyterlab/apputils';
import { ActionButton } from './ActionButton';
import { classes } from 'typestyle';
import { remoteDialogClass, remoteDialogInputClass, existingRemoteWrapperClass, existingRemoteGridClass, actionsWrapperClass } from '../style/ManageRemoteDialog';
import { buttonClass, closeButtonClass, contentWrapperClass, createButtonClass, titleClass, titleWrapperClass } from '../style/NewBranchDialog';
import { trashIcon } from '../style/icons';
export class ManageRemoteDialogue extends React.Component {
constructor(props) {
super(props);
this._nameInput = null;
this._urlInput = null;
this._addRemoteButton = null;
this.state = {
newRemote: {
name: '',
url: ''
},
existingRemotes: null
};
}
async componentDidMount() {
try {
const remotes = await this.props.model.getRemotes();
this.setState({ existingRemotes: remotes });
}
catch (err) {
console.error(err);
}
}
render() {
return (React.createElement(Dialog, { classes: {
paper: remoteDialogClass
}, open: true, onClose: this.props.onClose },
React.createElement("div", { className: titleWrapperClass },
React.createElement("p", { className: titleClass }, this.props.trans.__('Manage Remotes')),
React.createElement("button", { className: closeButtonClass },
React.createElement(ClearIcon, { titleAccess: this.props.trans.__('Close this dialog'), fontSize: "small", onClick: () => this.props.onClose() }))),
React.createElement("div", { className: contentWrapperClass },
React.createElement("label", { className: remoteDialogInputClass },
React.createElement("span", null, this.props.trans.__('Enter a new remote repository name and URL')),
React.createElement("input", { ref: node => {
this._nameInput = node;
}, type: "text", placeholder: this.props.trans.__('name'), onChange: event => this.setState({
newRemote: {
...this.state.newRemote,
name: event.target.value
}
}) }),
React.createElement("input", { ref: node => {
this._urlInput = node;
}, type: "text", placeholder: this.props.trans.__('Remote Git repository URL'), onChange: event => this.setState({
newRemote: {
...this.state.newRemote,
url: event.target.value
}
}), onKeyPress: e => {
var _a;
if (e.key === 'Enter') {
(_a = this._addRemoteButton) === null || _a === void 0 ? void 0 : _a.click();
}
} })),
this.props.warningContent && (React.createElement("div", { className: "jp-RemoteDialog-warning" }, this.props.warningContent)),
React.createElement(DialogActions, { className: actionsWrapperClass },
React.createElement("input", { ref: btn => {
this._addRemoteButton = btn;
}, className: classes(buttonClass, createButtonClass), type: "button", title: this.props.trans.__('Add Remote'), value: this.props.trans.__('Add'), onClick: async () => {
const { name, url } = this.state.newRemote;
try {
await this.props.model.addRemote(url, name);
this._nameInput.value = '';
this._urlInput.value = '';
this.setState(prevState => {
var _a;
return ({
existingRemotes: [
...((_a = prevState.existingRemotes) !== null && _a !== void 0 ? _a : []),
prevState.newRemote
],
newRemote: { name: '', url: '' }
});
});
}
catch (error) {
console.error(error);
showErrorMessage(this.props.trans.__('Error when adding remote repository'), error);
}
}, disabled: !this.state.newRemote.name || !this.state.newRemote.url })),
React.createElement("div", { className: existingRemoteWrapperClass },
React.createElement("p", null, this.props.trans.__('Existing Remotes:')),
this.state.existingRemotes === null ? (React.createElement("p", null, "Loading remote repositories...")) : this.state.existingRemotes.length > 0 ? (React.createElement("div", { className: existingRemoteGridClass }, this.state.existingRemotes.map((remote, index) => (React.createElement(React.Fragment, { key: `remote-${index}` },
React.createElement("span", null, remote.name),
React.createElement("span", null, remote.url),
React.createElement(ActionButton, { icon: trashIcon, title: this.props.trans.__('Remove this remote'), onClick: async () => {
var _a;
await this.props.model.removeRemote(remote.name);
this.setState({
existingRemotes: ((_a = this.state.existingRemotes) !== null && _a !== void 0 ? _a : []).filter(r => r.name !== remote.name)
});
} })))))) : (React.createElement("p", null, " This repository does not have any remote. "))))));
}
}