/** * 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 { useEffect, Fragment } from 'react'; import { observer } from 'mobx-react-lite'; import { EditorGroup } from '../editor/editor-group/EditorGroup.js'; import { GrammarTextEditor } from '../editor/editor-group/GrammarTextEditor.js'; import { LEGEND_STUDIO_TEST_ID } from '../../__lib__/LegendStudioTesting.js'; import { ACTIVITY_MODE, GRAPH_EDITOR_MODE, } from '../../stores/editor/EditorConfig.js'; import { type ResizablePanelHandlerProps, clsx, ResizablePanel, ResizablePanelGroup, ResizablePanelSplitter, getCollapsiblePanelGroupProps, RepoIcon, CodeBranchIcon, HackerIcon, WrenchIcon, FileTrayIcon, AssistantIcon, useResizeDetector, FireIcon, TrashIcon, HammerIcon, TerminalIcon, ResizablePanelSplitterLine, GitlabIcon, } from '@finos/legend-art'; import { assertErrorThrown, isNonNullable } from '@finos/legend-shared'; import { useProjectViewerStore, withProjectViewerStore, } from './ProjectViewerStoreProvider.js'; import { type ProjectViewerPathParams, generateSetupRoute, generateViewProjectRoute, } from '../../__lib__/LegendStudioNavigation.js'; import { ProjectSearchCommand } from '../editor/command-center/ProjectSearchCommand.js'; import { flowResult } from 'mobx'; import { useEditorStore, withEditorStore, } from '../editor/EditorStoreProvider.js'; import { useApplicationStore, useCommands } from '@finos/legend-application'; import { useParams } from '@finos/legend-application/browser'; import { Explorer } from '../editor/side-bar/Explorer.js'; import { ProjectOverview } from '../editor/side-bar/ProjectOverview.js'; import { WorkflowManager } from '../editor/side-bar/WorkflowManager.js'; import { useLegendStudioApplicationStore, useLegendStudioBaseStore, } from '../LegendStudioFrameworkProvider.js'; import { EmbeddedQueryBuilder } from '../editor/EmbeddedQueryBuilder.js'; import type { ActivityBarItemConfig } from '@finos/legend-lego/application'; import { ActivityBarMenu, ColorThemeToggle } from '../editor/ActivityBar.js'; import { PanelGroup } from '../editor/panel-group/PanelGroup.js'; import { StoreProjectData } from '@finos/legend-server-depot'; import { generateGAVCoordinates } from '@finos/legend-storage'; import { Project } from '@finos/legend-server-sdlc'; const ProjectViewerStatusBar = observer(() => { const params = useParams(); const viewerStore = useProjectViewerStore(); const editorStore = useEditorStore(); const applicationStore = useLegendStudioApplicationStore(); const latestVersion = viewerStore.onLatestVersion; const currentRevision = viewerStore.onCurrentRevision; const extraSDLCInfo = params.revisionId ?? params.versionId ?? 'HEAD'; const projectId = params.projectId; const currentProject = editorStore.sdlcState.currentProject; const gav = viewerStore.projectGAVCoordinates; const versionBehindProjectHead = viewerStore.currentRevision && viewerStore.version && params.versionId && viewerStore.currentRevision.id !== viewerStore.version.revisionId; const description = `${ latestVersion ? versionBehindProjectHead ? 'latest behind project' : 'latest' : currentRevision ? 'current' : '' }`; const editable = editorStore.graphManagerState.graphBuildState.hasCompleted && editorStore.isInitialized; const handleTextModeClick = applicationStore.guardUnhandledError(() => flowResult(editorStore.toggleTextMode()), ); const compile = applicationStore.guardUnhandledError(() => flowResult(editorStore.graphEditorMode.globalCompile()), ); const generate = applicationStore.guardUnhandledError(() => flowResult(editorStore.graphState.graphGenerationState.globalGenerate()), ); const emptyGenerationEntities = applicationStore.guardUnhandledError(() => flowResult(editorStore.graphState.graphGenerationState.clearGenerations()), ); const toggleAssistant = (): void => applicationStore.assistantService.toggleAssistant(); const togglePanel = (): void => editorStore.panelGroupDisplayState.toggle(); const visitProject = async (): Promise => { try { if (gav) { const project = StoreProjectData.serialization.fromJson( await editorStore.depotServerClient.getProject( gav.groupId, gav.artifactId, ), ); const sdlcProjectUrl = generateViewProjectRoute(project.projectId); applicationStore.navigationService.navigator.visitAddress( applicationStore.navigationService.navigator.generateAddress( sdlcProjectUrl, ), ); } } catch (error) { assertErrorThrown(error); editorStore.applicationStore.notificationService.notifyError( `Can't open project.`, ); } }; const visitWebProjectUrl = async (): Promise => { try { if (gav) { const project = StoreProjectData.serialization.fromJson( await editorStore.depotServerClient.getProject( gav.groupId, gav.artifactId, ), ); const sdlcProject = Project.serialization.fromJson( await editorStore.sdlcServerClient.getProject(project.projectId), ); applicationStore.navigationService.navigator.visitAddress( sdlcProject.webUrl, ); } } catch (error) { assertErrorThrown(error); editorStore.applicationStore.notificationService.notifyError( `Can't open project.`, ); } }; return (
{currentProject && (
/
{extraSDLCInfo}
{description && (
({description})
)}
)} {!currentProject && gav && (
/
flowResult(visitWebProjectUrl())} className="editor__status-bar__workspace__workspace" > {gav.versionId}
)}
); }); const ProjectViewerSideBar = observer(() => { const viewerStore = useProjectViewerStore(); const editorStore = useEditorStore(); const renderSideBar = (): React.ReactNode => { switch (editorStore.activeActivity) { case ACTIVITY_MODE.EXPLORER: return ; case ACTIVITY_MODE.PROJECT_OVERVIEW: return ; case ACTIVITY_MODE.WORKFLOW_MANAGER: return viewerStore.workflowManagerState ? ( ) : null; default: return null; } }; return (
{renderSideBar()}
); }); const ProjectViewerActivityBar = observer(() => { const viewerStore = useProjectViewerStore(); const baseStore = useLegendStudioBaseStore(); const editorStore = useEditorStore(); const changeActivity = (activity: string): (() => void) => (): void => editorStore.setActiveActivity(activity); // tabs const activities: ActivityBarItemConfig[] = ( [ { mode: ACTIVITY_MODE.EXPLORER, title: 'Explorer (Ctrl + Shift + X)', icon: , }, baseStore.isSDLCAuthorized !== undefined && { mode: ACTIVITY_MODE.PROJECT_OVERVIEW, title: 'Project', icon: (
), }, viewerStore.workflowManagerState && { mode: ACTIVITY_MODE.WORKFLOW_MANAGER, title: 'WORKFLOW MANAGER', icon: , }, ] as (ActivityBarItemConfig | boolean)[] ).filter((activity): activity is ActivityBarItemConfig => Boolean(activity)); return (
{activities.map((activity) => ( ))}
); }); export const ProjectViewer = withEditorStore( withProjectViewerStore( observer(() => { const params = useParams(); const viewerStore = useProjectViewerStore(); const editorStore = useEditorStore(); const applicationStore = useApplicationStore(); // Extensions const extraEditorExtensionComponents = editorStore.pluginManager .getApplicationPlugins() .flatMap( (plugin) => plugin.getExtraEditorExtensionComponentRendererConfigurations?.() ?? [], ) .filter(isNonNullable) .map((config) => ( {config.renderer(editorStore)} )); // layout const resizeSideBar = (handleProps: ResizablePanelHandlerProps): void => editorStore.sideBarDisplayState.setSize( (handleProps.domElement as HTMLDivElement).getBoundingClientRect() .width, ); const sideBarCollapsiblePanelGroupProps = getCollapsiblePanelGroupProps( editorStore.sideBarDisplayState.size === 0, { onStopResize: resizeSideBar, size: editorStore.sideBarDisplayState.size, }, ); const resizePanel = (handleProps: ResizablePanelHandlerProps): void => editorStore.panelGroupDisplayState.setSize( (handleProps.domElement as HTMLDivElement).getBoundingClientRect() .height, ); const maximizedCollapsiblePanelGroupProps = getCollapsiblePanelGroupProps( editorStore.panelGroupDisplayState.isMaximized, ); const collapsiblePanelGroupProps = getCollapsiblePanelGroupProps( editorStore.panelGroupDisplayState.size === 0, { onStopResize: resizePanel, size: editorStore.panelGroupDisplayState.size, }, ); const { ref, width, height } = useResizeDetector(); useEffect(() => { if (ref.current) { editorStore.panelGroupDisplayState.setMaxSize( ref.current.offsetHeight, ); } }, [ref, editorStore, width, height]); // initialize useEffect(() => { viewerStore.internalizeEntityPath(params); }, [viewerStore, params]); // NOTE: since we internalize the entity path in the route, we should not re-initialize the graph // on the second call when we remove entity path from the route useEffect(() => { flowResult(viewerStore.initialize(params)).catch( applicationStore.alertUnhandledError, ); }, [applicationStore, viewerStore, params]); useCommands(editorStore); return (
{editorStore.graphEditorMode.mode === GRAPH_EDITOR_MODE.FORM && } {editorStore.graphEditorMode.mode === GRAPH_EDITOR_MODE.GRAMMAR_TEXT && ( )}
{editorStore.graphManagerState.graphBuildState.hasSucceeded && ( )} {extraEditorExtensionComponents}
); }), ), );