/** * Copyright (c) 2026-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 { useState, type CSSProperties } from 'react'; import { Dialog, LongArrowRightIcon, Modal, ModalBody, ModalFooter, ModalFooterButton, ModalHeader, PencilEditIcon, PlusIcon, Tooltip, } from '@finos/legend-art'; import { ActionAlertActionType, ActionAlertType, } from '@finos/legend-application'; import type { RelationElementState } from '../../../../stores/editor/editor-state/element-editor-state/data/EmbeddedDataState.js'; import { RelationElementEditor } from './RelationElementsDataEditor.js'; import { useEditorStore } from '../../EditorStoreProvider.js'; export interface RelationElementSampleValuesReadOnlySource { label: string; message?: string | undefined; onNavigate: () => void; } export const RelationElementSampleValuesEditor = observer( (props: { title: string; relationElementState: RelationElementState | undefined; isReadOnly: boolean; isBusy?: boolean | undefined; hideColumnDefinitions?: boolean | undefined; deleteConfirmMessage: string; onAdd: () => Promise | void; onDelete: () => void; hasMismatch?: boolean | undefined; mismatchMessage?: string | undefined; readOnlySource?: RelationElementSampleValuesReadOnlySource | undefined; }) => { const { title, relationElementState, isReadOnly, isBusy, hideColumnDefinitions, deleteConfirmMessage, onAdd, onDelete, hasMismatch, mismatchMessage, readOnlySource, } = props; const editorStore = useEditorStore(); const [isModalOpen, setIsModalOpen] = useState(false); const isEditMode = Boolean(relationElementState) || Boolean(readOnlySource); const closeModal = (): void => setIsModalOpen(false); const handleClick = (): void => { if (isEditMode) { setIsModalOpen(true); return; } Promise.resolve(onAdd()) .then(() => setIsModalOpen(true)) .catch(editorStore.applicationStore.alertUnhandledError); }; const handleDelete = (): void => { editorStore.applicationStore.alertService.setActionAlertInfo({ message: deleteConfirmMessage, type: ActionAlertType.CAUTION, actions: [ { label: 'Confirm', type: ActionAlertActionType.PROCEED_WITH_CAUTION, handler: (): void => { onDelete(); closeModal(); }, }, { label: 'Cancel', type: ActionAlertActionType.PROCEED, default: true, }, ], }); }; const buttonStyle: CSSProperties = { cursor: isReadOnly ? 'not-allowed' : 'pointer', }; if (relationElementState && !readOnlySource) { buttonStyle.border = hasMismatch ? '2px solid var(--color-red-300)' : '1px solid var(--color-blue-200)'; } return ( <> {isModalOpen && (
{readOnlySource ? (
{readOnlySource.message ?? 'Sample Values already in Data Element'}
{readOnlySource.label}
) : ( <>
DO NOT ADD SENSITIVE DATA
{relationElementState && (
)} )}
{!readOnlySource && ( )}
)} ); }, );