Skip to content
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/eighty-crews-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@finos/legend-query": patch
---

Sort query builder explorer nodes by their return types with primitives going first following by enumeration, class and class subtypes.
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,28 @@ const QueryBuilderExplorerTreeNodeView = observer(
},
);

/**
* Sort order for Query Builder tree nodes will be ranked by return type as followed:
* 1. Primitive
* 2. Enumeration
* 3. Class
* 4. Class Subtypes
* Note: Derived property nodes will be ranked lower for each relevant return type
*/
const getQueryBuilderExplorerTreeNodeSortRank = (
node: QueryBuilderExplorerTreeNodeData,
): number => {
if (node instanceof QueryBuilderExplorerTreeSubTypeNodeData) {
return 0;
} else if (node.type instanceof Class) {
return node.isPartOfDerivedPropertyBranch ? 1 : 2;
} else if (node.type instanceof Enumeration) {
return node.isPartOfDerivedPropertyBranch ? 3 : 4;
} else {
return node.isPartOfDerivedPropertyBranch ? 5 : 6;
}
};

const QueryBuilderExplorerTree = observer(
(props: { queryBuilderState: QueryBuilderState }) => {
const { queryBuilderState } = props;
Expand Down Expand Up @@ -719,7 +741,6 @@ const QueryBuilderExplorerTree = observer(
}
explorerState.refreshTree();
};

const getChildNodes = (
node: QueryBuilderExplorerTreeNodeData,
): QueryBuilderExplorerTreeNodeData[] =>
Expand All @@ -738,20 +759,8 @@ const QueryBuilderExplorerTree = observer(
.sort((a, b) => a.label.localeCompare(b.label))
.sort(
(a, b) =>
(b instanceof QueryBuilderExplorerTreeSubTypeNodeData
? 0
: b.type instanceof Class
? 3
: b.type instanceof Enumeration
? 2
: 1) -
(a instanceof QueryBuilderExplorerTreeSubTypeNodeData
? 0
: a.type instanceof Class
? 3
: a.type instanceof Enumeration
? 2
: 1),
getQueryBuilderExplorerTreeNodeSortRank(b) -
getQueryBuilderExplorerTreeNodeSortRank(a),
);

return (
Expand Down