Feat: Search for timeline nodes. (#17996)

This commit is contained in:
balibabu
2026-08-07 17:06:19 +08:00
committed by GitHub
parent 2eb1ef6c67
commit ec09d4e3bd
6 changed files with 38 additions and 60 deletions

View File

@@ -153,37 +153,6 @@ export function adaptTreeToTreeData(
return buildTreeDataItems(template.entities, template.relations, ['child']);
}
function filterTreeDataItems(
items: TreeDataItem[],
keyword: string,
): TreeDataItem[] {
const lowerKeyword = keyword.toLowerCase();
return items.reduce<TreeDataItem[]>((acc, item) => {
const children = item.children
? filterTreeDataItems(item.children, keyword)
: [];
const matches = item.name.toLowerCase().includes(lowerKeyword);
if (matches || children.length > 0) {
acc.push({
...item,
children: children.length > 0 ? children : item.children,
});
}
return acc;
}, []);
}
export function filterTreeDataByKeyword(
data: TreeDataItem[],
keyword: string,
): TreeDataItem[] {
if (!keyword.trim()) return data;
return filterTreeDataItems(data, keyword);
}
export function adaptKnowledgeGraphToForceGraph(
template: IStructureGraphTemplate,
): IArtifactGraph {

View File

@@ -16,7 +16,6 @@ import {
adaptPageIndexToTreeData,
adaptTimelineToX6Data,
adaptTreeToTreeData,
filterTreeDataByKeyword,
} from './adapters';
import MindMapG6Graph from './mindmap-g6-graph';
import TimelineX6Graph from './timeline-x6-graph';
@@ -31,7 +30,6 @@ const EmptyForceGraphData: IArtifactGraph = { entities: [], relations: [] };
interface RepresentationRendererProps {
template?: IStructureGraphTemplate;
searchKeyword?: string;
onNodeClick?: (node: ClickableNode) => void;
highlightNodeId?: string | null;
}
@@ -51,7 +49,6 @@ function UnsupportedPlaceholder({ kind }: { kind: StructureTemplateKind }) {
export function RepresentationRenderer({
template,
searchKeyword = '',
onNodeClick,
highlightNodeId,
}: RepresentationRendererProps) {
@@ -104,22 +101,16 @@ export function RepresentationRenderer({
[],
);
const filteredTreeData = useMemo<TreeDataItem[]>(() => {
const treeData = useMemo<TreeDataItem[]>(() => {
if (!template) return [];
if (template.kind === CompilationTemplateKind.PageIndex) {
const data = adaptPageIndexToTreeData(template);
return searchKeyword.trim()
? filterTreeDataByKeyword(data, searchKeyword)
: data;
return adaptPageIndexToTreeData(template);
}
if (template.kind === CompilationTemplateKind.Tree) {
const data = adaptTreeToTreeData(template);
return searchKeyword.trim()
? filterTreeDataByKeyword(data, searchKeyword)
: data;
return adaptTreeToTreeData(template);
}
return [];
}, [template, searchKeyword]);
}, [template]);
// Keep a stable reference across re-renders so the memoized ArtifactForceGraph
// does not restart its force simulation when only highlightNodeId changes
@@ -140,7 +131,7 @@ export function RepresentationRenderer({
return (
<div className="mt-6 overflow-auto scrollbar-auto">
<TreeView
data={filteredTreeData}
data={treeData}
expandAll
onSelectChange={handleTreeItemClick}
/>
@@ -150,7 +141,7 @@ export function RepresentationRenderer({
return (
<div className="mt-6 overflow-auto scrollbar-auto">
<TreeView
data={filteredTreeData}
data={treeData}
expandAll
onSelectChange={handleTreeItemClick}
/>