Skip to content

Commit

Permalink
Revert "binding to extend packagable element + remove external format… (
Browse files Browse the repository at this point in the history
  • Loading branch information
MauricioUyaguari authored Jul 10, 2023
1 parent 38e28d6 commit 7d870c2
Show file tree
Hide file tree
Showing 36 changed files with 571 additions and 110 deletions.
5 changes: 5 additions & 0 deletions .changeset/empty-dingos-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@finos/legend-application-studio': patch
'@finos/legend-query-builder': patch
'@finos/legend-graph': patch
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* 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 {
ExternalFormatConnection,
PackageableElementExplicitReference,
UrlStream,
type Binding,
} from '@finos/legend-graph';
import { computed, makeObservable } from 'mobx';
import { ConnectionValueState } from '../../../../stores/editor/editor-state/element-editor-state/connection/ConnectionEditorState.js';
import type { EditorStore } from '../../../../stores/editor/EditorStore.js';
import { NewConnectionValueDriver } from '../../../../stores/editor/NewElementState.js';
import { externalFormat_urlStream_setUrl } from '../../../../stores/graph-modifier/DSL_ExternalFormat_GraphModifierHelper.js';
import { EXTERNAL_FORMAT_CONNECTION } from '../../../extensions/DSL_ExternalFormat_LegendStudioApplicationPlugin.js';

export class ExternalFormatConnectionValueState extends ConnectionValueState {
override connection: ExternalFormatConnection;

constructor(editorStore: EditorStore, connection: ExternalFormatConnection) {
super(editorStore, connection);
this.connection = connection;
}

label(): string {
return 'external format connection';
}
}

export const ExternalFormatConnectionEditor = observer(
(props: {
connectionValueState: ExternalFormatConnectionValueState;
isReadOnly: boolean;
}) => {
const { connectionValueState, isReadOnly } = props;
const connection = connectionValueState.connection;
const changeUrl: React.ChangeEventHandler<HTMLTextAreaElement> = (event) =>
externalFormat_urlStream_setUrl(
connection.externalSource,
event.target.value,
);
return (
<div className="external-format-connection-editor">
<div className="external-format-connection-editor__section">
<div className="external-format-connection-editor__section__header__label">
URL
</div>
<div className="external-format-connection-editor__section__header__prompt">
Specifies the connection URL
</div>
<textarea
className="external-format-connection-editor__section__textarea"
spellCheck={false}
value={connection.externalSource.url}
onChange={changeUrl}
disabled={isReadOnly}
/>
</div>
</div>
);
},
);

