All files / src/components/dashboard/widgets registry.tsx

83.33% Statements 5/6
100% Branches 2/2
50% Functions 1/2
83.33% Lines 5/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109                                                                                                                                  5x           5x           5x                                                         5x 91x  
import { WidgetType } from "@/objects/Dashboard";
import {
  BadgeCheck,
  BarChart3,
  Bot,
  ChartColumnBig,
  Bookmark,
  Brain,
  CloudSun,
  Globe,
  LayoutGrid,
  Link2,
  Network,
  Quote,
  Rss,
  Scale,
  Share2,
  StickyNote,
  TrendingUp,
} from "lucide-react";
import React from "react";
import { Tone } from "@/components/appearance/tones";
import {
  MessageListWidgetBody,
  NoteWidgetBody,
  PinnedMessageWidgetBody,
  ShortcutsWidgetBody,
} from "./ContentWidgets";
import {
  MarketWidgetBody,
  RSSWidgetBody,
  WeatherWidgetBody,
} from "./FeedWidgets";
import {
  BreakdownWidgetBody,
  ChartWidgetBody,
  ResourceListWidgetBody,
  StatWidgetBody,
} from "./PlatformWidgets";
import {
  AutomationWidgetBody,
  ComparisonWidgetBody,
} from "./IntelligenceWidgets";
import {
  AgentMemoryWidgetBody,
  KnowledgeGraphWidgetBody,
  KnowledgeNetworkWidgetBody,
  WebLinkGraphWidgetBody,
} from "./NetworkWidgets";
import { AssuranceWidgetBody } from "./AssuranceWidgets";
import { WidgetBodyProps } from "./types";
 
/** How this app draws one widget type.
 *
 *  The backend registry decides which types *exist* (and is served to the
 *  widget picker); this one decides how each is drawn. A type the backend
 *  adds but this app has not learned to draw still appears in the picker and
 *  falls back to `FALLBACK` rather than crashing the board.
 */
export interface WidgetPresenter {
  body: React.FC<WidgetBodyProps>;
  icon: React.ElementType;
  tone: Tone;
}
 
const FallbackBody: React.FC<WidgetBodyProps> = ({ widget }) => (
  <p className="text-xs text-gray-400 dark:text-gray-500 italic">
    This app does not know how to display a “{widget.widget_type}” widget yet.
  </p>
);
 
export const FALLBACK: WidgetPresenter = {
  body: FallbackBody,
  icon: LayoutGrid,
  tone: "slate",
};
 
const PRESENTERS: Record<WidgetType, WidgetPresenter> = {
  note: { body: NoteWidgetBody, icon: StickyNote, tone: "amber" },
  shortcuts: { body: ShortcutsWidgetBody, icon: Link2, tone: "sky" },
  stat: { body: StatWidgetBody, icon: TrendingUp, tone: "emerald" },
  chart: { body: ChartWidgetBody, icon: BarChart3, tone: "blue" },
  breakdown: { body: BreakdownWidgetBody, icon: ChartColumnBig, tone: "indigo" },
  pinned_message: { body: PinnedMessageWidgetBody, icon: Quote, tone: "violet" },
  message_list: { body: MessageListWidgetBody, icon: Bookmark, tone: "violet" },
  resource_list: { body: ResourceListWidgetBody, icon: LayoutGrid, tone: "indigo" },
  weather: { body: WeatherWidgetBody, icon: CloudSun, tone: "sky" },
  rss: { body: RSSWidgetBody, icon: Rss, tone: "amber" },
  market: { body: MarketWidgetBody, icon: TrendingUp, tone: "emerald" },
  automation: { body: AutomationWidgetBody, icon: Bot, tone: "violet" },
  comparison: { body: ComparisonWidgetBody, icon: Scale, tone: "rose" },
  knowledge_network: {
    body: KnowledgeNetworkWidgetBody,
    icon: Network,
    tone: "indigo",
  },
  agent_memory: { body: AgentMemoryWidgetBody, icon: Brain, tone: "amber" },
  web_link_graph: { body: WebLinkGraphWidgetBody, icon: Globe, tone: "sky" },
  knowledge_graph: {
    body: KnowledgeGraphWidgetBody,
    icon: Share2,
    tone: "emerald",
  },
  assurance: { body: AssuranceWidgetBody, icon: BadgeCheck, tone: "indigo" },
};
 
export const presenterFor = (type: WidgetType | string): WidgetPresenter =>
  PRESENTERS[type as WidgetType] ?? FALLBACK;