/**
* 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 {
BlankPanelPlaceholder,
CaretDownIcon,
clsx,
ContextMenu,
CustomSelectorInput,
Dialog,
ControlledDropdownMenu,
InfoCircleIcon,
MaskIcon,
MenuContent,
MenuContentItem,
Modal,
ModalBody,
ModalFooter,
ModalFooterButton,
ModalHeader,
PanelLoadingIndicator,
PlusIcon,
PURE_ConnectionIcon,
RefreshIcon,
ResizablePanel,
ResizablePanelGroup,
ResizablePanelSplitter,
ResizablePanelSplitterLine,
TimesIcon,
} from '@finos/legend-art';
import {
type IdentifiedConnection,
type ConnectionTestData,
type DataElement,
type ValueSpecification,
getAllIdentifiedServiceConnections,
DataElementReference,
PackageableElementExplicitReference,
Column,
} from '@finos/legend-graph';
import { observer } from 'mobx-react-lite';
import { forwardRef, useState } from 'react';
import {
createMockPrimitiveValueSpecificationFromRelationalDataType,
type ConnectionTestDataState,
type RowIdentifierState,
type ServiceTestDataState,
type TableRowIdentifierState,
} from '../../../../../stores/editor/editor-state/element-editor-state/service/testable/ServiceTestDataState.js';
import type { EmbeddedDataTypeOption } from '../../../../../stores/editor/editor-state/element-editor-state/data/DataEditorState.js';
import { EmbeddedDataEditor } from '../../data-editor/EmbeddedDataEditor.js';
import { EmbeddedDataType } from '../../../../../stores/editor/editor-state/ExternalFormatState.js';
import { flowResult } from 'mobx';
import {
ActionAlertActionType,
ActionAlertType,
useApplicationStore,
} from '@finos/legend-application';
import { buildElementOption } from '@finos/legend-lego/graph-editor';
import {
filterByType,
guaranteeNonNullable,
prettyCONSTName,
} from '@finos/legend-shared';
import type { DSL_Data_LegendStudioApplicationPlugin_Extension } from '../../../../../stores/extensions/DSL_Data_LegendStudioApplicationPlugin_Extension.js';
import { useEditorStore } from '../../../EditorStoreProvider.js';
import {
BasicValueSpecificationEditor,
LambdaParameterValuesEditor,
} from '@finos/legend-query-builder';
import { LEGEND_STUDIO_DOCUMENTATION_KEY } from '../../../../../__lib__/LegendStudioDocumentation.js';
import type { TableOption } from '../../data-editor/RelationalCSVDataEditor.js';
import { getPrimitiveTypeFromRelationalType } from '../../../../../stores/editor/utils/MockDataUtils.js';
export interface ColumnOption {
value: Column;
label: string;
}
export const RowIdentifierEditor = observer(
(props: {
tableRowIdentifierState: TableRowIdentifierState;
rowIdentifierState: RowIdentifierState;
}) => {
const { tableRowIdentifierState, rowIdentifierState } = props;
const applicationStore = useApplicationStore();
const columnOptions = tableRowIdentifierState.table.columns
.filter(filterByType(Column))
.map((_c) => ({
label: _c.name,
value: _c,
}));
const changeColumn = (val: ColumnOption): void => {
if (rowIdentifierState.column.name !== val.value.name) {
const valueSpec =
createMockPrimitiveValueSpecificationFromRelationalDataType(
guaranteeNonNullable(rowIdentifierState.column.type),
tableRowIdentifierState.connectionTestDataState.editorStore
.graphManagerState.graph,
tableRowIdentifierState.connectionTestDataState.editorStore
.changeDetectionState.observerContext,
);
rowIdentifierState.updateRowIdentifierValue(valueSpec);
rowIdentifierState.updateRowIdentifierColumn(val.value);
}
};
const resetNode = (): void => {
const valueSpec =
createMockPrimitiveValueSpecificationFromRelationalDataType(
guaranteeNonNullable(rowIdentifierState.column.type),
tableRowIdentifierState.connectionTestDataState.editorStore
.graphManagerState.graph,
tableRowIdentifierState.connectionTestDataState.editorStore
.changeDetectionState.observerContext,
);
rowIdentifierState.updateRowIdentifierValue(valueSpec);
};
return (