export class NewExternalFormatConnectionDriver extends NewConnectionValueDriver<ExternalFormatConnection> {
constructor(editorStore: EditorStore) {
super(editorStore);

makeObservable(this, {
isValid: computed,
});
}

get isValid(): boolean {
return true;
}

getConnectionType(): string {
return EXTERNAL_FORMAT_CONNECTION;
}

createConnection(store: Binding): ExternalFormatConnection {
const externalFormatConnection = new ExternalFormatConnection(
PackageableElementExplicitReference.create(store),
);
const urlStream = new UrlStream();
externalFormat_urlStream_setUrl(urlStream, '');
externalFormatConnection.externalSource = urlStream;
return externalFormatConnection;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,21 @@ import packageJson from '../../../package.json' assert { type: 'json' };
import { BufferIcon, SitemapIcon } from '@finos/legend-art';
import { SchemaSetEditor } from '../editor/editor-group/external-format-editor/DSL_ExternalFormat_SchemaSetElementEditor.js';
import {
type Connection,
type PackageableElement,
type Store,
PackageableElementExplicitReference,
SchemaSet,
Binding,
ModelUnit,
ExternalFormatConnection,
UrlStream,
} from '@finos/legend-graph';
import {
ExternalFormatConnectionEditor,
ExternalFormatConnectionValueState,
NewExternalFormatConnectionDriver,
} from '../editor/editor-group/external-format-editor/DSL_ExternalFormat_ExternalFormatConnectionEditor.js';
import { BindingEditor } from '../editor/editor-group/external-format-editor/DSL_ExternalFormat_BindingElementEditor.js';
import { guaranteeNonNullable, prettyCONSTName } from '@finos/legend-shared';
import type { ReactNode } from 'react';
Expand All @@ -43,14 +53,24 @@ import {
type DSL_LegendStudioApplicationPlugin_Extension,
} from '../../stores/LegendStudioApplicationPlugin.js';
import type {
ConnectionEditorRenderer,
ConnectionTypeOption,
ConnectionValueEditorStateBuilder,
DefaultConnectionValueBuilder,
DSL_Mapping_LegendStudioApplicationPlugin_Extension,
NewConnectionDriverCreator,
PureGrammarConnectionLabeler,
RuntimeConnectionTooltipTextBuilder,
} from '../../stores/extensions/DSL_Mapping_LegendStudioApplicationPlugin_Extension.js';
import type { EditorStore } from '../../stores/editor/EditorStore.js';
import type { ElementEditorState } from '../../stores/editor/editor-state/element-editor-state/ElementEditorState.js';
import { SchemaSetEditorState } from '../../stores/editor/editor-state/element-editor-state/external-format/DSL_ExternalFormat_SchemaSetEditorState.js';
import { BindingEditorState } from '../../stores/editor/editor-state/element-editor-state/external-format/DSL_ExternalFormat_BindingEditorState.js';
import { externalFormat_Binding_setContentType } from '../../stores/graph-modifier/DSL_ExternalFormat_GraphModifierHelper.js';
import type { ConnectionValueState } from '../../stores/editor/editor-state/element-editor-state/connection/ConnectionEditorState.js';
import {
externalFormat_Binding_setContentType,
externalFormat_urlStream_setUrl,
} from '../../stores/graph-modifier/DSL_ExternalFormat_GraphModifierHelper.js';
import type { DocumentationEntry } from '@finos/legend-application';
import { DSL_EXTERNAL_FORMAT_LEGEND_STUDIO_DOCUMENTATION_KEY } from '../../__lib__/DSL_ExternalFormat_LegendStudioDocumentation.js';
import {
Expand All @@ -65,6 +85,7 @@ import {
NewSchemaSetDriverEditor,
} from '../editor/editor-group/external-format-editor/DSL_ExternalFormat_NewSchemaSetDriver.js';
import type {
NewConnectionValueDriver,
NewElementDriver,
NewElementState,
} from '../../stores/editor/NewElementState.js';
Expand All @@ -80,6 +101,8 @@ export const EXTERNAL_FORMAT_CONNECTION = 'EXTERNAL_FORMAT_CONNECTION';
const PURE_GRAMMAR_EXTERNAL_FORMAT_PARSER_NAME = 'ExternalFormat';
const PURE_GRAMMAR_BINDING_ELEMENT_TYPE_LABEL = 'Binding';
const PURE_GRAMMAR_SCHEMA_SET_ELEMENT_TYPE_LABEL = 'SchemaSet';
const PURE_GRAMMAR_EXTERNAL_FORMAT_CONNECTION_TYPE_LABEL =
'ExternalFormatConnection';

export class DSL_ExternalFormat_LegendStudioApplicationPlugin
extends LegendStudioApplicationPlugin
Expand All @@ -106,6 +129,18 @@ export class DSL_ExternalFormat_LegendStudioApplicationPlugin
return [
PURE_GRAMMAR_BINDING_ELEMENT_TYPE_LABEL,
PURE_GRAMMAR_SCHEMA_SET_ELEMENT_TYPE_LABEL,
PURE_GRAMMAR_EXTERNAL_FORMAT_CONNECTION_TYPE_LABEL,
];
}

getExtraPureGrammarConnectionLabelers(): PureGrammarConnectionLabeler[] {
return [
(connection): string | undefined => {
if (connection instanceof ExternalFormatConnection) {
return PURE_GRAMMAR_EXTERNAL_FORMAT_CONNECTION_TYPE_LABEL;
}
return undefined;
},
];
}

Expand Down Expand Up @@ -251,6 +286,89 @@ export class DSL_ExternalFormat_LegendStudioApplicationPlugin
];
}

getExtraRuntimeConnectionTooltipTextBuilders(): RuntimeConnectionTooltipTextBuilder[] {
return [
(connection: Connection): string | undefined => {
if (connection instanceof ExternalFormatConnection) {
return `External format connection \u2022 store ${connection.store.value.path}`;
}
return undefined;
},
];
}

getExtraDefaultConnectionValueBuilders(): DefaultConnectionValueBuilder[] {
return [
(store: Store): Connection | undefined => {
if (store instanceof Binding) {
const externalFormatConnection = new ExternalFormatConnection(
PackageableElementExplicitReference.create(store),
);
const urlStream = new UrlStream();
externalFormat_urlStream_setUrl(urlStream, '');
externalFormatConnection.externalSource = urlStream;
return externalFormatConnection;
}
return undefined;
},
];
}

