All files / src/components/appearance icons.ts

100% Statements 19/19
100% Branches 10/10
100% Functions 7/7
100% Lines 19/19

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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175                                                                                                                                22x       67x 1x   66x       22x                                           22x                                             22x                                                     22x 126x     22x   413x             22x     6x   22x 26x   22x 3x   22x   3x  
/** Icon registries for resources the user can style.
 *
 *  A resource stores its icon as a *name*, not a component, so the set can
 *  grow without invalidating rows that already chose one — an unknown name
 *  simply falls back to the registry's default glyph. Each registry is a
 *  closed, ordered set so the picker, the list surfaces, and svc-core's
 *  generative setup all agree on what may be chosen.
 *
 *  `DASHBOARD_ICONS` / `AGENT_ICONS` / `REPOSITORY_ICONS` in svc-core's
 *  `app/services/appearance.py` are the server-side mirrors of these — keep
 *  the two in step when adding a glyph.
 */
 
import {
  Activity,
  Archive,
  BellRing,
  BookOpen,
  Bookmark,
  Bot,
  Boxes,
  Brain,
  Briefcase,
  CloudSun,
  Cog,
  Compass,
  Database,
  FlaskConical,
  FolderGit2,
  Gavel,
  Globe,
  GraduationCap,
  Home,
  Landmark,
  LayoutGrid,
  Library,
  Lightbulb,
  MessageSquare,
  Microscope,
  Network,
  Newspaper,
  PenLine,
  Rocket,
  Scale,
  Scroll,
  ShieldCheck,
  Sparkles,
  Stethoscope,
  Sunrise,
  Telescope,
  Workflow,
} from "lucide-react";
import React from "react";
 
export interface IconRegistry {
  /** Glyphs offered in the picker, in the order they are shown. */
  readonly icons: Record<string, React.ElementType>;
  /** Used when nothing was chosen, or the stored name is not in the set. */
  readonly fallback: string;
}
 
/** Build a registry and validate its own fallback at module load, so a typo
 *  in a new registry fails loudly here rather than silently rendering the
 *  wrong glyph everywhere the resource appears. */
export const createIconRegistry = (
  icons: Record<string, React.ElementType>,
  fallback: string,
): IconRegistry => {
  if (!(fallback in icons)) {
    throw new Error(`Icon registry fallback "${fallback}" is not in its set.`);
  }
  return { icons, fallback };
};
 
/** Icons a dashboard may be given. */
export const BOARD_ICON_REGISTRY = createIconRegistry(
  {
    LayoutGrid,
    Home,
    Sunrise,
    Newspaper,
    Activity,
    CloudSun,
    Scale,
    Bookmark,
    ShieldCheck,
    Library,
    Bot,
  },
  "LayoutGrid",
);
 
/** Icons an agent may be given.
 *
 *  Chosen to say something about an agent's *job* — support, research,
 *  review, automation — so a list of many agents is scannable, rather than
 *  being a general-purpose glyph picker. */
export const AGENT_ICON_REGISTRY = createIconRegistry(
  {
    Bot,
    Brain,
    Sparkles,
    MessageSquare,
    Compass,
    Telescope,
    PenLine,
    Gavel,
    Stethoscope,
    Rocket,
    ShieldCheck,
    Cog,
  },
  "Bot",
);
 
/** Icons a knowledge repository may be given.
 *
 *  A repository is a themed shelf of sources, so the set names *what kind of
 *  material* it holds — reference, legal, research, operational — rather than
 *  the file types inside it, which the member chips already show. */
export const REPOSITORY_ICON_REGISTRY = createIconRegistry(
  {
    FolderGit2,
    Library,
    BookOpen,
    Archive,
    Landmark,
    Scroll,
    FlaskConical,
    GraduationCap,
    Briefcase,
    Database,
    Globe,
    Boxes,
    // The kinds of method and update the built-in repositories hold.
    Network,
    Workflow,
    Lightbulb,
    Microscope,
    ShieldCheck,
    Telescope,
    BellRing,
  },
  "FolderGit2",
);
 
/** The names a registry offers, in picker order. */
export const iconNames = (registry: IconRegistry): string[] =>
  Object.keys(registry.icons);
 
/** Resolve a stored icon name to a component, falling back when unknown. */
export const iconOf = (
  registry: IconRegistry,
  name: string | null | undefined,
): React.ElementType =>
  (name ? registry.icons[name] : undefined) ??
  registry.icons[registry.fallback];
 
/** Resolve a stored icon name to a *name* in the registry — for picker state,
 *  where the selected key must be one the set actually contains. */
export const iconNameOf = (
  registry: IconRegistry,
  name: string | null | undefined,
): string => (name && name in registry.icons ? name : registry.fallback);
 
export const boardIcon = (name: string | null | undefined): React.ElementType =>
  iconOf(BOARD_ICON_REGISTRY, name);
 
export const agentIcon = (name: string | null | undefined): React.ElementType =>
  iconOf(AGENT_ICON_REGISTRY, name);
 
export const repositoryIcon = (
  name: string | null | undefined,
): React.ElementType => iconOf(REPOSITORY_ICON_REGISTRY, name);