Skip to content

Commit

Permalink
Merge pull request #175 from InseeFr/fix/solve-types-scrollablebox
Browse files Browse the repository at this point in the history
fix: try to find a better solution for typing Select component
  • Loading branch information
EmmanuelDemey authored Dec 3, 2024
2 parents e8a0819 + e9fbb4d commit 88f63a7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pearl",
"version": "2.5.0",
"version": "2.5.1",
"private": true,
"dependencies": {
"@emotion/react": "^11.11.1",
Expand Down
16 changes: 7 additions & 9 deletions src/pages/StatsTracking.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Box, Card, CardContent, Stack, Typography, Grid, SelectChangeEvent } from '@mui/material';
import { useState, useMemo, SetStateAction } from 'react';
import { Box, Card, CardContent, Grid, SelectChangeEvent, Stack, Typography } from '@mui/material';
import D from 'i18n';
import { useMemo, useState } from 'react';
import { SurveyUnit } from 'types/pearl';
import { ScrollableBox } from 'ui/ScrollableBox';
import { Select } from 'ui/Select';
import { CampaignProgress } from 'ui/Stats/CampaignProgress';
import { CampaignProgressPieChart } from 'ui/Stats/CampaignProgressPieChart';
import { daysLeftForSurveyUnit } from 'utils/functions';
import { groupBy } from 'utils/functions/array';
import D from 'i18n';
import { SurveyUnit } from 'types/pearl';
import { Select } from 'ui/Select';
import { ScrollableBox } from 'ui/ScrollableBox';

type SortDirection = 'asc' | 'desc' | 'deadlineDesc' | 'deadlineAsc';

Expand Down Expand Up @@ -78,9 +78,7 @@ export function StatsTracking({ surveyUnits }: Readonly<StatsTrackingProps>) {
<Select
options={sortOptions}
value={sortDirection}
onChange={(e: SelectChangeEvent<SortDirection>) =>
setSortDirection(e.target.value as SortDirection)
}
onChange={e => setSortDirection(e.target.value as SortDirection)}
placeholder={D.noSorting}
allowEmpty
sx={{ width: '210px' }}
Expand Down
4 changes: 1 addition & 3 deletions src/pages/TrackingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ export const Component = () => {
<>
{' | '}
<Select
onChange={(e: SelectChangeEvent<unknown>) =>
setCampaign(e.target.value as string)
}
onChange={e => setCampaign(e.target.value as string)}
sx={{ minWidth: 210 }}
value={campaign}
placeholder={D.trackingSelect}
Expand Down
7 changes: 2 additions & 5 deletions src/ui/Select.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import MenuItem from '@mui/material/MenuItem';
import SelectMaterial, { SelectChangeEvent } from '@mui/material/Select';
import React, { ReactNode } from 'react';
import SelectMaterial, { SelectProps as MaterialSelectProps } from '@mui/material/Select';

// extends React.ComponentProps<typeof SelectMaterial>
interface SelectProps extends React.ComponentProps<typeof SelectMaterial> {
interface SelectProps extends MaterialSelectProps {
options: { value: string | number; label: string }[];
placeholder: string;
allowEmpty: boolean;
onChange: (e: SelectChangeEvent<any>, child: ReactNode) => void;
}

export function Select({ options, placeholder, allowEmpty, ...props }: Readonly<SelectProps>) {
Expand Down

0 comments on commit 88f63a7

Please sign in to comment.