feat: allow chip click to open doc or history tab#1475
feat: allow chip click to open doc or history tab#1475zhouyu123666 merged 2 commits intochaterm:mainfrom
Conversation
📝 WalkthroughWalkthroughThis PR implements drag-and-drop functionality for document and chat chips within the AI Tab editor. Users can drag docs, chats, and hosts into the input area, with payloads parsed and converted to chips. Chip clicks trigger navigation via handlers that manage document opening and history tab restoration. Path normalization and event-based signaling coordinate interactions between composables and components. Changes
Sequence DiagramsequenceDiagram
actor User
participant TerminalTab as Terminal/KB Tab
participant EditableArea as InputSendContainer<br/>(Editable Area)
participant EditableComposable as useEditableContent
participant ContextComposable as useContext
participant TabMgmt as useTabManagement
participant EventBus as EventBus
User->>TerminalTab: Drag tab (doc or host)
TerminalTab->>EditableArea: dataTransfer with<br/>context payload
User->>EditableArea: Drop on input area
EditableArea->>EditableArea: handleEditableDrop()
EditableArea->>EditableComposable: parseContextDragPayload()
EditableComposable-->>EditableArea: ContextDragPayload<br/>(doc/chat/host)
EditableArea->>EditableArea: Insert chip element
User->>EditableArea: Click on doc/chat chip
EditableArea->>EditableComposable: handleChipClick()
EditableComposable-->>EditableArea: callback invoked
alt Doc Chip
EditableArea->>ContextComposable: openDocFromChip(docRef)
ContextComposable->>ContextComposable: Resolve KB root & relPath
ContextComposable->>EventBus: emit openUserTab
EventBus->>TerminalTab: Navigate to KB Editor
else Chat Chip
EditableArea->>TabMgmt: openHistoryTab(history)
TabMgmt->>TabMgmt: Check forceNewTab flag
TabMgmt-->>EditableArea: New tab created/restored
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Fix all issues with AI agents
In `@src/renderer/src/views/components/AiTab/composables/useContext.ts`:
- Around line 866-880: The openDocFromChip function emits the event
'openUserTab' but the app listens for 'open-user-tab', causing clicks to no-op;
update openDocFromChip to emit 'open-user-tab' (preserving payload shape) so it
matches the listener (or alternatively change the listener to 'openUserTab') and
also update the test expectation in useContext.test.ts to the chosen event name;
ensure references to the event key in eventBus.emit inside openDocFromChip and
any related tests are consistent.
In `@src/renderer/src/views/components/AiTab/index.vue`:
- Around line 12-18: handleTabDragStart is serializing a drag payload using
tab.title which can be undefined and later fails parseContextDragPayload
expecting a string title; update handleTabDragStart (and any other drag-start
handlers for tabs) to ensure the payload always includes a string title by
providing a fallback (e.g., tab.title || '' or tab.title || 'Untitled') before
serializing so parseContextDragPayload will accept it on drop.
In `@src/renderer/src/views/layouts/TerminalLayout.vue`:
- Around line 2230-2238: In TerminalLayout.vue update the dragPayload
construction so the connect property uses an explicit connection type instead of
falling back to params.ip: use data.connect or data.connectionType (or a safe
default like 'ssh' or null) and remove the params.ip fallback; modify the
dragPayload creation near the host context block (the object with keys
contextType, uuid, label, connect, assetType, isLocalHost) to read connect:
data.connect || data.connectionType || 'ssh' (or null) so chips always receive a
connection-type string rather than an IP.
- Around line 2215-2217: The code uses a loose Record<string, any> for panel
params which defeats TS safety; define a DockviewPanelParams interface (or type)
listing the expected fields: content, title, ip, organizationId, id, props, and
data, then replace the cast in TerminalLayout.vue so const params = panel.params
as DockviewPanelParams | undefined; update any usages in this file to rely on
those typed fields (e.g., content, title, ip, organizationId, id, props, data)
to restore type checking and avoid any implicit any.
♻️ Duplicate comments (1)
src/renderer/src/views/components/AiTab/composables/__tests__/useContext.test.ts (1)
268-287: Expectation should track the final event name.
Keep this assertion aligned with the emitter name finalized inuseContext.ts.
🧹 Nitpick comments (1)
src/renderer/src/views/components/AiTab/components/InputSendContainer.vue (1)
343-347: Remove the commented-out dragover handler or wire it upCommented blocks tend to rot; either connect it via
@dragoveror delete it.Proposed cleanup
-// const handleEditableDragOver = (e: DragEvent) => { -// const dragPayload = parseContextDragPayload(e.dataTransfer) -// if (!dragPayload) return -// e.preventDefault() -// }
|
❤️ Great PR @dsd2077 ❤️ Thank you for your contribution to Chaterm! The growth of this project is inseparable from community feedback and contributions like yours. We appreciate your time and effort in making Chaterm better! 🎉 |
Summary by CodeRabbit
Release Notes
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.