/** * 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 { clsx, PlusIcon, TimesIcon, WarningIcon } from '@finos/legend-art'; import { DataSpaceSupportEmail, DataSpaceSupportCombinedInfo, } from '@finos/legend-extension-dsl-data-space/graph'; import { observer } from 'mobx-react-lite'; import { dataSpace_email_setSupportInfoEmail, dataSpace_setDocumentationUrl, dataSpace_combined_setWebsite, dataSpace_combined_setFaqUrl, dataSpace_combined_setSupportUrl, dataSpace_combined_addEmail, dataSpace_combined_deleteEmail, dataSpace_setSupportInfo, } from '../../stores/studio/DSL_DataSpace_GraphModifierHelper.js'; import { EditorFormSection, useEditorStore, } from '@finos/legend-application-studio'; import { DataSpaceEditorState } from '../../stores/DataSpaceEditorState.js'; import { useState } from 'react'; type SupportInfoKind = 'none' | 'email' | 'combined'; const SupportLinkField = (props: { label: string; value: string | undefined; placeholder: string; isReadOnly: boolean; onChange: (value: string) => void; }): React.ReactNode => ( ); export const DataSpaceSupportInfoSection = observer(() => { const editorStore = useEditorStore(); const dataSpaceState = editorStore.tabManagerState.getCurrentEditorState(DataSpaceEditorState); const dataSpace = dataSpaceState.dataSpace; const isReadOnly = dataSpaceState.isReadOnly; const supportInfo = dataSpace.supportInfo; const [newEmail, setNewEmail] = useState(''); const kind: SupportInfoKind = supportInfo instanceof DataSpaceSupportCombinedInfo ? 'combined' : supportInfo instanceof DataSpaceSupportEmail ? 'email' : 'none'; const changeKind = (type: SupportInfoKind): void => { if (type === kind) { return; } if (type === 'combined') { const combined = new DataSpaceSupportCombinedInfo(); if (supportInfo instanceof DataSpaceSupportEmail) { combined.emails = supportInfo.address ? [supportInfo.address] : []; combined.documentationUrl = supportInfo.documentationUrl; } dataSpace_setSupportInfo(dataSpace, combined); } else if (type === 'email') { const email = new DataSpaceSupportEmail(); if (supportInfo instanceof DataSpaceSupportCombinedInfo) { email.address = supportInfo.emails?.[0] ?? ''; email.documentationUrl = supportInfo.documentationUrl; } dataSpace_setSupportInfo(dataSpace, email); } else { dataSpace_setSupportInfo(dataSpace, undefined); } }; const addEmail = (): void => { const email = newEmail.trim(); if ( email && supportInfo instanceof DataSpaceSupportCombinedInfo && !supportInfo.emails?.includes(email) ) { dataSpace_combined_addEmail(supportInfo, email); } setNewEmail(''); }; // the single-email form is kept for data spaces that already use it const kinds: { kind: SupportInfoKind; label: string }[] = [ { kind: 'none', label: 'None' }, ...(kind === 'email' ? [{ kind: 'email' as const, label: 'Email only' }] : []), { kind: 'combined', label: 'Contacts and links' }, ]; return (
{kinds.map((option) => ( ))}
{supportInfo instanceof DataSpaceSupportCombinedInfo && ( <>
Contacts
{(supportInfo.emails ?? []).map((email) => ( {email} {!isReadOnly && ( )} ))} {!isReadOnly && ( setNewEmail(event.target.value)} onKeyDown={(event): void => { if (event.key === 'Enter') { addEmail(); } }} placeholder="Add an email, then Enter" /> {newEmail && ( )} )}
{!supportInfo.emails?.length && ( At least one email is required )}
dataSpace_setDocumentationUrl(supportInfo, value) } /> dataSpace_combined_setWebsite(supportInfo, value) } /> dataSpace_combined_setFaqUrl(supportInfo, value) } /> dataSpace_combined_setSupportUrl(supportInfo, value) } />
)} {supportInfo instanceof DataSpaceSupportEmail && (
dataSpace_email_setSupportInfoEmail(supportInfo, value) } /> dataSpace_setDocumentationUrl(supportInfo, value) } />
)} {!supportInfo && (
No support information: people who open this data space won't see who to contact.
)}
); });