/** * 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 { EditorFormSection, getElementIcon, useEditorStore, } from '@finos/legend-application-studio'; import { CustomSelectorInput, PlusIcon, TimesIcon } from '@finos/legend-art'; import { DataSpaceDiagram } from '@finos/legend-extension-dsl-data-space/graph'; import { observer } from 'mobx-react-lite'; import { useState } from 'react'; import { uuid } from '@finos/legend-shared'; import { DataSpaceEditorState } from '../../stores/DataSpaceEditorState.js'; import { PackageableElementExplicitReference } from '@finos/legend-graph'; import { type Diagram } from '@finos/legend-extension-dsl-diagram/graph'; import { dataSpace_addDiagram, dataSpace_removeDiagram, dataSpace_setDiagramTitle, dataSpace_setDiagramDescription, } from '../../stores/studio/DSL_DataSpace_GraphModifierHelper.js'; // the same diagram can be listed twice (with different titles), so rows are keyed by entry const diagramRowKeys = new WeakMap(); const getDiagramRowKey = (diagram: DataSpaceDiagram): string => { let key = diagramRowKeys.get(diagram); if (!key) { key = uuid(); diagramRowKeys.set(diagram, key); } return key; }; export const DataSpaceDiagramsSection = observer(() => { const editorStore = useEditorStore(); const dataSpaceState = editorStore.tabManagerState.getCurrentEditorState(DataSpaceEditorState); const dataSpace = dataSpaceState.dataSpace; const isReadOnly = dataSpaceState.isReadOnly; const diagrams = dataSpace.diagrams ?? []; const [isAdding, setIsAdding] = useState(false); const addDiagram = (option: { label: string; value: Diagram }): void => { const newDiagram = new DataSpaceDiagram(); newDiagram.title = option.value.name; newDiagram.diagram = PackageableElementExplicitReference.create( option.value, ); dataSpace_addDiagram(dataSpace, newDiagram); setIsAdding(false); }; return ( {diagrams.length ? (
Diagram
Title
Description
{diagrams.map((diagram) => (
{getElementIcon(diagram.diagram.value, editorStore)} {diagram.diagram.value.name} {diagram.diagram.value.package?.path}
dataSpace_setDiagramTitle(diagram, event.target.value) } placeholder="Title" title="Diagram title" /> dataSpace_setDiagramDescription( diagram, event.target.value || undefined, ) } placeholder="Add a description" title="Diagram description" />
))}
) : (
No diagrams yet. A diagram helps people see the shape of the model before they query it.
)} {isAdding ? (
) : ( )} ); });