/** * 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 { clsx, CustomSelectorInput, PlusIcon, TimesIcon, } from '@finos/legend-art'; import { type DataSpaceElement, DataSpaceElementPointer, } from '@finos/legend-extension-dsl-data-space/graph'; import { observer } from 'mobx-react-lite'; import { useState } from 'react'; import { prettyCONSTName, returnUndefOnError } from '@finos/legend-shared'; import { DataSpaceEditorState } from '../../stores/DataSpaceEditorState.js'; import { PackageableElementExplicitReference } from '@finos/legend-graph'; import { dataSpace_addElement, dataSpace_removeElement, dataSpace_setElementExclude, } from '../../stores/studio/DSL_DataSpace_GraphModifierHelper.js'; export const DataSpaceElementsSection = observer(() => { const editorStore = useEditorStore(); const dataSpaceState = editorStore.tabManagerState.getCurrentEditorState(DataSpaceEditorState); const dataSpace = dataSpaceState.dataSpace; const isReadOnly = dataSpaceState.isReadOnly; const elements = dataSpace.elements ?? []; const [isAdding, setIsAdding] = useState(false); const addElement = (option: { label: string; value: DataSpaceElement; }): void => { const elementPointer = new DataSpaceElementPointer(); elementPointer.element = PackageableElementExplicitReference.create( option.value, ); dataSpace_addElement(dataSpace, elementPointer); setIsAdding(false); }; const getTypeLabel = (pointer: DataSpaceElementPointer): string => { const type = returnUndefOnError(() => editorStore.graphState.getPackageableElementType(pointer.element.value), ); return type ? prettyCONSTName(type) : ''; }; return ( {elements.length ? (
Element
Type
In this data space
{elements.map((pointer) => (
{getElementIcon(pointer.element.value, editorStore)} {pointer.element.value.name} {pointer.element.value.package?.path}
{getTypeLabel(pointer)}
))}
) : (
No elements listed yet. Add the classes, enumerations, associations or packages people should find documented here.
)} {isAdding ? (
) : ( )} ); });