UNPKG

@jupyterlab/git

Version:

A JupyterLab extension for version control using git

76 lines (75 loc) 3.95 kB
import { Dialog, showDialog } from '@jupyterlab/apputils'; import Button from '@mui/material/Button'; import ButtonGroup from '@mui/material/ButtonGroup'; import { ClickAwayListener } from '@mui/base'; import Grow from '@mui/material/Grow'; import MenuItem from '@mui/material/MenuItem'; import MenuList from '@mui/material/MenuList'; import Paper from '@mui/material/Paper'; import Popper from '@mui/material/Popper'; import React from 'react'; import { classes } from 'typestyle'; import { commitButtonClass, commitPaperClass, commitRoot, commitVariantSelector, disabledStyle } from '../style/CommitBox'; import { verticalMoreIcon } from '../style/icons'; import { rebaseActionStyle } from '../style/RebaseActionStyle'; import { CommandIDs } from '../tokens'; /** * Component to trigger action resolving a rebase. * * @param props Component properties */ export function RebaseAction(props) { const [open, setOpen] = React.useState(false); const anchor = React.useRef(null); const onToggle = React.useCallback(() => { setOpen(!open); }, []); const onClose = React.useCallback((event) => { var _a; if ((_a = anchor.current) === null || _a === void 0 ? void 0 : _a.contains(event.target)) { return; } setOpen(false); }, []); const onContinue = React.useCallback(async () => { await props.commands.execute(CommandIDs.gitResolveRebase, { action: 'continue' }); }, []); const onSkip = React.useCallback(async () => { await props.commands.execute(CommandIDs.gitResolveRebase, { action: 'skip' }); }, []); const onAbort = React.useCallback(async () => { const answer = await showDialog({ title: props.trans.__('Abort rebase'), body: props.trans.__('Are you sure you want to abort the rebase?'), buttons: [ Dialog.cancelButton(), Dialog.warnButton({ label: props.trans.__('Abort') }) ] }); if (answer.button.accept) { await props.commands.execute(CommandIDs.gitResolveRebase, { action: 'abort' }); } }, []); return (React.createElement("div", { className: rebaseActionStyle }, React.createElement(ButtonGroup, { ref: anchor, fullWidth: true, size: "small" }, React.createElement(Button, { classes: { root: commitButtonClass, disabled: disabledStyle }, disabled: props.hasConflict, title: props.trans.__('Continue the rebase.'), onClick: onContinue }, props.trans.__('Continue')), React.createElement(Button, { title: props.trans.__('Pick another rebase action.'), classes: { root: classes(commitButtonClass, commitVariantSelector) }, onClick: onToggle, size: "small", "aria-controls": open ? 'rebase-split-button-menu' : undefined, "aria-expanded": open ? 'true' : undefined }, React.createElement(verticalMoreIcon.react, { tag: "span" }))), React.createElement(Popper, { open: open, anchorEl: anchor.current, transition: true, disablePortal: true }, ({ TransitionProps }) => (React.createElement(Grow, { ...TransitionProps }, React.createElement(Paper, { classes: { root: classes(commitRoot, commitPaperClass) } }, React.createElement(ClickAwayListener, { onClickAway: onClose }, React.createElement(MenuList, { id: "rebase-split-button-menu" }, React.createElement(MenuItem, { key: 'skip', classes: { root: commitRoot }, onClick: onSkip, title: props.trans.__('Skip the current commit.') }, props.trans.__('Skip')), React.createElement(MenuItem, { key: 'abort', classes: { root: commitRoot }, onClick: onAbort, title: props.trans.__('Abort the rebase.') }, props.trans.__('Abort')))))))))); }