feat: insights routing forms (#17583)

Co-authored-by: Joe Au-Yeung <[email protected]>
This commit is contained in:
sean-brydonandJoe Au-Yeung authored and GitHub committed 2024-11-15 14:54:51 -05:00
1 parent e85c0e1a85
commit 7ce5886b4f
34 files changed
+2762 -870

No files matched your search

@@ -0,0 +1,105 @@
import { classNames } from "@calcom/lib";
import {
Button,
Popover,
PopoverTrigger,
PopoverContent,
Command,
CommandInput,
CommandList,
CommandEmpty,
CommandGroup,
CommandItem,
CommandSeparator,
Badge,
Icon,
} from "@calcom/ui";
export interface FilterOption {
value: string | number;
label: string;
icon?: React.ReactNode;
}
interface FilterSelectProps {
title: string;
options: FilterOption[];
selectedValue?: string | number | null;
onChange: (value: string | number | null) => void;
buttonIcon?: React.ReactNode;
placeholder?: string;
emptyText?: string;
testId?: string;
}
export function FilterSelect({
title,
options,
selectedValue,
onChange,
buttonIcon,
placeholder,
emptyText = "No results",
testId,
}: FilterSelectProps) {
const selectedOption = options.find((option) => option.value === selectedValue);
return (
<Popover>
<PopoverTrigger asChild>
<Button color="secondary" className="border-subtle rounded-md" data-testid={`${testId}-button`}>
{buttonIcon}
{title}
{selectedValue && (
<div className="ml-2 hidden space-x-1 md:flex">
<Badge color="gray" className="rounded-sm px-1 font-normal">
{selectedOption?.label}
</Badge>
</div>
)}
</Button>
</PopoverTrigger>
<PopoverContent className="w-[200px] p-0" align="start">
<Command>
<CommandInput placeholder={placeholder ?? title} />
<CommandList>
<CommandEmpty>{emptyText}</CommandEmpty>
<CommandGroup data-testId={`${testId}-group`}>
{options.map((option, index) => {
const isSelected = selectedValue === option.value;
return (
<CommandItem
key={option.value}
onSelect={() => {
onChange(isSelected ? null : option.value);
}}
data-testId={`${testId}-group-option-${index}`}>
<div
className={classNames(
"border-subtle mr-2 flex h-4 w-4 items-center justify-center rounded-sm border",
isSelected ? "text-emphasis" : "opacity-50 [&_svg]:invisible"
)}>
<Icon name="check" className="h-4 w-4" />
</div>
{option.icon}
<span>{option.label}</span>
</CommandItem>
);
})}
</CommandGroup>
{selectedValue && (
<>
<CommandSeparator />
<CommandGroup>
<CommandItem onSelect={() => onChange(null)} className="justify-center text-center">
Clear filter
</CommandItem>
</CommandGroup>
</>
)}
</CommandList>
</Command>
</PopoverContent>
</Popover>
);
}
+1
View File
@@ -15,6 +15,7 @@ export { Button, LinkIconButton, buttonClasses } from "./components/button";
export type { ButtonBaseProps, ButtonProps } from "./components/button";
export { ButtonGroup } from "./components/buttonGroup";
export { EditableHeading } from "./components/editable-heading";
export { FilterSelect } from "./components/filter-select";
export {
Checkbox,
CheckboxField,
+1
View File
@@ -48,6 +48,7 @@
"./toast": "./components/toast/index.ts",
"./tooltip": "./components/tooltip/index.ts",
"./top-banner": "./components/top-banner/index.ts",
"./filter-select": "./components/filter-select/index.ts",
"./unpublished-entity/UnpublishedEntity": "./components/unpublished-entity/index.ts",
"./components/icon": "./components/icon/index.ts",
"./components/icon/SatSymbol": "./components/icon/SatSymbol.tsx",