Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(dynamic-ui): delete the stat and card widgets (#5540)

Eric Hayes3d24bdb86667
diff --git a/apps/web/src/features/dynamic-ui/Gallery.tsx b/apps/web/src/features/dynamic-ui/Gallery.tsx
index 5f1b999ce4..f219b1ae9a 100644
--- a/apps/web/src/features/dynamic-ui/Gallery.tsx
+++ b/apps/web/src/features/dynamic-ui/Gallery.tsx
@@ -12,7 +12,7 @@ import { Widget as WidgetNS } from './widget';
* plus a few composed views — the same data shape the eventual `compose_view` AI
* tool will emit. No AI involved: everything below is hand-written fixtures.
*
- * The `card`/`list`/`timeline` entity refs below are REAL ids from dev-assets
+ * The `list`/`timeline` entity refs below are REAL ids from dev-assets
* (the macro-db-dev RDS the running app talks to), owned by [email protected],
* so they resolve to real previews via ItemPreview. Swap them for other ids as
* needed.
@@ -47,16 +47,6 @@ const CATALOG: Array<{ label: string; widget: Widget }> = [
'## Weekly summary\n\nYou shipped **4 PRs** and closed *6 tickets*. See the [tracker](https://macro.com) for the full breakdown.\n\n- Auth race fix\n- Tool render stabilization\n\n> Nice momentum this week.',
},
},
- {
- label: 'stat',
- widget: {
- type: 'stat',
- label: 'PRs merged',
- value: 12,
- unit: 'PRs',
- delta: { value: 40, direction: 'up', label: 'vs last week' },
- },
- },
{
label: 'timeline',
widget: {
@@ -97,19 +87,6 @@ const CATALOG: Array<{ label: string; widget: Widget }> = [
source: { kind: 'items', entities: SAMPLE_ENTITIES },
},
},
- {
- // Both card kinds (a task and an md doc) in one labeled section.
- label: 'card',
- widget: {
- type: 'container',
- direction: 'col',
- gap: 3,
- children: [
- { type: 'card', entity: { id: TASK_REVIEW_PR, type: 'document' } },
- { type: 'card', entity: { id: DOC_SHOWCASE, type: 'document' } },
- ],
- },
- },
{
label: 'channelMessage',
widget: {
@@ -127,16 +104,14 @@ const CATALOG: Array<{ label: string; widget: Widget }> = [
gap: 3,
children: [
{
- type: 'stat',
- label: 'Throughput',
- value: 14,
- unit: '/day',
- delta: { value: 3, direction: 'up', label: 'vs last week' },
+ type: 'md',
+ markdown:
+ '### Throughput\n\nUp **3/day** vs last week. Steady climb since the sprint started.',
},
{
type: 'md',
markdown:
- '### Notes\n\nLayout is flexbox — child **order** sets position. This row places a stat and notes side by side.',
+ '### Notes\n\nLayout is flexbox — child **order** sets position. This row places two notes side by side.',
},
],
},
@@ -149,27 +124,9 @@ const COMPOSED: View[] = [
title: 'What did I get done yesterday?',
widgets: [
{
- type: 'container',
- direction: 'row',
- gap: 3,
- children: [
- {
- type: 'stat',
- label: 'PRs merged',
- value: 4,
- delta: { value: 2, direction: 'up', label: 'vs avg' },
- },
- {
- type: 'stat',
- label: 'Tickets closed',
- value: 6,
- },
- {
- type: 'stat',
- label: 'Messages sent',
- value: 28,
- },
- ],
+ type: 'md',
+ markdown:
+ 'You merged **4 PRs** (up 2 vs avg), closed **6 tickets**, and sent **28 messages**.',
},
{
type: 'timeline',
@@ -186,25 +143,8 @@ const COMPOSED: View[] = [
title: 'My current work',
widgets: [
{
- type: 'card',
- entity: { id: DOC_STABILIZE, type: 'document' },
- },
- {
- type: 'container',
- direction: 'row',
- gap: 3,
- children: [
- {
- type: 'stat',
- label: 'In review',
- value: 3,
- },
- {
- type: 'stat',
- label: 'Blocked',
- value: 1,
- },
- ],
+ type: 'md',
+ markdown: '**3 items** in review, **1** blocked.',
},
{
type: 'list',
@@ -219,38 +159,15 @@ const COMPOSED: View[] = [
{
type: 'md',
markdown:
- '### Tool render stabilization\n\nA compact project readout that mixes narrative, metrics, trends, and the source document driving the work.',
+ '### Tool render stabilization\n\nA compact project readout that mixes narrative, metrics, and the source document driving the work.\n\n- Ready checks: **7/9** (up 3 since standup)\n- Open risks: **2** (down 1 from yesterday)\n- Confidence: **82%** (up 6 this week)',
},
{
- type: 'container',
- direction: 'row',
- gap: 3,
- wrap: true,
- children: [
- {
- type: 'stat',
- label: 'Ready checks',
- value: '7/9',
- delta: { value: 3, direction: 'up', label: 'since standup' },
- },
- {
- type: 'stat',
- label: 'Open risks',
- value: 2,
- delta: { value: 1, direction: 'down', label: 'from yesterday' },
- },
- {
- type: 'stat',
- label: 'Confidence',
- value: 82,
- unit: '%',
- delta: { value: 6, direction: 'up', label: 'this week' },
- },
- ],
- },
- {
- type: 'card',
- entity: { id: DOC_STABILIZE, type: 'document' },
+ type: 'list',
+ title: 'Source document',
+ source: {
+ kind: 'items',
+ entities: [{ id: DOC_STABILIZE, type: 'document' }],
+ },
},
],
},
@@ -258,22 +175,9 @@ const COMPOSED: View[] = [
title: 'Review queue',
widgets: [
{
- type: 'container',
- direction: 'row',
- gap: 3,
- children: [
- {
- type: 'stat',
- label: 'In queue',
- value: 6,
- delta: { value: 2, direction: 'down', label: 'since 9a' },
- },
- {
- type: 'md',
- markdown:
- '### Triage notes\n\n- Prioritize items with product impact\n- Pull docs into review comments\n- Leave owners with one clear next action',
- },
- ],
+ type: 'md',
+ markdown:
+ '### Triage notes\n\n**6 in queue** (down 2 since 9a).\n\n- Prioritize items with product impact\n- Pull docs into review comments\n- Leave owners with one clear next action',
},
{
type: 'list',
@@ -317,32 +221,10 @@ const COMPOSED: View[] = [
channelId: '019467c2-49d0-7d99-b0b9-d535811a337d',
messageId: '019eb2e2-c4f5-730e-8aee-70794417ddbd',
},
- {
- type: 'container',
- direction: 'row',
- gap: 3,
- children: [
- {
- type: 'stat',
- label: 'Replies needed',
- value: 3,
- },
- {
- type: 'stat',
- label: 'Linked tasks',
- value: 2,
- },
- {
- type: 'stat',
- label: 'ETA',
- value: 'Today',
- },
- ],
- },
{
type: 'md',
markdown:
- '### Draft response checklist\n\n- Confirm the owner\n- Link the relevant task\n- Call out the next checkpoint',
+ '### Draft response checklist\n\n**3 replies needed**, 2 linked tasks, ETA today.\n\n- Confirm the owner\n- Link the relevant task\n- Call out the next checkpoint',
},
],
},
diff --git a/apps/web/src/features/dynamic-ui/render.tsx b/apps/web/src/features/dynamic-ui/render.tsx
index 71c5874c17..65333f8d0e 100644
--- a/apps/web/src/features/dynamic-ui/render.tsx
+++ b/apps/web/src/features/dynamic-ui/render.tsx
@@ -7,11 +7,9 @@ import type {
WidgetOf,
WidgetType,
} from './schema';
-import { Card } from './widgets/Card';
import { ChannelMessage } from './widgets/ChannelMessage';
import { List } from './widgets/List';
import { Md } from './widgets/Md';
-import { Stat } from './widgets/Stat';
import { Timeline } from './widgets/Timeline';
/**
@@ -24,9 +22,7 @@ import { Timeline } from './widgets/Timeline';
export function Render(props: { node: Widget }): JSX.Element {
return match(props.node)
.with({ type: 'md' }, (n) => <Md {...n} />)
- .with({ type: 'stat' }, (n) => <Stat {...n} />)
.with({ type: 'timeline' }, (n) => <Timeline {...n} />)
- .with({ type: 'card' }, (n) => <Card {...n} />)
.with({ type: 'channelMessage' }, (n) => <ChannelMessage {...n} />)
.with({ type: 'list' }, (n) => <List {...n} />)
.with({ type: 'container' }, (n) => <Container node={n} />)
diff --git a/apps/web/src/features/dynamic-ui/schema.ts b/apps/web/src/features/dynamic-ui/schema.ts
index 636514c293..ab15ccb721 100644
--- a/apps/web/src/features/dynamic-ui/schema.ts
+++ b/apps/web/src/features/dynamic-ui/schema.ts
@@ -43,25 +43,6 @@ export const MdWidgetSchema = z.object({
});
export type MdWidget = z.infer<typeof MdWidgetSchema>;
-/** A single labelled metric, optionally with a trend delta. */
-export const StatWidgetSchema = z.object({
- type: z.literal('stat'),
- label: z.string(),
- value: z.union([z.string(), z.number()]),
- /** e.g. "PRs", "%", "ms" — rendered next to the value. */
- unit: z.string().optional(),
- /** Change vs a prior period. */
- delta: z
- .object({
- value: z.number(),
- direction: z.enum(['up', 'down', 'neutral']),
- /** e.g. "vs last week". */
- label: z.string().optional(),
- })
- .optional(),
-});
-export type StatWidget = z.infer<typeof StatWidgetSchema>;
-
/** A chronological sequence of events. Great for "what happened" answers. */
export const TimelineWidgetSchema = z.object({
type: z.literal('timeline'),
@@ -101,14 +82,6 @@ export const ListWidgetSchema = z.object({
});
export type ListWidget = z.infer<typeof ListWidgetSchema>;
-/** A rich preview card for a single entity (task, md doc, …) — the same rich
- * body shown on hover, rendered inline. */
-export const CardWidgetSchema = z.object({
- type: z.literal('card'),
- entity: EntityRefSchema,
-});
-export type CardWidget = z.infer<typeof CardWidgetSchema>;
-
/** Render a single channel message with surrounding context. */
export const ChannelMessageWidgetSchema = z.object({
type: z.literal('channelMessage'),
@@ -153,19 +126,15 @@ export const ContainerWidgetSchema: z.ZodType<ContainerWidget> = z.object({
export type Widget =
| MdWidget
- | StatWidget
| TimelineWidget
| ListWidget
- | CardWidget
| ChannelMessageWidget
| ContainerWidget;
export const WidgetSchema: z.ZodType<Widget> = z.union([
MdWidgetSchema,
- StatWidgetSchema,
TimelineWidgetSchema,
ListWidgetSchema,
- CardWidgetSchema,
ChannelMessageWidgetSchema,
ContainerWidgetSchema,
]);
diff --git a/apps/web/src/features/dynamic-ui/toolSchema.ts b/apps/web/src/features/dynamic-ui/toolSchema.ts
index 69307d5e99..4a76ef2269 100644
--- a/apps/web/src/features/dynamic-ui/toolSchema.ts
+++ b/apps/web/src/features/dynamic-ui/toolSchema.ts
@@ -20,14 +20,14 @@ export function displayResultsInstructions(): string {
const jsonSchema = z.toJSONSchema(ViewSchema, { unrepresentable: 'any' });
cached = [
'# displayResults',
- '`displayResults` renders a rich, interactive view (cards, lists, timelines, stats, channel messages) directly in the chat. PREFER it over a plain-text answer whenever your response is largely about the user\'s workspace data — summaries of tasks/docs/activity, lists of entities, anything you would otherwise format as a markdown table or a long bulleted list. You do NOT need the user to ask for a "dashboard" or a "view": proactively call `displayResults` whenever it presents the information more clearly than text would.',
+ '`displayResults` renders a rich, interactive view (lists, timelines, channel messages) directly in the chat. PREFER it over a plain-text answer whenever your response is largely about the user\'s workspace data — summaries of tasks/docs/activity, lists of entities, anything you would otherwise format as a markdown table or a long bulleted list. You do NOT need the user to ask for a "dashboard" or a "view": proactively call `displayResults` whenever it presents the information more clearly than text would.',
'Typical triggers — call it even though the user never said "dashboard": "what did I get done this week?", "what\'s <teammate> working on?", "show me my open tasks", "summarize this project", "what happened in <channel>?". When in doubt and the answer is mostly workspace entities or metrics, render a view.',
'When you DO render a view, keep any accompanying chat text short (a one-line lead-in at most) — the view IS the answer; do not also restate it in prose.',
'Its `view` argument MUST be a JSON object matching this JSON Schema (a `title` plus an ordered `widgets` array; layout is flexbox via the `container` widget):',
'```json',
JSON.stringify(jsonSchema, null, 2),
'```',
- 'Entity-backed widgets (`card`, `list`, `timeline`, `channelMessage`) take real workspace entity ids — use ids you obtained from other tools (ListEntities, search, etc.), never invented ones.',
+ 'Entity-backed widgets (`list`, `timeline`, `channelMessage`) take real workspace entity ids — use ids you obtained from other tools (ListEntities, search, etc.), never invented ones.',
].join('\n');
return cached;
}
diff --git a/apps/web/src/features/dynamic-ui/widget.ts b/apps/web/src/features/dynamic-ui/widget.ts
index ee1437f016..ad8dada9ac 100644
--- a/apps/web/src/features/dynamic-ui/widget.ts
+++ b/apps/web/src/features/dynamic-ui/widget.ts
@@ -1,15 +1,13 @@
import { Col, Row, View } from './core/Layout';
import { Compose, Render } from './render';
-import { Card } from './widgets/Card';
import { ChannelMessage } from './widgets/ChannelMessage';
import { List } from './widgets/List';
import { Md } from './widgets/Md';
-import { Stat } from './widgets/Stat';
import { Timeline } from './widgets/Timeline';
/**
* The public dynamic-ui API: a namespace of composable components plus the two
- * renderers. Consumers either compose primitives directly (`<Widget.Stat …/>`)
+ * renderers. Consumers either compose primitives directly (`<Widget.Md …/>`)
* or hand a schema node / view to `<Widget.Render>` / `<Widget.Compose>`.
*/
export const Widget = {
@@ -19,9 +17,7 @@ export const Widget = {
Row,
Col,
Md,
- Stat,
Timeline,
- Card,
ChannelMessage,
List,
};
diff --git a/apps/web/src/features/dynamic-ui/widgets/Card.tsx b/apps/web/src/features/dynamic-ui/widgets/Card.tsx
deleted file mode 100644
index d141af95ec..0000000000
--- a/apps/web/src/features/dynamic-ui/widgets/Card.tsx
+++ /dev/null
@@ -1,96 +0,0 @@
-import type { BlockName } from '@core/block';
-import { DocumentPreviewContent } from '@core/component/DocumentPreview';
-import { useItemPreviewData } from '@core/component/ItemPreview';
-import { fileTypeToBlockName } from '@core/constant/allBlocks';
-import type { ItemEntity } from '@queries/preview';
-import { cn } from '@ui';
-import { Suspense } from 'solid-js';
-import type { EntityRef, WidgetOf } from '../schema';
-import { SURFACE } from '../tokens';
-
-/**
- * A rich preview card for a single entity — a task, an md document, or anything
- * else with a preview — by rendering the SAME rich body the list's hover card
- * shows, but
- * INLINE (always visible, not on hover) and inside a NORMAL border instead of
- * the floating hover-card's highlighted chrome.
- *
- * The hover card in {@link import('@core/component/ItemPreview').ItemPreview}
- * renders {@link import('@core/component/DocumentPreview').PopupPreview}, whose
- * outer shell bakes in a colored highlight border + drop shadow. Rather than
- * suppress that chrome with a flag, we COMPOSE: we render the extracted
- * {@link DocumentPreviewContent} body directly and wrap it in our own ordinary
- * card border.
- *
- * Picking `documentInfo.type` is the crux of making BOTH a task and an md doc
- * look like their hover card. `DocumentPreviewContent` gates its body branches
- * (the task status/priority/assignee block, the image cover strip, the
- * copy-branch button) on `documentInfo.type` LITERALLY — it does NOT use the
- * block type it re-resolves internally for those. So a static default like
- * `'document'` would render an md doc fine but would never show a task's task
- * body. We therefore derive the block name from the FETCHED item exactly the
- * way the hover card does — `fileTypeToBlockName(targetType() ?? itemType)`
- * (see ItemPreviewInner's `blockName()`), which resolves the document subType
- * `task` to the `task` block and a plain md doc to `md`. That makes each entity
- * render identically to its hover card. Until the item resolves we fall back to
- * the caller's EntityRef type; the body re-renders once it loads.
- */
-
-export type CardProps = Omit<WidgetOf<'card'>, 'type'>;
-
-/** Map a schema EntityType onto the ItemType string the preview query expects. */
-function toItemType(type: EntityRef['type']): string {
- switch (type) {
- case 'email_thread':
- return 'email';
- case 'foreign_entity':
- return 'foreign';
- default:
- return type;
- }
-}
-
-export function Card(props: CardProps) {
- const itemEntity = () =>
- ({
- id: props.entity.id,
- type: toItemType(props.entity.type),
- }) as ItemEntity;
-
- const { item, targetType } = useItemPreviewData(itemEntity);
-
- // Mirror ItemPreviewInner's `blockName()`: resolve the real block (task / md
- // / …) from the fetched item so the body branches in DocumentPreviewContent
- // match the hover card. Falls back to the caller's EntityRef type pre-load.
- const blockName = (): BlockName => {
- const i = item();
- const resolved =
- !i.loading && i.access === 'access'
- ? fileTypeToBlockName(targetType() ?? i.type)
- : fileTypeToBlockName(props.entity.type);
- return (resolved || props.entity.type) as BlockName;
- };
-
- const documentInfo = () => ({
- id: props.entity.id,
- type: blockName(),
- params: {},
- isOpenable: true,
- });
-
- return (
- // DocumentPreviewContent fetches preview + property data; guard with our own
- // boundary so a suspending fetch can't bubble past this widget.
- <Suspense>
- <div
- class={cn(
- 'w-full max-w-sm overflow-hidden rounded-lg border text-ink',
- SURFACE.borderMuted,
- SURFACE.panel
- )}
- >
- <DocumentPreviewContent documentInfo={documentInfo()} />
- </div>
- </Suspense>
- );
-}
diff --git a/apps/web/src/features/dynamic-ui/widgets/Stat.tsx b/apps/web/src/features/dynamic-ui/widgets/Stat.tsx
deleted file mode 100644
index 48e1dca268..0000000000
--- a/apps/web/src/features/dynamic-ui/widgets/Stat.tsx
+++ /dev/null
@@ -1,44 +0,0 @@
-import { cn } from '@ui';
-import { Show } from 'solid-js';
-import type { WidgetOf } from '../schema';
-import { TEXT } from '../tokens';
-
-export type StatProps = Omit<WidgetOf<'stat'>, 'type'>;
-
-/** Arrow glyph for a delta direction. */
-const DELTA_GLYPH: Record<'up' | 'down' | 'neutral', string> = {
- up: '▲',
- down: '▼',
- neutral: '—',
-};
-
-/** A compact stat card: label, prominent value (+unit), optional delta. */
-export function Stat(props: StatProps) {
- return (
- <div class="w-full gap-1 rounded-lg border border-edge-muted bg-surface p-3">
- <span class="text-ink-extra-muted text-xxs font-medium uppercase tracking-wide break-words">
- {props.label}
- </span>
- <div class="flex items-baseline gap-1">
- <span class={cn('text-2xl font-semibold leading-none', TEXT.primary)}>
- {props.value}
- </span>
- <Show when={props.unit}>
- <span class="text-ink-muted text-sm">{props.unit}</span>
- </Show>
- </div>
-
- <Show when={props.delta}>
- {(delta) => (
- <span class={cn('flex items-center gap-1 text-xs', TEXT.accent)}>
- <span aria-hidden="true">{DELTA_GLYPH[delta().direction]}</span>
- <span class="font-medium">{delta().value}</span>
- <Show when={delta().label}>
- <span class="text-ink-extra-muted">{delta().label}</span>
- </Show>
- </span>
- )}
- </Show>
- </div>
- );
-}