/******************************************************************************** * Copyright (c) 2026 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * https://www.eclipse.org/legal/epl-2.0 * * SPDX-License-Identifier: EPL-2.0 ********************************************************************************/ import { FunctionComponent, useState } from 'react'; import { Box, Typography, Button, Checkbox, FormControlLabel, Select, MenuItem, SelectChangeEvent, ToggleButtonGroup, ToggleButton, Menu, Badge } from '@mui/material'; import { FilterList as FilterListIcon } from '@mui/icons-material'; import { useTheme } from '@mui/material/styles'; interface CountDisplay { label: string; value: number; color?: string; } interface FilterOption { label: string; value: string; checked: boolean; } interface CountsToolbarProps { // Counts to display counts: CountDisplay[]; // Optional filter button with menu filterOptions?: FilterOption[]; onFilterOptionToggle?: (value: string) => void; // Optional date range filter dateRange?: 'today' | 'last7days' | 'last30days' | 'last90days' | 'all'; onDateRangeChange?: (range: 'today' | 'last7days' | 'last30days' | 'last90days' | 'all') => void; // Optional enforcement filter enforcement?: 'enforced' | 'notEnforced' | 'all'; onEnforcementChange?: (enforcement: 'enforced' | 'notEnforced' | 'all') => void; } export const CountsToolbar: FunctionComponent = ({ counts, filterOptions = [], onFilterOptionToggle, dateRange = 'all', onDateRangeChange, enforcement = 'all', onEnforcementChange, }) => { const theme = useTheme(); const [filterMenuAnchor, setFilterMenuAnchor] = useState(null); const filterMenuOpen = Boolean(filterMenuAnchor); const activeFilterCount = filterOptions.filter(opt => opt.checked).length; if (counts.length === 0) { return null; } return ( {counts.map((count, index) => ( {count.label}: {count.value} ))} {/* Right-aligned controls */} {/* Filter Button with Menu */} {onFilterOptionToggle && ( <> setFilterMenuAnchor(null)} PaperProps={{ sx: { maxHeight: 400, minWidth: 200, backgroundColor: theme.palette.scanBackground.dark, }, }} > {filterOptions.map((option) => ( onFilterOptionToggle(option.value)} sx={{ py: 0.5, '&:hover': { backgroundColor: theme.palette.scanBackground.default, }, }} > } label={ {option.label} } sx={{ m: 0, width: '100%', pointerEvents: 'none' }} /> ))} )} {/* Enforcement Filter */} {onEnforcementChange && ( value && onEnforcementChange(value)} size='small' sx={{ height: '32px', '& .MuiToggleButton-root': { py: 0.5, px: 1.5, fontSize: '0.8125rem', textTransform: 'none', whiteSpace: 'nowrap', borderColor: 'divider', '&.Mui-selected': { backgroundColor: theme.palette.secondary.main, color: theme.palette.secondary.contrastText, '&:hover': { backgroundColor: theme.palette.secondary.dark, }, }, }, }} > Enforced Not Enforced All )} {/* Date Range Filter */} {onDateRangeChange && ( Date Range: )} ); };