/** * 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 { PanelFormBooleanField, Panel, PanelFormTextField, PanelForm, CloudDownloadIcon, PanelFormListItems, ServerIcon, clsx, } from '@finos/legend-art'; import { ContentType, downloadFileUsingDataURI, getContentTypeFileExtension, isValidUrl, } from '@finos/legend-shared'; import { useEditorStore } from '../EditorStoreProvider.js'; import { LEGEND_STUDIO_SETTING_KEY } from '../../../__lib__/LegendStudioSetting.js'; import { PARSER_SECTION_MARKER, PURE_PARSER } from '@finos/legend-graph'; import { ProjectDependencyCoordinates } from '@finos/legend-server-depot'; /** * The backend servers Studio uses, and the way to the backend servers dialog, * which overrides them for the whole application from the next reload */ const DevToolBackendServers = observer(() => { const editorStore = useEditorStore(); const backendOverrideService = editorStore.applicationStore.backendOverrideService; if (!backendOverrideService.isEnabled) { return null; } return ( {backendOverrideService.entries.map((entry) => (
{entry.entry.label}
{entry.url} {entry.override && ' (overridden)'}
))}
backendOverrideService.open()} role="button" tabIndex={-1} title="Change backend servers..." >
change backend servers...
); }); export const DevToolPanel = observer(() => { const editorStore = useEditorStore(); // Engine const engineConfig = editorStore.graphManagerState.graphManager.TEMPORARY__getEngineConfig(); const toggleEngineClientRequestPayloadCompression = (): void => engineConfig.setUseClientRequestPayloadCompression( !engineConfig.useClientRequestPayloadCompression, ); const toggleEngineClientRequestPayloadDebugging = (): void => engineConfig.setEnableDebuggingPayload( !engineConfig.enableDebuggingPayload, ); const toggleEngineClientDataURLEncoding = (): void => engineConfig.setUseBase64ForAdhocConnectionDataUrls( !engineConfig.useBase64ForAdhocConnectionDataUrls, ); const toggleSetUseDevClientProtocol = (): void => engineConfig.setUseDevClientProtocol(!engineConfig.useDevClientProtocol); // Graph Manager const toggleStrictMode = (): void => { editorStore.graphState.setEnableStrictMode( !editorStore.graphState.enableStrictMode, ); editorStore.applicationStore.settingService.persistValue( LEGEND_STUDIO_SETTING_KEY.EDITOR_STRICT_MODE, editorStore.graphState.enableStrictMode, ); }; const toggleArtifactGeneration = (): void => { editorStore.graphState.graphGenerationState.setEnableArtifactGeneration( !editorStore.graphState.graphGenerationState.enableArtifactGeneration, ); }; const downloadProjectGrammar = async ( withDependency: boolean, ): Promise => { const graphManager = editorStore.graphManagerState.graphManager; const graphGrammar = await graphManager.graphToPureCode( editorStore.graphManagerState.graph, { pretty: true }, ); let dependencyGrammar: string | undefined; if (withDependency) { // Fetch the dependency graph directly from Depot as a // `V1_PureModelContextData` payload and hand it straight to the engine // grammar transform. This skips building a `PureModel` for dependencies // and collapses the whole dependency graph into a single engine call. const projectDependencies = editorStore.projectConfigurationEditorState.currentProjectConfiguration .projectDependencies; if (projectDependencies.length) { const dependencyCoordinates = await editorStore.graphState.buildProjectDependencyCoordinates( projectDependencies, ); const dependencyProtocolGraph = await editorStore.depotServerClient.collectDependencyEntitiesAsPureModelContextData( dependencyCoordinates.map((e) => ProjectDependencyCoordinates.serialization.toJson(e), ), true, true, ); dependencyGrammar = await graphManager.protocolToPureCode( dependencyProtocolGraph, { pretty: true }, ); } } const fullGrammar = dependencyGrammar === undefined ? graphGrammar : `${graphGrammar}\n${PARSER_SECTION_MARKER}${PURE_PARSER.PURE}\n// ------------------------------------------------------------\n// Dependency grammar starts here\n// ------------------------------------------------------------\n${dependencyGrammar}`; const fileName = `grammar.${getContentTypeFileExtension( ContentType.TEXT_PLAIN, )}`; downloadFileUsingDataURI(fileName, fullGrammar, ContentType.TEXT_PLAIN); }; return ( engineConfig.setBaseUrl(value === '' ? undefined : value) } errorMessage={ !isValidUrl(engineConfig.baseUrl ?? '') ? 'Invalid URL' : '' } /> {Boolean( editorStore.applicationStore.config.options .TEMPORARY__serviceRegistrationConfig.length, ) && ( engineConfig.setBaseUrlForServiceRegistration( value === '' ? undefined : value, ) } errorMessage={ Boolean(engineConfig.baseUrlForServiceRegistration) && !isValidUrl(engineConfig.baseUrlForServiceRegistration ?? '') ? 'Invalid URL' : '' } /> )}
{ downloadProjectGrammar(false).catch( editorStore.applicationStore.alertUnhandledError, ); }} role="button" tabIndex={-1} title="Download Project Grammar" >
download grammar without dependency
{ downloadProjectGrammar(true).catch( editorStore.applicationStore.alertUnhandledError, ); }} role="button" tabIndex={-1} title="Download Project Grammar with Dependency" >
download grammar with dependency
); });