@finos/legend-extension-dsl-data-space-studio
Version:
Legend extension for Data Space DSL - Studio
120 lines • 8.93 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/**
* 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 { PanelFormSection, CustomSelectorInput, PanelFormTextField, ListEditor, 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_addEmail, dataSpace_combined_deleteEmail, dataSpace_setSupportInfo, } from '../../stores/studio/DSL_DataSpace_GraphModifierHelper.js';
import { useEditorStore } from '@finos/legend-application-studio';
import { DataSpaceEditorState } from '../../stores/DataSpaceEditorState.js';
import { useState } from 'react';
export const DataSpaceSupportInfoSection = observer(() => {
const editorStore = useEditorStore();
const dataSpaceState = editorStore.tabManagerState.getCurrentEditorState(DataSpaceEditorState);
const dataSpace = dataSpaceState.dataSpace;
// Event handlers
const handleSupportInfoTypeChange = (option) => {
if (typeof option !== 'object' || !('value' in option)) {
return;
}
const type = option.value;
if (type === 'email' &&
!(dataSpace.supportInfo instanceof DataSpaceSupportEmail)) {
const supportInfo = new DataSpaceSupportEmail();
if (dataSpace.supportInfo instanceof DataSpaceSupportCombinedInfo) {
supportInfo.address = dataSpace.supportInfo.emails?.[0] ?? '';
supportInfo.documentationUrl = dataSpace.supportInfo.documentationUrl;
}
dataSpace_setSupportInfo(dataSpace, supportInfo);
}
else if (type === 'combined' &&
!(dataSpace.supportInfo instanceof DataSpaceSupportCombinedInfo)) {
const supportInfo = new DataSpaceSupportCombinedInfo();
if (dataSpace.supportInfo instanceof DataSpaceSupportEmail &&
dataSpace.supportInfo.address) {
supportInfo.emails = [dataSpace.supportInfo.address];
supportInfo.documentationUrl = dataSpace.supportInfo.documentationUrl;
}
dataSpace_setSupportInfo(dataSpace, supportInfo);
}
else {
dataSpace_setSupportInfo(dataSpace, undefined);
}
};
const handleSupportInfoEmailAdd = (email) => {
if (dataSpace.supportInfo instanceof DataSpaceSupportCombinedInfo) {
dataSpace_combined_addEmail(dataSpace.supportInfo, email);
}
};
const handleSupportInfoEmailRemove = (email) => {
if (dataSpace.supportInfo instanceof DataSpaceSupportCombinedInfo) {
dataSpace_combined_deleteEmail(dataSpace.supportInfo, email);
}
};
// ListEditor component renderers
const SupportEmailComponent = observer((props) => {
const { item } = props;
return (_jsx("div", { className: "panel__content__form__section__list__item__content", children: _jsx("div", { className: "panel__content__form__section__header__label", children: item }) }));
});
const NewSupportEmailComponent = observer((props) => {
const { onFinishEditing } = props;
const [email, setEmail] = useState('');
return (_jsxs("div", { className: "dataSpace-editor__general__support-info__new-email", children: [_jsx("div", { className: "panel__content__form__section__list__new-item__input", children: _jsx("input", { className: "input input-group__input panel__content__form__section__input input--dark", type: "email", placeholder: "Enter email", value: email, onChange: (event) => {
setEmail(event.target.value);
} }) }), _jsx("button", { className: "panel__content__form__section__list__new-item__add-btn btn btn--dark", onClick: () => {
handleSupportInfoEmailAdd(email);
setEmail('');
onFinishEditing();
}, children: "Save" })] }));
});
return (_jsxs(PanelFormSection, { className: "dataSpace-editor__general__support-info", children: [_jsx("div", { className: "panel__content__form__section__header__label", children: "Support Information" }), _jsx("div", { className: "panel__content__form__section__header__prompt", children: "Configure support information for this Data Product." }), !(dataSpace.supportInfo instanceof DataSpaceSupportCombinedInfo) && (_jsx(CustomSelectorInput, { options: [
{ label: 'None', value: 'none' },
{ label: 'Combined', value: 'combined' },
], onChange: (option) => handleSupportInfoTypeChange(option), value: {
label: dataSpace.supportInfo
? dataSpace.supportInfo instanceof DataSpaceSupportEmail
? 'Email'
: 'Combined'
: 'None',
value: dataSpace.supportInfo
? dataSpace.supportInfo instanceof DataSpaceSupportEmail
? 'email'
: 'combined'
: 'none',
}, darkMode: true })), dataSpace.supportInfo ? (dataSpace.supportInfo instanceof DataSpaceSupportEmail ? (_jsxs(PanelFormSection, { className: "dataSpace-editor__general__support-info__content", children: [_jsx(PanelFormTextField, { name: "Email Address", value: dataSpace.supportInfo.address, update: (value) => {
if (dataSpace.supportInfo instanceof DataSpaceSupportEmail) {
dataSpace_email_setSupportInfoEmail(dataSpace.supportInfo, value ?? '');
}
}, placeholder: "Enter email address" }), _jsx(PanelFormTextField, { name: "Documentation URL", value: dataSpace.supportInfo.documentationUrl, update: (value) => {
if (dataSpace.supportInfo) {
dataSpace_setDocumentationUrl(dataSpace.supportInfo, value ?? '');
}
}, placeholder: "Enter documentation URL" })] })) : dataSpace.supportInfo instanceof DataSpaceSupportCombinedInfo ? (_jsxs("div", { children: [_jsx(ListEditor, { title: "Emails", items: dataSpace.supportInfo.emails, keySelector: (element) => element, ItemComponent: SupportEmailComponent, NewItemComponent: NewSupportEmailComponent, handleRemoveItem: handleSupportInfoEmailRemove, isReadOnly: dataSpaceState.isReadOnly, emptyMessage: "No emails specified" }), (dataSpace.supportInfo.emails === undefined ||
dataSpace.supportInfo.emails.length === 0) && (_jsxs("div", { className: "service-editor__owner__validation", children: [_jsx(WarningIcon, {}), _jsx("div", { className: "service-editor__owner__validation-label", children: "At least one email is required" })] })), _jsx(PanelFormTextField, { name: "Documentation URL", value: dataSpace.supportInfo.documentationUrl, update: (value) => {
if (dataSpace.supportInfo) {
dataSpace_setDocumentationUrl(dataSpace.supportInfo, value ?? '');
}
}, placeholder: "Enter documentation URL" }), _jsx(PanelFormTextField, { name: "Website", value: dataSpace.supportInfo.website, update: (value) => {
if (dataSpace.supportInfo instanceof DataSpaceSupportCombinedInfo) {
dataSpace_combined_setWebsite(dataSpace.supportInfo, value ?? '');
}
}, placeholder: "Enter website URL" }), _jsx(PanelFormTextField, { name: "FAQ URL", value: dataSpace.supportInfo.faqUrl, update: (value) => {
if (dataSpace.supportInfo instanceof DataSpaceSupportCombinedInfo) {
dataSpace_combined_setFaqUrl(dataSpace.supportInfo, value ?? '');
}
}, placeholder: "Enter FAQ URL" })] })) : (_jsx("div", { children: "Unknown support info type" }))) : null] }));
});
//# sourceMappingURL=DataSpaceSupportInfoSection.js.map