getExtraConnectionValueEditorStateBuilders(): ConnectionValueEditorStateBuilder[] {
return [
(
editorStore: EditorStore,
connection: Connection,
): ConnectionValueState | undefined => {
if (connection instanceof ExternalFormatConnection) {
return new ExternalFormatConnectionValueState(
editorStore,
connection,
);
}
return undefined;
},
];
}

getExtraConnectionEditorRenderers(): ConnectionEditorRenderer[] {
return [
(
connectionValueState: ConnectionValueState,
isReadOnly: boolean,
): React.ReactNode | undefined => {
if (
connectionValueState instanceof ExternalFormatConnectionValueState
) {
return (
<ExternalFormatConnectionEditor
connectionValueState={connectionValueState}
isReadOnly={isReadOnly}
/>
);
}
return undefined;
},
];
}

getExtraNewConnectionDriverCreators(): NewConnectionDriverCreator[] {
return [
(
editorStore: EditorStore,
typeOrStore: Store | string,
): NewConnectionValueDriver<Connection> | undefined => {
if (typeOrStore instanceof Binding) {
return new NewExternalFormatConnectionDriver(editorStore);
}
if (typeOrStore === EXTERNAL_FORMAT_CONNECTION) {
return new NewExternalFormatConnectionDriver(editorStore);
}
return undefined;
},
];
}

getExtraConnectionTypeOptions(): ConnectionTypeOption[] {
return [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const generateStoreTestDataFromSetImpl = (
);
if (_table instanceof TableAlias) {
const relation = _table.relation.value;
const owner = _table.relation.ownerReference.value;
const owner = relation.schema._OWNER;
const val = new RelationalCSVData();
if (tryAndMockTable && relation instanceof Table) {
const mockTable = new RelationalCSVDataTable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ import type {
TextCompilationResult,
} from './action/compilation/CompilationResult.js';
import type { ParameterValue } from '../DSL_Service_Exports.js';
import type { ModelUnit } from '../graph/metamodel/pure/packageableElements/externalFormat/binding/DSL_ExternalFormat_ModelUnit.js';
import type { ModelUnit } from '../graph/metamodel/pure/packageableElements/externalFormat/store/DSL_ExternalFormat_ModelUnit.js';
import type {
DatasetEntitlementReport,
DatasetSpecification,
Expand Down
10 changes: 0 additions & 10 deletions packages/legend-graph/src/graph-manager/GraphManagerState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import type { FileGenerationSpecification } from '../graph/metamodel/pure/packag
import type { GenerationSpecification } from '../graph/metamodel/pure/packageableElements/generationSpecification/GenerationSpecification.js';
import type { Type } from '../graph/metamodel/pure/packageableElements/domain/Type.js';
import { PrimitiveType } from '../graph/metamodel/pure/packageableElements/domain/PrimitiveType.js';
import type { Binding } from '../graph/metamodel/pure/packageableElements/externalFormat/binding/DSL_ExternalFormat_Binding.js';

export class BasicGraphManagerState {
readonly pluginManager: GraphManagerPluginManager;
Expand Down Expand Up @@ -242,15 +241,6 @@ export class GraphManagerState extends BasicGraphManagerState {
...this.graph.ownStores,
];
}
get usableBindings(): Binding[] {
return [
...this.graphManager.collectExposedSystemElements(
this.graph.systemModel.ownBindings,
),
...this.graph.dependencyManager.bindings,
...this.graph.ownBindings,
];
}
get usableDatabases(): Database[] {
return [
...this.graphManager.collectExposedSystemElements(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,23 @@ export const roundtripTestData = [
},
classifierPath: 'meta::external::shared::format::binding::Binding',
},
{
path: 'anything::tConn',
content: {
_type: 'connection',
connectionValue: {
_type: 'ExternalFormatConnection',
element: 'binding1',
externalSource: {
_type: 'urlStream',
url: 'test',
},
},
name: 'tConn',
package: 'anything',
},
classifierPath: 'meta::pure::runtime::PackageableConnection',
},
{
path: '__internal__::SectionIndex',
content: {
Expand Down Expand Up @@ -94,6 +111,12 @@ export const roundtripTestData = [
elements: ['anything::binding1'],
parserName: 'Binding',
},
{
_type: 'importAware',
imports: ['anything'],
elements: ['anything::tConn'],
parserName: 'Connection',
},
],
},
classifierPath: 'meta::pure::metamodel::section::SectionIndex',
Expand Down
Loading

0 comments on commit 7d870c2

Please sign in to comment.