/** * 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 { BlankPanelPlaceholder, BlankPanelContent, ContextMenu, CustomSelectorInput, Dialog, ErrorWarnIcon, FilledWindowMaximizeIcon, MenuContent, MenuContentItem, Modal, ModalBody, ModalFooter, ModalFooterButton, ModalHeader, ModalTitle, Panel, PanelFormTextField, PanelHeader, PanelHeaderActionItem, PanelHeaderActions, PlayIcon, PlusIcon, RefreshIcon, ResizablePanel, ResizablePanelGroup, ResizablePanelSplitter, ResizablePanelSplitterLine, RunAllIcon, RunErrorsIcon, TimesIcon, clsx, } from '@finos/legend-art'; import { forwardRef, useEffect, useRef, useState } from 'react'; import { type FunctionTestSuite, type DataElement, type EmbeddedData, type ValueSpecification, DataElementReference, PackageableElementExplicitReference, RelationalCSVData, ModelStoreData, ExternalFormatData, ModelEmbeddedData, PrimitiveInstanceValue, PrimitiveType, } from '@finos/legend-graph'; import { FunctionValueSpecificationTestParameterState, type FunctionStoreTestDataState, type FunctionTestState, type FunctionTestSuiteState, type FunctionTestableState, } from '../../../../../stores/editor/editor-state/element-editor-state/function-activator/testable/FunctionTestableState.js'; import { TESTABLE_RESULT, getTestableResultFromTestResult, } from '../../../../../stores/editor/sidebar-state/testable/GlobalTestRunnerState.js'; import { flowResult } from 'mobx'; import { getTestableResultIcon } from '../../../side-bar/testable/GlobalTestRunner.js'; import { ExternalFormatParameterEditorModal, RenameModal, SharedDataElementModal, TestAssertionEditor, } from '../../testable/TestableSharedComponents.js'; import { filterByType, prettyCONSTName, returnUndefOnError, } from '@finos/legend-shared'; import { EmbeddedDataCreatorFromEmbeddedData, validateTestableId, type TestParamContentType, getContentTypeWithParamFromQuery, } from '../../../../../stores/editor/utils/TestableUtils.js'; import { EmbeddedDataEditor } from '../../data-editor/EmbeddedDataEditor.js'; import { LEGEND_STUDIO_APPLICATION_NAVIGATION_CONTEXT_KEY } from '../../../../../__lib__/LegendStudioApplicationNavigationContext.js'; import { useApplicationNavigationContext } from '@finos/legend-application'; import { BasicValueSpecificationEditor, instanceValue_setValue, } from '@finos/legend-query-builder'; import { TESTABLE_TEST_TAB } from '../../../../../stores/editor/editor-state/element-editor-state/testable/TestableEditorState.js'; import { atomicTest_setDoc } from '../../../../../stores/graph-modifier/Testable_GraphModifierHelper.js'; const FunctionTestableContextMenu = observer( forwardRef< HTMLDivElement, { addName?: string; _delete?: () => void; rename?: () => void; add?: () => void; } >(function TestContainerContextMenu(props, ref) { const { addName, add, rename, _delete } = props; const addTest = (): void => { add?.(); }; const remove = (): void => _delete?.(); const handleRename = (): void => rename?.(); return ( {rename && ( Rename )} {_delete && Delete} {addName && rename && ( {`Add ${addName}`} )} ); }), ); const FunctionTestDataStateEditor = observer( (props: { functionTestSuiteState: FunctionTestSuiteState; storeTestDataState: FunctionStoreTestDataState; }) => { const { functionTestSuiteState, storeTestDataState } = props; const functionTestableState = functionTestSuiteState.functionTestableState; const isReadOnly = functionTestableState.functionEditorState.isReadOnly; const embeddedState = storeTestDataState.embeddedEditorState; const currentData = embeddedState.embeddedData; const isUsingReference = currentData instanceof DataElementReference; const open = (): void => storeTestDataState.setDataElementModal(true); const close = (): void => storeTestDataState.setDataElementModal(false); const changeToUseMyOwn = (): void => { if (isUsingReference) { const newBare = returnUndefOnError(() => currentData.accept_EmbeddedDataVisitor( new EmbeddedDataCreatorFromEmbeddedData( functionTestableState.editorStore, ), ), ); if (newBare) { storeTestDataState.changeEmbeddedData(newBare); } } }; const sharedDataHandler = (val: DataElement): void => { const dataRef = new DataElementReference(); dataRef.dataElement = PackageableElementExplicitReference.create(val); const dataElementValue = val.data; let embeddedData: EmbeddedData = dataRef; if ( currentData instanceof ModelStoreData && dataElementValue instanceof ExternalFormatData ) { const modelStoreVal = currentData.modelData?.[0]; if (modelStoreVal instanceof ModelEmbeddedData) { const newModelEmbeddedData = new ModelEmbeddedData(); newModelEmbeddedData.model = PackageableElementExplicitReference.create( modelStoreVal.model.value, ); newModelEmbeddedData.data = dataRef; const modelStoreData = new ModelStoreData(); modelStoreData.modelData = [newModelEmbeddedData]; embeddedData = modelStoreData; } } storeTestDataState.changeEmbeddedData(embeddedData); }; const dataElements = functionTestSuiteState.editorStore.graphManagerState.graph.dataElements; const filter = (val: DataElement): boolean => { const dataElementData = val.data; if (currentData instanceof RelationalCSVData) { if (dataElementData instanceof RelationalCSVData) { return true; } return false; } else if (currentData instanceof ModelStoreData) { if ( dataElementData instanceof ExternalFormatData || dataElementData instanceof ModelStoreData ) { return true; } return false; } return true; }; return (
input data
{isUsingReference ? ( ) : ( )}
{storeTestDataState.dataElementModal && ( )}
); }, ); const FunctionTestParameterEditor = observer( (props: { isReadOnly: boolean; paramState: FunctionValueSpecificationTestParameterState; functionTestState: FunctionTestState; contentTypeParamPair: TestParamContentType | undefined; }) => { const { functionTestState, paramState, isReadOnly, contentTypeParamPair } = props; const [showPopUp, setShowPopUp] = useState(false); const paramIsRequired = paramState.varExpression.multiplicity.lowerBound > 0; const type = contentTypeParamPair ? contentTypeParamPair.contentType : (paramState.varExpression.genericType?.value.rawType.name ?? 'unknown'); const paramValue = paramState.varExpression.genericType?.value.rawType === PrimitiveType.BYTE ? atob( (paramState.valueSpec as PrimitiveInstanceValue) .values[0] as string, ) : ((paramState.valueSpec as PrimitiveInstanceValue) .values[0] as string); const openInPopUp = (): void => setShowPopUp(!showPopUp); const closePopUp = (): void => setShowPopUp(false); const updateParamValue = (val: string): void => { if (paramState.valueSpec instanceof PrimitiveInstanceValue) { instanceValue_setValue( paramState.valueSpec, paramState.varExpression.genericType?.value.rawType === PrimitiveType.BYTE ? btoa(val) : val, 0, functionTestState.editorStore.changeDetectionState.observerContext, ); paramState.updateValueSpecification(paramState.valueSpec); } }; return (
{paramState.parameterValue.name}
<> {contentTypeParamPair ? (