UNPKG

@finos/legend-extension-dsl-data-space

Version:
136 lines 6.72 kB
/** * 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 { collectKeyedCommandConfigEntriesFromConfig, LegendApplicationPlugin, } from '@finos/legend-application'; import packageJson from '../../package.json' with { type: 'json' }; import { DataSpaceQueryBuilderState } from '../stores/query-builder/DataSpaceQueryBuilderState.js'; import { DSL_DATA_SPACE_LEGEND_APPLICATION_COMMAND_CONFIG } from '../__lib__/DSL_DataSpace_LegendApplicationCommand.js'; import {} from '@finos/legend-graph'; import { DataSpaceExecutableTemplate } from '../graph/metamodel/pure/model/packageableElements/dataSpace/DSL_DataSpace_DataSpace.js'; import { filterByType } from '@finos/legend-shared'; import { createQueryClassTaggedValue, createQueryDataSpaceTaggedValue, } from '../stores/shared/DataSpaceUtils.js'; import { renderDataSpaceQueryBuilderTemplateQueryPanelContent } from './query-builder/DataSpaceQueryBuilderTemplateQueryPanelContent.js'; export class DSL_DataSpace_LegendApplicationPlugin extends LegendApplicationPlugin { static NAME = packageJson.extensions.applicationPlugin; constructor() { super(DSL_DataSpace_LegendApplicationPlugin.NAME, packageJson.version); } install(pluginManager) { pluginManager.registerApplicationPlugin(this); } getExtraKeyedCommandConfigEntries() { return collectKeyedCommandConfigEntriesFromConfig(DSL_DATA_SPACE_LEGEND_APPLICATION_COMMAND_CONFIG); } getExtraLoadQueryFilterOptions() { return [ { key: 'data-space-filter-option', label: (queryBuilderState) => { if (queryBuilderState instanceof DataSpaceQueryBuilderState) { return 'Current Data Product'; } return undefined; }, filterFunction: (searchSpecification, queryBuilderState) => { if (queryBuilderState instanceof DataSpaceQueryBuilderState) { searchSpecification.taggedValues = [ createQueryDataSpaceTaggedValue(queryBuilderState.dataSpace.path), ]; } return searchSpecification; }, }, { key: 'class-filter-option', label: (queryBuilderState) => { if (queryBuilderState instanceof DataSpaceQueryBuilderState) { return 'Current Class'; } return undefined; }, filterFunction: (searchSpecification, queryBuilderState) => { if (queryBuilderState instanceof DataSpaceQueryBuilderState && queryBuilderState.class) { searchSpecification.taggedValues = [ createQueryDataSpaceTaggedValue(queryBuilderState.dataSpace.path), createQueryClassTaggedValue(queryBuilderState.class.path), ]; searchSpecification.combineTaggedValuesCondition = true; } return searchSpecification; }, }, ]; } getQueryFilterOptionsRelatedToTemplateQuery() { return (queryBuilderState) => { if (queryBuilderState instanceof DataSpaceQueryBuilderState) { return ['Current Data Product']; } return []; }; } getExtraTemplateQueryPanelContentRenderer() { return [ (queryBuilderState) => { if (queryBuilderState instanceof DataSpaceQueryBuilderState) { return renderDataSpaceQueryBuilderTemplateQueryPanelContent(queryBuilderState); } return undefined; }, ]; } getCuratedTemplateQuerySpecifications() { return [ { getCuratedTemplateQueries: (queryBuilderState) => { if (queryBuilderState instanceof DataSpaceQueryBuilderState) { const executableTemplates = queryBuilderState.dataSpace.executables?.filter(filterByType(DataSpaceExecutableTemplate)); return executableTemplates ? executableTemplates.map((e) => ({ id: e.id, title: e.title, description: e.description, query: e.query, executionContextKey: e.executionContextKey ?? queryBuilderState.dataSpace.defaultExecutionContext .name, })) : []; } return []; }, loadCuratedTemplateQuery: async (templateQuery, queryBuilderState) => { if (queryBuilderState instanceof DataSpaceQueryBuilderState) { if (queryBuilderState.executionContext.name !== templateQuery.executionContextKey) { const executionContext = queryBuilderState.dataSpace.executionContexts.find((c) => c.name === templateQuery.executionContextKey); if (executionContext) { queryBuilderState.setExecutionContext(executionContext); await queryBuilderState.propagateExecutionContextChange(); queryBuilderState.initializeWithQuery(templateQuery.query); queryBuilderState.onExecutionContextChange?.(executionContext); } } else { queryBuilderState.initializeWithQuery(templateQuery.query); } } }, }, ]; } } //# sourceMappingURL=DSL_DataSpace_LegendApplicationPlugin.js.map