From 2c804328a6430656c262e9d4cdc2b9f2dd635a73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Rialland?= Date: Wed, 6 Jul 2022 13:50:01 +0200 Subject: [PATCH] Fix some bug + type error on stats page --- .../design-system/field/Select/index.tsx | 15 +++--- site/source/pages/Stats/Chart.tsx | 1 + site/source/pages/Stats/Stats.tsx | 51 +++++++++++++------ site/source/pages/Stats/utils.tsx | 12 +---- 4 files changed, 48 insertions(+), 31 deletions(-) diff --git a/site/source/design-system/field/Select/index.tsx b/site/source/design-system/field/Select/index.tsx index 585e2dd26..87750f493 100644 --- a/site/source/design-system/field/Select/index.tsx +++ b/site/source/design-system/field/Select/index.tsx @@ -1,10 +1,10 @@ +import { CarretDown } from '@/design-system/icons/carret-down' import { useButton } from '@react-aria/button' import { useFocusRing } from '@react-aria/focus' import { HiddenSelect, useSelect } from '@react-aria/select' import { mergeProps } from '@react-aria/utils' import { useSelectState } from '@react-stately/select' import type { AriaSelectProps } from '@react-types/select' -import { CarretDown } from '@/design-system/icons/carret-down' import { useEffect, useRef } from 'react' import { useTranslation } from 'react-i18next' import styled, { css } from 'styled-components' @@ -35,10 +35,11 @@ export const Label = styled.label` } `} ` - -const Button = styled.button<{ +interface ButtonProps { isFocusVisible?: boolean -}>` +} + +const Button = styled.button` display: inline-flex; align-items: center; justify-content: space-between; @@ -75,12 +76,14 @@ const StyledIcon = styled(CarretDown)` margin: 0 4px; ` -export const Wrapper = styled.div<{ +interface WrapperProps { hasError: boolean hasLabel: boolean small?: boolean isOpen?: boolean -}>` +} + +export const Wrapper = styled.div` display: flex; border-radius: ${({ theme }) => theme.box.borderRadius}; border: ${({ theme }) => diff --git a/site/source/pages/Stats/Chart.tsx b/site/source/pages/Stats/Chart.tsx index 7212f6ea4..ddbc61a9c 100644 --- a/site/source/pages/Stats/Chart.tsx +++ b/site/source/pages/Stats/Chart.tsx @@ -161,6 +161,7 @@ export default function VisitsChart({ /> ) : ( { const paramsEntries = [ ['periode', period !== defaultPeriod ? period : ''], ['module', chapter2], - ] as [string, string][] - setSearchParams(paramsEntries.filter(([, val]) => val !== '')) + ].filter(([, val]) => val !== '') as [string, string][] + + setSearchParams(paramsEntries, { replace: true }) }, [period, chapter2, setSearchParams]) const visites = useMemo(() => { @@ -203,7 +204,10 @@ const StatsDetail = () => {
- + setPeriod(val as Period)} + defaultValue={period} + > jours @@ -332,9 +336,16 @@ function getChapter2(s: SimulatorData[keyof SimulatorData]): Chapter2 | '' { return toAtString(chapter2) as typeof chapter2 } + function SelectedSimulator(props: { chapter2: Chapter2 | '' }) { const simulateur = Object.values(useSimulatorsData()).find( - (s) => getChapter2(s) === props.chapter2 && !(s.tracking as any).chapter3 + (s) => + getChapter2(s) === props.chapter2 && + !( + typeof s.tracking === 'object' && + 'chapter3' in s.tracking && + s.tracking.chapter3 + ) ) if (!simulateur) { return null @@ -355,24 +366,34 @@ function SimulateursChoice(props: { return ( chapter2 && props.possibleValues.includes(chapter2) && - !(s.tracking as any).chapter3 + !( + typeof s.tracking === 'object' && + 'chapter3' in s.tracking && + s.tracking.chapter3 + ) ) }) .sort((a, b) => (a.shortName < b.shortName ? -1 : 1)) return ( ) } diff --git a/site/source/pages/Stats/utils.tsx b/site/source/pages/Stats/utils.tsx index b54115aa0..5de27e5a6 100644 --- a/site/source/pages/Stats/utils.tsx +++ b/site/source/pages/Stats/utils.tsx @@ -13,18 +13,10 @@ export function Indicator({ main, subTitle, footnote }: IndicatorProps) { return (

{subTitle}

- + {main} - {footnote && ( - - {footnote} - - )} + {footnote && {footnote}}
) }