/**
* 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, useCallback, useState, forwardRef } from 'react';
import { observer } from 'mobx-react-lite';
import { ServiceEditorState } from '../../../../stores/editor/editor-state/element-editor-state/service/ServiceEditorState.js';
import {
type ServiceExecutionContextState,
SingleServicePureExecutionState,
ServicePureExecutionState,
MultiServicePureExecutionState,
InlineServicePureExecutionState,
} from '../../../../stores/editor/editor-state/element-editor-state/service/ServiceExecutionState.js';
import { EmbeddedRuntimeEditor } from '../RuntimeEditor.js';
import { useDrop } from 'react-dnd';
import {
CORE_DND_TYPE,
type ElementDragSource,
type UMLEditorElementDropTarget,
} from '../../../../stores/editor/utils/DnDUtils.js';
import { UnsupportedEditorPanel } from '../UnsupportedElementEditor.js';
import {
clsx,
ResizablePanelGroup,
ResizablePanel,
ResizablePanelSplitter,
ResizablePanelSplitterLine,
PURE_MappingIcon,
PURE_RuntimeIcon,
ErrorIcon,
CogIcon,
LongArrowRightIcon,
ExclamationTriangleIcon,
CustomSelectorInput,
ContextMenu,
KeyIcon,
MenuContent,
MenuContentItem,
Dialog,
InputWithInlineValidation,
BlankPanelPlaceholder,
PlusIcon,
ArrowsJoinIcon,
ArrowsSplitIcon,
PanelDropZone,
Panel,
PanelContent,
ModalTitle,
PanelHeaderActionItem,
PanelHeaderActions,
PanelHeader,
} from '@finos/legend-art';
import { ServiceExecutionQueryEditor } from './ServiceExecutionQueryEditor.js';
import { useEditorStore } from '../../EditorStoreProvider.js';
import {
type KeyedExecutionParameter,
type Runtime,
Mapping,
RuntimePointer,
PackageableRuntime,
PackageableElementExplicitReference,
validate_PureExecutionMapping,
} from '@finos/legend-graph';
import { guaranteeNonNullable } from '@finos/legend-shared';
import {
buildElementOption,
type PackageableElementOption,
} from '@finos/legend-lego/graph-editor';
import { CUSTOM_LABEL } from '../../../../stores/editor/NewElementState.js';
const PureExecutionContextConfigurationEditor = observer(
(props: {
pureExecutionState: ServicePureExecutionState;
executionContextState: ServiceExecutionContextState;
}) => {
const { executionContextState, pureExecutionState } = props;
const executionContext = executionContextState.executionContext;
const editorStore = useEditorStore();
const applicationStore = editorStore.applicationStore;
const serviceState =
editorStore.tabManagerState.getCurrentEditorState(ServiceEditorState);
const isReadOnly = serviceState.isReadOnly;
// mapping
// TODO: this is not generic error handling, as there could be other problems
// with mapping, we need to genericize this
const isMappingEmpty = validate_PureExecutionMapping(
executionContext.mapping.value,
);
const mapping = executionContext.mapping.value;
const mappingOptions =
editorStore.graphManagerState.usableMappings.map(buildElementOption);
const noMappingLabel = (
);
// only show custom runtime option when a runtime pointer is currently selected
let runtimeOptions = !isRuntimePointer
? []
: ([{ label: customRuntimeLabel }] as {
label: string | React.ReactNode;
value: Runtime | undefined;
}[]);
// NOTE: for now, only include runtime associated with the mapping
// TODO?: Should we bring the runtime compatibility check from query to here?
const runtimes = editorStore.graphManagerState.graph.runtimes.filter((rt) =>
rt.runtimeValue.mappings.map((m) => m.value).includes(mapping),
);
runtimeOptions = runtimeOptions.concat(
runtimes.map((rt) => ({
label: rt.path,
value: new RuntimePointer(
PackageableElementExplicitReference.create(rt),
),
})),
);
const runtimePointerWarning =
runtime instanceof RuntimePointer &&
!runtimes.includes(runtime.packageableRuntime.value) // if the runtime does not belong to the chosen mapping
? `runtime is not associated with specified mapping '${mapping.path}'`
: undefined;
const selectedRuntimeOption = {
value: runtime,
label:
runtime instanceof RuntimePointer ? (