import Stack from "@mui/material/Stack"; import Box from "@mui/material/Box"; import Typography from "@mui/material/Typography"; import FormControlLabel from "@mui/material/FormControlLabel"; import { useTheme } from "@mui/material/styles"; import { useTranslation } from "react-i18next"; import { useMemo } from "react"; import { Dialog, Checkbox } from "@/Components/inputs"; import { LAYOUT } from "@/Utils/Theme/constants"; import { CardGroups, type CardDefinition, type CardGroup, type CardId } from "../cards"; interface CardPickerProps { open: boolean; available: CardDefinition[]; selected: CardId[]; onAdd: (id: CardId) => void; onRemove: (id: CardId) => void; onReset: () => void; onClose: () => void; } /** * Cards are grouped by sidebar section, not by load cost: you look for a card * where you look for the feature it belongs to. Admin-only cards never reach * `available` for a non-admin, so nobody is offered a card they cannot load. */ export const CardPicker = ({ open, available, selected, onAdd, onRemove, onReset, onClose, }: CardPickerProps) => { const theme = useTheme(); const { t } = useTranslation(); const grouped = useMemo(() => { return CardGroups.map((group: CardGroup) => ({ group, cards: available.filter((card) => card.group === group), })).filter((entry) => entry.cards.length > 0); }, [available]); const chosen = new Set(selected); return ( {/* * Two columns: seventeen cards in one list makes the dialog scroll, * which hides most of the catalogue behind a scrollbar. Groups flow * down the columns and are kept whole, so a group is never split * across the gap. */} {grouped.map(({ group, cards }) => ( {/* * The picker has its own group labels rather than reusing the * sidebar's: the Logs page hosts logs, queue and diagnostics * tabs, so "Logs" would misdescribe the three cards under it. */} {t(`pages.dashboard.picker.groups.${group}`, { defaultValue: group, })} {cards.map((card) => ( {t(`pages.dashboard.cards.${card.key}.title`)} } control={ chosen.has(card.id) ? onRemove(card.id) : onAdd(card.id) } /> } /> ))} ))} ); };