Skip to content

Extract duplicate TYPE_ICONS constant from citation components into a shared module #1190

@MODSetter

Description

@MODSetter

Description

The exact same TYPE_ICONS record mapping CitationType to Lucide icons is defined twice, in two files:

  1. surfsense_web/components/tool-ui/citation/citation.tsx (lines 13–20)
  2. surfsense_web/components/tool-ui/citation/citation-list.tsx (lines 12–19)

Both definitions are byte-for-byte identical:

const TYPE_ICONS: Record<CitationType, LucideIcon> = {
	webpage: Globe,
	document: FileText,
	article: Newspaper,
	api: Database,
	code: Code2,
	other: File,
};

Both files import the same 6 Lucide icons (Globe, FileText, Newspaper, Database, Code2, File) for this map.

What to do

  1. Create a new file, e.g. surfsense_web/components/tool-ui/citation/type-icons.ts:
import type { LucideIcon } from "lucide-react";
import { Code2, Database, File, FileText, Globe, Newspaper } from "lucide-react";
import type { CitationType } from "./schema";

export const TYPE_ICONS: Record<CitationType, LucideIcon> = {
	webpage: Globe,
	document: FileText,
	article: Newspaper,
	api: Database,
	code: Code2,
	other: File,
};
  1. In both citation.tsx and citation-list.tsx:
    • Import TYPE_ICONS from "./type-icons"
    • Remove the local TYPE_ICONS definition
    • Remove the now-unused Lucide icon imports that were only used for TYPE_ICONS (keep any that are still used elsewhere in the file)

Verify after changes:

  • Both Citation and CitationList components still render the correct type icons
  • citation-list.tsx's OverflowItem and StackedCitations components still show correct icons
  • next build succeeds

Acceptance criteria

  • TYPE_ICONS is defined in exactly ONE place
  • Both citation.tsx and citation-list.tsx import it from the shared module
  • No duplicate Lucide icon imports remain

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions