Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
YannanGao-gs committed Oct 18, 2024
1 parent 04837d5 commit 50d50d6
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class LegendQueryApplicationCoreOptions {
TEMPORARY__serviceRegistrationConfig: ServiceRegistrationEnvironmentConfig[] =
[];

TEMPORARY__enableMinimalGraph = true;
TEMPORARY__enableMinimalGraph = false;

/**
* Config specific to query builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

import {
type QueryGraphBuilderGetter,
type QuerySetupActionConfiguration,
LegendQueryApplicationPlugin,
QuerySetupActionTag,
Expand Down Expand Up @@ -73,7 +72,6 @@ import {
QUERY_BUILDER_SUPPORTED_GET_ALL_FUNCTIONS,
} from '@finos/legend-query-builder';
import {
type QueryEditorStore,
ExistingQueryEditorStore,
QueryBuilderActionConfig_QueryApplication,
} from '../stores/QueryEditorStore.js';
Expand All @@ -85,11 +83,8 @@ import {
import {
createGraphBuilderReport,
GRAPH_MANAGER_EVENT,
isValidFullPath,
LegendSDLC,
PackageableElementPointerType,
QUERY_PROFILE_PATH,
QueryDataSpaceExecutionContext,
resolvePackagePathAndElementName,
RuntimePointer,
V1_EngineRuntime,
Expand All @@ -101,7 +96,6 @@ import {
import { LegendQueryTelemetryHelper } from '../__lib__/LegendQueryTelemetryHelper.js';
import { resolveVersion, StoreProjectData } from '@finos/legend-server-depot';
import {
type GeneratorFn,
ActionState,
assertErrorThrown,
buildUrl,
Expand All @@ -119,7 +113,6 @@ import { createViewSDLCProjectHandler } from '../stores/data-space/DataSpaceQuer
import { DataSpaceQueryCreatorStore } from '../stores/data-space/DataSpaceQueryCreatorStore.js';
import { configureCodeEditorComponent } from '@finos/legend-lego/code-editor';
import {
QUERY_PROFILE_TAG_DATA_SPACE,
resolveUsableDataSpaceClasses,
V1_DataSpace,
V1_DataSpaceExecutionContext,
Expand Down Expand Up @@ -765,34 +758,6 @@ export class Core_LegendQueryApplicationPlugin extends LegendQueryApplicationPlu
};
}

override getExtraQueryGraphBuilderGetters(): QueryGraphBuilderGetter[] {
return [
(
editorStore: QueryEditorStore,
): ((editorStore: QueryEditorStore) => GeneratorFn<void>) | undefined => {
function* buildGraph(): GeneratorFn<void> {
// do nothing
}
if (editorStore instanceof ExistingQueryEditorStore) {
const query = editorStore.query;
const dataSpaceTaggedValue = query?.taggedValues?.find(
(taggedValue) =>
taggedValue.profile === QUERY_PROFILE_PATH &&
taggedValue.tag === QUERY_PROFILE_TAG_DATA_SPACE &&
isValidFullPath(taggedValue.value),
);
if (
dataSpaceTaggedValue ||
query?.executionContext instanceof QueryDataSpaceExecutionContext
) {
return buildGraph;
}
}
return undefined;
},
];
}

getExtraQueryBuilderPropagateExecutionContextChangeHelper?(): QueryBuilderPropagateExecutionContextChangeHelper[] {
return [
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,13 +472,13 @@ const QueryEditorExistingQueryInfoModal = observer(
<div className="query-preview__field">
<div className="query-preview__field__label">Mapping</div>
<div className="query-preview__field__value">
{executionContext.mapping}
{executionContext.mapping.value.name}
</div>
</div>
<div className="query-preview__field">
<div className="query-preview__field__label">Runtime</div>
<div className="query-preview__field__value">
{executionContext.runtime}
{executionContext.runtime.value.name}
</div>
</div>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
RawLambda,
QueryExplicitExecutionContext,
QueryDataSpaceExecutionContext,
PackageableElementExplicitReference,
} from '@finos/legend-graph';
import { DepotServerClient } from '@finos/legend-server-depot';
import {
Expand Down Expand Up @@ -154,11 +155,11 @@ export const TEST__setUpQueryEditor = async (
query.owner = lightQuery.owner;
query.isCurrentUserQuery = lightQuery.isCurrentUserQuery;
const _mapping = graphManagerState.graph.getMapping(mappingPath);
query.mapping = mappingPath;
query.runtime = runtimePath;
const execContext = new QueryExplicitExecutionContext();
execContext.mapping = mappingPath;
execContext.runtime = runtimePath;
execContext.mapping = PackageableElementExplicitReference.create(_mapping);
execContext.runtime = PackageableElementExplicitReference.create(
graphManagerState.graph.getRuntime(runtimePath),
);
query.executionContext = execContext;
query.content = 'some content';
createSpy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import type {
QueryBuilder_LegendApplicationPlugin_Extension,
QueryBuilderState,
} from '@finos/legend-query-builder';
import type { GeneratorFn } from '@finos/legend-shared';
import type React from 'react';
import type { LegendQueryPluginManager } from '../application/LegendQueryPluginManager.js';
import type {
Expand Down Expand Up @@ -65,10 +64,6 @@ export type NewQueryNavigationPath = (
editorStore: ExistingQueryEditorStore,
) => string | undefined;

export type QueryGraphBuilderGetter = (
editorStore: QueryEditorStore,
) => ((editorStore: QueryEditorStore) => GeneratorFn<void>) | undefined;

export type QueryEditorActionConfiguration = {
key: string;
renderer: (
Expand Down Expand Up @@ -103,9 +98,4 @@ export class LegendQueryApplicationPlugin
* Get the list of actions (configurations) for query setup.
*/
getExtraQuerySetupActionConfigurations?(): QuerySetupActionConfiguration[];

/**
* Get the list of query graph builders
*/
getExtraQueryGraphBuilderGetters?(): QueryGraphBuilderGetter[];
}
79 changes: 39 additions & 40 deletions packages/legend-application-query/src/stores/QueryEditorStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
type ValueSpecification,
type GraphInitializationReport,
type PackageableRuntime,
type QueryInfo,
GraphManagerState,
Query,
PureExecution,
Expand All @@ -72,6 +73,8 @@ import {
VariableExpression,
PrimitiveType,
CORE_PURE_PATH,
isValidFullPath,
QUERY_PROFILE_PATH,
} from '@finos/legend-graph';
import {
generateExistingQueryEditorRoute,
Expand Down Expand Up @@ -126,6 +129,7 @@ import {
type DataSpaceExecutionContext,
DSL_DataSpace_getGraphManagerExtension,
getOwnDataSpace,
QUERY_PROFILE_TAG_DATA_SPACE,
retrieveAnalyticsResultCache,
} from '@finos/legend-extension-dsl-data-space/graph';
import { generateDataSpaceQueryCreatorRoute } from '../__lib__/DSL_DataSpace_LegendQueryNavigation.js';
Expand Down Expand Up @@ -436,13 +440,6 @@ export abstract class QueryEditorStore {
this.queryBuilderState.executionContextState.mapping,
'Query required mapping to update',
);
const runtimeValue = guaranteeType(
this.queryBuilderState.executionContextState.runtimeValue,
RuntimePointer,
'Query runtime must be of type runtime pointer',
);
query.mapping = this.queryBuilderState.executionContextState.mapping.path;
query.runtime = runtimeValue.packageableRuntime.value.path;
query.executionContext =
this.queryBuilderState.getQueryExecutionContext();
query.content =
Expand Down Expand Up @@ -685,16 +682,6 @@ export abstract class QueryEditorStore {
}

*buildGraph(): GeneratorFn<void> {
const queryGraphBuilderGetters = this.applicationStore.pluginManager
.getApplicationPlugins()
.flatMap((plugin) => plugin.getExtraQueryGraphBuilderGetters?.() ?? []);
for (const getter of queryGraphBuilderGetters) {
const builderFunction = getter(this);
if (builderFunction) {
yield flowResult(builderFunction(this));
return;
}
}
yield flowResult(this.buildFullGraph());
}
}
Expand Down Expand Up @@ -1217,6 +1204,7 @@ export class ExistingQueryEditorStore extends QueryEditorStore {
private queryId: string;
private _lightQuery?: LightQuery | undefined;
query: Query | undefined;
queryInfo: QueryInfo | undefined;
urlQueryParamValues: Record<string, string> | undefined;
updateState: ExistingQueryUpdateState;

Expand All @@ -1230,11 +1218,13 @@ export class ExistingQueryEditorStore extends QueryEditorStore {

makeObservable<ExistingQueryEditorStore, '_lightQuery'>(this, {
query: observable,
queryInfo: observable,
updateState: observable,
_lightQuery: observable,
lightQuery: computed,
setLightQuery: action,
setQuery: action,
setQueryInfo: action,
isPerformingBlockingAction: override,
});

Expand Down Expand Up @@ -1281,6 +1271,10 @@ export class ExistingQueryEditorStore extends QueryEditorStore {
this.query = val;
}

setQueryInfo(val: QueryInfo): void {
this.queryInfo = val;
}

getProjectInfo(): ProjectGAVCoordinates {
return {
groupId: this.lightQuery.groupId,
Expand All @@ -1289,16 +1283,35 @@ export class ExistingQueryEditorStore extends QueryEditorStore {
};
}

override *buildGraph(): GeneratorFn<void> {
const query = this.query;
const dataSpaceTaggedValue = query?.taggedValues?.find(
(taggedValue) =>
taggedValue.profile === QUERY_PROFILE_PATH &&
taggedValue.tag === QUERY_PROFILE_TAG_DATA_SPACE &&
isValidFullPath(taggedValue.value),
);
if (
!(
dataSpaceTaggedValue ||
query?.executionContext instanceof QueryDataSpaceExecutionContext
)
) {
yield flowResult(this.buildFullGraph());
}
}

override async setUpEditorState(): Promise<void> {
const query = await this.graphManagerState.graphManager.getQuery(
const queryInfo = await this.graphManagerState.graphManager.getQueryInfo(
this.queryId,
this.graphManagerState.graph,
);
this.setQuery(query);
this.setLightQuery(toLightQuery(query));
this.setLightQuery(
await this.graphManagerState.graphManager.getLightQuery(this.queryId),
);
this.setQueryInfo(queryInfo);
LegendQueryUserDataHelper.addRecentlyViewedQuery(
this.applicationStore.userDataService,
query.id,
queryInfo.id,
);
}

Expand Down Expand Up @@ -1423,17 +1436,11 @@ export class ExistingQueryEditorStore extends QueryEditorStore {
exec.dataSpacePath,
this.graphManagerState.graph,
);
const mapping = query.mapping
? this.graphManagerState.graph.getMapping(query.mapping)
: undefined;
const runtime = query.runtime
? this.graphManagerState.graph.getRuntime(query.runtime)
: undefined;
const matchingExecutionContext = resolveExecutionContext(
dataSpace,
exec.executionKey,
mapping,
runtime,
query.mapping?.value,
query.runtime?.value,
);
if (matchingExecutionContext) {
const sourceInfo = {
Expand Down Expand Up @@ -1574,18 +1581,10 @@ export class ExistingQueryEditorStore extends QueryEditorStore {
new QueryBuilderActionConfig_QueryApplication(this),
);
classQueryBuilderState.executionContextState.setMapping(
exec.mapping
? this.graphManagerState.graph.getMapping(exec.mapping)
: undefined,
exec.mapping.value,
);
classQueryBuilderState.executionContextState.setRuntimeValue(
exec.runtime
? new RuntimePointer(
PackageableElementExplicitReference.create(
this.graphManagerState.graph.getRuntime(exec.runtime),
),
)
: undefined,
exec.runtime.value,
);
return classQueryBuilderState;
}
Expand Down
16 changes: 9 additions & 7 deletions packages/legend-graph/src/graph-manager/action/query/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
* limitations under the License.
*/

import type { Mapping } from '../../../graph/metamodel/pure/packageableElements/mapping/Mapping.js';
import type { PackageableElementReference } from '../../../graph/metamodel/pure/packageableElements/PackageableElementReference.js';
import type { PackageableRuntime } from '../../../graph/metamodel/pure/packageableElements/runtime/PackageableRuntime.js';

export class QueryTaggedValue {
profile!: string;
tag!: string;
Expand All @@ -33,9 +37,8 @@ export class QueryParameterValue {
export abstract class QueryExecutionContext {}

export class QueryExplicitExecutionContext extends QueryExecutionContext {
// NOTE: Query can be built before the actual graph is built so we can't have the reference of metamodels here
mapping!: string;
runtime!: string;
mapping!: PackageableElementReference<Mapping>;
runtime!: PackageableElementReference<PackageableRuntime>;
}

export class QueryDataSpaceExecutionContext extends QueryExecutionContext {
Expand Down Expand Up @@ -72,17 +75,16 @@ export class Query {
content!: string;
executionContext!: QueryExecutionContext;

// NOTE: Query can be built before the actual graph is built so we can't have the reference of metamodels here
/**
* mapping, runtime have been deprecated in favor of `V1_QueryExecutionContext`
* @deprecated
*/
mapping?: string | undefined;
mapping?: PackageableElementReference<Mapping> | undefined;
/**
* mapping, runtime have been deprecated in favor of `V1_QueryExecutionContext`
* @deprecated
*/
runtime?: string | undefined;
runtime?: PackageableElementReference<PackageableRuntime> | undefined;

lastUpdatedAt?: number | undefined;
createdAt?: number | undefined;
Expand Down Expand Up @@ -154,7 +156,7 @@ export interface QueryInfo {
name: string;
id: string;
versionId: string;
origignalVersionId?: string | undefined;
originalVersionId?: string | undefined;
groupId: string;
artifactId: string;
executionContext: QueryExecutionContextInfo;
Expand Down
Loading

0 comments on commit 50d50d6

Please sign in to comment.