From 777e14d690bda9c1bcfa95955b556b7c11a48945 Mon Sep 17 00:00:00 2001 From: Toufic Batache <taffou2a@gmail.com> Date: Thu, 4 Jul 2024 16:49:38 +0300 Subject: [PATCH] Added billActive context variable, added billMockValues environment variable, corrected README accordingly --- README.md | 10 +++--- example.env | 3 ++ src/lib/components/NavBar.svelte | 14 ++++----- src/lib/components/ReformsChanges.svelte | 3 +- src/lib/components/ValueChange.svelte | 27 +++++++++------- src/lib/components/ValueChangeCompare.svelte | 31 ++++++++++--------- .../test_cases/TestCaseGraph.svelte | 5 +-- .../VariableReferredScaleParameter.svelte | 4 +-- .../VariableReferredValueParameter.svelte | 4 +-- src/lib/server/auditors/config.ts | 8 ++++- src/lib/server/config.ts | 2 ++ src/routes/+layout.server.ts | 2 ++ src/routes/+layout.svelte | 14 +++++++-- src/routes/+page.svelte | 6 ++-- 14 files changed, 82 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index b70757766..c73a19c2b 100644 --- a/README.md +++ b/README.md @@ -47,29 +47,29 @@ Bravo ! Vous êtes prêts à utiliser et contribuer à `leximpact-socio-fiscal-u ### Afficher un contenu uniquement en mode PLF/PLFSS -Il faut utiliser la variable `billName` +Il faut utiliser la variable de contexte `billActive` Ajouter en haut du fichier : ```js - const billName = getContext("billName") as Writable<string | undefined> + const billActive = getContext("billActive") as Writable<boolean> ``` Et ensuite utiliser un test : ```js -{#if $billName === undefined} +{#if !$billActive} "COUCOU qui s'affiche si le PLF n'est pas activé" {/if} ``` ```js -{#if $billName === undefined} +{#if $billActive} "COUCOU qui s'affiche si le PLF est activé" {/if} ``` -$billName !== undefined => plf activé +$billActive => plf activé ### Ajouter une variable calculée dans le simulateur diff --git a/example.env b/example.env index 42dd53018..2f1eac40f 100644 --- a/example.env +++ b/example.env @@ -79,6 +79,9 @@ PROXY=false # Reform name must belong to a name of an OpenFisca reform in metadata.json # REFORM=reforme_test_1 +# Whether reform has mock values or not +# REFORM_MOCK_VALUES=false + # Optional name of revaluation reform to use # Reform name must belong to a name of an OpenFisca reform in metadata.json # REFORM_REVALUATION=contrefactuel_plf diff --git a/src/lib/components/NavBar.svelte b/src/lib/components/NavBar.svelte index 8e62ce2af..6e5980836 100644 --- a/src/lib/components/NavBar.svelte +++ b/src/lib/components/NavBar.svelte @@ -1,14 +1,14 @@ <script lang="ts"> - import type { SearchResult } from "minisearch" - import { getContext } from "svelte" - import type { Writable } from "svelte/store" - import { fade } from "svelte/transition" import { Menu, MenuButton, MenuItem, MenuItems, } from "@rgossiaux/svelte-headlessui" + import type { SearchResult } from "minisearch" + import { getContext } from "svelte" + import type { Writable } from "svelte/store" + import { fade } from "svelte/transition" import { browser } from "$app/environment" import { goto } from "$app/navigation" @@ -21,7 +21,7 @@ import WithLinkedVariablesSearchWorker from "$lib/search/search_worker_variables_with_linked?worker" import { newSimulationUrl } from "$lib/urls" - const billName = getContext("billName") as Writable<string | undefined> + const billActive = getContext("billActive") as Writable<boolean> const displayMode = getContext("displayMode") as Writable< DisplayMode | undefined > @@ -254,7 +254,7 @@ Socio-Fiscal </span> </div> - {#if billName !== undefined} + {#if $billActive} <div class="m-1 flex -rotate-6 flex-col rounded-sm bg-white p-0.5 px-1 pt-0 text-[0.62rem] text-le-gris-dispositif-dark shadow-lg" > @@ -453,7 +453,7 @@ <span class="font-light leading-4">LexImpact</span> <span class="text-lg leading-5">Socio-Fiscal</span> </div> - {#if billName !== undefined} + {#if $billActive} <div class="m-1 flex -rotate-6 flex-col rounded-sm bg-white p-0.5 px-1 py-0 text-[0.62rem] text-le-gris-dispositif-dark shadow-lg" > diff --git a/src/lib/components/ReformsChanges.svelte b/src/lib/components/ReformsChanges.svelte index 36d56d8e6..1b19926ca 100644 --- a/src/lib/components/ReformsChanges.svelte +++ b/src/lib/components/ReformsChanges.svelte @@ -22,6 +22,7 @@ export let displayMode: DisplayMode + const billActive = getContext("billActive") as Writable<boolean> const billName = getContext("billName") as Writable<string | undefined> const parametricReform = getContext( "parametricReform", @@ -70,7 +71,7 @@ )[0] </script> -{#if $billName !== undefined} +{#if $billActive} <div class="m-2 mb-6 lg:m-4"> <h4 class="text-xs font-bold text-le-rouge-bill lg:text-sm"> Projet de loi du Gouvernement : diff --git a/src/lib/components/ValueChange.svelte b/src/lib/components/ValueChange.svelte index 7991adb81..4428ef9ae 100644 --- a/src/lib/components/ValueChange.svelte +++ b/src/lib/components/ValueChange.svelte @@ -13,7 +13,8 @@ export let valueByCalculationName: VariableValueByCalculationName export let bold = false - const billName = getContext("billName") as Writable<string | undefined> + const billActive = getContext("billActive") as Writable<boolean> + const billMockValues = getContext("billMockValues") as Writable<boolean> let introWarningBillModalOpen = false const yearPLF = getContext("yearPLF") as Writable<number> @@ -105,7 +106,7 @@ ? `Droit attendu en ${$yearPLF} suite aux revalorisations automatiques prévues dans la loi, sans les modifications qui seront apportées par le PLF et le PLFSS ${$yearPLF}.` : `Droit en vigueur en ${$yearPLF - 1}`} > - {#if $billName !== undefined} + {#if $billActive} Droit {$yearPLF} <br />sans PLF/PLSS {:else} Droit en vigueur @@ -130,16 +131,18 @@ > PLF/PLFSS {$yearPLF} <br /> - <!-- QUAND FAUX PLF--> - <span class="bg-orange-200 px-1"> - ⚠️ - <a - class="italic text-orange-800 hover:underline cursor-pointer" - on:click={() => (introWarningBillModalOpen = true)} - > - à confirmer avec PLF/PLFSS - </a> - </span> + {#if $billMockValues} + <!-- FAUX PLF--> + <span class="bg-orange-200 px-1"> + ⚠️ + <button + class="italic text-orange-800 hover:underline cursor-pointer" + on:click={() => (introWarningBillModalOpen = true)} + > + à confirmer avec PLF/PLFSS + </button> + </span> + {/if} </span> {/if} </span> diff --git a/src/lib/components/ValueChangeCompare.svelte b/src/lib/components/ValueChangeCompare.svelte index 797b2ad67..5a6cefd45 100644 --- a/src/lib/components/ValueChangeCompare.svelte +++ b/src/lib/components/ValueChangeCompare.svelte @@ -11,7 +11,8 @@ export let valueByCalculationName1: VariableValueByCalculationName export let legend = false - const billName = getContext("billName") as Writable<string | undefined> + const billActive = getContext("billActive") as Writable<boolean> + const billMockValues = getContext("billMockValues") as Writable<boolean> let introWarningBillModalOpen = false const yearPLF = getContext("yearPLF") as Writable<number> @@ -143,7 +144,7 @@ class="ml-1 text-xs font-normal underline decoration-dotted" title="Droit attendu en {$yearPLF} suite aux revalorisations automatiques prévues dans la loi, sans les modifications qui seront apportées par le PLF et le PLFSS {$yearPLF}" > - {#if $billName !== undefined} + {#if $billActive} Droit {$yearPLF} <br />sans PLF/PLSS {:else} Droit en vigueur @@ -170,7 +171,7 @@ class="ml-1 self-center text-xs font-normal text-gray-500 underline decoration-dotted" title="Droit attendu en {$yearPLF} suite aux revalorisations automatiques prévues dans la loi, sans les modifications qui seront apportées par le PLF et le PLFSS {$yearPLF}." > - {#if $billName !== undefined} + {#if $billActive} Droit {$yearPLF} <br />sans PLF/PLSS {:else} Droit en vigueur @@ -195,7 +196,7 @@ class="ml-1 self-center text-xs font-normal text-gray-500 underline decoration-dotted" title="Droit attendu en {$yearPLF} suite aux revalorisations automatiques prévues dans la loi, sans les modifications qui seront apportées par le PLF et le PLFSS {$yearPLF}." > - {#if $billName !== undefined} + {#if $billActive} Droit {$yearPLF} <br />sans PLF/PLSS {:else} Droit en vigueur @@ -221,16 +222,18 @@ <div class="ml-1 text-xs font-normal text-le-rouge-bill"> PLF/PLFSS {$yearPLF} <br /> - <!-- QUAND FAUX PLF --> - <span class="bg-orange-200 px-1"> - ⚠️ - <a - class="italic text-orange-800 hover:underline cursor-pointer" - on:click={() => (introWarningBillModalOpen = true)} - > - à confirmer avec PLF/PLFSS - </a> - </span> + {#if $billMockValues} + <!-- FAUX PLF --> + <span class="bg-orange-200 px-1"> + ⚠️ + <button + class="italic text-orange-800 hover:underline cursor-pointer" + on:click={() => (introWarningBillModalOpen = true)} + > + à confirmer avec PLF/PLFSS + </button> + </span> + {/if} </div> {/if} </div> diff --git a/src/lib/components/test_cases/TestCaseGraph.svelte b/src/lib/components/test_cases/TestCaseGraph.svelte index 1e20b2efe..e037607d5 100644 --- a/src/lib/components/test_cases/TestCaseGraph.svelte +++ b/src/lib/components/test_cases/TestCaseGraph.svelte @@ -78,6 +78,7 @@ export let waterfall: Waterfall export let year: number + const billActive = getContext("billActive") as Writable<boolean> const billName = getContext("billName") as Writable<string | undefined> const calculationByName = getContext( "calculationByName", @@ -1608,7 +1609,7 @@ > <h3 class="font-semibold text-gray-900"> Déciles de niveau de vie - {#if $billName !== undefined} + {#if $billActive} droit {$yearPLF} <br />sans PLF/PLSS {:else} droit {$yearPLF - 1} @@ -1642,7 +1643,7 @@ </div> </Tooltip> <span class="text-nowrap text-xs" - >({#if $billName !== undefined} + >({#if $billActive} droit {$yearPLF} <br />sans PLF/PLSS {:else} droit {$yearPLF - 1} diff --git a/src/lib/components/variables/VariableReferredScaleParameter.svelte b/src/lib/components/variables/VariableReferredScaleParameter.svelte index c9b2c6809..a59ae5f91 100644 --- a/src/lib/components/variables/VariableReferredScaleParameter.svelte +++ b/src/lib/components/variables/VariableReferredScaleParameter.svelte @@ -48,7 +48,7 @@ export let name: string | undefined = undefined export let revaluationParameter: ScaleParameter - const billName = getContext("billName") as Writable<string | undefined> + const billActive = getContext("billActive") as Writable<boolean> const dateFormatter = new Intl.DateTimeFormat("fr-FR", { dateStyle: "full" }) .format let isInflationLawInfoModalOpen = false @@ -220,7 +220,7 @@ title="Droit attendu en {$yearPLF} suite aux revalorisations automatiques prévues dans la loi, sans les modifications qui seront apportées par le PLF et le PLFSS {$yearPLF}." class="font-bold underline decoration-dotted" > - {#if $billName !== undefined} + {#if $billActive} Droit {$yearPLF} <br />sans PLF/PLSS {:else} Droit en vigueur diff --git a/src/lib/components/variables/VariableReferredValueParameter.svelte b/src/lib/components/variables/VariableReferredValueParameter.svelte index 52d8a9ca8..41beba90a 100644 --- a/src/lib/components/variables/VariableReferredValueParameter.svelte +++ b/src/lib/components/variables/VariableReferredValueParameter.svelte @@ -60,8 +60,8 @@ export let name: string | undefined = undefined export let revaluationParameter: ValueParameter + const billActive = getContext("billActive") as Writable<boolean> let billLatestInstantValueCouplesArray: [string, ValueAtInstant][] - const billName = getContext("billName") as Writable<string | undefined> const dateFormatter = new Intl.DateTimeFormat("fr-FR", { dateStyle: "full" }) .format let isLawInfoModalOpen = false @@ -294,7 +294,7 @@ title="Droit attendu en {$yearPLF} suite aux revalorisations automatiques prévues dans la loi, sans les modifications qui seront apportées par le PLF et le PLFSS {$yearPLF}." class="font-bold underline decoration-dotted" > - {#if $billName !== undefined} + {#if $billActive} Droit {$yearPLF} <br />sans PLF/PLSS {:else} Droit en vigueur diff --git a/src/lib/server/auditors/config.ts b/src/lib/server/auditors/config.ts index 823d02997..55f963eaa 100644 --- a/src/lib/server/auditors/config.ts +++ b/src/lib/server/auditors/config.ts @@ -31,7 +31,13 @@ export function auditConfig( const errors: { [key: string]: unknown } = {} const remainingKeys = new Set(Object.keys(data)) - for (const key of ["advanced", "allowRobots", "proxy", "showTutorial"]) { + for (const key of [ + "advanced", + "allowRobots", + "proxy", + "reformMockValues", + "showTutorial", + ]) { audit.attribute( data, key, diff --git a/src/lib/server/config.ts b/src/lib/server/config.ts index c586df34a..befdbb6be 100644 --- a/src/lib/server/config.ts +++ b/src/lib/server/config.ts @@ -33,6 +33,7 @@ export interface Config { } portalUrl: string proxy: boolean + reformMockValues?: boolean reformName?: string revaluationName?: string showTutorial?: boolean @@ -84,6 +85,7 @@ const [validConfig, error] = validateConfig({ : null, portalUrl: process.env["PORTAL_URL"], proxy: process.env["PROXY"], + reformMockValues: process.env["REFORM_MOCK_VALUES"], reformName: process.env["REFORM"], revaluationName: process.env["REFORM_REVALUATION"], showTutorial: process.env["SHOW_TUTORIAL"], diff --git a/src/routes/+layout.server.ts b/src/routes/+layout.server.ts index 9d94316fd..f6bc0f01f 100644 --- a/src/routes/+layout.server.ts +++ b/src/routes/+layout.server.ts @@ -28,6 +28,7 @@ export const load: LayoutServerLoad = async ( } openfiscaRepository: RepositoryConfig portalUrl: string + reformMockValues?: boolean reformName?: string revaluationName?: string showTutorial?: boolean @@ -62,6 +63,7 @@ export const load: LayoutServerLoad = async ( urlTemplate: openfiscaRepository.urlTemplate, }, portalUrl: config.portalUrl, + reformMockValues: config.reformMockValues, reformName: config.reformName, revaluationName: config.revaluationName, showTutorial: config.showTutorial, diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index f09e77321..10a96c745 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -91,6 +91,10 @@ const calculationByName: Writable<CalculationByName> = writable({}) setContext("calculationByName", calculationByName) + /** + * Bill (PLF) + */ + let currentBillName: string | undefined = data.reformName === undefined ? undefined @@ -99,6 +103,12 @@ : data.reformName const billName: Writable<string | undefined> = writable(currentBillName) setContext("billName", billName) + const billActive: Writable<boolean> = writable(currentBillName !== undefined) + setContext("billActive", billActive) + const billMockValues: Writable<boolean> = writable( + data.reformMockValues === true, + ) + setContext("billMockValues", billMockValues) let currentRevaluationName: string | undefined = data.revaluationName === undefined @@ -258,7 +268,7 @@ const yearPLF = writable( new Date().getFullYear() + - (currentBillName !== undefined && new Date().getMonth() > 1 ? 1 : 0), + ($billActive && new Date().getMonth() > 1 ? 1 : 0), ) setContext("yearPLF", yearPLF) @@ -580,7 +590,7 @@ } const billSituationIndex = situationIndexByCalculationName.bill - if (billSituationIndex !== undefined && $billName !== undefined) { + if (billSituationIndex !== undefined && $billActive) { const calculation: Calculation = (newCalculationByName.bill = { running: true, }) diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index eaac73432..0f039f0c4 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -93,6 +93,7 @@ export let data: PageData let animationEndedTimeoutId = undefined + const billActive = getContext("billActive") as Writable<boolean> const billName = getContext("billName") as Writable<string | undefined> const budgetSimulation = getContext("budgetSimulation") as Writable< BudgetSimulation | undefined @@ -432,8 +433,7 @@ $: modificationsAmendmentCount = Object.keys($parametricReform).length - $: modificationsCount = - modificationsAmendmentCount + ($billName !== undefined ? 1 : 0) + $: modificationsCount = modificationsAmendmentCount + ($billActive ? 1 : 0) $: showBudgetBlurred = displayMode.budget && @@ -1154,7 +1154,7 @@ : `${modificationsCount} modifications`} </div> <div class="absolute -top-3 -right-2 flex"> - {#if $billName !== undefined} + {#if $billActive} <span class="z-10 w-5 h-5 flex justify-center items-center shadow rounded-full bg-le-rouge-bill text-black text-xs font-bold tracking-wider border-[1.5px] border-white transition-all duration-200 ease-out-back translate-x-2" class:translate-x-6={!showBudgetParametersError} -- GitLab