MCPcopy Create free account
hub / github.com/OpenPipe/OpenPipe / SelectFieldDropdown

Function SelectFieldDropdown

app/src/components/Filters/SelectFieldDropdown.tsx:8–50  ·  view source on GitHub ↗
({
  filterOptions,
  filter,
  urlKey,
}: {
  filterOptions: AtLeastOne<FilterOption>;
  filter: FilterData;
  urlKey?: string;
})

Source from the content-addressed store, hash-verified

6import { type AtLeastOne } from "~/types/shared.types";
7
8const SelectFieldDropdown = ({
9 filterOptions,
10 filter,
11 urlKey,
12}: {
13 filterOptions: AtLeastOne<FilterOption>;
14 filter: FilterData;
15 urlKey?: string;
16}) => {
17 const updateFilter = useFilters({ urlKey }).updateFilter;
18
19 const { field } = filter;
20
21 const selectedOption = useMemo(() => {
22 return filterOptions.find((option) => option.field === field);
23 }, [field, filterOptions]);
24
25 const updateFieldSelection = (option: FilterOption) => {
26 const optionTypeChanged = option.type !== selectedOption?.type;
27 let comparator = filter.comparator;
28 let value = filter.value;
29 if (optionTypeChanged) {
30 const newComparatorOptions = comparatorsForFilterType(option.type);
31 comparator = newComparatorOptions[0];
32 value = "";
33 }
34
35 updateFilter({ ...filter, field: option.field, comparator, value });
36 };
37
38 if (!selectedOption) {
39 return null;
40 }
41
42 return (
43 <InputDropdown
44 options={filterOptions}
45 getDisplayLabel={(option) => (!!option.label ? option.label : option.field)}
46 selectedOption={selectedOption}
47 onSelect={updateFieldSelection}
48 />
49 );
50};
51
52export default SelectFieldDropdown;

Callers

nothing calls this directly

Calls 1

useFiltersFunction · 0.90

Tested by

no test coverage detected