Skip to content
Snippets Groups Projects
Commit be962ef8 authored by Emmanuel Raviart's avatar Emmanuel Raviart
Browse files

Improve formatting of values in ValueChange.

parent 4b469439
No related branches found
No related tags found
No related merge requests found
<script lang="ts">
import type { VariableValueByCalculationName } from "$lib/variables"
import type { Unit } from "@openfisca/json-model"
const euroAmountFormatter = new Intl.NumberFormat("fr-FR", {
currency: "EUR",
maximumFractionDigits: 0,
minimumFractionDigits: 0,
style: "currency",
})
import type { VariableValueByCalculationName } from "$lib/variables"
export let unit: Unit | undefined | null
export let valueByCalculationName: VariableValueByCalculationName
$: amendmentValue = valueByCalculationName.amendment as number | undefined
$: amendmentValueFormatted =
amendmentValue === undefined
? undefined
: euroAmountFormatter.format(amendmentValue)
$: billValue = valueByCalculationName.bill as number | undefined
$: billValueFormatted =
billValue === undefined ? undefined : euroAmountFormatter.format(billValue)
$: lawValue = valueByCalculationName.law as number | undefined
$: lawValueFormatted = euroAmountFormatter.format(lawValue)
$: baseValue =
lawValue === undefined
? billValue === undefined
? amendmentValue
: billValue
: lawValue
$: format = (
baseValue === undefined
? () => ""
: typeof baseValue === "boolean"
? (value: boolean) => (value ? "vrai" : "faux")
: typeof baseValue === "number"
? unit != null && unit.startsWith("currency-")
? new Intl.NumberFormat("fr-FR", {
currency: unit.replace(/^currency-/, ""),
maximumFractionDigits: 0,
minimumFractionDigits: 0,
style: "currency",
}).format
: new Intl.NumberFormat("fr-FR").format
: (value: unknown) => value.toString()
) as (value: unknown) => string
$: amendmentValueFormatted =
amendmentValue === undefined ? undefined : format(amendmentValue)
$: billValueFormatted =
billValue === undefined ? undefined : format(billValue)
$: lawValueFormatted = lawValue === undefined ? undefined : format(lawValue)
$: showAmendmentValue = mustShowAmendmentValue(
amendmentValueFormatted,
......@@ -35,6 +53,8 @@
$: showBillValue =
billValueFormatted !== undefined && billValueFormatted !== lawValueFormatted
$: showLawValue = lawValueFormatted !== undefined
function mustShowAmendmentValue(
amendmentValueFormatted: string | undefined,
billValueFormatted: string | undefined,
......@@ -50,6 +70,7 @@
}
</script>
{#if showLawValue}
<span
class={showBillValue
? "line-through-bill"
......@@ -57,6 +78,7 @@
? "line-through-amendment"
: ""}>{lawValueFormatted}</span
>
{/if}
{#if showBillValue}
<span
class="text-le-rouge-bill"
......
......@@ -4,6 +4,7 @@
Variable,
Waterfall,
} from "@openfisca/json-model"
import { Unit } from "@openfisca/json-model"
import { createEventDispatcher, getContext } from "svelte"
import type { Writable } from "svelte/store"
......@@ -422,6 +423,7 @@
title="⚠️ Les dispositifs n'étant pas tous à jour, ce montant est à considérer avec prudence."
>
<ValueChange
unit={Unit.CurrencyEUR}
valueByCalculationName={{
amendment:
Object.keys($parametricReform).length === 0
......
......@@ -329,6 +329,7 @@
>{/if}
{:else}
<ValueChange
unit={null}
valueByCalculationName={getCalculatedVariableValueByCalculationName(
situation,
valuesByCalculationNameByVariableName,
......
......@@ -166,6 +166,7 @@ export function labelFromUnit(
[Unit.CodesDepartements]: "code département",
[Unit.CountryCode]: "code pays",
[Unit.Currency]: metadata.currency,
[Unit.CurrencyEUR]: "",
[Unit.CurrencyFRF]: "FRF",
[Unit.CurrencyGBP]: "£",
[Unit.CurrencyUSD]: "$",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment