/** * 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 { useEditorStore, withEditorStore, } from '../editor/EditorStoreProvider.js'; import { useShowcaseViewerStore, withShowcaseViewerStore, } from './ShowcaseViewerStoreProvider.js'; import { useParams } from '@finos/legend-application/browser'; import type { ShowcaseViewerPathParams } from '../../__lib__/LegendStudioNavigation.js'; import { isNonNullable } from '@finos/legend-shared'; import { Fragment, useEffect } from 'react'; import { getCollapsiblePanelGroupProps, useResizeDetector, type ResizablePanelHandlerProps, ResizablePanel, ResizablePanelSplitter, ResizablePanelGroup, FileTrayIcon, clsx, HackerIcon, AssistantIcon, ReadMeIcon, FireIcon, HammerIcon, TerminalIcon, TrashIcon, ResizablePanelSplitterLine, } from '@finos/legend-art'; import { useApplicationStore, useCommands } from '@finos/legend-application'; import { flowResult } from 'mobx'; import { EditorGroup } from '../editor/editor-group/EditorGroup.js'; import { GrammarTextEditor } from '../editor/editor-group/GrammarTextEditor.js'; import { ProjectSearchCommand } from '../editor/command-center/ProjectSearchCommand.js'; import { EmbeddedQueryBuilder } from '../editor/EmbeddedQueryBuilder.js'; import { ACTIVITY_MODE, GRAPH_EDITOR_MODE, } from '../../stores/editor/EditorConfig.js'; import { ActivityBarMenu, ColorThemeToggle } from '../editor/ActivityBar.js'; import type { ActivityBarItemConfig } from '@finos/legend-lego/application'; import { useLegendStudioApplicationStore } from '../LegendStudioFrameworkProvider.js'; import { LEGEND_STUDIO_TEST_ID } from '../../__lib__/LegendStudioTesting.js'; import { Explorer } from '../editor/side-bar/Explorer.js'; import { PanelGroup } from '../editor/panel-group/PanelGroup.js'; import { QueryDataCubeViewer } from '@finos/legend-query-builder'; import { ShowcaseFeedback } from './ShowcaseFeedback.js'; import { SHOWCASE_FEEDBACK_SURFACE } from '../../__lib__/LegendStudioTelemetryHelper.js'; const ShowcaseViewerStatusBar = observer(() => { const editorStore = useEditorStore(); const showcaseStore = useShowcaseViewerStore(); const showcase = showcaseStore._showcase; const applicationStore = useLegendStudioApplicationStore(); const handleTextModeClick = applicationStore.guardUnhandledError(() => flowResult(editorStore.toggleTextMode()), ); const editable = editorStore.graphManagerState.graphBuildState.hasCompleted && editorStore.isInitialized; const togglePanel = (): void => editorStore.panelGroupDisplayState.toggle(); 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(); return (
{showcase && (
)} {showcase && ( )}
); }); const ShowcaseViewerActivityBar = observer(() => { 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: , }, ] as (ActivityBarItemConfig | boolean)[] ).filter((activity): activity is ActivityBarItemConfig => Boolean(activity)); return (
{activities.map((activity) => ( ))}
); }); const ShowcaseViewerSideBar = observer(() => { const editorStore = useEditorStore(); const renderSideBar = (): React.ReactNode => { switch (editorStore.activeActivity) { case ACTIVITY_MODE.EXPLORER: return ; default: return null; } }; return (
{renderSideBar()}
); }); export const ShowcaseViewer = withEditorStore( withShowcaseViewerStore( observer(() => { const params = useParams(); const showcaseStore = useShowcaseViewerStore(); const applicationStore = useApplicationStore(); const editorStore = useEditorStore(); // 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 collapsiblePanelGroupProps = getCollapsiblePanelGroupProps( editorStore.panelGroupDisplayState.size === 0, { onStopResize: resizePanel, size: editorStore.panelGroupDisplayState.size, }, ); const collapsibleSideBarGroupProps = getCollapsiblePanelGroupProps( editorStore.sideBarDisplayState.size === 0, { onStopResize: resizeSideBar, size: editorStore.sideBarDisplayState.size, }, ); const maximizedCollapsiblePanelGroupProps = getCollapsiblePanelGroupProps( editorStore.panelGroupDisplayState.isMaximized, ); const { ref, width, height } = useResizeDetector(); useEffect(() => { if (ref.current) { editorStore.panelGroupDisplayState.setMaxSize( ref.current.offsetHeight, ); } }, [ref, editorStore, width, height]); // initialize useEffect(() => { flowResult(showcaseStore.initialize(params)).catch( applicationStore.alertUnhandledError, ); }, [applicationStore, showcaseStore, params]); useCommands(editorStore); return (
{editorStore.graphEditorMode.mode === GRAPH_EDITOR_MODE.FORM && } {editorStore.graphEditorMode.mode === GRAPH_EDITOR_MODE.GRAMMAR_TEXT && ( )}
{editorStore.graphManagerState.graphBuildState.hasSucceeded && ( )} {editorStore.embeddedDataCubeViewerState && ( editorStore.setEmbeddedDataCubeViewerState(undefined) } options={{ fullScreen: true, }} /> )} {extraEditorExtensionComponents}
); }), ), );