Skip to content

Commit 69ade8b

Browse files
committed
present shared topics
1 parent ca1f165 commit 69ade8b

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

src/views/SelectedNodePanel.tsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,58 @@ const SelectedNodePanel: FC<{ node: string; data: NodeData }> = ({ node, data: {
131131
</ul>
132132
</>
133133
)}
134+
135+
<hr />
136+
137+
{/* Shared Topics with Neighbors Section */}
138+
{(() => {
139+
const currentTopics = currentAttributes.attributes?.topics;
140+
if (!currentTopics || typeof currentTopics !== 'string') return null;
141+
142+
const currentTopicsArray = currentTopics.split('|').map(t => t.trim()).filter(Boolean);
143+
if (currentTopicsArray.length === 0) return null;
144+
145+
const allNeighbors = [...visibleNeighbors, ...hiddenNeighbors];
146+
if (allNeighbors.length === 0) return null;
147+
148+
const neighborsWithSharedTopics = allNeighbors.map(neighbor => {
149+
const neighborTopics = graph.getNodeAttributes(neighbor).attributes?.topics;
150+
if (!neighborTopics || typeof neighborTopics !== 'string') return null;
151+
152+
const neighborTopicsArray = neighborTopics.split('|').map(t => t.trim()).filter(Boolean);
153+
const sharedTopics = currentTopicsArray.filter(topic => neighborTopicsArray.includes(topic));
154+
155+
return {
156+
neighbor,
157+
sharedTopics
158+
};
159+
}).filter((item): item is { neighbor: string; sharedTopics: string[] } => item !== null);
160+
161+
if (neighborsWithSharedTopics.length === 0) return null;
162+
163+
// Collect all unique shared topics across all neighbors
164+
const allSharedTopics = new Set<string>();
165+
neighborsWithSharedTopics.forEach(({ sharedTopics }) => {
166+
sharedTopics.forEach(topic => allSharedTopics.add(topic));
167+
});
168+
169+
const uniqueSharedTopics = Array.from(allSharedTopics).sort();
170+
171+
return (
172+
<>
173+
<div className="text-muted mb-2 mt-4">
174+
<strong>Shared Topics with Neighbors:</strong>
175+
</div>
176+
<div className="mb-3">
177+
{uniqueSharedTopics.length > 0 ? (
178+
<span>{uniqueSharedTopics.join(', ')}</span>
179+
) : (
180+
<span className="text-muted">No shared topics</span>
181+
)}
182+
</div>
183+
</>
184+
);
185+
})()}
134186
</div>
135187
);
136188
};

0 commit comments

Comments
 (0)