Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix([issue-715]): portal provenance popover out of clipped grid cells
Adam Eivy4d3ebd0c5322
diff --git a/client/src/components/ui/ProvenanceChip.jsx b/client/src/components/ui/ProvenanceChip.jsxindex fe43b225ae..fc81e69857 100644--- a/client/src/components/ui/ProvenanceChip.jsx+++ b/client/src/components/ui/ProvenanceChip.jsx@@ -1,8 +1,26 @@-import { useCallback, useEffect, useId, useRef, useState } from 'react';+import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from 'react';import { BadgeCheck, FlaskConical, HelpCircle, Sigma, Telescope } from 'lucide-react';import { getProvenanceLevel } from '../../lib/healthProvenance.js';import useClickOutside from '../../hooks/useClickOutside';+const POPOVER_WIDTH = 256; // w-64+const VIEWPORT_MARGIN = 8;+const POPOVER_GAP = 6; // ~mt-1.5 below the chip++// Position the fixed popover from the chip's viewport rect, biased to `align`+// (start = popover's left edge under the chip; end = its right edge under the+// chip) and then clamped to the viewport so it never runs off-screen. Fixed+// positioning is what lets the popover escape the `overflow-hidden` dashboard+// grid cell it can live inside — an absolutely-positioned panel would clip+// against the cell on narrow widget widths regardless of which edge it anchored.+function popoverStyleFor(rect, align) {+ const vw = window.innerWidth;+ const width = Math.min(POPOVER_WIDTH, vw - VIEWPORT_MARGIN * 2);+ const rawLeft = align === 'end' ? rect.right - width : rect.left;+ const left = Math.max(VIEWPORT_MARGIN, Math.min(rawLeft, vw - width - VIEWPORT_MARGIN));+ return { position: 'fixed', top: rect.bottom + POPOVER_GAP, left, width };+}+// Source-style provenance chip for health/longevity insights. Tap (or click) to// reveal how the insight was derived plus a "what would change this?" explainer.// Mirrors Ask's SourceChip affordance but for confidence/derivation rather than@@ -41,12 +59,29 @@ export default function ProvenanceChip({}) {const meta = getProvenanceLevel(level);const [open, setOpen] = useState(false);+ const [popStyle, setPopStyle] = useState(null);const wrapRef = useRef(null);+ const btnRef = useRef(null);const popId = useId();const close = useCallback(() => setOpen(false), []);useClickOutside(wrapRef, open, close);+ // Measure the chip and place the fixed popover before paint so it never flashes+ // at the wrong spot; re-measure on scroll/resize while open since fixed coords+ // are viewport-relative and the chip can move under them.+ useLayoutEffect(() => {+ if (!open || !btnRef.current) return undefined;+ const reposition = () => setPopStyle(popoverStyleFor(btnRef.current.getBoundingClientRect(), align));+ reposition();+ window.addEventListener('scroll', reposition, true);+ window.addEventListener('resize', reposition);+ return () => {+ window.removeEventListener('scroll', reposition, true);+ window.removeEventListener('resize', reposition);+ };+ }, [open, align]);+useEffect(() => {if (!open) return undefined;const onKey = (e) => {@@ -65,6 +100,7 @@ export default function ProvenanceChip({return (<div ref={wrapRef} className={`relative inline-flex align-middle ${className}`}><button+ ref={btnRef}type="button"onClick={() => setOpen((v) => !v)}aria-expanded={open}@@ -76,14 +112,14 @@ export default function ProvenanceChip({<span>{label ?? meta.label}</span><HelpCircle size={10} aria-hidden="true" className="shrink-0 opacity-60" /></button>- {open && (+ {open && popStyle && (<divid={popId}- // `align="end"` anchors the popover to the chip's right edge (opens- // leftward) so a chip sitting in a right-aligned header — dashboard- // widget headers, the goal detail panel — doesn't push its 16rem panel- // off the card's right edge (dashboard cells clip with overflow-hidden).- className={`absolute ${align === 'end' ? 'right-0' : 'left-0'} top-full z-30 mt-1.5 w-64 max-w-[calc(100vw-2rem)] rounded-lg border border-port-border bg-port-card p-3 text-left shadow-xl`}+ // Fixed + viewport-clamped (see popoverStyleFor) so the panel escapes+ // any overflow-hidden ancestor — e.g. the dashboard grid cell — and+ // never renders off-screen, on a narrow widget or near the viewport edge.+ style={popStyle}+ className="z-30 rounded-lg border border-port-border bg-port-card p-3 text-left shadow-xl"><p className="mb-1 flex items-center gap-1.5 text-xs font-semibold text-gray-200 normal-case tracking-normal"><Icon size={12} aria-hidden="true" className={`shrink-0 ${iconTone}`} />diff --git a/client/src/components/ui/ProvenanceChip.test.jsx b/client/src/components/ui/ProvenanceChip.test.jsxindex 21639a498e..c5930fb98b 100644--- a/client/src/components/ui/ProvenanceChip.test.jsx+++ b/client/src/components/ui/ProvenanceChip.test.jsx@@ -1,10 +1,14 @@-import { describe, it, expect } from 'vitest';+import { describe, it, expect, vi, afterEach } from 'vitest';import { render, screen, fireEvent } from '@testing-library/react';import ProvenanceChip from './ProvenanceChip';import { PROVENANCE_LEVELS } from '../../lib/healthProvenance.js';describe('ProvenanceChip', () => {+ afterEach(() => {+ vi.restoreAllMocks();+ });+it('renders the level label and the success tone for data-backed', () => {render(<ProvenanceChip level="data-backed" />);const btn = screen.getByRole('button', { name: /data-backed/i });@@ -72,21 +76,50 @@ describe('ProvenanceChip', () => {expect(screen.queryByText('What would change this?')).toBeNull();});- it('anchors the popover left by default and right when align="end"', () => {- // Right-aligned headers (dashboard widgets, the goal detail panel) sit inside- // overflow-hidden cells, so a left-anchored (rightward-opening) popover would- // clip off the card edge. align="end" opens it leftward instead.+ // Position the chip at a known viewport rect so the fixed-popover math is+ // deterministic (jsdom's getBoundingClientRect is all-zero otherwise).+ const stubChipRect = (rect) => {+ vi.spyOn(HTMLButtonElement.prototype, 'getBoundingClientRect').mockReturnValue({+ left: 0, right: 0, top: 0, bottom: 0, width: 0, height: 0, x: 0, y: 0,+ ...rect, toJSON: () => {},+ });+ };++ const openPopover = (props = {}) => {+ render(<ProvenanceChip level="inferred" {...props} />);+ fireEvent.click(screen.getByRole('button'));+ return screen.getByText('What would change this?').closest('div');+ };++ it('renders the popover as a fixed, viewport-escaping layer', () => {+ stubChipRect({ left: 500, right: 560, top: 20, bottom: 40 });+ const popover = openPopover();+ // Fixed (not absolute) is what lets the panel escape an overflow-hidden+ // dashboard cell instead of clipping inside it.+ expect(popover.style.position).toBe('fixed');+ expect(popover.style.top).toBe('46px'); // bottom (40) + 6px gap+ });++ it('biases the popover under the chip\'s left edge for align="start" and right edge for align="end"', () => {+ stubChipRect({ left: 500, right: 560, top: 20, bottom: 40 }); // innerWidth 1024 in jsdomconst { unmount } = render(<ProvenanceChip level="inferred" />);fireEvent.click(screen.getByRole('button'));- let popover = screen.getByText('What would change this?').closest('div');- expect(popover.className).toContain('left-0');- expect(popover.className).not.toContain('right-0');+ // start → popover left edge sits at the chip's left (500).+ expect(screen.getByText('What would change this?').closest('div').style.left).toBe('500px');unmount();render(<ProvenanceChip level="inferred" align="end" />);fireEvent.click(screen.getByRole('button'));- popover = screen.getByText('What would change this?').closest('div');- expect(popover.className).toContain('right-0');- expect(popover.className).not.toContain('left-0');+ // end → popover right edge sits at the chip's right (560): 560 - 256 = 304.+ expect(screen.getByText('What would change this?').closest('div').style.left).toBe('304px');+ });++ it('clamps the popover into the viewport when the chip is near the right edge', () => {+ // A chip in a narrow widget near the right edge would push a 256px panel+ // off-screen; the clamp pulls it back to (innerWidth - width - margin).+ stubChipRect({ left: 1000, right: 1020, top: 20, bottom: 40 }); // innerWidth 1024+ const popover = openPopover();+ // 1024 - 256 - 8 = 760.+ expect(popover.style.left).toBe('760px');});});