From 443eeca06168d79a61ac5fbfe8e9c2583769f50e Mon Sep 17 00:00:00 2001 From: Johan Girod Date: Thu, 4 Feb 2021 18:30:57 +0100 Subject: [PATCH] :green_heart: lint & typescript --- .../source/components/PercentageField.tsx | 12 +++---- .../source/components/SimulationGoals.tsx | 2 +- .../source/components/conversation/Input.tsx | 8 ++--- .../conversation/ParagrapheInput.tsx | 4 +-- .../components/conversation/Question.tsx | 6 ++-- .../components/conversation/RuleInput.tsx | 8 +++-- .../components/conversation/TextInput.tsx | 4 +-- .../conversation/select/SelectCommune.tsx | 15 ++++---- .../select/SelectEuropeCountry.tsx | 6 ++-- .../source/pages/Simulateurs/ISSimulation.tsx | 2 +- publicodes/core/source/format.ts | 35 ++++++++++--------- 11 files changed, 49 insertions(+), 53 deletions(-) diff --git a/mon-entreprise/source/components/PercentageField.tsx b/mon-entreprise/source/components/PercentageField.tsx index bbade0a39..c5800b0d9 100644 --- a/mon-entreprise/source/components/PercentageField.tsx +++ b/mon-entreprise/source/components/PercentageField.tsx @@ -1,14 +1,12 @@ import { formatValue } from 'publicodes' -import { Evaluation } from 'publicodes/dist/types/AST/types' import { useCallback, useState } from 'react' import { useTranslation } from 'react-i18next' import { debounce as debounceFn } from '../utils' -import { InputCommonProps } from './conversation/RuleInput' +import { InputProps } from './conversation/RuleInput' import './PercentageField.css' -type PercentageFieldProps = InputCommonProps & { +type PercentageFieldProps = InputProps & { debounce: number - value: Evaluation } export default function PercentageField({ @@ -16,7 +14,7 @@ export default function PercentageField({ value, debounce = 0, }: PercentageFieldProps) { - const [localValue, setLocalValue] = useState(value) + const [localValue, setLocalValue] = useState(value as number) const debouncedOnChange = useCallback( debounce ? debounceFn(debounce, onChange) : onChange, [debounce, onChange] @@ -29,11 +27,11 @@ export default function PercentageField({ className="range" onChange={(e) => { const value = e.target.value - setLocalValue(value) + setLocalValue(+value) debouncedOnChange(value) }} type="range" - value={localValue} + value={localValue as number} name="volume" min="0" step="0.05" diff --git a/mon-entreprise/source/components/SimulationGoals.tsx b/mon-entreprise/source/components/SimulationGoals.tsx index ebf9d2795..d465005fd 100644 --- a/mon-entreprise/source/components/SimulationGoals.tsx +++ b/mon-entreprise/source/components/SimulationGoals.tsx @@ -144,7 +144,7 @@ export function SimulationGoal({ )} {!isFocused && !small && ( - + )} diff --git a/mon-entreprise/source/components/conversation/Input.tsx b/mon-entreprise/source/components/conversation/Input.tsx index 382f4e712..3194abac8 100644 --- a/mon-entreprise/source/components/conversation/Input.tsx +++ b/mon-entreprise/source/components/conversation/Input.tsx @@ -1,10 +1,10 @@ -import { formatValue, Evaluation, Unit } from 'publicodes' +import { formatValue, Unit } from 'publicodes' import { useCallback } from 'react' import { useTranslation } from 'react-i18next' import NumberFormat from 'react-number-format' import { currencyFormat, debounce } from '../../utils' import InputSuggestions from './InputSuggestions' -import { InputCommonProps } from './RuleInput' +import { InputProps } from './RuleInput' // TODO: fusionner Input.js et CurrencyInput.js export default function Input({ @@ -16,10 +16,8 @@ export default function Input({ missing, unit, autoFocus, -}: InputCommonProps & { - onSubmit: (source: string) => void +}: InputProps & { unit: Unit | undefined - value: Evaluation }) { const debouncedOnChange = useCallback(debounce(550, onChange), []) const { language } = useTranslation().i18n diff --git a/mon-entreprise/source/components/conversation/ParagrapheInput.tsx b/mon-entreprise/source/components/conversation/ParagrapheInput.tsx index b6b890885..c200144c3 100644 --- a/mon-entreprise/source/components/conversation/ParagrapheInput.tsx +++ b/mon-entreprise/source/components/conversation/ParagrapheInput.tsx @@ -1,7 +1,7 @@ import { Evaluation } from 'publicodes/dist/types/AST/types' import { useCallback } from 'react' import { debounce } from '../../utils' -import { InputCommonProps } from './RuleInput' +import { InputProps } from './RuleInput' export default function ParagrapheInput({ onChange, @@ -9,7 +9,7 @@ export default function ParagrapheInput({ id, missing, autoFocus, -}: InputCommonProps & { value: Evaluation }) { +}: InputProps & { value: Evaluation }) { const debouncedOnChange = useCallback(debounce(1000, onChange), []) return ( diff --git a/mon-entreprise/source/components/conversation/Question.tsx b/mon-entreprise/source/components/conversation/Question.tsx index 3bf23b4f5..1512e4f54 100644 --- a/mon-entreprise/source/components/conversation/Question.tsx +++ b/mon-entreprise/source/components/conversation/Question.tsx @@ -13,7 +13,7 @@ import { import emoji from 'react-easy-emoji' import { Trans } from 'react-i18next' import { Explicable } from './Explicable' -import { binaryQuestion, InputCommonProps, RuleInputProps } from './RuleInput' +import { binaryQuestion, InputProps } from './RuleInput' /* Ceci est une saisie de type "radio" : l'utilisateur choisit une réponse dans une liste, ou une liste de listes. Les données @choices sont un arbre de type: @@ -36,7 +36,7 @@ export type Choice = RuleNode & { children: Array } -type QuestionProps = InputCommonProps & { +type QuestionProps = InputProps & { onSubmit: (source: string) => void dottedName: DottedName choices: Choice | typeof binaryQuestion @@ -217,7 +217,7 @@ type RadioLabelContentProps = { name: string currentSelection?: null | string icônes?: string - onChange: RuleInputProps['onChange'] + onChange: InputProps['onChange'] onSubmit: (src: string, value: string) => void } diff --git a/mon-entreprise/source/components/conversation/RuleInput.tsx b/mon-entreprise/source/components/conversation/RuleInput.tsx index 454f1713f..cec09285c 100644 --- a/mon-entreprise/source/components/conversation/RuleInput.tsx +++ b/mon-entreprise/source/components/conversation/RuleInput.tsx @@ -17,11 +17,12 @@ import ParagrapheInput from './ParagrapheInput' import SelectEuropeCountry from './select/SelectEuropeCountry' import TextInput from './TextInput' -export type Props = Omit< +type Props = Omit< React.HTMLAttributes, - 'onChange' | 'defaultValue' + 'onChange' | 'defaultValue' | 'onSubmit' > & { required?: boolean + autoFocus?: boolean dottedName: Name onChange: (value: Parameters['evaluate']>[0]) => void useSwitch?: boolean @@ -144,8 +145,9 @@ export default function RuleInput({ debounce={750} name={dottedName} {...commonProps} - value={value as number} + onSubmit={() => {}} onChange={(evt) => onChange({ valeur: evt.target.value, unité })} + value={value as number} /> ) diff --git a/mon-entreprise/source/components/conversation/TextInput.tsx b/mon-entreprise/source/components/conversation/TextInput.tsx index dbdbf396a..1fdfc0f64 100644 --- a/mon-entreprise/source/components/conversation/TextInput.tsx +++ b/mon-entreprise/source/components/conversation/TextInput.tsx @@ -1,7 +1,7 @@ import { Evaluation } from 'publicodes/dist/types/AST/types' import { useCallback } from 'react' import { debounce } from '../../utils' -import { InputCommonProps } from './RuleInput' +import { InputProps } from './RuleInput' export default function TextInput({ onChange, @@ -9,7 +9,7 @@ export default function TextInput({ id, missing, autoFocus, -}: InputCommonProps & { value: Evaluation }) { +}: InputProps & { value: Evaluation }) { const debouncedOnChange = useCallback(debounce(1000, onChange), []) return (
diff --git a/mon-entreprise/source/components/conversation/select/SelectCommune.tsx b/mon-entreprise/source/components/conversation/select/SelectCommune.tsx index 4d9d3185b..0cbc1020b 100644 --- a/mon-entreprise/source/components/conversation/select/SelectCommune.tsx +++ b/mon-entreprise/source/components/conversation/select/SelectCommune.tsx @@ -1,9 +1,9 @@ import * as Animate from 'Components/ui/animate' import React, { useCallback, useMemo, useState } from 'react' import { Trans, useTranslation } from 'react-i18next' -import { debounce } from '../../../utils' import styled, { css } from 'styled-components' -import { InputCommonProps } from '../RuleInput' +import { debounce } from '../../../utils' +import { InputProps } from '../RuleInput' export type ApiCommuneJson = { _score: number @@ -62,13 +62,10 @@ async function searchCommunes(input: string): Promise | null> { .slice(0, 10) } -export default function Select({ - onChange, - value, - id, - missing, -}: InputCommonProps) { - const [name, setName] = useState(missing ? '' : formatCommune(value)) +export default function Select({ onChange, value, id, missing }: InputProps) { + const [name, setName] = useState( + missing ? '' : formatCommune(value as Commune) + ) const [searchResults, setSearchResults] = useState>( null ) diff --git a/mon-entreprise/source/components/conversation/select/SelectEuropeCountry.tsx b/mon-entreprise/source/components/conversation/select/SelectEuropeCountry.tsx index bc37362f5..2caf5ce61 100644 --- a/mon-entreprise/source/components/conversation/select/SelectEuropeCountry.tsx +++ b/mon-entreprise/source/components/conversation/select/SelectEuropeCountry.tsx @@ -1,4 +1,4 @@ -import { InputCommonProps } from '../RuleInput' +import { InputProps } from '../RuleInput' const STATES = [ 'Allemagne', @@ -39,14 +39,14 @@ export default function SelectEuropeCountry({ value, onChange, id, -}: InputCommonProps) { +}: InputProps) { return (