Skip to content

Commit 40d2e86

Browse files
authored
fix: the problem of click module then jump to the wrong chunk's same module (#1446)
1 parent a0aa79f commit 40d2e86

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

packages/components/src/components/Charts/TreeMap.tsx

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,15 @@ const TreeMapInner: React.FC<
166166
parentColor?: string,
167167
siblingIndex = 0,
168168
siblingCount = 1,
169+
chunkPath?: string,
169170
): TreemapDataNode {
170171
const baseColor =
171172
parentColor || TREE_COLORS[index % TREE_COLORS.length];
172173

174+
// For level 0 (chunk level), use the chunk's path/name as chunkPath
175+
const currentChunkPath =
176+
level === 0 ? node.path || node.name || '' : chunkPath || '';
177+
173178
const children = node.children?.map((c, childIndex) =>
174179
convert(
175180
c,
@@ -178,6 +183,7 @@ const TreeMapInner: React.FC<
178183
baseColor,
179184
childIndex,
180185
node.children?.length || 0,
186+
currentChunkPath,
181187
),
182188
);
183189

@@ -189,9 +195,12 @@ const TreeMapInner: React.FC<
189195

190196
if (!val && node.value) val = node.value;
191197

192-
const nodeId = node.path
193-
? hashString(node.path)
194-
: hashString(node.name || '');
198+
// Include chunk path in nodeId for non-root nodes to ensure uniqueness across chunks
199+
const nodeIdString =
200+
level === 0
201+
? node.path || node.name || ''
202+
: `${currentChunkPath}::${node.path || node.name || ''}`;
203+
const nodeId = hashString(nodeIdString);
195204
const isHighlighted = highlightNodeId === nodeId;
196205

197206
const baseColorRatio =
@@ -286,7 +295,7 @@ const TreeMapInner: React.FC<
286295

287296
const data = treeData
288297
.map((item, index) =>
289-
convert(item, index, 0, undefined, index, treeData.length),
298+
convert(item, index, 0, undefined, index, treeData.length, undefined),
290299
)
291300
.filter(
292301
(item) =>
@@ -759,17 +768,26 @@ const AssetTreemapWithFilterInner: React.FC<{
759768
const regex = new RegExp(searchQuery, 'i');
760769
const results: Array<{ path: string; nodeId: number }> = [];
761770

762-
const collectMatchingPaths = (node: TreeNode) => {
771+
const collectMatchingPaths = (node: TreeNode, chunkPath?: string) => {
772+
// For chunk level (root of filteredTreeData), use its path/name as chunkPath
773+
const currentChunkPath = chunkPath || node.path || node.name || '';
774+
763775
if (node.path && regex.test(node.path)) {
764-
const nodeId = hashString(node.path);
776+
// Use the same nodeId calculation as in convert function
777+
const nodeIdString = chunkPath
778+
? `${chunkPath}::${node.path}`
779+
: node.path;
780+
const nodeId = hashString(nodeIdString);
765781
results.push({ path: node.path, nodeId });
766782
}
767783
if (node.children) {
768-
node.children.forEach(collectMatchingPaths);
784+
node.children.forEach((child) =>
785+
collectMatchingPaths(child, currentChunkPath),
786+
);
769787
}
770788
};
771789

772-
filteredTreeData.forEach(collectMatchingPaths);
790+
filteredTreeData.forEach((chunk) => collectMatchingPaths(chunk));
773791
return results;
774792
}, [filteredTreeData, searchQuery]);
775793

0 commit comments

Comments
 (0)