diff --git a/src/lib/components/test_cases/TestCaseGraph.svelte b/src/lib/components/test_cases/TestCaseGraph.svelte index 16367f96a22eb639a5bc9ab6a9141a9bd9c8d815..df0450c6fc95761544a3c567e1e3d0d38114ea9b 100644 --- a/src/lib/components/test_cases/TestCaseGraph.svelte +++ b/src/lib/components/test_cases/TestCaseGraph.svelte @@ -129,7 +129,9 @@ let svgPadding = { bottom: 20, left: 8, right: 20, top: 20 } let grapheExplanationOpen = $state(false) - let variableCustomizations = $state(variableCustomizationsBase) + let variableCustomizations = $state( + structuredClone(variableCustomizationsBase), + ) let variableValues: VariableGraph[][] = $state([]) let variableGroups: { css?: string @@ -137,7 +139,7 @@ name?: string hideOpen?: boolean variables: VariableGraph[] - }[] = $state() + }[] = $state([]) let visibleDecompositionsGraph: VisibleDecompositionForGraph[] | undefined = $state(undefined) @@ -168,8 +170,8 @@ ) { untrack(() => { const ressourcesBrutes = [ - "remuneration_brute", "chomage_brut", + "remuneration_brute", "retraite_brute", ] @@ -240,10 +242,9 @@ ] const splitIndex = - prelevementsValues.findIndex( - (variable) => variable.name === "remuneration_brute", + prelevementsValues.findLastIndex((variable) => + ressourcesBrutes.includes(variable.name), ) + 1 - variableGroups = [ { variables: [ @@ -273,28 +274,24 @@ for (const row of variable.rows) { const key = `${variable.name}_${row.calculationName}` if ( - !Object.keys(variableCustomizations).includes(key) && - ((row.calculationName !== "law" && - row.calculationName !== "revaluation") || - !Object.keys(variableCustomizations).includes( - variable.name, - )) + variableCustomizations[variable.name] === undefined || + (variableCustomizations[key] === undefined && + row.calculationName !== "law" && + row.calculationName !== "revaluation") ) { const types = ["base", "prelevement", "prestation"] - variableCustomizations[key] = JSON.parse( - JSON.stringify( - variableCustomizations[ - getVariableCustomizationName( - variable.parent, - row.calculationName, - ) - ] ?? - defaultCustomization[waterfall.name][types[groupIndex]][ - row.calculationName === "revaluation" - ? "law" - : row.calculationName - ], - ), + variableCustomizations[key] = structuredClone( + variableCustomizations[ + getVariableCustomizationName( + variable.parent, + row.calculationName, + ) + ] ?? + defaultCustomization[waterfall.name][types[groupIndex]][ + row.calculationName === "revaluation" + ? "law" + : row.calculationName + ], ) } } @@ -369,28 +366,24 @@ for (const row of variable.rows) { const key = `${variable.name}_${row.calculationName}` if ( - !Object.keys(variableCustomizations).includes(key) && - ((row.calculationName !== "law" && - row.calculationName !== "revaluation") || - !Object.keys(variableCustomizations).includes( - variable.name, - )) + variableCustomizations[variable.name] === undefined || + (variableCustomizations[key] === undefined && + row.calculationName !== "law" && + row.calculationName !== "revaluation") ) { const types = ["base", "cotisation", "allegement"] - variableCustomizations[key] = JSON.parse( - JSON.stringify( - variableCustomizations[ - getVariableCustomizationName( - variable.parent, - row.calculationName, - ) - ] ?? - defaultCustomization[waterfall.name][types[groupIndex]][ - row.calculationName === "revaluation" - ? "law" - : row.calculationName - ], - ), + variableCustomizations[key] = structuredClone( + variableCustomizations[ + getVariableCustomizationName( + variable.parent, + row.calculationName, + ) + ] ?? + defaultCustomization[waterfall.name][types[groupIndex]][ + row.calculationName === "revaluation" + ? "law" + : row.calculationName + ], ) } }