Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extension mechanism for class mapping decorators #654

Merged
merged 5 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/blue-jars-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@finos/legend-studio": minor
---

Add extension mechanism for `class mapping` decorators in form mode
5 changes: 5 additions & 0 deletions .changeset/flat-lies-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@finos/legend-extension-external-store-service": patch
"@finos/legend-manual-tests": patch
"@finos/legend-extension-dsl-serializer": patch
---
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class DSLSerializer_StudioPlugin
return [
(connection: Connection): string | undefined => {
if (connection instanceof ExternalFormatConnection) {
return `External format connection \u2020 store ${connection.store.value.path}`;
return `External format connection \u2022 store ${connection.store.value.path}`;
}
return undefined;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import type {
StudioPluginManager,
NewElementFromStateCreator,
RuntimeConnectionTooltipTextBuilder,
EditorStore,
ElementEditorState,
ElementEditorStateCreator,
Expand All @@ -38,11 +39,13 @@ import type {
MappingElementSource,
} from '@finos/legend-studio';
import type {
Connection,
PackageableElement,
SetImplementation,
} from '@finos/legend-graph';
import { ServiceStore } from '../models/metamodels/pure/model/packageableElements/store/serviceStore/model/ServiceStore';
import { RootServiceInstanceSetImplementation } from '../models/metamodels/pure/model/packageableElements/store/serviceStore/mapping/RootServiceInstanceSetImplementation';
import { ServiceStoreConnection } from '../models/metamodels/pure/model/packageableElements/store/serviceStore/connection/ServiceStoreConnection';

const SERVICE_STORE_ELEMENT_TYPE = 'SERVICE_STORE';
const SERVICE_STORE_ELEMENT_PROJECT_EXPLORER_DND_TYPE =
Expand Down Expand Up @@ -161,4 +164,15 @@ export class ESService_StudioPlugin
},
];
}

