@@ -3,7 +3,9 @@ import { createRoot, Root } from "react-dom/client";
33import { StrictMode , useState , useEffect , useCallback } from "react" ;
44import type DiscourseGraphPlugin from "../index" ;
55import type { ImportableNode , GroupWithNodes } from "~/types" ;
6+ import { getUserNameById } from "~/utils/typeUtils" ;
67import {
8+ fetchUserNames ,
79 getAvailableGroupIds ,
810 getPublishedNodesForGroups ,
911 getLocalNodeInstanceIds ,
@@ -61,6 +63,8 @@ const ImportNodesContent = ({ plugin, onClose }: ImportNodesModalProps) => {
6163 return ;
6264 }
6365
66+ await fetchUserNames ( plugin , client ) ;
67+
6468 const publishedNodes = await getPublishedNodesForGroups ( {
6569 client,
6670 groupIds,
@@ -82,7 +86,7 @@ const ImportNodesContent = ({ plugin, onClose }: ImportNodesModalProps) => {
8286 getSpaceUris ( client , uniqueSpaceIds ) ,
8387 ] ) ;
8488
85- // Populate plugin settings with current space names so they stay up to date
89+ // Keep spaceNames in settings up to date for UI display (formatImportSource reads it)
8690 if ( uniqueSpaceIds . length > 0 ) {
8791 if ( ! plugin . settings . spaceNames ) plugin . settings . spaceNames = { } ;
8892
@@ -106,21 +110,26 @@ const ImportNodesContent = ({ plugin, onClose }: ImportNodesModalProps) => {
106110 groupName :
107111 spaceNames . get ( node . space_id ) ?? `Space ${ node . space_id } ` ,
108112 nodes : [ ] ,
113+ authorIds : new Set ( ) ,
109114 } ) ;
110115 }
111116
112117 const group = grouped . get ( groupId ) ! ;
118+ const spaceName =
119+ spaceNames . get ( node . space_id ) ?? `Space ${ node . space_id } ` ;
113120 group . nodes . push ( {
114121 nodeInstanceId : node . source_local_id ,
115122 title : node . text ,
116123 spaceId : node . space_id ,
117- spaceName : spaceNames . get ( node . space_id ) ?? `Space ${ node . space_id } ` ,
124+ spaceName,
118125 groupId,
119126 selected : false ,
120127 createdAt : node . createdAt ,
121128 modifiedAt : node . modifiedAt ,
122129 filePath : node . filePath ,
130+ authorId : node . authorId ,
123131 } ) ;
132+ if ( node . authorId ) group . authorIds . add ( node . authorId ) ;
124133 }
125134
126135 setGroupsWithNodes ( Array . from ( grouped . values ( ) ) ) ;
@@ -258,6 +267,7 @@ const ImportNodesContent = ({ plugin, onClose }: ImportNodesModalProps) => {
258267 number ,
259268 {
260269 spaceName : string ;
270+ authorIds : Set < number > ;
261271 nodes : Array < {
262272 node : ImportableNode ;
263273 groupId : string ;
@@ -271,6 +281,7 @@ const ImportNodesContent = ({ plugin, onClose }: ImportNodesModalProps) => {
271281 if ( ! nodesBySpace . has ( node . spaceId ) ) {
272282 nodesBySpace . set ( node . spaceId , {
273283 spaceName : node . spaceName ,
284+ authorIds : group . authorIds ,
274285 nodes : [ ] ,
275286 } ) ;
276287 }
@@ -322,14 +333,19 @@ const ImportNodesContent = ({ plugin, onClose }: ImportNodesModalProps) => {
322333
323334 < div className = "max-h-96 overflow-y-auto rounded border" >
324335 { Array . from ( nodesBySpace . entries ( ) ) . map (
325- ( [ spaceId , { spaceName, nodes } ] ) => {
336+ ( [ spaceId , { spaceName, nodes, authorIds } ] ) => {
326337 return (
327338 < div key = { spaceId } className = "border-b" >
328339 < div className = "bg-muted/10 flex items-center px-3 py-2" >
329340 < span className = "mr-2" > 📂</ span >
330341 < span className = "text-accent-foreground line-clamp-1 font-medium italic" >
331342 { spaceName }
332343 </ span >
344+ { authorIds . size === 1 && (
345+ < span >
346+ ({ getUserNameById ( plugin , [ ...authorIds ] [ 0 ] ! ) } )
347+ </ span >
348+ ) }
333349 < span className = "text-muted ml-2 text-sm" >
334350 ({ nodes . length } node{ nodes . length !== 1 ? "s" : "" } )
335351 </ span >
@@ -349,6 +365,11 @@ const ImportNodesContent = ({ plugin, onClose }: ImportNodesModalProps) => {
349365 < div className = "min-w-0 flex-1" >
350366 < div className = "line-clamp-3 font-medium" >
351367 { node . title }
368+ { node . authorId && authorIds . size > 1 && (
369+ < span className = "font-light" >
370+ ({ getUserNameById ( plugin , node . authorId ) } )
371+ </ span >
372+ ) }
352373 </ div >
353374 </ div >
354375 </ div >
0 commit comments