UNPKG

@finos/legend-application

Version:
70 lines 3.95 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; /** * Copyright (c) 2020-present, Goldman Sachs * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { Dialog, ModalBody, ModalFooter, ModalHeader } from '@finos/legend-art'; import { ActionAlertActionType, ActionAlertType, } from '../stores/AlertService.js'; import { observer } from 'mobx-react-lite'; import { noop } from '@finos/legend-shared'; import { useApplicationStore } from './ApplicationStoreProvider.js'; const getActionButtonClassName = (type) => { switch (type) { case ActionAlertActionType.PROCEED_WITH_CAUTION: return 'btn--caution'; case ActionAlertActionType.PROCEED: case ActionAlertActionType.STANDARD: default: return 'btn--dark'; } }; const ActionAlertContent = observer((props) => { const { info } = props; const applicationStore = useApplicationStore(); const { title, message, prompt, type, onClose, onEnter, actions } = info; const handleClose = () => { onClose?.(); applicationStore.alertService.setActionAlertInfo(undefined); }; const handleEnter = () => onEnter?.(); const handleSubmit = () => { actions.find((action) => action.default)?.handler?.(); handleClose(); }; return (_jsx(Dialog, { open: Boolean(applicationStore.alertService.actionAlertInfo), onClose: noop, TransitionProps: { onEnter: handleEnter, }, children: _jsxs("form", { onSubmit: (event) => { event.preventDefault(); handleSubmit(); }, className: `modal search-modal modal--dark blocking-alert blocking-alert--${(type ?? ActionAlertType.STANDARD).toLowerCase()}`, children: [title && _jsx(ModalHeader, { title: title }), _jsxs(ModalBody, { children: [_jsx("div", { className: "blocking-alert__summary-text", children: message }), _jsx("div", { className: "blocking-alert__prompt-text", children: prompt })] }), _jsxs(ModalFooter, { children: [actions.map((action, idx) => { // NOTE: need to prevent default for the submit button, otherwise, we would get the warning "Form submission canceled because the form is not connected" // See https://stackoverflow.com/a/58234405 const handler = (e) => { e.preventDefault(); action.handler?.(); handleClose(); }; return (_jsx("button", { type: action.default ? 'submit' : 'button', className: `btn btn--dark ${getActionButtonClassName(action.type ?? ActionAlertActionType.STANDARD)}`, onClick: handler, autoFocus: Boolean(action.default), children: action.label }, idx)); }), !actions.length && (_jsx("button", { type: "button" // prevent this toggler being activated on form submission , className: "btn btn--dark blocking-alert__action--standard", onClick: handleClose, children: "Cancel" }))] })] }) })); }); export const ActionAlert = observer(() => { const applicationStore = useApplicationStore(); const actionAlertInfo = applicationStore.alertService.actionAlertInfo; if (!actionAlertInfo) { return null; } return _jsx(ActionAlertContent, { info: actionAlertInfo }); }); //# sourceMappingURL=ActionAlert.js.map