🔥 Enlève UNSAFE_evaluateRule de ChômagePartiel.tsx
parent
300e0c587e
commit
2bbf4738ce
|
@ -30,6 +30,7 @@ import { DottedName } from 'modele-social'
|
|||
import { targetUnitSelector } from 'Selectors/simulationSelectors'
|
||||
import CurrencyInput from './CurrencyInput/CurrencyInput'
|
||||
import './TargetSelection.css'
|
||||
import { Names } from 'modele-social/dist/names'
|
||||
|
||||
export default function TargetSelection({ showPeriodSwitch = true }) {
|
||||
const objectifs = useSelector(
|
||||
|
@ -297,14 +298,15 @@ function TitreRestaurant() {
|
|||
function AidesGlimpse() {
|
||||
const targetUnit = useSelector(targetUnitSelector)
|
||||
const { language } = useTranslation().i18n
|
||||
const dottedName = 'contrat salarié . aides employeur'
|
||||
const dottedName = 'contrat salarié . aides employeur' as Names
|
||||
const engine = useEngine()
|
||||
const aides = UNSAFE_evaluateRule(engine, dottedName, {
|
||||
const evaluation = engine.evaluate({
|
||||
valeur: dottedName,
|
||||
unité: targetUnit,
|
||||
arrondi: 'oui',
|
||||
})
|
||||
|
||||
if (!aides?.nodeValue) return null
|
||||
const aides = engine.getRule(dottedName)
|
||||
if (!evaluation?.nodeValue) return null
|
||||
|
||||
// Dans le cas où il n'y a qu'une seule aide à l'embauche qui s'applique, nous
|
||||
// faisons un lien direct vers cette aide, plutôt qu'un lien vers la liste qui
|
||||
|
@ -312,10 +314,9 @@ function AidesGlimpse() {
|
|||
const aideLink = reduceAST(
|
||||
(acc, node) => {
|
||||
if (node.nodeKind === 'somme') {
|
||||
const aidesNotNul = (node.explanation as EvaluatedNode[]).filter(
|
||||
({ nodeValue }) => nodeValue !== false
|
||||
)
|
||||
console.log('aidesNotNul', aidesNotNul, node.explanation)
|
||||
const aidesNotNul = node.explanation
|
||||
.map((n) => engine.evaluate(n))
|
||||
.filter(({ nodeValue }) => nodeValue !== false)
|
||||
if (aidesNotNul.length === 1) {
|
||||
return (aidesNotNul[0] as ASTNode & { nodeKind: 'reference' })
|
||||
.dottedName as DottedName
|
||||
|
@ -324,8 +325,8 @@ function AidesGlimpse() {
|
|||
}
|
||||
}
|
||||
},
|
||||
aides.dottedName,
|
||||
engine.evaluate(engine.getRules()[dottedName])
|
||||
dottedName,
|
||||
aides
|
||||
)
|
||||
return (
|
||||
<Animate.fromTop>
|
||||
|
@ -333,9 +334,11 @@ function AidesGlimpse() {
|
|||
<RuleLink dottedName={aideLink}>
|
||||
<Trans>en incluant</Trans>{' '}
|
||||
<strong>
|
||||
<span>{formatValue(aides, { displayedUnit: '€', language })}</span>
|
||||
<span>
|
||||
{formatValue(evaluation, { displayedUnit: '€', language })}
|
||||
</span>
|
||||
</strong>{' '}
|
||||
<Trans>d'aides</Trans> {emoji(aides.icônes ?? '')}
|
||||
<Trans>d'aides</Trans> {emoji(aides.rawNode.icônes ?? '')}
|
||||
</RuleLink>
|
||||
</div>
|
||||
</Animate.fromTop>
|
||||
|
|
|
@ -73,30 +73,11 @@ function ExplanationSection() {
|
|||
} = useTranslation()
|
||||
|
||||
const engine = useEngine()
|
||||
const net = UNSAFE_evaluateRule(
|
||||
engine,
|
||||
'contrat salarié . rémunération . net'
|
||||
)
|
||||
const netHabituel = UNSAFE_evaluateRule(
|
||||
engine,
|
||||
'chômage partiel . revenu net habituel'
|
||||
)
|
||||
const totalEntreprise = UNSAFE_evaluateRule(
|
||||
engine,
|
||||
'contrat salarié . prix du travail'
|
||||
)
|
||||
const totalEntrepriseHabituel = UNSAFE_evaluateRule(
|
||||
engine,
|
||||
'chômage partiel . coût employeur habituel'
|
||||
)
|
||||
if (
|
||||
typeof net?.nodeValue !== 'number' ||
|
||||
typeof netHabituel?.nodeValue !== 'number' ||
|
||||
typeof totalEntreprise?.nodeValue !== 'number' ||
|
||||
typeof totalEntrepriseHabituel?.nodeValue !== 'number'
|
||||
) {
|
||||
return null
|
||||
}
|
||||
const net = 'contrat salarié . rémunération . net'
|
||||
const netHabituel = 'chômage partiel . revenu net habituel'
|
||||
const totalEntreprise = 'contrat salarié . prix du travail'
|
||||
const totalEntrepriseHabituel = 'chômage partiel . coût employeur habituel'
|
||||
|
||||
return (
|
||||
<Animate.fromTop>
|
||||
<div
|
||||
|
@ -116,17 +97,20 @@ function ExplanationSection() {
|
|||
rows={[
|
||||
['', t('Habituellement'), t('Avec chômage partiel')],
|
||||
[
|
||||
net,
|
||||
netHabituel,
|
||||
{ dottedName: net },
|
||||
{ dottedName: netHabituel },
|
||||
{
|
||||
...net,
|
||||
dottedName: net,
|
||||
additionalText: language === 'fr' && (
|
||||
<span data-test-id="comparaison-net">
|
||||
Soit{' '}
|
||||
<strong>
|
||||
{formatValue(
|
||||
(net.nodeValue / netHabituel.nodeValue) * 100,
|
||||
{ displayedUnit: '%', precision: 0 }
|
||||
engine.evaluate({
|
||||
valeur: `${net} / ${netHabituel}`,
|
||||
unité: '%',
|
||||
arrondi: 'oui',
|
||||
})
|
||||
)}
|
||||
</strong>{' '}
|
||||
du revenu net
|
||||
|
@ -135,22 +119,20 @@ function ExplanationSection() {
|
|||
},
|
||||
],
|
||||
[
|
||||
totalEntreprise,
|
||||
totalEntrepriseHabituel,
|
||||
{ dottedName: totalEntreprise },
|
||||
{ dottedName: totalEntrepriseHabituel },
|
||||
{
|
||||
...totalEntreprise,
|
||||
dottedName: totalEntreprise,
|
||||
additionalText: language === 'fr' && (
|
||||
<span data-test-id="comparaison-total">
|
||||
Soit{' '}
|
||||
<strong>
|
||||
{formatValue(
|
||||
(totalEntreprise.nodeValue /
|
||||
totalEntrepriseHabituel.nodeValue) *
|
||||
100,
|
||||
{
|
||||
displayedUnit: '%',
|
||||
precision: 0,
|
||||
}
|
||||
engine.evaluate({
|
||||
valeur: `${totalEntreprise} / ${totalEntrepriseHabituel}`,
|
||||
unité: '%',
|
||||
arrondi: 'oui',
|
||||
})
|
||||
)}
|
||||
</strong>{' '}
|
||||
du coût habituel
|
||||
|
@ -170,11 +152,10 @@ type ComparaisonTableProps = {
|
|||
rows: [Array<string>, ...Array<Line>]
|
||||
}
|
||||
|
||||
type Line = Array<
|
||||
EvaluatedRule<DottedName> & {
|
||||
additionalText?: React.ReactNode
|
||||
}
|
||||
>
|
||||
type Line = Array<{
|
||||
dottedName: DottedName
|
||||
additionalText?: React.ReactNode
|
||||
}>
|
||||
|
||||
function ComparaisonTable({ rows: [head, ...body] }: ComparaisonTableProps) {
|
||||
const columns = head.filter((x) => x !== '')
|
||||
|
@ -248,11 +229,12 @@ function ComparaisonTable({ rows: [head, ...body] }: ComparaisonTableProps) {
|
|||
)
|
||||
}
|
||||
|
||||
function ValueWithLink(rule: EvaluatedRule<DottedName>) {
|
||||
function ValueWithLink({ dottedName }: { dottedName: DottedName }) {
|
||||
const { language } = useTranslation().i18n
|
||||
const engine = useEngine()
|
||||
return (
|
||||
<RuleLink dottedName={rule.dottedName}>
|
||||
{formatValue(rule, {
|
||||
<RuleLink dottedName={dottedName}>
|
||||
{formatValue(engine.evaluate(dottedName), {
|
||||
language,
|
||||
displayedUnit: '€',
|
||||
precision: 0,
|
||||
|
@ -261,7 +243,8 @@ function ValueWithLink(rule: EvaluatedRule<DottedName>) {
|
|||
)
|
||||
}
|
||||
|
||||
function RowLabel(target: EvaluatedRule<DottedName>) {
|
||||
function RowLabel({ dottedName }: { dottedName: DottedName }) {
|
||||
const target = useEngine().getRule(dottedName)
|
||||
return (
|
||||
<>
|
||||
{' '}
|
||||
|
@ -272,7 +255,7 @@ function RowLabel(target: EvaluatedRule<DottedName>) {
|
|||
>
|
||||
{target.title}
|
||||
</div>
|
||||
<p className="ui__ notice">{target.résumé}</p>
|
||||
<p className="ui__ notice">{target.rawNode.résumé}</p>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue