/** * 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 { observer } from 'mobx-react-lite'; import { useEffect } from 'react'; import { ServiceEditorState } from '../../../../stores/editor/editor-state/element-editor-state/service/ServiceEditorState.js'; import { clsx, PanelLoadingIndicator, CustomSelectorInput, CheckSquareIcon, SquareIcon, ExternalLinkSquareIcon, CircleNotchIcon, } from '@finos/legend-art'; import { prettyCONSTName } from '@finos/legend-shared'; import { LEGEND_STUDIO_TEST_ID } from '../../../../__lib__/LegendStudioTesting.js'; import { ServiceExecutionMode } from '@finos/legend-graph'; import { flowResult } from 'mobx'; import { useEditorStore } from '../../EditorStoreProvider.js'; import { useApplicationStore } from '@finos/legend-application'; import { MASTER_SNAPSHOT_ALIAS } from '@finos/legend-server-depot'; import { LATEST_PROJECT_REVISION, generateServiceManagementUrl, } from '../../../../stores/editor/editor-state/element-editor-state/service/ServiceRegistrationState.js'; export const ServiceRegistrationEditor = observer(() => { const editorStore = useEditorStore(); const applicationStore = useApplicationStore(); const serviceState = editorStore.tabManagerState.getCurrentEditorState(ServiceEditorState); const registrationState = serviceState.registrationState; // env & execution server const envOptions = registrationState.options.map((info) => ({ label: info.env.toUpperCase(), value: info.env, })); const selectedEnvOption = registrationState.serviceEnv ? { label: registrationState.serviceEnv.toUpperCase(), value: registrationState.serviceEnv, } : null; const onServerEnvChange = ( val: { label: string; value: string } | null, ): void => { registrationState.updateEnv(val?.value); }; // execution mode const serviceTypesOptions = registrationState.executionModes.map((mode) => ({ label: prettyCONSTName(mode), value: mode, })); const selectedServiceType = registrationState.serviceExecutionMode ? { label: prettyCONSTName(registrationState.serviceExecutionMode), value: registrationState.serviceExecutionMode, } : null; const onServiceTypeSelectionChange = ( val: { label: string; value: ServiceExecutionMode } | null, ): void => { registrationState.updateType(val?.value); }; // version const selectedVersion = registrationState.projectVersion ? { label: registrationState.projectVersion === MASTER_SNAPSHOT_ALIAS ? LATEST_PROJECT_REVISION : registrationState.projectVersion, value: registrationState.projectVersion, } : null; const onVersionSelectionChange = ( val: { label: string; value: string } | null, ): void => { registrationState.setProjectVersion(val?.value); }; const versionPlaceholder = registrationState.versionOptions === undefined ? `Only valid for ${prettyCONSTName( ServiceExecutionMode.SEMI_INTERACTIVE, )} and ${prettyCONSTName(ServiceExecutionMode.PROD)} service types` : !registrationState.versionOptions.length ? 'Project has no versions' : undefined; // activate const toggleActivatePostRegistration = (): void => { registrationState.setActivatePostRegistration( !registrationState.activatePostRegistration, ); }; // store model for full interactive const toggleUseStoreModel = (): void => { registrationState.setUseStoreModelWithFullInteractive( !registrationState.TEMPORARY__useStoreModel, ); }; const toggleUseGenerateLineage = (): void => { registrationState.setUseGenerateLineage( !registrationState.TEMPORARY__useGenerateLineage, ); }; const toggleUseGenerateOpenApi = (): void => { registrationState.setUseGenerateOpenApi( !registrationState.TEMPORARY__useGenerateOpenApi, ); }; // actions const registerService = (): void => { if (selectedEnvOption && selectedServiceType) { flowResult(registrationState.registerService()).catch( applicationStore.alertUnhandledError, ); } }; const disableRegistration = !selectedEnvOption || !selectedServiceType || registrationState.registrationState.isInProgress; useEffect(() => { flowResult(registrationState.checkServiceRegistration()).catch( applicationStore.alertUnhandledError, ); }, [registrationState, applicationStore]); return (
Register Service
{registrationState.registrationState.message && (
{`${registrationState.registrationState.message}...`}
)}
Deployment Status
Environments where this service is currently deployed
{registrationState.deploymentCheckState.isInProgress && (
Fetching deployment status...
)} {registrationState.deploymentCheckState.hasCompleted && registrationState.registeredEnvs.length === 0 && (
Service is not deployed to any environment
)} {registrationState.deploymentCheckState.hasCompleted && registrationState.registeredEnvs.length > 0 && (
Service is deployed to {registrationState.registeredEnvs.map((env) => { const envConfig = registrationState.registrationOptions.find( (e) => e.env === env, ); return envConfig ? ( {env.toUpperCase()} ) : null; })}
)}
Activate Service
Activates service after registration
Execution Server
The execution server where your service will be registered
Service Type
The kind of service you want to register. Used to determine how the metadata will be fetched
{registrationState.serviceExecutionMode === ServiceExecutionMode.FULL_INTERACTIVE && (
Store Model
Use Store Model (slower)
)} {
Generate Lineage
Generate Lineage (slower)
} {registrationState.serviceExecutionMode === ServiceExecutionMode.PROD && (
Generate Open Api
Generate Open Api
)}
Project Version
The version of your project you want to use for registration. Only relevant for semi-interactive and production services.
); });