From 3a5ecbf44e5c2fdefffd418aa0851c2536ff7d6b Mon Sep 17 00:00:00 2001 From: Sky Rubenstein Date: Fri, 6 Dec 2024 11:34:48 -0500 Subject: [PATCH] Typescriptify the filters file --- ...etFilterList.jsx => DatasetFilterList.tsx} | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) rename src/components/data_search/{DatasetFilterList.jsx => DatasetFilterList.tsx} (82%) diff --git a/src/components/data_search/DatasetFilterList.jsx b/src/components/data_search/DatasetFilterList.tsx similarity index 82% rename from src/components/data_search/DatasetFilterList.jsx rename to src/components/data_search/DatasetFilterList.tsx index c8ff3d562..8205a7cfc 100644 --- a/src/components/data_search/DatasetFilterList.jsx +++ b/src/components/data_search/DatasetFilterList.tsx @@ -9,9 +9,13 @@ import Divider from '@mui/material/Divider'; import { Button, TextField, Typography } from '@mui/material'; import { Checkbox } from '@mui/material'; import { flatten, uniq, compact, orderBy } from 'lodash'; -import { getAccessManagementSummary } from '../../types/model'; +import {DatasetTerm, getAccessManagementSummary} from '../../types/model'; -export const FilterItemHeader = (props) => { +interface FilterItemHeaderProps { + title: React.ReactNode; + headerStyle?: React.CSSProperties; +} +export const FilterItemHeader = (props: FilterItemHeaderProps) => { const { title, headerStyle = { fontFamily: 'Montserrat', fontWeight: '600', marginTop: '1em' } } = props; return ( @@ -20,7 +24,16 @@ export const FilterItemHeader = (props) => { ); }; -export const FilterItemList = (props) => { +interface FilterItemListProps { + category: string; + datasets: DatasetTerm[] + filter: string[]; + filterHandler: (category: string, filter: string) => void; + isFiltered: (filter: string, category: string) => boolean; + filterNameFn: (filter: string) => string; + filterDisplayFn?: (filter: string) => React.ReactNode; +} +export const FilterItemList = (props: FilterItemListProps) => { const { category, filter, filterHandler, isFiltered, filterNameFn, filterDisplayFn } = props; return ( @@ -45,9 +58,18 @@ export const FilterItemList = (props) => { ); }; -export const FilterItemRange = (props) => { +interface FilterItemRangeProps { + min: number; + max: number; + minCategory: string; + maxCategory: string; + datasets: DatasetTerm[]; + filterHandler: (category: string, filter: string) => void; +} + +export const FilterItemRange = (props: FilterItemRangeProps) => { const { min, max, minCategory, maxCategory, filterHandler } = props; - const getValue = (val, defaultVal) => isNaN(Number(val)) ? defaultVal : Number(val); + const getValue = (val: any, defaultVal: any) => isNaN(Number(val)) ? defaultVal : Number(val); return ( { ); }; -export const DatasetFilterList = (props) => { +interface DatasetFilterListProps { + datasets: DatasetTerm[]; + filterHandler: (category: string, filter: string) => void; + isFiltered: (filter: string, category: string) => boolean; + onClear: () => void; +} +export const DatasetFilterList = (props: DatasetFilterListProps) => { const { datasets, filterHandler, isFiltered, onClear } = props; const accessManagementFilters = uniq(compact(datasets.map((dataset) => dataset.accessManagement)));