getExtraRuntimeConnectionTooltipTextBuilders(): RuntimeConnectionTooltipTextBuilder[] {
return [
(connection: Connection): string | undefined => {
if (connection instanceof ServiceStoreConnection) {
return `Service store connection \u2022 store ${connection.store.value.path}`;
}
return undefined;
},
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ enum ROUNTRIP_TEST_PHASES {
const SKIP = Symbol('SKIP GRAMMAR ROUNDTRIP TEST');

const EXCLUSIONS: { [key: string]: ROUNTRIP_TEST_PHASES[] | typeof SKIP } = {
'ESService-basic.pure': SKIP, //Needs https://github.com/finos/legend-engine/pull/417 to be merged
// post processor mismatch between engine (undefined) vs studio ([])
'relational-connection.pure': [ROUNTRIP_TEST_PHASES.PROTOCOL_ROUNDTRIP],

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,17 +354,17 @@ export const EnumerationMappingEditor = observer(
);
useEffect(() => {
if (!isReadOnly) {
new MappingElementDecorator().visitEnumerationMapping(
new MappingElementDecorator(editorStore).visitEnumerationMapping(
enumerationMapping,
);
}
return isReadOnly
? noop()
: (): void =>
new MappingElementDecorationCleaner().visitEnumerationMapping(
enumerationMapping,
);
}, [enumerationMapping, isReadOnly]);
new MappingElementDecorationCleaner(
editorStore,
).visitEnumerationMapping(enumerationMapping);
}, [enumerationMapping, isReadOnly, editorStore]);
return (
<div data-testid={STUDIO_TEST_ID.MAIN_EDITOR} className="editor__main">
<div className="mapping-element-editor enumeration-mapping-editor">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,13 +463,14 @@ export const InstanceSetImplementationEditor = observer(
? noop()
: (): void =>
setImplementation.accept_SetImplementationVisitor(
new MappingElementDecorationCleaner(),
new MappingElementDecorationCleaner(editorStore),
);
}, [
applicationStore,
setImplementation,
isReadOnly,
instanceSetImplementationState,
editorStore,
]);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ export const InstanceSetImplementationSourceSelectorModal = observer(
});
const sourceSelectorRef = useRef<SelectComponent>(null);
const selectedSourceType = buildMappingElementSourceOption(
sourceElementToSelect ?? getMappingElementSource(setImplementation),
sourceElementToSelect ??
getMappingElementSource(
setImplementation,
editorStore.pluginManager.getStudioPlugins(),
),
);
const changeSourceType = (
val: MappingElementSourceSelectOption | null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ const MappingExecutionQueryEditor = observer(
);
} else {
executionState.setInputDataStateBasedOnSource(
getMappingElementSource(setImplementation),
getMappingElementSource(
setImplementation,
editorStore.pluginManager.getStudioPlugins(),
),
true,
);
}
Expand All @@ -246,7 +249,10 @@ const MappingExecutionQueryEditor = observer(
type: ActionAlertActionType.PROCEED_WITH_CAUTION,
handler: (): void =>
executionState.setInputDataStateBasedOnSource(
getMappingElementSource(setImplementation),
getMappingElementSource(
setImplementation,
editorStore.pluginManager.getStudioPlugins(),
),
true,
),
},
Expand Down Expand Up @@ -521,6 +527,7 @@ const RelationalMappingExecutionInputDataTypeSelector = observer(
export const MappingExecutionInputDataBuilder = observer(
(props: { executionState: MappingExecutionState }) => {
const { executionState } = props;
const editorStore = useEditorStore();
const mappingEditorState = executionState.mappingEditorState;
const inputDataState = executionState.inputDataState;

Expand All @@ -535,14 +542,17 @@ export const MappingExecutionInputDataBuilder = observer(
(setImplementation: SetImplementation | undefined): void => {
executionState.setInputDataStateBasedOnSource(
setImplementation
? getMappingElementSource(setImplementation)
? getMappingElementSource(
setImplementation,
editorStore.pluginManager.getStudioPlugins(),
)
: undefined,
true,
);
executionState.setExecutionResultText(undefined);
hideClassMappingSelectorModal();
},
[executionState],
[executionState, editorStore],
);
const classMappingFilterFn = (setImp: SetImplementation): boolean =>
!(setImp instanceof OperationSetImplementation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,16 @@ export const MappingExplorerContextMenu = observer(
).catch(applicationStore.alertIllegalUnhandledError);
}
if (currentMappingElement instanceof EnumerationMapping) {
new MappingElementDecorator().visitEnumerationMapping(
new MappingElementDecorator(editorStore).visitEnumerationMapping(
currentMappingElement,
);
} else if (currentMappingElement instanceof SetImplementation) {
const mappingElementDecorator = new MappingElementDecorator(
editorStore,
);
mappingElementDecorator.editorStore = editorStore;
currentMappingElement.accept_SetImplementationVisitor(
new MappingElementDecorator(),
new MappingElementDecorator(editorStore),
);
}
mappingEditorState.reprocessMappingExplorerTree();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ const MappingTestQueryEditor = observer(
type: ActionAlertActionType.PROCEED_WITH_CAUTION,
handler: (): void =>
testState.setInputDataStateBasedOnSource(
getMappingElementSource(setImplementation),
getMappingElementSource(
setImplementation,
editorStore.pluginManager.getStudioPlugins(),
),
true,
),
},
Expand Down Expand Up @@ -392,6 +395,7 @@ export const MappingTestInputDataBuilder = observer(
(props: { testState: MappingTestState; isReadOnly: boolean }) => {
const { testState, isReadOnly } = props;
const inputDataState = testState.inputDataState;
const editorStore = useEditorStore();

// Class mapping selector
const [openClassMappingSelectorModal, setOpenClassMappingSelectorModal] =
Expand All @@ -404,13 +408,16 @@ export const MappingTestInputDataBuilder = observer(
(setImplementation: SetImplementation | undefined): void => {
testState.setInputDataStateBasedOnSource(
setImplementation
? getMappingElementSource(setImplementation)
? getMappingElementSource(
setImplementation,
editorStore.pluginManager.getStudioPlugins(),
)
: undefined,
true,
);
hideClassMappingSelectorModal();
},
[testState],
[testState, editorStore],
);
const classMappingFilterFn = (setImp: SetImplementation): boolean =>
!(setImp instanceof OperationSetImplementation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,16 @@ export const OperationSetImplementationEditor = observer(
useEffect(() => {
if (!isReadOnly) {
setImplementation.accept_SetImplementationVisitor(
new MappingElementDecorator(),
new MappingElementDecorator(editorStore),
);
}
return isReadOnly
? noop()
: (): void =>
setImplementation.accept_SetImplementationVisitor(
new MappingElementDecorationCleaner(),
new MappingElementDecorationCleaner(editorStore),
);
}, [setImplementation, isReadOnly]);
}, [setImplementation, isReadOnly, editorStore]);

return (
<div className="mapping-element-editor__content">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type {
Connection,
Runtime,
SetImplementation,
InstanceSetImplementation,
} from '@finos/legend-graph';
import type { ServicePureExecutionState } from './editor-state/element-editor-state/service/ServiceExecutionState';
import type { MappingTestState } from './editor-state/element-editor-state/mapping/MappingTestState';
Expand All @@ -33,6 +34,14 @@ import type {
} from './editor-state/element-editor-state/mapping/MappingEditorState';
import type { MappingElementState } from './editor-state/element-editor-state/mapping/MappingElementState';

export type SetImplementationDecorator = (
setImplementation: InstanceSetImplementation,
) => void;

export type SetImplementationDecorationCleaner = (
setImplementation: InstanceSetImplementation,
) => void;

export type MappingElementSourceGetter = (
mappingElement: MappingElement,
) => MappingElementSource | undefined;
Expand Down Expand Up @@ -106,6 +115,16 @@ export type TEMP__ServiceTestRuntimeConnectionBuilder = (

export interface DSLMapping_StudioPlugin_Extension
extends DSL_StudioPlugin_Extension {
/**
* Get the list of extra set implementation decorators.
*/
getExtraSetImplementationDecorationCleaners?(): SetImplementationDecorationCleaner[];

/**
* Get the list of extra set implementation decorators.
*/
getExtraSetImplementationDecorators?(): SetImplementationDecorator[];

/**
* Get the list of extra set implementation classifiers.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/legend-studio/src/stores/NewElementState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ export class NewElementState {
decorateRuntimeWithNewMapping(
runtimeValue,
mapping,
this.editorStore.graphManagerState.graph,
this.editorStore,
);
}
service.setExecution(
Expand Down
Loading