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 16, 2024
1 parent a886047 commit f00d016
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { integrationTest } from '@finos/legend-shared/test';
import TEST_DATA_SimpleCalendarModel from '../../stores/__tests__/TEST_DATA__QueryBuilder_Model_Calendar.json' with { type: 'json' };
import { expect, test } from '@jest/globals';
import {
findByText,
fireEvent,
getByText,
getByTitle,
Expand All @@ -39,6 +38,25 @@ const firstDependencyEntities = {
artifactId: 'artifact-1',
versionId: '1.0.0',
entities: [
{
path: 'test::Address',
content: {
_type: 'class',
name: 'Address',
package: 'test',
properties: [
{
multiplicity: {
lowerBound: 1,
upperBound: 1,
},
name: 'zipCode',
type: 'String',
},
],
},
classifierPath: 'meta::pure::metamodel::type::Class',
},
{
classifierPath:
'meta::pure::metamodel::function::ConcreteFunctionDefinition',
Expand Down Expand Up @@ -75,9 +93,28 @@ const firstDependencyEntities = {
value: '',
},
],
name: 'testFunction2__String_1_',
name: 'testFunction2_String_1__Address_1__String_1_',
package: 'domain::my',
parameters: [],
parameters: [
{
_type: 'var',
class: 'String',
multiplicity: {
lowerBound: 1,
upperBound: 1,
},
name: 'name',
},
{
_type: 'var',
class: 'test::Address',
multiplicity: {
lowerBound: 1,
upperBound: 1,
},
name: 'address',
},
],
postConstraints: [],
preConstraints: [],
returnMultiplicity: {
Expand Down Expand Up @@ -123,9 +160,8 @@ test(
await act(async () => {
queryBuilderState.changeClass(employeeClass);
});
await act(async () => {
queryBuilderState.setShowFunctionsExplorerPanel(true);
});
fireEvent.click(renderResult.getByText('Advanced'));
fireEvent.click(renderResult.getByText('Show Function(s)'));
const queryBuilderFunctionPanel = await waitFor(() =>
renderResult.getByTestId(QUERY_BUILDER_TEST_ID.QUERY_BUILDER_FUNCTIONS),
);
Expand All @@ -144,7 +180,7 @@ test(
expect(
getByText(
queryBuilderFunctionPanel,
'domain::my::testFunction2():String[1]',
'domain::my::testFunction2(name:String[1],address:Address[1]):String[1]',
),
).not.toBeNull();
fireEvent.click(getByTitle(queryBuilderFunctionPanel, 'View as Tree'));
Expand All @@ -160,7 +196,10 @@ test(
).not.toBeNull();
fireEvent.click(getByTitle(queryBuilderFunctionPanel, 'my'));
expect(
getByText(queryBuilderFunctionPanel, 'testFunction2():String[1]'),
getByText(
queryBuilderFunctionPanel,
'testFunction2(name:String[1],address:Address[1]):String[1]',
),
).not.toBeNull();

//drag and drop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
getOrCreateGraphPackage,
} from '@finos/legend-graph';
import {
ActionState,
addUniqueEntry,
guaranteeNonNullable,
isNonNullable,
Expand Down Expand Up @@ -266,12 +267,14 @@ export class QueryFunctionExplorerState {
}

export class QueryFunctionsExplorerState {
readonly initState = ActionState.create();

queryBuilderState: QueryBuilderState;
treeData?: TreeData<QueryBuilderFunctionsExplorerTreeNodeData> | undefined;
dependencyTreeData?:
| TreeData<QueryBuilderFunctionsExplorerTreeNodeData>
| undefined;
graph: PureModel;
_functionGraph: PureModel;
functionExplorerStates: QueryFunctionExplorerState[] = [];
dependencyFunctionExplorerStates: QueryFunctionExplorerState[] = [];
displayablePackagesSet: Set<Package> = new Set<Package>();
Expand All @@ -286,7 +289,7 @@ export class QueryFunctionsExplorerState {
dependencyFunctionExplorerStates: observable.ref,
treeData: observable.ref,
dependencyTreeData: observable.ref,
graph: observable,
_functionGraph: observable,
functionInfoMap: observable,
dependencyFunctionInfoMap: observable,
packagePathToFunctionInfoMap: observable,
Expand All @@ -300,7 +303,8 @@ export class QueryFunctionsExplorerState {
initializeTreeData: action,
});
this.queryBuilderState = queryBuilderState;
this.graph = this.queryBuilderState.graphManagerState.createNewGraph();
this._functionGraph =
this.queryBuilderState.graphManagerState.createNewGraph();
}

getTreeData(
Expand Down Expand Up @@ -330,7 +334,11 @@ export class QueryFunctionsExplorerState {
if (this.functionInfoMap) {
Array.from(this.functionInfoMap.values())
.map((info) =>
getOrCreateGraphPackage(this.graph, info.packagePath, undefined),
getOrCreateGraphPackage(
this._functionGraph,
info.packagePath,
undefined,
),
)
.map((f) => getAllPackagesFromElement(f))
.flat()
Expand All @@ -342,7 +350,11 @@ export class QueryFunctionsExplorerState {
if (this.dependencyFunctionInfoMap) {
Array.from(this.dependencyFunctionInfoMap.values())
.map((info) =>
getOrCreateGraphPackage(this.graph, info.packagePath, undefined),
getOrCreateGraphPackage(
this._functionGraph,
info.packagePath,
undefined,
),
)
.map((f) => getAllPackagesFromElement(f))
.flat()
Expand Down Expand Up @@ -410,7 +422,7 @@ export class QueryFunctionsExplorerState {
const functionInfos =
buildFunctionAnalysisInfoFromConcreteFunctionDefinition(
this.queryBuilderState.graphManagerState.graph.ownFunctions,
this.graph,
this._functionGraph,
);
functionInfos.forEach((info) =>
functionInfoMap.set(info.functionPath, info),
Expand All @@ -425,7 +437,7 @@ export class QueryFunctionsExplorerState {
const dependencyFunctionInfos =
buildFunctionAnalysisInfoFromConcreteFunctionDefinition(
dependencyFunctions,
this.graph,
this._functionGraph,
);
dependencyFunctionInfos.forEach((info) =>
dependencyFunctionInfoMap.set(info.functionPath, info),
Expand Down Expand Up @@ -463,13 +475,18 @@ export class QueryFunctionsExplorerState {
}

initializeTreeData(): void {
if (!this.initState.isInInitialState) {
return;
}

this.initState.inProgress();
this.initializeFunctionInfoMap();
this.initializeDisplayablePackagesSet()
.catch(noop())
.finally(() => {
this.setTreeData(
getFunctionsExplorerTreeData(
[this.graph.root],
[this._functionGraph.root],
this.queryBuilderState,
ROOT_PACKAGE_NAME.MAIN,
),
Expand All @@ -486,7 +503,7 @@ export class QueryFunctionsExplorerState {
.finally(() => {
this.setDependencyTreeData(
getFunctionsExplorerTreeData(
[this.graph.root],
[this._functionGraph.root],
this.queryBuilderState,
ROOT_PACKAGE_NAME.PROJECT_DEPENDENCY_ROOT,
),
Expand All @@ -498,5 +515,6 @@ export class QueryFunctionsExplorerState {
: [];
});
}
this.initState.pass();
}
}

0 comments on commit f00d016

Please sign in to comment.