Implement the following plan: Plan: Canvas-linked Notifications with Submenu Context…
Rate quality
Private research annotation
Sign in to add a private research label or note.
- User
Implement the following plan:
Plan: Canvas-linked Notifications with Submenu
Context
Notifications are currently standalone — they have an optional
conversation_idbut no canvas link. Clicking a notification navigates to the/notificationspage. The goal is to make every notification belong to a Canvas (AiPage), and when clicked, show a submenu that lets the user either open an existing conversation on that canvas or create a new one prefilled with the notification content.Changes
1. Migration: Add
ai_page_idto notificationsFile:
workspace/migrations/YYYYMMDDNNNNNN_add_ai_page_id_to_notifications.rb- Add
ai_page_idinteger column (NOT NULL, FK toai_pages) - Index on
ai_page_id
2. Model: Update
Ai::NotificationFile:
ai/models/notification.rb- Add
belongs_to :ai_page - Update
start_conversation!to create the conversation onself.ai_page(setai_page_idon the new conversation) - Add validation for
ai_page_idpresence
3. Tool: Update
create_notificationFile:
ai/tools/create_notification_tool.rb- Add required
canvas_idargument (theai_page_id) - Pass it through to
Notification.create!
4. View: Notification card with submenu
File:
web/view_helpers.rb—render_notification_card_htmlReplace "Start Chat" button with a "Go to Canvas" button that toggles a submenu dropdown inline. The submenu lists:
- Existing conversations on the notification's canvas (clickable links)
- A "New Chat" option that creates a conversation with the notification content
The submenu is pure HTML/CSS (details/summary or a toggle class) — no JS controller needed. Each option calls JS:
chatFooter.openCanvas(...)for existing convos, or does a POST to create + open.5. Route: Add API endpoint for notification→chat on canvas
File:
web/app.rb- Update
POST /notifications/:id/chatto create the conversation on the notification's canvas, return JSON so the JS can call directly instead of doing a full redirect.
- Add
Assistant
Let me also check a few more files to understand the existing structures.
Assistant
Now let me check the AiPage model and the JS that handles the chat footer.
Assistant
Now I have a clear picture. Let me implement all the changes.
Assistant
Now let me start implementing. I'll do the migration, model, and tool changes first (they're independent).
Assistant
Now the view helper and route changes.
Assistant
Now let me run the migration to verify everything works.
Assistant
Migration ran successfully. Now let me also update the workspace CLAUDE.md to document the new
canvas_idparameter for thecreate_notificationtool.Assistant
I need to find the tool table in workspace/CLAUDE.md to update the
create_notificationtool description.Assistant
All changes are done. Let me do a quick review of the final state of the modified files.
Assistant
I notice the
new_chat_buttonhas identical branches for theif page/elsecase — let me simplify that.Assistant
All changes are implemented. Here's a summary of what was done:
Files Modified
-
workspace/migrations/20260218000003_add_ai_page_id_to_notifications.rb(new) — Addsai_page_idcolumn with index to notifications table. -
ai/models/notification.rb— Addedbelongs_to :ai_page(optional), updatedstart_conversation!to create conversations on the notification's canvas, and addedensure_ai_page!fallback for notifications without a canvas. -
ai/tools/create_notification_tool.rb— Added requiredcanvas_idargument that maps toai_page_id. -
web/view_helpers.rb— Replaced the "Start Chat" button with a<details>submenu showing the canvas name. The submenu lists existing conversations (clicking opens the canvas in the chat footer + marks read) and a "+ New Chat" button (POSTs to create a conversation, then opens it).
-
- User
when i click in the notification bell does not open anything it seems to subscribe mutiple times to notifications, TypeError: Cannot read properties of undefined (reading 'renderMethod') at FrameView.render (turbo.es2017-esm.js:1490:79) at async #loadFrameResponse (turbo.es2017-esm.js:6001:7) at async FrameController.loadResponse (turbo.es2017-esm.js:5824:11) at async FrameController.requestSucceededWithResponse (turbo.es2017-esm.js:5898:5)
Assistant
Let me look at the layout to understand how the notification bell link works and the notifications view.
Assistant
Two issues here:
- The notification bell has a
<button type="button">nested inside an<a>tag — Turbo can't properly follow the link click - Every time the notifications page loads into the frame, a new
data-controller="notifications"creates another SSE subscription
- The notification bell has a
Assistant
Now fix the multiple SSE subscription issue. The notifications controller opens a new EventSource every time the page loads into the turbo-frame. It should use a singleton approach — only one SSE connection for notifications, managed at the document level rather than per-frame-load.
Assistant
The two fixes:
-
Bell link — Removed the nested
<button type="button">from inside the<a>tag. Turbo intercepts<a>clicks but the nested button was swallowing them, causing therenderMethoderror because the frame navigation never completed properly. Now the<a>itself is styled as the icon button. -
Multiple SSE subscriptions — The notifications Stimulus controller now uses a singleton
EventSourcewith reference counting. Multiple controller instances (from repeated turbo-frame loads) share one SSE connection, and it only closes when the last instance disconnects.
-
- User
now when i click in the bell it makes a request to notifications that is returning html but the dropdown does not appear
Assistant
The request works but the content is hidden behind canvas overlays. When a canvas is open in the chat footer, its overlay (
position: absolute; inset: 0) covers the turbo-frame content. Let me check the structure.Assistant
The problem is that the
#conversation-canvasesdiv with active canvas overlays (position: absolute; inset: 0) sits on top of the<turbo-frame id="canvas-content">. When you click the bell, the notifications HTML loads into the frame but is hidden behind the canvas overlay.The fix: when navigating to a frame page (notifications, jobs, settings), deactivate canvas overlays so the frame content is visible.
Assistant
Now when the
canvas-contentturbo-frame loads new content (like the notifications page), all active canvas overlays are hidden, making the frame content visible.- User
remove the notifications page. the bell should only show a dropdown with the latest 5 notifications with a button below to loadmore (paginate? use pagy gem if paginates)
Assistant
Now let me read the current notification card helper and the CSS to understand what I'm working with.
Assistant
Now I have the full picture. No pagy needed — simple offset-based "load more" with a small API endpoint is cleaner for a dropdown. Let me implement everything.
Assistant
Wait, that's ugly. Let me just remove it cleanly.
Assistant
Now replace the bell link with a button that toggles a dropdown, and add the dropdown panel to the layout.
Assistant
Now rewrite the notifications Stimulus controller to manage the dropdown.
Assistant
Now add the API endpoint that returns notification card HTML.
Assistant
Now add the
/api/notificationsendpoint.Assistant
Now add the dropdown CSS.
Assistant
Now remove the turbo:frame-load listener from the layout since it was only for the old notification page navigation, and delete the notifications.erb view.
Assistant
Now delete the notifications.erb view and also update the notification broadcast to work with the dropdown (prepend to the list).
Assistant
Now let me also make the mark-read route return JSON instead of redirecting to
/notifications(which no longer exists).Let me verify that change went through properly in the routes.
Assistant
Good — mark-read now returns JSON. Let me also check the API notifications endpoint got added properly.
Assistant
Good. Now let me also update the notification card helper — in the dropdown context the cards should be more compact and the canvas submenu should close the dropdown when an action is taken.
Assistant
Let me verify the final state of the layout.
Assistant
Everything looks good. Here's a summary of all the changes:
Removed:
web/views/notifications.erb— deleted the full page- Notifications link from sidebar nav
/notificationsGET list route fromweb/app.rb
Changed:
- Bell icon (
layout.erb) — now a<button>withdata-action="click->notifications#toggle"that opens a dropdown panel inline. The dropdown has a header, scrollable list, and "Load more" footer. - Notifications controller (
notifications_controller.js) — completely rewritten. Manages dropdown open/close, fetches cards from/api/notifications?offset=&limit=, handles "load more" pagination, SSE for real-time updates, and outside-click-to-close. /api/notificationsroute added (web/app.rb) — returns{ html, count, has_more }JSON. Fetcheslimit + 1records to detect if there are more, uses offset-based pagination.
- User
commit
Assistant
Committed as
ca8f519. Working tree is clean.