UNPKG

@finos/legend-application-pure-ide

Version:
63 lines 8.75 kB
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } 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 { FileCoordinate, trimPathLeadingSlash, } from '../../server/models/File.js'; import { flowResult } from 'mobx'; import { getConceptInfoLabel } from '../../server/models/Usage.js'; import { BlankPanelContent, ChevronDownIcon, ChevronRightIcon, CloseIcon, CollapseTreeIcon, ExpandTreeIcon, FileAltIcon, PanelLoadingIndicator, PlusIcon, RefreshIcon, TimesIcon, } from '@finos/legend-art'; import { useApplicationStore } from '@finos/legend-application'; import { usePureIDEStore } from '../PureIDEStoreProvider.js'; const ReferenceUsageSearchResultEntryDisplay = observer((props) => { const { referenceUsageResult, result } = props; const ideStore = usePureIDEStore(); const applicationStore = useApplicationStore(); const goToResult = (coordinate) => () => flowResult(ideStore.loadFile(result.sourceId, new FileCoordinate(result.sourceId, coordinate.startLine, coordinate.startColumn))).catch(applicationStore.alertUnhandledError); const dismissResultForFile = () => referenceUsageResult.dismissSearchEntry(result); const dismissCoordinate = (coordinate) => () => { result.dismissCoordinate(coordinate); if (!result.coordinates.length) { referenceUsageResult.dismissSearchEntry(result); } }; return (_jsxs("div", { className: "references-panel__entry", children: [_jsxs("div", { className: "references-panel__entry__header", onClick: () => result.setIsExpanded(!result.isExpanded), children: [_jsxs("div", { className: "references-panel__entry__header__title", children: [_jsx("div", { className: "references-panel__entry__header__title__expander", children: result.isExpanded ? _jsx(ChevronDownIcon, {}) : _jsx(ChevronRightIcon, {}) }), _jsx("div", { className: "references-panel__entry__header__title__label", children: _jsx(FileAltIcon, {}) }), _jsx("div", { className: "references-panel__entry__header__title__content", children: trimPathLeadingSlash(result.sourceId) })] }), _jsxs("div", { className: "references-panel__entry__header__actions", children: [_jsx("div", { className: "references-panel__entry__header__action references-panel__entry__header__action--with-counter", children: _jsx("div", { className: "references-panel__entry__header__action__counter", children: result.coordinates.length }) }), _jsx("button", { className: "references-panel__entry__header__action references-panel__entry__header__action--hidden", tabIndex: -1, title: "Dismiss", onClick: dismissResultForFile, children: _jsx(TimesIcon, {}) })] })] }), result.isExpanded && (_jsx("div", { className: "references-panel__entry__content", children: result.coordinates.map((coordinate) => (_jsxs("div", { className: "references-panel__entry__content__item", children: [_jsxs("div", { className: "references-panel__entry__content__item__label references-panel__entry__content__item__label--full", title: coordinate.preview ? `${coordinate.preview.before}${coordinate.preview.found.replaceAll(/\n/g, '\u21B5')}${coordinate.preview.after}` : 'Go To Result', onClick: goToResult(coordinate), children: [coordinate.preview && (_jsxs("div", { className: "references-panel__entry__content__item__label__content", children: [_jsx("div", { className: "references-panel__entry__content__item__label__coordinates", children: `[${coordinate.startLine}:${coordinate.startColumn}]` }), _jsxs("div", { className: "references-panel__entry__content__item__label__preview", children: [_jsx("span", { className: "references-panel__entry__content__item__label__preview__text", children: coordinate.preview.before }), _jsx("span", { className: "references-panel__entry__content__item__label__preview__text references-panel__entry__content__item__label__preview__text--found", children: coordinate.preview.found.replaceAll(/\n/g, '\u21B5') }), _jsx("span", { className: "references-panel__entry__content__item__label__preview__text", children: coordinate.preview.after })] })] })), !coordinate.preview && (_jsx(_Fragment, { children: `line: ${coordinate.startLine} - column: ${coordinate.startColumn}` }))] }), _jsx("div", { className: "references-panel__entry__content__item__actions", children: _jsx("button", { className: "references-panel__entry__content__item__action references-panel__entry__content__item__action--hidden", tabIndex: -1, title: "Dismiss", onClick: dismissCoordinate(coordinate), children: _jsx(TimesIcon, {}) }) })] }, coordinate.uuid))) }))] })); }); const UsageResultDisplay = observer((props) => { const { referenceUsageState } = props; const ideStore = usePureIDEStore(); const applicationStore = useApplicationStore(); const showExpandAction = referenceUsageState.searchEntries.some((entry) => !entry.isExpanded); const refresh = () => { flowResult(ideStore.findUsages(referenceUsageState.usageConcept)).catch(applicationStore.alertUnhandledError); }; const clear = () => ideStore.setReferenceUsageResult(undefined); const expandAll = () => { referenceUsageState.searchEntries.forEach((entry) => entry.setIsExpanded(true)); }; const collapseAll = () => { referenceUsageState.searchEntries.forEach((entry) => entry.setIsExpanded(false)); }; return (_jsxs("div", { className: "references-panel__content", children: [_jsxs("div", { className: "references-panel__content__header", children: [_jsx("div", { className: "references-panel__content__header__title", children: !referenceUsageState.searchEntries.length ? `No usages found for ${getConceptInfoLabel(referenceUsageState.usageConcept)}` : `${referenceUsageState.numberOfResults} usages(s) in ${referenceUsageState.numberOfFiles} files for ${getConceptInfoLabel(referenceUsageState.usageConcept)}` }), _jsxs("div", { className: "references-panel__content__header__actions", children: [_jsx("button", { className: "references-panel__content__header__action", tabIndex: -1, title: "Refresh", onClick: refresh, children: _jsx(RefreshIcon, {}) }), _jsx("button", { className: "references-panel__content__header__action", tabIndex: -1, title: "Clear", onClick: clear, children: _jsx(CloseIcon, {}) }), !showExpandAction && (_jsx("button", { className: "references-panel__content__header__action", tabIndex: -1, title: "Collapse All", onClick: collapseAll, children: _jsx(CollapseTreeIcon, {}) })), showExpandAction && (_jsx("button", { className: "references-panel__content__header__action", tabIndex: -1, title: "Expand All", onClick: expandAll, children: _jsx(ExpandTreeIcon, {}) }))] })] }), _jsx("div", { className: "references-panel__content__results", children: referenceUsageState.searchEntries.map((searchEntry) => (_jsx(ReferenceUsageSearchResultEntryDisplay, { referenceUsageResult: referenceUsageState, result: searchEntry }, searchEntry.uuid))) })] })); }); export const ReferenceUsagePanel = observer(() => { const ideStore = usePureIDEStore(); return (_jsxs("div", { className: "references-panel", children: [_jsx(PanelLoadingIndicator, { isLoading: ideStore.referenceUsageLoadState.isInProgress }), !ideStore.referenceUsageResult && (_jsx(BlankPanelContent, { children: _jsx("div", { className: "panel-group__splash-screen", children: _jsx("div", { className: "panel-group__splash-screen__content", children: _jsxs("div", { className: "panel-group__splash-screen__content__item", children: [_jsx("div", { className: "panel-group__splash-screen__content__item__label", children: "Find Concept References" }), _jsxs("div", { className: "panel-group__splash-screen__content__item__hot-keys", children: [_jsx("div", { className: "hotkey__key", children: "Alt" }), _jsx("div", { className: "hotkey__plus", children: _jsx(PlusIcon, {}) }), _jsx("div", { className: "hotkey__key", children: "F7" })] })] }) }) }) })), ideStore.referenceUsageResult && (_jsx(UsageResultDisplay, { referenceUsageState: ideStore.referenceUsageResult }))] })); }); //# sourceMappingURL=ReferenceUsagePanel.js.map