@jupyterlab/git
Version:
A JupyterLab extension for version control using git
63 lines (62 loc) • 3.05 kB
JavaScript
import { ReactWidget } from '@jupyterlab/apputils';
import * as React from 'react';
import { PanelWithToolbar, SidePanel } from '@jupyterlab/ui-components';
import { GitPanel } from '../components/GitPanel';
import { Toolbar } from '../components/Toolbar';
import { gitWidgetStyle, sectionBodyStyle, sectionStyle } from '../style/GitWidgetStyle';
/**
* The Git extension's main side-bar widget.
*/
export class GitWidget extends SidePanel {
constructor(model, settings, commands, fileBrowserModel, trans, options) {
super({
...options
});
this.node.id = 'GitSession-root';
this.addClass(gitWidgetStyle);
this._gitTrans = trans;
this._commands = commands;
this._fileBrowserModel = fileBrowserModel;
this._model = model;
this._settings = settings;
const topToolbar = ReactWidget.create(this._renderTopToolbar());
topToolbar.addClass('jp-git-TopToolbar');
this.layout.insertWidget(0, topToolbar);
this.addWidget(this._createSection('Changes', this._createChangesSection()));
this.addWidget(this._createSection('History', this._createHistorySection()));
this.addWidget(this._createSection('Branches and Tags', this._createBranchesSection()));
// Add refresh standby condition if this widget is hidden
model.refreshStandbyCondition = () => !this._settings.composite['refreshIfHidden'] && this.isHidden;
}
/**
* A message handler invoked on a `'before-show'` message.
*/
onBeforeShow(msg) {
// Trigger refresh when the widget is displayed
this._model.refresh().catch(error => {
console.error('Fail to refresh model when displaying GitWidget.', error);
});
super.onBeforeShow(msg);
}
_createSection(title, body) {
const section = new PanelWithToolbar();
section.title.label = title;
section.addClass(sectionStyle);
const reactWidget = ReactWidget.create(body);
reactWidget.addClass(sectionBodyStyle);
section.addWidget(reactWidget);
return section;
}
_createChangesSection() {
return (React.createElement(GitPanel, { commands: this._commands, filebrowser: this._fileBrowserModel, model: this._model, settings: this._settings, trans: this._gitTrans, contentMode: "changes", showNoRepositoryWarning: true }));
}
_createHistorySection() {
return (React.createElement(GitPanel, { commands: this._commands, filebrowser: this._fileBrowserModel, model: this._model, settings: this._settings, trans: this._gitTrans, contentMode: "history" }));
}
_createBranchesSection() {
return (React.createElement(GitPanel, { commands: this._commands, filebrowser: this._fileBrowserModel, model: this._model, settings: this._settings, trans: this._gitTrans, contentMode: "branches" }));
}
_renderTopToolbar() {
return (React.createElement(Toolbar, { commands: this._commands, model: this._model, trans: this._gitTrans }));
}
}