/** * 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 { type SelectComponent, Panel, PanelHeader, PanelContent, PanelForm, PanelFormTextField, PURE_FunctionIcon, LongArrowRightIcon, PanelLoadingIndicator, PURE_ConnectionIcon, CustomSelectorInput, createFilter, DataAccessIcon, ControlledDropdownMenu, MenuContent, MenuContentItem, CaretDownIcon, } from '@finos/legend-art'; import { type PackageableConnection, generateFunctionPrettyName, RelationalDatabaseConnection, DatabaseType, SnowflakePermissionScheme, } from '@finos/legend-graph'; import { observer } from 'mobx-react-lite'; import { useApplicationStore } from '@finos/legend-application'; import { useEditorStore } from '../../EditorStoreProvider.js'; import { SnowflakeAppFunctionActivatorEdtiorState } from '../../../../stores/editor/editor-state/element-editor-state/function-activator/SnowflakeAppFunctionActivatorEditorState.js'; import { flowResult } from 'mobx'; import { useRef } from 'react'; import { type RelationalDatabaseConnectionOption, buildRelationalDatabaseConnectionOption, } from '../connection-editor/RelationalDatabaseConnectionEditor.js'; import { ActivatorOwnershipForm } from './ActivatorFormComponents.js'; import { ActivatorArtifactViewer } from './ActivatorArtifactViewer.js'; export const SnowflakeAppFunctionActivatorEditor = observer(() => { const editorStore = useEditorStore(); const applicationStore = useApplicationStore(); const editorState = editorStore.tabManagerState.getCurrentEditorState( SnowflakeAppFunctionActivatorEdtiorState, ); const isReadOnly = editorState.isReadOnly; const activator = editorState.activator; const connectionSelectorRef = useRef(null); const connectionFilterOption = createFilter({ ignoreCase: true, ignoreAccents: false, stringify: (option: { data: RelationalDatabaseConnectionOption }): string => option.data.value.path, }); const connectionOptions = editorStore.graphManagerState.usableConnections .filter( (connection) => connection.connectionValue instanceof RelationalDatabaseConnection && connection.connectionValue.type === DatabaseType.Snowflake, ) .map(buildRelationalDatabaseConnectionOption); const permissionSchemeOptions = Object.values(SnowflakePermissionScheme).map( (type) => ({ value: type, label: type, }), ); const initializeActivationConnection = ( val: PackageableConnection | undefined, ): PackageableConnection | undefined => { if (val) { editorState.updateConnection(val); } return !val ? undefined : activator.activationConfiguration.activationConnection ?.packageableConnection.value; }; const activationConnection = activator.activationConfiguration .activationConnection ? activator.activationConfiguration.activationConnection .packageableConnection.value : initializeActivationConnection(connectionOptions.at(0)?.value); const changeConnection = (val: RelationalDatabaseConnectionOption): void => { if (!isReadOnly && val.value === activationConnection) { return; } editorState.updateConnection(val.value); }; const changePermissionScheme = (val: { value: SnowflakePermissionScheme; label: SnowflakePermissionScheme; }): void => { if (!isReadOnly && val.value === activator.permissionScheme) { return; } editorState.updatePermissionScopte(val.value); }; const changeDescription: React.ChangeEventHandler = ( event, ) => { if (!isReadOnly) { editorState.updateAppDescription(event.target.value); } }; const visitFunction = (): void => editorState.editorStore.graphEditorMode.openElement( activator.function.value, ); const visitConnection = (): void => { if (activationConnection) { editorState.editorStore.graphEditorMode.openElement(activationConnection); } }; const validate = (): void => { flowResult(editorState.validate()).catch( applicationStore.alertUnhandledError, ); }; const renderArtifact = (): void => { flowResult(editorState.renderArtifact()).catch( applicationStore.alertUnhandledError, ); }; const deploy = (): void => { flowResult(editorState.deployToSandbox()).catch( applicationStore.alertUnhandledError, ); }; return (
Snowflake Activator Metadata
Render Artifact } menuProps={{ anchorOrigin: { vertical: 'bottom', horizontal: 'right', }, transformOrigin: { vertical: 'top', horizontal: 'right', }, }} >
Function
Connection
editorState.updateApplicationName(value ?? '') } />
Permission Scheme
editorState.updateUsageRole(value) } /> editorState.updateDeploymentSchema(value) } />
Description
{`Provide a brief description of Snowflake App`}