diff --git a/mon-entreprise/source/components/simulationExplanation/IndépendantExplanation.tsx b/mon-entreprise/source/components/simulationExplanation/IndépendantExplanation.tsx index 61e34a924..ab7520df0 100644 --- a/mon-entreprise/source/components/simulationExplanation/IndépendantExplanation.tsx +++ b/mon-entreprise/source/components/simulationExplanation/IndépendantExplanation.tsx @@ -97,17 +97,17 @@ const CotisationsSection: Partial>> = { function Distribution() { const targetUnit = useSelector(targetUnitSelector) const engine = useEngine() - const distribution = (Object.entries( - CotisationsSection - ).map(([section, cotisations]) => [ - section, - cotisations - .map((c) => engine.evaluate({ valeur: c, unité: targetUnit })) - .reduce( - (acc, evaluation) => acc + ((evaluation?.nodeValue as number) || 0), - 0 - ), - ]) as Array<[DottedName, number]>) + const distribution = ( + Object.entries(CotisationsSection).map(([section, cotisations]) => [ + section, + cotisations + .map((c) => engine.evaluate({ valeur: c, unité: targetUnit })) + .reduce( + (acc, evaluation) => acc + ((evaluation?.nodeValue as number) || 0), + 0 + ), + ]) as Array<[DottedName, number]> + ) .filter(([, value]) => value > 0) .sort(([, a], [, b]) => b - a) diff --git a/publicodes/ui-react/source/mecanisms/Replacement.tsx b/publicodes/ui-react/source/mecanisms/Replacement.tsx index 5922f2410..4f5a1c371 100644 --- a/publicodes/ui-react/source/mecanisms/Replacement.tsx +++ b/publicodes/ui-react/source/mecanisms/Replacement.tsx @@ -1,10 +1,57 @@ import { VariationNode } from 'publicodes/source/mecanisms/variations' +import { useState } from 'react' +import emoji from 'react-easy-emoji' +import Variations from './Variations' import Explanation from '../Explanation' +import Overlay from '../Overlay' +import { RuleLinkWithContext } from '../RuleLink' +import { NodeValuePointer } from './common' +import { EvaluatedNode } from 'publicodes/source/AST/types' -export default function Replacement(node: VariationNode) { +export default function Replacement(node: VariationNode & EvaluatedNode) { const applicableReplacement = node.explanation.find( (ex) => ex.satisfied )?.consequence - const replacedNode = node.explanation.slice(-1)[0].consequence - return + const replacedNode = node.explanation.slice(-1)[0].consequence as { + dottedName: string + } + + const [displayReplacements, changeDisplayReplacement] = useState(false) + return ( + <> + +   + {applicableReplacement && ( + + )} +   + + {displayReplacements && ( + changeDisplayReplacement(false)}> +

Remplacement existant

+

+ Un ou plusieurs remplacements ciblent la règle{' '} + à cet + endroit. Sa valeur est calculée selon la formule suivante : +

+ + +
+

+ + En savoir plus sur le remplacement dans publicodes + +

+ + )} + + ) } diff --git a/publicodes/ui-react/source/mecanisms/Variations.js b/publicodes/ui-react/source/mecanisms/Variations.tsx similarity index 90% rename from publicodes/ui-react/source/mecanisms/Variations.js rename to publicodes/ui-react/source/mecanisms/Variations.tsx index bbf393f44..e95b1cef9 100644 --- a/publicodes/ui-react/source/mecanisms/Variations.js +++ b/publicodes/ui-react/source/mecanisms/Variations.tsx @@ -2,13 +2,18 @@ import classnames from 'classnames' import { useState } from 'react' import emoji from 'react-easy-emoji' import styled from 'styled-components' +import { EvaluatedNode } from 'publicodes/source/AST/types' +import { VariationNode } from 'publicodes/dist/types/mecanisms/variations' import Explanation from '../Explanation' import writtenNumbers from '../writtenNumbers' import { CapitalizeFirstLetter, InlineMecanismName, Mecanism } from './common' -export default function Variations({ nodeValue, explanation, unit }) { - let [expandedVariation, toggleVariation] = useState(null) - +export default function Variations({ + nodeValue, + explanation, + unit, +}: VariationNode & EvaluatedNode) { + const [expandedVariation, toggleVariation] = useState(null) return ( ) } else { - return {nodeValue} + return {formatValue({ nodeValue, unit })} } }