💚 lint & typescript
parent
009f8cc9b4
commit
443eeca061
|
@ -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<string>
|
||||
}
|
||||
|
||||
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"
|
||||
|
|
|
@ -144,7 +144,7 @@ export function SimulationGoal({
|
|||
)}
|
||||
{!isFocused && !small && (
|
||||
<span style={{ position: 'relative', top: '-1rem' }}>
|
||||
<AnimatedTargetValue value={evaluation.nodeValue} />
|
||||
<AnimatedTargetValue value={evaluation.nodeValue as number} />
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
@ -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<number>
|
||||
}) {
|
||||
const debouncedOnChange = useCallback(debounce(550, onChange), [])
|
||||
const { language } = useTranslation().i18n
|
||||
|
|
|
@ -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<string> }) {
|
||||
}: InputProps & { value: Evaluation<string> }) {
|
||||
const debouncedOnChange = useCallback(debounce(1000, onChange), [])
|
||||
|
||||
return (
|
||||
|
|
|
@ -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<Choice>
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -17,11 +17,12 @@ import ParagrapheInput from './ParagrapheInput'
|
|||
import SelectEuropeCountry from './select/SelectEuropeCountry'
|
||||
import TextInput from './TextInput'
|
||||
|
||||
export type Props<Name extends string = DottedName> = Omit<
|
||||
type Props<Name extends string = DottedName> = Omit<
|
||||
React.HTMLAttributes<HTMLInputElement>,
|
||||
'onChange' | 'defaultValue'
|
||||
'onChange' | 'defaultValue' | 'onSubmit'
|
||||
> & {
|
||||
required?: boolean
|
||||
autoFocus?: boolean
|
||||
dottedName: Name
|
||||
onChange: (value: Parameters<Engine<Name>['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}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
|
|
|
@ -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<string> }) {
|
||||
}: InputProps & { value: Evaluation<string> }) {
|
||||
const debouncedOnChange = useCallback(debounce(1000, onChange), [])
|
||||
return (
|
||||
<div className="step input">
|
||||
|
|
|
@ -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<Array<Commune> | 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 | Array<Commune>>(
|
||||
null
|
||||
)
|
||||
|
|
|
@ -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 (
|
||||
<div>
|
||||
<select
|
||||
name="country"
|
||||
id={id}
|
||||
className="ui__"
|
||||
defaultValue={value ? value.slice(1, -1) : undefined}
|
||||
defaultValue={value ? (value as string).slice(1, -1) : undefined}
|
||||
onChange={(e) => onChange(`'${e.target.value}'`)}
|
||||
>
|
||||
<option disabled selected hidden></option>
|
||||
|
|
|
@ -38,7 +38,7 @@ export default function ISSimulation() {
|
|||
<ExerciceDate />
|
||||
<Notifications />
|
||||
<SimulationGoals className="plain">
|
||||
<SimulationGoal dottedName="entreprise . bénéfice" autoFocus={true} />
|
||||
<SimulationGoal dottedName="entreprise . bénéfice" />
|
||||
</SimulationGoals>
|
||||
<Explanations />
|
||||
</>
|
||||
|
|
|
@ -30,7 +30,10 @@ export const numberFormatter = ({
|
|||
}).format(value)
|
||||
}
|
||||
|
||||
export const formatCurrency = (nodeValue: number | undefined, language: string) => {
|
||||
export const formatCurrency = (
|
||||
nodeValue: number | undefined,
|
||||
language: string
|
||||
) => {
|
||||
return nodeValue == null
|
||||
? ''
|
||||
: (formatNumber({ unit: '€', language, nodeValue }) ?? '').replace(
|
||||
|
@ -122,43 +125,41 @@ export function formatValue(
|
|||
? value
|
||||
: value.nodeValue
|
||||
|
||||
|
||||
if (
|
||||
(typeof nodeValue === 'number' && Number.isNaN(nodeValue)) ||
|
||||
nodeValue == null
|
||||
) {
|
||||
return '-'
|
||||
}
|
||||
if (typeof nodeValue === 'string'){
|
||||
if (typeof nodeValue === 'string') {
|
||||
return capitalise0(nodeValue.replace('\\n', '\n'))
|
||||
}
|
||||
if (typeof nodeValue === 'object')
|
||||
return (nodeValue as any).nom
|
||||
if (typeof nodeValue === 'object') return (nodeValue as any).nom
|
||||
if (typeof nodeValue === 'boolean')
|
||||
return booleanTranslations[language][nodeValue]
|
||||
if (typeof nodeValue === 'number'){
|
||||
let unit =
|
||||
(typeof value === 'number' ||
|
||||
if (typeof nodeValue === 'number') {
|
||||
let unit =
|
||||
typeof value === 'number' ||
|
||||
typeof value === 'undefined' ||
|
||||
!('unit' in value)
|
||||
? undefined
|
||||
: value.unit)
|
||||
: value.unit
|
||||
if (unit) {
|
||||
const simplifiedNode = simplifyNodeUnit({
|
||||
unit,
|
||||
nodeValue
|
||||
nodeValue,
|
||||
})
|
||||
unit = simplifiedNode.unit
|
||||
nodeValue = simplifiedNode.nodeValue as number
|
||||
}
|
||||
return formatNumber({
|
||||
minimumFractionDigits: 0,
|
||||
maximumFractionDigits: precision,
|
||||
language,
|
||||
formatUnit,
|
||||
nodeValue,
|
||||
unit: displayedUnit ?? unit
|
||||
})
|
||||
minimumFractionDigits: 0,
|
||||
maximumFractionDigits: precision,
|
||||
language,
|
||||
formatUnit,
|
||||
nodeValue,
|
||||
unit: displayedUnit ?? unit,
|
||||
})
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue