Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

feat: add project path tooltip to ProjectEntityRow component

zhengkailan459bc6c2972c
diff --git a/jiuwenswarm/channels/web/frontend/src/multi-session/sidebar/ConversationSidebar.css b/jiuwenswarm/channels/web/frontend/src/multi-session/sidebar/ConversationSidebar.css
index e0c434154f..89059c1824 100644
--- a/jiuwenswarm/channels/web/frontend/src/multi-session/sidebar/ConversationSidebar.css
+++ b/jiuwenswarm/channels/web/frontend/src/multi-session/sidebar/ConversationSidebar.css
@@ -1014,3 +1014,59 @@
background: var(--color-feedback-warning-subtle);
color: var(--color-feedback-warning);
}
+
+.project-path-tooltip {
+ z-index: 80;
+ box-sizing: border-box;
+ width: max-content;
+ max-width: 360px;
+ padding: 8px 10px;
+ border-radius: 6px;
+ background: var(--color-surface-popover);
+ border: 1px solid var(--color-border-default);
+ box-shadow: var(--effect-shadow-lg);
+ color: var(--color-text-primary);
+ font-size: 12px;
+ line-height: 16px;
+ pointer-events: none;
+ transition: opacity 0.08s ease-out;
+}
+
+.project-path-tooltip__row {
+ display: flex;
+ align-items: center;
+ gap: 6px;
+ min-width: 0;
+}
+
+.project-path-tooltip__icon {
+ flex: 0 0 auto;
+ width: 14px;
+ height: 14px;
+ color: var(--color-text-tertiary);
+}
+
+.project-path-tooltip__name {
+ overflow-wrap: anywhere;
+ word-break: break-word;
+ font-weight: 600;
+}
+
+.project-path-tooltip__divider {
+ height: 1px;
+ margin: 6px 0;
+ background: var(--color-border-default);
+}
+
+.project-path-tooltip__row--muted {
+ color: var(--color-text-secondary);
+}
+
+.project-path-tooltip__icon--muted {
+ color: var(--color-text-secondary);
+}
+
+.project-path-tooltip__path {
+ overflow-wrap: anywhere;
+ word-break: break-all;
+}
diff --git a/jiuwenswarm/channels/web/frontend/src/multi-session/sidebar/ConversationSidebar.tsx b/jiuwenswarm/channels/web/frontend/src/multi-session/sidebar/ConversationSidebar.tsx
index 0388fa91e8..89b844a680 100644
--- a/jiuwenswarm/channels/web/frontend/src/multi-session/sidebar/ConversationSidebar.tsx
+++ b/jiuwenswarm/channels/web/frontend/src/multi-session/sidebar/ConversationSidebar.tsx
@@ -1,4 +1,5 @@
-import { useEffect, useMemo, useRef, useState } from 'react';
+import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from 'react';
+import { createPortal } from 'react-dom';
import { Check, ChevronDown, CircleAlert, Code2, LoaderCircle, Workflow } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { useChatStore, type ChatRuntime } from '../../stores/chatStore';
@@ -307,6 +308,7 @@ function ConversationListItem({
function ProjectEntityRow({
title,
+ path,
isExpanded,
isPinned,
hideActions = false,
@@ -318,6 +320,7 @@ function ProjectEntityRow({
newLabel,
}: {
title: string;
+ path?: string;
isExpanded: boolean;
isPinned?: boolean;
hideActions?: boolean;
@@ -330,7 +333,13 @@ function ProjectEntityRow({
}) {
const { t } = useTranslation();
const rowRef = useRef<HTMLDivElement>(null);
+ const mainRef = useRef<HTMLButtonElement>(null);
+ const tooltipId = useId();
const [menuOpen, setMenuOpen] = useState(false);
+ const [tooltipPos, setTooltipPos] = useState<{ left: number; top: number } | null>(null);
+ // 分别跟踪 hover 与 focus 状态:任一活跃即保持 tooltip,避免 mouseleave/blur 互相误清
+ const hoverRef = useRef(false);
+ const focusRef = useRef(false);
useEffect(() => {
if (!menuOpen) return;
@@ -348,9 +357,35 @@ function ProjectEntityRow({
};
}, [menuOpen]);
+ const showTooltip = (source: 'hover' | 'focus') => {
+ if (source === 'hover') hoverRef.current = true;
+ else focusRef.current = true;
+ if (!path || !mainRef.current) return;
+ const rect = mainRef.current.getBoundingClientRect();
+ setTooltipPos({ left: rect.left, top: rect.bottom + 6 });
+ };
+
+ const hideTooltip = (source: 'hover' | 'focus') => {
+ if (source === 'hover') hoverRef.current = false;
+ else focusRef.current = false;
+ if (hoverRef.current || focusRef.current) return;
+ setTooltipPos(null);
+ };
+
return (
<div ref={rowRef} className={`conversation-entity-row${menuOpen ? ' is-menu-open' : ''}`}>
- <button type="button" className="conversation-entity-row__main" onClick={onToggle} title={title}>
+ <button
+ type="button"
+ ref={mainRef}
+ className="conversation-entity-row__main"
+ onClick={onToggle}
+ title={path ? undefined : title}
+ aria-describedby={path ? tooltipId : undefined}
+ onMouseEnter={() => showTooltip('hover')}
+ onMouseLeave={() => hideTooltip('hover')}
+ onFocus={() => showTooltip('focus')}
+ onBlur={() => hideTooltip('focus')}
+ >
<span className="conversation-entity-row__icon">
{isExpanded ? <FolderFoldIcon aria-hidden /> : <FolderIcon aria-hidden />}
</span>
@@ -408,6 +443,84 @@ function ProjectEntityRow({
}}
/>
) : null}
+ {tooltipPos && path
+ ? createPortal(
+ <ProjectPathTooltip id={tooltipId} title={title} path={path} anchor={tooltipPos} mainRef={mainRef} />,
+ document.body,
+ )
+ : null}
+ </div>
+ );
+}
+
+function ProjectPathTooltip({
+ id,
+ title,
+ path,
+ anchor,
+ mainRef,
+}: {
+ id: string;
+ title: string;
+ path: string;
+ anchor: { left: number; top: number };
+ mainRef: React.RefObject<HTMLButtonElement | null>;
+}) {
+ const tipRef = useRef<HTMLDivElement>(null);
+ const [placed, setPlaced] = useState<{ left: number; top: number } | null>(null);
+
+ useLayoutEffect(() => {
+ const tip = tipRef.current;
+ const main = mainRef.current;
+ if (!tip || !main) return;
+ const reposition = () => {
+ const tipRect = tip.getBoundingClientRect();
+ const mainRect = main.getBoundingClientRect();
+ const margin = 6;
+ let top = mainRect.bottom + margin;
+ // 下方空间不足则翻转到上方
+ if (top + tipRect.height > window.innerHeight) {
+ top = mainRect.top - tipRect.height - margin;
+ }
+ let left = mainRect.left;
+ // 右侧溢出则向左收
+ if (left + tipRect.width > window.innerWidth - margin) {
+ left = Math.max(margin, window.innerWidth - tipRect.width - margin);
+ }
+ setPlaced({ left, top });
+ };
+ reposition();
+ // 滚动/缩放/列表重排时按钮位置会变,需重算定位
+ window.addEventListener('scroll', reposition, true);
+ window.addEventListener('resize', reposition);
+ return () => {
+ window.removeEventListener('scroll', reposition, true);
+ window.removeEventListener('resize', reposition);
+ };
+ }, [mainRef]);
+
+ return (
+ <div
+ ref={tipRef}
+ id={id}
+ className="project-path-tooltip"
+ role="tooltip"
+ style={{
+ position: 'fixed',
+ left: placed ? placed.left : anchor.left,
+ top: placed ? placed.top : anchor.top,
+ opacity: placed ? 1 : 0,
+ }}
+ >
+ <div className="project-path-tooltip__row">
+ <FolderIcon className="project-path-tooltip__icon" aria-hidden />
+ <span className="project-path-tooltip__name">{title}</span>
+ </div>
+ <div className="project-path-tooltip__divider" />
+ <div className="project-path-tooltip__row project-path-tooltip__row--muted">
+ <FolderIcon className="project-path-tooltip__icon project-path-tooltip__icon--muted" aria-hidden />
+ <span className="project-path-tooltip__path" dir="ltr">{path}</span>
+ </div>
</div>
);
}
@@ -1040,6 +1153,7 @@ export function ConversationSidebar({
<div key={project.project_id} className="conversation-sidebar__group">
<ProjectEntityRow
title={project.name}
+ path={project.project_dir || undefined}
isExpanded={expanded}
isPinned={project.pinned}
hideActions={isDefaultProject(project)}