Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DT-1081] Typescriptify the filters file #2746

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ import Divider from '@mui/material/Divider';
import { Button, TextField, Typography } from '@mui/material';
import { Checkbox } from '@mui/material';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR, but I think these two imports can be merged into one

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 (
<Typography variant='h6' gutterBottom component='div' sx={headerStyle}>
Expand All @@ -20,7 +24,16 @@ export const FilterItemHeader = (props) => {
);
};

export const FilterItemList = (props) => {
interface FilterItemListProps {
category: string;
datasets: DatasetTerm[]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This declares datasets but this prop is not extracted below. Is the idea that it will be needed in the future?

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 (
<List sx={{ margin: '-0.5em -0.5em' }}>
Expand All @@ -45,9 +58,18 @@ export const FilterItemList = (props) => {
);
};

export const FilterItemRange = (props) => {
interface FilterItemRangeProps {
min: number;
max: number;
minCategory: string;
maxCategory: string;
datasets: DatasetTerm[];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also appears to be unused

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 (
<Box key={minCategory + '-' + maxCategory} sx={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
<TextField id={minCategory + '-range-input'} size='small' margin='dense' variant='outlined' defaultValue={min}
Expand All @@ -64,7 +86,13 @@ export const FilterItemRange = (props) => {
);
};

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)));
Expand Down
Loading