Skip to content

Commit

Permalink
read from() functions
Browse files Browse the repository at this point in the history
  • Loading branch information
MauricioUyaguari committed Jul 10, 2023
1 parent 38e28d6 commit 197febc
Show file tree
Hide file tree
Showing 30 changed files with 769 additions and 202 deletions.
7 changes: 7 additions & 0 deletions .changeset/warm-drinks-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@finos/legend-extension-dsl-data-space': patch
'@finos/legend-extension-dsl-service': patch
'@finos/legend-application-studio': patch
'@finos/legend-application-query': patch
'@finos/legend-query-builder': patch
---
21 changes: 13 additions & 8 deletions packages/legend-application-query/src/stores/QueryEditorStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,16 +393,16 @@ export abstract class QueryEditorStore {
'Query builder state required to build query to edit',
);
assertNonNullable(
this.queryBuilderState.mapping,
this.queryBuilderState.executionContextState.mapping,
'Query required mapping to update',
);
const runtimeValue = guaranteeType(
this.queryBuilderState.runtimeValue,
this.queryBuilderState.executionContextState.runtimeValue,
RuntimePointer,
'Query runtime must be of type runtime pointer',
);
query.mapping = PackageableElementExplicitReference.create(
this.queryBuilderState.mapping,
this.queryBuilderState.executionContextState.mapping,
);
query.runtime = runtimeValue.packageableRuntime;
query.content =
Expand Down Expand Up @@ -672,8 +672,10 @@ export class MappingQueryCreatorStore extends QueryEditorStore {
this.artifactId,
this.versionId,
val.path,
guaranteeType(queryBuilderState.runtimeValue, RuntimePointer)
.packageableRuntime.value.path,
guaranteeType(
queryBuilderState.executionContextState.runtimeValue,
RuntimePointer,
).packageableRuntime.value.path,
),
);
},
Expand All @@ -683,7 +685,10 @@ export class MappingQueryCreatorStore extends QueryEditorStore {
this.groupId,
this.artifactId,
this.versionId,
guaranteeType(queryBuilderState.mapping, Mapping).path,
guaranteeType(
queryBuilderState.executionContextState.mapping,
Mapping,
).path,
guaranteeType(val, RuntimePointer).packageableRuntime.value.path,
),
);
Expand Down Expand Up @@ -1015,8 +1020,8 @@ export class ExistingQueryEditorStore extends QueryEditorStore {
queryBuilderState ??
new ClassQueryBuilderState(this.applicationStore, this.graphManagerState);

queryBuilderState.setMapping(query.mapping.value);
queryBuilderState.setRuntimeValue(
queryBuilderState.executionContextState.setMapping(query.mapping.value);
queryBuilderState.executionContextState.setRuntimeValue(
new RuntimePointer(
PackageableElementExplicitReference.create(query.runtime.value),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,91 +115,78 @@ export const ServiceExecutionQueryEditor = observer(
applicationStore.guardUnhandledError(async () => {
const selectedExecutionState =
executionState.selectedExecutionContextState;
if (selectedExecutionState?.executionContext.mapping === undefined) {
applicationStore.notificationService.notifyError(
'Editing query without runtime and mapping is unsupported via query builder, please leverage the text mode to edit query',
);
executionState.setOpeningQueryEditor(false);
} else {
const mapping = selectedExecutionState.executionContext.mapping.value;
if (!isStubbed_PackageableElement(mapping)) {
await flowResult(
embeddedQueryBuilderState.setEmbeddedQueryBuilderConfiguration({
setupQueryBuilderState: (): QueryBuilderState => {
const queryBuilderState = new ServiceQueryBuilderState(
embeddedQueryBuilderState.editorStore.applicationStore,
embeddedQueryBuilderState.editorStore.graphManagerState,
service,
undefined,
selectedExecutionState.executionContext instanceof
KeyedExecutionParameter
? selectedExecutionState.executionContext.key
: undefined,

await flowResult(
embeddedQueryBuilderState.setEmbeddedQueryBuilderConfiguration({
setupQueryBuilderState: (): QueryBuilderState => {
const queryBuilderState = new ServiceQueryBuilderState(
embeddedQueryBuilderState.editorStore.applicationStore,
embeddedQueryBuilderState.editorStore.graphManagerState,
service,
undefined,
selectedExecutionState?.executionContext instanceof
KeyedExecutionParameter
? selectedExecutionState.executionContext.key
: undefined,
);
queryBuilderState.initializeWithQuery(
executionState.execution.func,
);
if (openInTextMode) {
queryBuilderState.textEditorState.openModal(
QueryBuilderTextEditorMode.TEXT,
);
}
return queryBuilderState;
},
actionConfigs: [
{
key: 'save-query-btn',
renderer: (
queryBuilderState: QueryBuilderState,
): React.ReactNode => {
const save = applicationStore.guardUnhandledError(
async () => {
try {
const rawLambda = queryBuilderState.buildQuery();
await flowResult(
executionState.queryState.updateLamba(rawLambda),
);
applicationStore.notificationService.notifySuccess(
`Service query is updated`,
);
embeddedQueryBuilderState.setEmbeddedQueryBuilderConfiguration(
undefined,
);
} catch (error) {
assertErrorThrown(error);
applicationStore.notificationService.notifyError(
`Can't save query: ${error.message}`,
);
}
},
);
queryBuilderState.initializeWithQuery(
executionState.execution.func,

return (
<button
className="query-builder__dialog__header__custom-action"
tabIndex={-1}
disabled={isReadOnly}
onClick={save}
>
Save Query
</button>
);
if (openInTextMode) {
queryBuilderState.textEditorState.openModal(
QueryBuilderTextEditorMode.TEXT,
);
}
return queryBuilderState;
},
actionConfigs: [
{
key: 'save-query-btn',
renderer: (
queryBuilderState: QueryBuilderState,
): React.ReactNode => {
const save = applicationStore.guardUnhandledError(
async () => {
try {
const rawLambda = queryBuilderState.buildQuery();
await flowResult(
executionState.queryState.updateLamba(rawLambda),
);
applicationStore.notificationService.notifySuccess(
`Service query is updated`,
);
embeddedQueryBuilderState.setEmbeddedQueryBuilderConfiguration(
undefined,
);
} catch (error) {
assertErrorThrown(error);
applicationStore.notificationService.notifyError(
`Can't save query: ${error.message}`,
);
}
},
);

return (
<button
className="query-builder__dialog__header__custom-action"
tabIndex={-1}
disabled={isReadOnly}
onClick={save}
>
Save Query
</button>
);
},
},
],
disableCompile: isStubbed_RawLambda(
executionState.queryState.query,
),
}),
);
executionState.setOpeningQueryEditor(false);
return;
}
applicationStore.notificationService.notifyWarning(
'Please specify a mapping and a runtime for the execution context to edit with query builder',
);
executionState.setOpeningQueryEditor(false);
}
},
],
disableCompile: isStubbed_RawLambda(
executionState.queryState.query,
),
}),
);
executionState.setOpeningQueryEditor(false);
return;
});

const importQuery = (): void =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ const promoteQueryToService = async (
const applicationStore = editorStore.applicationStore;
try {
const mapping = guaranteeNonNullable(
queryBuilderState.mapping,
queryBuilderState.executionContextState.mapping,
'Mapping is required to create service execution',
);
const runtime = guaranteeNonNullable(
queryBuilderState.runtimeValue,
queryBuilderState.executionContextState.runtimeValue,
'Runtime is required to create service execution',
);
const query = queryBuilderState.buildQuery();
Expand Down Expand Up @@ -269,15 +269,23 @@ const PromoteToServiceQueryBuilderAction = observer(
setPromoteQueryType(type);
const closeNewServiceModal = (): void => setPromoteQueryType(undefined);
const allowPromotion = Boolean(
queryBuilderState.mapping &&
queryBuilderState.runtimeValue &&
queryBuilderState.executionContextState.mapping &&
queryBuilderState.executionContextState.runtimeValue &&
!queryBuilderState.allValidationIssues.length,
);
console.log(
'queryBuilderState.executionContextState.mapping',
queryBuilderState.executionContextState.mapping,
);
console.log(
'queryBuilderState.executionContextState.runtimeValue',
queryBuilderState.executionContextState.runtimeValue,
);

const renderSaveAsModal = (): React.ReactNode => {
if (
promoteQueryModal === PROMOTE_QUERY_TYPE.SERVICE &&
queryBuilderState.mapping
queryBuilderState.executionContextState.mapping
) {
const promoteToService = async (
packagePath: string,
Expand All @@ -295,7 +303,7 @@ const PromoteToServiceQueryBuilderAction = observer(

return (
<NewServiceModal
mapping={queryBuilderState.mapping}
mapping={queryBuilderState.executionContextState.mapping}
close={closeNewServiceModal}
showModal={true}
promoteToService={promoteToService}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ export class MappingExecutionQueryBuilderState extends QueryBuilderState {
mapping: Mapping,
) {
super(applicationStore, graphManagerState);

this.executionMapping = mapping;
this.mapping = mapping;
this.executionContextState.mapping = mapping;
}

override get isMappingReadOnly(): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
getValueSpecificationReturnType,
type Type,
resolveServiceQueryRawLambda,
PureExecution,
} from '@finos/legend-graph';
import { ServiceTestableState } from './testable/ServiceTestableState.js';
import { User } from '@finos/legend-server-sdlc';
Expand Down Expand Up @@ -132,10 +133,13 @@ export class ServiceEditorState extends ElementEditorState {
editorStore.sdlcServerClient.features.canCreateVersion,
);
this.testableState = new ServiceTestableState(editorStore, this);
const query = this.executionState.serviceExecutionParameters?.query;
const executionQuery =
this.service.execution instanceof PureExecution
? this.service.execution.func
: undefined;
// default to execution tab if query is defined
this.selectedTab =
query && !isStubbed_RawLambda(query)
executionQuery && !isStubbed_RawLambda(executionQuery)
? SERVICE_TAB.EXECUTION
: SERVICE_TAB.GENERAL;
this.postValidationState = new ServicePostValidationsState(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,16 @@ const DataSpaceQueryBuilderSetupPanelContent = observer(
new RuntimePointer(PackageableElementExplicitReference.create(rt)),
)
.map(buildRuntimeValueOption);
const selectedRuntimeOption = queryBuilderState.runtimeValue
? buildRuntimeValueOption(queryBuilderState.runtimeValue)
const selectedRuntimeOption = queryBuilderState.executionContextState
.runtimeValue
? buildRuntimeValueOption(
queryBuilderState.executionContextState.runtimeValue,
)
: null;
const changeRuntime = (option: { value: Runtime }): void => {
if (option.value === queryBuilderState.runtimeValue) {
if (
option.value === queryBuilderState.executionContextState.runtimeValue
) {
return;
}
queryBuilderState.changeRuntime(option.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class DataSpaceQueryCreatorStore extends QueryEditorStore {
(ec: DataSpaceExecutionContext) => {
// runtime should already be set
const runtimePointer = guaranteeType(
queryBuilderState.runtimeValue,
queryBuilderState.executionContextState.runtimeValue,
RuntimePointer,
);
this.applicationStore.navigationService.navigator.updateCurrentLocation(
Expand Down Expand Up @@ -194,7 +194,7 @@ export class DataSpaceQueryCreatorStore extends QueryEditorStore {
(_class: Class) => {
// runtime should already be set
const runtimePointer = guaranteeType(
queryBuilderState.runtimeValue,
queryBuilderState.executionContextState.runtimeValue,
RuntimePointer,
);
queryBuilderState.applicationStore.navigationService.navigator.updateCurrentLocation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,11 @@ const ServiceRegisterModal = observer(
!servicePattern ||
!isServiceUrlPatternValid ||
!selectedEnvOption ||
!queryBuilderState.mapping ||
!(queryBuilderState.runtimeValue instanceof RuntimePointer)
!queryBuilderState.executionContextState.mapping ||
!(
queryBuilderState.executionContextState.runtimeValue instanceof
RuntimePointer
)
) {
return;
}
Expand All @@ -164,8 +167,9 @@ const ServiceRegisterModal = observer(
servicePattern,
owners.map((o) => o.value),
queryBuilderState.buildQuery(),
queryBuilderState.mapping.path,
queryBuilderState.runtimeValue.packageableRuntime.value.path,
queryBuilderState.executionContextState.mapping.path,
queryBuilderState.executionContextState.runtimeValue
.packageableRuntime.value.path,
editorStore.graphManagerState,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ test(integrationTest('test query execution with parameters'), async () => {
queryBuilderState.graphManagerState.graphManager as V1_PureGraphManager
).createExecutionInput(
queryBuilderState.graphManagerState.graph,
guaranteeNonNullable(queryBuilderState.mapping),
guaranteeNonNullable(queryBuilderState.executionContextState.mapping),
queryBuilderState.resultState.buildExecutionRawLambda(),
guaranteeNonNullable(queryBuilderState.runtimeValue),
guaranteeNonNullable(queryBuilderState.executionContextState.runtimeValue),
V1_PureGraphManager.DEV_PROTOCOL_VERSION,
parameterValues,
);
Expand Down
Loading

0 comments on commit 197febc

Please sign in to comment.