@finos/legend-extension-dsl-data-space
Version:
Legend extension for Data Space DSL
114 lines • 7.91 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 { PanelHeader, BasePopover, ClickAwayListener, ShareIcon, TagIcon, } from '@finos/legend-art';
import { observer } from 'mobx-react-lite';
import { useEffect, useRef } from 'react';
import { ActionAlertActionType, ActionAlertType, useApplicationStore, } from '@finos/legend-application';
import { DocumentationLink } from '@finos/legend-lego/application';
import { DSL_DATA_SPACE_LEGEND_QUERY_DOCUMENTATION_KEY } from '../../__lib__/query/DSL_DataSpace_LegendQueryDocumentation.js';
import { flowResult } from 'mobx';
const DataSpaceTemplateQueryDialog = observer((props) => {
const { triggerElement, queryBuilderState, templateQueries } = props;
const applicationStore = useApplicationStore();
const handleClose = () => {
queryBuilderState.setTemplateQueryDialogOpen(false);
};
const loadTemplateQuery = async (template) => {
let query;
if (template.info) {
query =
await queryBuilderState.graphManagerState.graphManager.pureCodeToLambda(template.info.query);
}
if (!query) {
applicationStore.notificationService.notifyError('Unable get a query from this template query');
}
else {
const executionContext = queryBuilderState.dataSpace.executionContexts.filter((ex) => ex.name === template.info?.executionContextKey)[0];
if (executionContext &&
executionContext.name !== queryBuilderState.executionContext.name) {
queryBuilderState.setExecutionContext(executionContext);
await queryBuilderState.propagateExecutionContextChange();
queryBuilderState.initializeWithQuery(query);
queryBuilderState.onExecutionContextChange?.(executionContext);
}
else {
queryBuilderState.initializeWithQuery(query);
}
}
handleClose();
};
const loadQuery = async (template) => {
if (queryBuilderState.changeDetectionState.hasChanged) {
applicationStore.alertService.setActionAlertInfo({
message: 'Unsaved changes will be lost if you continue. Do you still want to proceed?',
type: ActionAlertType.CAUTION,
actions: [
{
label: 'Proceed',
type: ActionAlertActionType.PROCEED_WITH_CAUTION,
handler: () => {
flowResult(loadTemplateQuery(template));
},
},
{
label: 'Abort',
type: ActionAlertActionType.PROCEED,
default: true,
},
],
});
}
else {
flowResult(loadTemplateQuery(template));
}
};
const visitTemplateQuery = (template) => {
if (queryBuilderState.canVisitTemplateQuery) {
queryBuilderState.visitTemplateQuery(queryBuilderState.dataSpace, template);
}
};
return (_jsx(ClickAwayListener, { onClickAway: handleClose, children: _jsx("div", { children: _jsx(BasePopover, { open: queryBuilderState.isTemplateQueryDialogOpen, slotProps: {
paper: {
classes: {
root: '"query-builder__data-space__template-query-panel__container__root',
},
},
}, className: "query-builder__data-space__template-query-panel__container", onClose: handleClose, anchorEl: triggerElement, anchorOrigin: {
vertical: 'bottom',
horizontal: 'left',
}, transformOrigin: {
vertical: 'top',
horizontal: 'center',
}, children: _jsxs("div", { className: "query-builder__data-space__template-query-panel", children: [_jsxs("div", { className: "query-builder__data-space__template-query-panel__header", children: ["Curated Template Queries", _jsx(DocumentationLink, { documentationKey: DSL_DATA_SPACE_LEGEND_QUERY_DOCUMENTATION_KEY.CURATED_TEMPLATE_QUERY })] }), templateQueries.map((query) => (_jsxs("div", { className: "query-builder__data-space__template-query-panel__query", children: [_jsx(TagIcon, { className: "query-builder__data-space__template-query-panel__query__icon" }), _jsx("button", { className: "query-builder__data-space__template-query-panel__query__entry", title: "click to load template query", onClick: () => {
flowResult(loadQuery(query));
}, children: _jsxs("div", { className: "query-builder__data-space__template-query-panel__query__entry__content", children: [_jsx("div", { className: "query-builder__data-space__template-query-panel__query__entry__content__title", children: query.title }), query.description && (_jsx("div", { className: "query-builder__data-space__template-query-panel__query__entry__content__description", children: query.description }))] }) }), _jsxs("button", { className: "query-builder__data-space__template-query-panel__query__share", title: "Visit...", disabled: !queryBuilderState.canVisitTemplateQuery, onClick: () => visitTemplateQuery(query), children: [_jsx(ShareIcon, {}), _jsx("div", { className: "query-builder__data-space__template-query-panel__query__share__label", children: "Visit" })] })] }, query.title)))] }) }) }) }));
});
const DataSpaceQueryBuilderTemplateQueryPanel = observer((props) => {
const { queryBuilderState } = props;
const applicationStore = useApplicationStore();
const templateQueryButtonRef = useRef(null);
const showTemplateQueries = () => {
queryBuilderState.setTemplateQueryDialogOpen(true);
};
const templateQueries = queryBuilderState.displayedTemplateQueries;
useEffect(() => {
flowResult(queryBuilderState.intialize()).catch(applicationStore.alertUnhandledError);
}, [queryBuilderState, applicationStore.alertUnhandledError]);
return (_jsx(_Fragment, { children: !templateQueries || templateQueries.length === 0 ? (_jsx(PanelHeader, { className: "query-builder__data-space__template-query", children: _jsx("button", { className: "query-builder__data-space__template-query__btn", ref: templateQueryButtonRef, onClick: showTemplateQueries, disabled: true, children: "Templates ( 0 )" }) })) : (_jsxs(PanelHeader, { className: "query-builder__data-space__template-query", children: [_jsxs("button", { className: "query-builder__data-space__template-query__btn", ref: templateQueryButtonRef, onClick: showTemplateQueries, children: ["Templates ( ", templateQueries.length, " )"] }), queryBuilderState.isTemplateQueryDialogOpen && (_jsx(DataSpaceTemplateQueryDialog, { triggerElement: templateQueryButtonRef.current, queryBuilderState: queryBuilderState, templateQueries: templateQueries }))] })) }));
});
export const renderDataSpaceQueryBuilderTemplateQueryPanelContent = (queryBuilderState) => (_jsx(DataSpaceQueryBuilderTemplateQueryPanel, { queryBuilderState: queryBuilderState }));
//# sourceMappingURL=DataSpaceQueryBuilderTemplateQueryPanelContent.js.map