@finos/legend-application-pure-ide
Version:
Legend Pure IDE application core
62 lines • 3.66 kB
JavaScript
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 { useMemo, useRef } from 'react';
import { observer } from 'mobx-react-lite';
import { flowResult } from 'mobx';
import { clsx, compareLabelFn, CustomSelectorInput, Dialog, RegexIcon, } from '@finos/legend-art';
import { debounce } from '@finos/legend-shared';
import { useApplicationStore } from '@finos/legend-application';
import { usePureIDEStore } from '../PureIDEStoreProvider.js';
export const FileSearchCommand = observer(() => {
const ideStore = usePureIDEStore();
const applicationStore = useApplicationStore();
const loadingOptionsState = ideStore.fileSearchCommandLoadState;
const searchState = ideStore.fileSearchCommandState;
const selectorRef = useRef(null);
// configs
const toggleRegExp = () => searchState.setRegExp(!searchState.isRegExp);
// actions
const debouncedSearch = useMemo(() => debounce(() => {
flowResult(ideStore.searchFile()).catch(applicationStore.alertUnhandledError);
}, 500), [applicationStore, ideStore]);
const closeModal = () => ideStore.setOpenFileSearchCommand(false);
const onSearchTextChange = (val) => {
searchState.setText(val);
debouncedSearch.cancel();
debouncedSearch();
};
const openFile = (val) => {
if (val?.value) {
closeModal();
searchState.reset();
flowResult(ideStore.loadFile(val.value)).catch(applicationStore.alertUnhandledError);
}
};
const handleEnter = () => {
selectorRef.current?.focus();
};
return (_jsx(Dialog, { open: ideStore.openFileSearchCommand, 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: "Open file" }), _jsxs("div", { className: "command-modal__content", children: [_jsx(CustomSelectorInput, { inputRef: selectorRef, className: "command-modal__content__input", options: ideStore.fileSearchCommandResults
.map((option) => ({ label: option, value: option }))
.sort(compareLabelFn), onChange: openFile, onInputChange: onSearchTextChange, placeholder: "Enter file name or path", escapeClearsValue: true, darkMode: !applicationStore.layoutService
.TEMPORARY__isLightColorThemeEnabled, isLoading: loadingOptionsState.isInProgress }), _jsx("button", { className: clsx('command-modal__content__config-btn btn--sm', {
'command-modal__content__config-btn--toggled': searchState.isRegExp,
}), title: `Use Regular Expression (${searchState.isRegExp ? 'on' : 'off'})`, onClick: toggleRegExp, children: _jsx(RegexIcon, {}) })] })] }) }));
});
//# sourceMappingURL=FileSearchCommand.js.map