@finos/legend-application-pure-ide
Version:
Legend Pure IDE application core
60 lines • 6.96 kB
JavaScript
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 { ArrowCircleRightIcon } from '@finos/legend-art';
import { useApplicationStore } from '@finos/legend-application';
import { usePureIDEStore } from '../PureIDEStoreProvider.js';
import { UnknownSymbolCodeFixSuggestion, UnmatchedFunctionCodeFixSuggestion, } from '../../stores/CodeFixSuggestion.js';
const CandidateWithPackageImportedDisplay = observer((props) => {
const { candidate } = props;
const ideStore = usePureIDEStore();
const applicationStore = useApplicationStore();
const goToResult = () => {
flowResult(ideStore.loadFile(candidate.sourceID, new FileCoordinate(candidate.sourceID, candidate.line, candidate.column))).catch(applicationStore.alertUnhandledError);
};
return (_jsxs("div", { className: "suggestions-panel__entry__content__item", children: [_jsxs("div", { className: "suggestions-panel__entry__content__item__label__candidate", title: "Go to Result", onClick: goToResult, children: [_jsx("div", { className: "suggestions-panel__entry__content__item__label__candidate-name", children: candidate.foundName }), _jsx("div", { className: "suggestions-panel__entry__content__item__label__candidate-location", children: `${trimPathLeadingSlash(candidate.sourceID)} [${candidate.line}:${candidate.column}]` })] }), _jsx("div", { className: "suggestions-panel__entry__content__item__actions", children: _jsx("button", { className: "suggestions-panel__entry__content__item__action", tabIndex: -1, title: "Go to Result", onClick: goToResult, children: _jsx(ArrowCircleRightIcon, {}) }) })] }));
});
const CandidateWithPackageNotImportedDisplay = observer((props) => {
const { candidate } = props;
const ideStore = usePureIDEStore();
const applicationStore = useApplicationStore();
const goToResult = () => {
flowResult(ideStore.loadFile(candidate.sourceID, new FileCoordinate(candidate.sourceID, candidate.line, candidate.column))).catch(applicationStore.alertUnhandledError);
};
const useCandidate = () => {
flowResult(ideStore.updateFileUsingSuggestionCandidate(candidate)).catch(applicationStore.alertUnhandledError);
};
return (_jsxs("div", { className: "suggestions-panel__entry__content__item", children: [_jsxs("div", { className: "suggestions-panel__entry__content__item__label__candidate", title: "Add Suggested Import", onClick: useCandidate, children: [_jsx("div", { className: "suggestions-panel__entry__content__item__label__candidate-name", children: candidate.foundName }), _jsx("div", { className: "suggestions-panel__entry__content__item__label__candidate-location", children: `${trimPathLeadingSlash(candidate.sourceID)} [${candidate.line}:${candidate.column}]` })] }), _jsx("div", { className: "suggestions-panel__entry__content__item__actions", children: _jsx("button", { className: "suggestions-panel__entry__content__item__action", tabIndex: -1, title: "Go to Result", onClick: goToResult, children: _jsx(ArrowCircleRightIcon, {}) }) })] }));
});
const UnmatchedFunctionExecutionResultDisplay = observer((props) => {
const { suggestionState } = props;
const result = suggestionState.result;
return (_jsxs("div", { className: "suggestions-panel__content", children: [!result.candidatesWithPackageImported.length && (_jsx("div", { className: "suggestions-panel__content__header", children: `No functions, in packages already imported, match the function '${result.candidateName}'` })), Boolean(result.candidatesWithPackageImported.length) && (_jsxs(_Fragment, { children: [_jsx("div", { className: "suggestions-panel__content__header", children: `These functions, in packages already imported, would match the function '${result.candidateName}' if you changed the parameters` }), _jsx("div", { className: "suggestions-panel__entry", children: result.candidatesWithPackageImported.map((candidate) => (_jsx(CandidateWithPackageImportedDisplay, { candidate: candidate }, candidate.uuid))) })] })), !result.candidatesWithPackageNotImported.length && (_jsx("div", { className: "suggestions-panel__content__header", children: `No functions, in packages not imported, match the function '${result.candidateName}'` })), Boolean(result.candidatesWithPackageNotImported.length) && (_jsxs(_Fragment, { children: [_jsx("div", { className: "suggestions-panel__content__header", children: `These functions, in packages not imported, match the function '${result.candidateName}'. Click on result to import the necessary package` }), _jsx("div", { className: "suggestions-panel__entry", children: result.candidatesWithPackageNotImported.map((candidate) => (_jsx(CandidateWithPackageNotImportedDisplay, { candidate: candidate }, candidate.uuid))) })] }))] }));
});
const UnmatchExecutionResultDisplay = observer((props) => {
const { suggestionState } = props;
const result = suggestionState.result;
return (_jsxs("div", { className: "suggestions-panel__content", children: [!result.candidates.length && (_jsx("div", { className: "suggestions-panel__content__header", children: `No possible matches found for '${result.candidateName}'` })), Boolean(result.candidates.length) && (_jsxs(_Fragment, { children: [_jsx("div", { className: "suggestions-panel__content__header", children: `Found possible matches for '${result.candidateName}'. Click on result to import the necessary package` }), _jsx("div", { className: "suggestions-panel__entry", children: result.candidates.map((candidate) => (_jsx(CandidateWithPackageNotImportedDisplay, { candidate: candidate }, candidate.uuid))) })] }))] }));
});
export const CodeFixSuggestionsPanel = observer(() => {
const ideStore = usePureIDEStore();
return (_jsxs("div", { className: "suggestions-panel", children: [ideStore.codeFixSuggestion instanceof
UnmatchedFunctionCodeFixSuggestion && (_jsx(UnmatchedFunctionExecutionResultDisplay, { suggestionState: ideStore.codeFixSuggestion })), ideStore.codeFixSuggestion instanceof UnknownSymbolCodeFixSuggestion && (_jsx(UnmatchExecutionResultDisplay, { suggestionState: ideStore.codeFixSuggestion }))] }));
});
//# sourceMappingURL=CodeFixSuggestionsPanel.js.map