UNPKG

@finos/legend-application-pure-ide

Version:
63 lines 3.51 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 { observer } from 'mobx-react-lite'; import { compareLabelFn, CustomSelectorInput, Dialog, } from '@finos/legend-art'; import { useApplicationStore } from '@finos/legend-application'; import { usePureIDEStore } from '../PureIDEStoreProvider.js'; import { flowResult } from 'mobx'; import { useRef, useState } from 'react'; function buildPCTAdapterOption(adapter) { return { label: adapter.name === '' ? adapter.func : adapter.name, value: adapter, }; } export const SelectPCTAdapterCommand = observer(() => { const ideStore = usePureIDEStore(); const applicationStore = useApplicationStore(); const selectorRef = useRef(null); const [menuOpen, setMenuOpen] = useState(false); const closeModal = () => ideStore.setPCTRunPath(undefined); const runPCT = (val) => { if (val) { ideStore.setSelectedPCTAdapter(val.value); if (ideStore.PCTRunPath) { flowResult(ideStore.executeTests(ideStore.PCTRunPath, false, ideStore.selectedPCTAdapter?.func)).catch(applicationStore.alertUnhandledError); } closeModal(); } }; const handleEnter = () => { selectorRef.current?.focus(); }; return (_jsx(Dialog, { open: Boolean(ideStore.PCTRunPath), onClose: closeModal, classes: { container: 'command-modal__container' }, slotProps: { transition: { onEnter: handleEnter }, paper: { classes: { root: 'command-modal__inner-container' } }, }, children: _jsxs("div", { className: "modal modal--dark command-modal", children: [_jsx("div", { className: "modal__title", children: "Select PCT Adapter" }), _jsx("div", { className: "command-modal__content", children: _jsx(CustomSelectorInput, { inputRef: selectorRef, className: "command-modal__content__input", options: ideStore.PCTAdapters.map(buildPCTAdapterOption).sort(compareLabelFn), onMenuOpen: () => setMenuOpen(true), onMenuClose: () => setMenuOpen(false), onKeyDown: (event) => { if (event.key === 'Enter' && ideStore.selectedPCTAdapter && !menuOpen) { event.stopPropagation(); event.preventDefault(); runPCT(buildPCTAdapterOption(ideStore.selectedPCTAdapter)); } }, value: ideStore.selectedPCTAdapter ? buildPCTAdapterOption(ideStore.selectedPCTAdapter) : null, onChange: runPCT, placeholder: "Select a PCT adapter", escapeClearsValue: true, darkMode: !applicationStore.layoutService .TEMPORARY__isLightColorThemeEnabled }) })] }) })); }); //# sourceMappingURL=SelectPCTAdapterCommand.js.map