diff --git a/src/lib/components/test_cases/TestCaseView.svelte b/src/lib/components/test_cases/TestCaseView.svelte index ee68196da3254e94a3395534f46d4f0c81bf4e51..2eef3aab597b7e152cbada7a932d8aa6258ffcf8 100644 --- a/src/lib/components/test_cases/TestCaseView.svelte +++ b/src/lib/components/test_cases/TestCaseView.svelte @@ -364,6 +364,10 @@ {#if displayMode.tab === "fiche_de_paie" || (displayMode.tab === undefined && tabsConfig.defaultTab === "fiche_de_paie")} <div class="bg-white"> {#if variableSummaryByName !== undefined} + {@const completeVariableSummaryByName = + $billName === undefined + ? variableSummaryByName + : variableSummaryByNameByReformName[$billName]} <div class="w-full flex justify-between bg-gray-100"> <!--Impacts et waterfall--> <div @@ -379,7 +383,7 @@ on:changeSituation {situation} {situationIndex} - {variableSummaryByName} + variableSummaryByName={completeVariableSummaryByName} {valuesByCalculationNameByVariableName} {year} /> diff --git a/src/lib/components/variables/VariableReferredNodeParameter.svelte b/src/lib/components/variables/VariableReferredNodeParameter.svelte index c3ac0a2099c675e9f86c00ddb2590dabafb95965..c54020134eba1b0d8784ad9fe445c1568e6ed19e 100644 --- a/src/lib/components/variables/VariableReferredNodeParameter.svelte +++ b/src/lib/components/variables/VariableReferredNodeParameter.svelte @@ -65,7 +65,7 @@ // A reform (bill) parameter is always more complete than a parameter before reform. // A reform never changes the class of a parameter const lawChild = lawParameter?.children[bothChild.id] // Sometimes undefined - const revaluationChild = revaluationParameter.children[bothChild.id] + const revaluationChild = revaluationParameter?.children[bothChild.id] const billChild = billParameter.children[bothChild.id] // Never undefined yield [bothChild, lawChild, revaluationChild, billChild] } diff --git a/src/lib/components/variables/VariableReferredParameters.svelte b/src/lib/components/variables/VariableReferredParameters.svelte index 80dd87d1a6d5c60a1009b016da451f6eab9c332e..37f6c89a0fc7b5d7f770b7cc16bbb5485929ae7e 100644 --- a/src/lib/components/variables/VariableReferredParameters.svelte +++ b/src/lib/components/variables/VariableReferredParameters.svelte @@ -84,7 +84,7 @@ : iterVariableParametersName(lawVariable, date)), ...(billVariable === undefined ? [] - : iterVariableParametersName(billVariable, date)), + : iterVariableParametersName(billVariable, date, $billName)), ]) $: bothDirectParametersName = new Set([ diff --git a/src/lib/components/variables/VariableReferredScaleParameter.svelte b/src/lib/components/variables/VariableReferredScaleParameter.svelte index 70e4e5af5bb19fdaf585f890d803426ab2b4eb0e..4193de71fbf4e9ef2894cd4cca0506e817bd4b7d 100644 --- a/src/lib/components/variables/VariableReferredScaleParameter.svelte +++ b/src/lib/components/variables/VariableReferredScaleParameter.svelte @@ -82,9 +82,10 @@ lawParameter === undefined ? undefined : scaleByInstantFromBrackets(lawParameter.brackets) - $: revaluationScaleByInstant = scaleByInstantFromBrackets( - revaluationParameter.brackets, - ) + $: revaluationScaleByInstant = + revaluationParameter === undefined + ? undefined + : scaleByInstantFromBrackets(revaluationParameter.brackets) $: billInstantScaleCouplesArray = Object.entries(billScaleByInstant).sort( ([instant1], [instant2]) => instant2.localeCompare(instant1), @@ -93,7 +94,7 @@ ([instant1], [instant2]) => instant2.localeCompare(instant1), ) $: revaluationInstantScaleCouplesArray = Object.entries( - revaluationScaleByInstant, + revaluationScaleByInstant ?? [], ).sort(([instant1], [instant2]) => instant2.localeCompare(instant1)) $: billLatestInstantScaleCouple = billInstantScaleCouplesArray[0] @@ -112,7 +113,7 @@ $: billScaleAtInstant = billLatestInstantScaleCouple[1] $: lawScaleAtInstant = lawLatestInstantScaleCouple?.[1] - $: revaluationScaleAtInstant = revaluationLatestInstantScaleCouple[1] + $: revaluationScaleAtInstant = revaluationLatestInstantScaleCouple?.[1] $: lawOrRevaluationScaleAtInstant = revaluationScaleAtInstant ?? lawScaleAtInstant @@ -122,20 +123,24 @@ lawParameter ?? billParameter, ) as string - $: showRevaluationLabel = !deepEqual( - revaluationScaleAtInstant.map((el) => el.threshold), - lawScaleAtInstant.map((el) => el.threshold), - ) - $: showBillLabel = !deepEqual( - billScaleAtInstant.map((el) => el.threshold), - revaluationScaleAtInstant.map((el) => el.threshold), - ) + $: showRevaluationLabel = + revaluationScaleAtInstant !== undefined && + !deepEqual( + revaluationScaleAtInstant.map((el) => el.threshold), + lawScaleAtInstant.map((el) => el.threshold), + ) + $: showBillLabel = + revaluationScaleAtInstant === undefined || + !deepEqual( + billScaleAtInstant.map((el) => el.threshold), + revaluationScaleAtInstant.map((el) => el.threshold), + ) $: showParametricReformLabel = !deepEqual( scaleAtInstant.map((el) => el.threshold), billScaleAtInstant.map((el) => el.threshold), ) - $: inflatorType = billParameter.inflator?.split("/") + $: inflatorType = revaluationParameter?.inflator?.split("/") $: hasInflator = inflatorType !== undefined && inflatorType.length === 2 $: inflatorByReformName = ( hasInflator diff --git a/src/lib/components/variables/VariableReferredValueParameter.svelte b/src/lib/components/variables/VariableReferredValueParameter.svelte index e87727dc001c90cbc9160a7cd0a58d46496adf25..4829f0c8e10590eed459a981881f3dfc7ce445cf 100644 --- a/src/lib/components/variables/VariableReferredValueParameter.svelte +++ b/src/lib/components/variables/VariableReferredValueParameter.svelte @@ -103,7 +103,7 @@ lawParameter?.values ?? [], ).sort(([instant1], [instant2]) => instant2.localeCompare(instant1)) $: revaluationLatestInstantValueCouplesArray = Object.entries( - revaluationParameter.values, + revaluationParameter?.values ?? [], ).sort(([instant1], [instant2]) => instant2.localeCompare(instant1)) $: billLatestInstantValueCouple = billLatestInstantValueCouplesArray[0] @@ -122,7 +122,7 @@ $: billValue = billLatestInstantValueCouple[1] $: lawValue = lawLatestInstantValueCouple?.[1] - $: revaluationValue = revaluationLatestInstantValueCouple[1] + $: revaluationValue = revaluationLatestInstantValueCouple?.[1] $: value = change?.value ?? (billValue === "expected" ? "expected" : billValue.value) @@ -131,11 +131,13 @@ lawParameter ?? billParameter, ) - $: isRevaluationActive = revaluationValue.value !== lawValue.value - $: isBillActive = billValue.value !== revaluationValue.value + $: isRevaluationActive = + revaluationValue !== undefined && revaluationValue.value !== lawValue.value + $: isBillActive = + revaluationValue === undefined || billValue.value !== revaluationValue.value $: isParametricReformActive = value !== billValue.value - $: inflatorType = revaluationParameter.inflator?.split("/") + $: inflatorType = revaluationParameter?.inflator?.split("/") $: hasInflator = inflatorType !== undefined && inflatorType.length === 2 $: inflatorByReformName = ( hasInflator diff --git a/src/lib/decompositions.ts b/src/lib/decompositions.ts index 795ef4a9bfdc7377d7fa3599a6fbfd8712c0132f..1e2e90b32d4d7bf36a84f7bb843a4e3e403287cf 100644 --- a/src/lib/decompositions.ts +++ b/src/lib/decompositions.ts @@ -457,9 +457,11 @@ function buildVisibleDecompositions1( visibleDecomposition.visibleEvaluationByCalculationName const rows: VisibleRow[] = (visibleDecomposition.rows = []) - const firstVisibleEvaluation = useRevaluationInsteadOfLaw - ? visibleEvaluationByCalculationName.revaluation - : visibleEvaluationByCalculationName.law + const firstVisibleEvaluation = + (useRevaluationInsteadOfLaw + ? visibleEvaluationByCalculationName.revaluation + : visibleEvaluationByCalculationName.law) ?? + visibleEvaluationByCalculationName.bill if (firstVisibleEvaluation !== undefined) { const firstRow: VisibleRow = { calculationName: useRevaluationInsteadOfLaw ? "revaluation" : "law", @@ -1209,11 +1211,12 @@ function buildVisibleDecompositionsForGraph1( const visibleEvaluationByCalculationName = visibleDecomposition.visibleEvaluationsByCalculationName - const rows: VisibleRowForGraph[] = (visibleDecomposition.rows = []) - - const firstVisibleEvaluation = useRevaluationInsteadOfLaw - ? visibleEvaluationByCalculationName.revaluation - : visibleEvaluationByCalculationName.law + const rows: VisibleRowForGraph[] = + (visibleDecomposition.rows = [])( + useRevaluationInsteadOfLaw + ? visibleEvaluationByCalculationName.revaluation + : visibleEvaluationByCalculationName.law, + ) ?? visibleEvaluationByCalculationName.bill if (firstVisibleEvaluation !== undefined) { const firstRow: VisibleRowForGraph = { calculationName: useRevaluationInsteadOfLaw ? "revaluation" : "law", diff --git a/src/lib/variables.ts b/src/lib/variables.ts index 6d85ba5f5726585b240f93fee6d21c270e35a05d..703db9f0b80af588e1b815881598c3bd7b82222c 100644 --- a/src/lib/variables.ts +++ b/src/lib/variables.ts @@ -976,6 +976,7 @@ export function* iterVariableInputVariables( export function* iterVariableParametersName( variable: Variable, date: string, + reformName: string | undefined = undefined, encounteredParametersName: Set<string> = new Set(), encounteredVariablesName: Set<string> = new Set(), ): Generator<string, void> { @@ -1005,7 +1006,11 @@ export function* iterVariableParametersName( const referredVariablesName = formula.variables if (referredVariablesName !== undefined) { for (const referredVariableName of referredVariablesName) { - const referredVariable = variableSummaryByName[referredVariableName] + const referredVariable = ( + reformName == undefined + ? variableSummaryByName + : variableSummaryByNameByReformName[reformName] + )[referredVariableName] if (referredVariable === undefined) { console.warn( `iterVariableParametersName: Undefined variable ${referredVariableName}`, @@ -1015,6 +1020,7 @@ export function* iterVariableParametersName( yield* iterVariableParametersName( referredVariable, date, + reformName, encounteredParametersName, encounteredVariablesName, ) diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 63e552f475364b0f7369c6e0bee0e9fa757882b5..e63427edd9ce945fa805b0a1cb1f48e0dcf6fcd8 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -74,6 +74,7 @@ type VariableValue, type VariableValues, variableSummaryByName, + variableSummaryByNameByReformName, } from "$lib/variables" export let data: LayoutData @@ -865,6 +866,10 @@ variables, }: TestCasesCalculationInput, ) { + const completeVariableSummaryByName = + $billName === undefined + ? variableSummaryByName + : variableSummaryByNameByReformName[$billName] try { // Note: crypto.randomUUID() is not supported by Safari before version 15.4. // const token = crypto.randomUUID() @@ -918,7 +923,7 @@ value, } of evaluations) { // Round returned values if unit of variable is a currency. - const variable = variableSummaryByName[variableName] + const variable = completeVariableSummaryByName[variableName] const roundedValue = variable.unit === "currency" || variable.unit?.startsWith("currency-") ? value.map((valueAtIndex) => Math.round(valueAtIndex as number)) diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 4e35cc8dc61e498cb56ba52e55da5544d18c8ca3..89c51ba0befb6fcfe7b30862c1bc55c0b4baeca1 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1663,10 +1663,7 @@ {@const shortLabel = $decompositionByName[ displayMode.parametersVariableName - ]?.short_label ?? - variableSummaryByName[ - displayMode.parametersVariableName - ].short_label} + ]?.short_label ?? variableSummary.short_label} {#if filteredTestCases.length > 0 || nonNullTestCases.length > 0} <h2 @@ -1856,14 +1853,19 @@ class:md:flex-row={!displayMode.edit} > {#if displayMode.parametersVariableName !== undefined} + {@const variableSummary = + $billName === undefined + ? variableSummaryByName[ + displayMode.parametersVariableName + ] + : variableSummaryByNameByReformName[$billName][ + displayMode.parametersVariableName + ]} {#if displayMode.testCasesIndex.length > 0} {@const shortLabel = $decompositionByName[ displayMode.parametersVariableName - ]?.short_label ?? - variableSummaryByName[ - displayMode.parametersVariableName - ].short_label} + ]?.short_label ?? variableSummary.short_label} <a class="lx-card flex items-start gap-5 px-7 py-5" href={newSimulationUrl({