feat(charts): manage investigation charts in a scrolling workspace
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import type { AnswerUiBlock } from "@/features/agent";
|
||||
|
||||
/** Include only reachable Chart nodes, preserving report props and their source. */
|
||||
export function presentationChartBlocks(blocks: AnswerUiBlock[]): AnswerUiBlock[] {
|
||||
return blocks.flatMap((block) => {
|
||||
const charts: AnswerUiBlock[] = [];
|
||||
const visited = new Set<string>();
|
||||
const visit = (id: string) => {
|
||||
if (visited.has(id)) return;
|
||||
visited.add(id);
|
||||
const element = block.spec.elements[id];
|
||||
if (!element) return;
|
||||
if (element.type === "Chart") charts.push({
|
||||
...block,
|
||||
block_id: `${block.block_id}:${id}`,
|
||||
spec: { root: id, elements: { [id]: element } }
|
||||
});
|
||||
else element.children?.forEach(visit);
|
||||
};
|
||||
visit(block.spec.root);
|
||||
return charts;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user