@jupyterlab/git
Version:
A JupyterLab extension for version control using git
57 lines (56 loc) • 1.98 kB
JavaScript
import { Dialog, showErrorMessage } from '@jupyterlab/apputils';
import * as React from 'react';
/**
* Build notification options to display in a dialog the detailed error.
*
* @param error Error object to display
* @param trans Extension translation object
* @returns Notification option to display the full error
*/
export function showError(error, trans) {
return {
autoClose: false,
actions: [
{
label: trans.__('Show'),
callback: () => {
showErrorMessage(trans.__('Error'), {
// Render error in a <pre> element to preserve line breaks and
// use a monospace font so e.g. pre-commit errors are readable.
// Ref: https://github.com/jupyterlab/jupyterlab-git/issues/1407
message: (React.createElement("pre", { style: { whiteSpace: 'pre-wrap', fontSize: '7pt' } }, error.message || error.stack || String(error)))
}, [Dialog.warnButton({ label: trans.__('Dismiss') })]);
},
displayType: 'warn'
}
]
};
}
/**
* Display additional information in a dialog from a notification
* button.
*
* Note: it will not add a button if the message is empty.
*
* @param message Details to display
* @param trans Translation object
* @returns Notification option to display the message
*/
export function showDetails(message, trans) {
return message
? {
autoClose: 5000,
actions: [
{
label: trans.__('Details'),
callback: () => {
showErrorMessage(trans.__('Detailed message'), message, [
Dialog.okButton({ label: trans.__('Dismiss') })
]);
},
displayType: 'warn'
}
]
}
: {};
}