Skip to content
Snippets Groups Projects
Unverified Commit d41751c1 authored by Dorine Lambinet's avatar Dorine Lambinet
Browse files

Supprime composant ValueChangeGraph

parent 621b69b4
Branches
Tags
1 merge request!296Resolve "Panneau d'information du graphique"
Pipeline #19414 passed
<script lang="ts">
import { shared } from "$lib/shared.svelte"
import { valueFormatter } from "$lib/values"
import type { VariableValueByCalculationName } from "$lib/variables"
interface Props {
showLoader?: boolean
unitName: string | undefined | null
valueByCalculationName: VariableValueByCalculationName
children?: import("svelte").Snippet<[any]>
}
let {
showLoader = true,
unitName,
valueByCalculationName,
children,
}: Props = $props()
function mustShowAmendmentValue(
amendmentValueFormatted: string | undefined,
billValueFormatted: string | undefined,
lawValueFormatted: string | undefined,
revaluationValueFormatted: string | undefined,
): boolean {
if (amendmentValueFormatted === undefined) {
return false
}
if (billValueFormatted !== undefined) {
return amendmentValueFormatted !== billValueFormatted
}
if (revaluationValueFormatted !== undefined) {
return amendmentValueFormatted !== revaluationValueFormatted
}
return amendmentValueFormatted !== lawValueFormatted
}
let amendmentValue = $derived(
valueByCalculationName.amendment as number | undefined,
)
let billValue = $derived(valueByCalculationName.bill as number | undefined)
let lawValue = $derived(valueByCalculationName.law as number | undefined)
let revaluationValue = $derived(
valueByCalculationName.revaluation as number | undefined,
)
let baseValue = $derived(
lawValue === undefined
? revaluationValue === undefined
? billValue === undefined
? amendmentValue
: billValue
: revaluationValue
: lawValue,
)
let format = $derived(valueFormatter(baseValue, unitName))
let runningCalculationNames = $derived(
Object.entries(shared.calculationByName)
.filter(([, calculation]) => calculation.running)
.map(([calculationName]) => calculationName),
)
let modificationsAmendmentCount = $derived(
Object.keys(shared.parametricReform).length,
)
let amendmentValueFormatted = $derived(
amendmentValue === undefined ? undefined : format(amendmentValue),
)
let billValueFormatted = $derived(
billValue === undefined ? undefined : format(billValue),
)
let lawValueFormatted = $derived(
lawValue === undefined ? undefined : format(lawValue),
)
let revaluationValueFormatted = $derived(
revaluationValue === undefined ? undefined : format(revaluationValue),
)
let showLawValue = $derived(lawValueFormatted !== undefined)
let showRevaluationValue = $derived(
revaluationValueFormatted !== undefined &&
revaluationValueFormatted !== lawValueFormatted,
)
let showBillValue = $derived(
billValueFormatted !== undefined &&
(showRevaluationValue
? billValueFormatted !== revaluationValueFormatted
: billValueFormatted !== lawValueFormatted),
)
let showAmendmentValue = $derived(
mustShowAmendmentValue(
amendmentValueFormatted,
billValueFormatted,
lawValueFormatted,
revaluationValueFormatted,
),
)
</script>
<ul class="flex flex-col">
{#if showLoader && (runningCalculationNames.includes("law") || runningCalculationNames.includes("revaluation"))}
<li class="animate-pulse-2 bg-gray-500 px-1 text-black blur-xs">
<span class="text-white blur">value €</span>&nbsp;/an
</li>
{:else if showLawValue || showRevaluationValue}
<li
class={showBillValue
? "line-through-bill "
: showAmendmentValue
? "line-through-amendment "
: ""}
>
{showRevaluationValue
? revaluationValueFormatted
: lawValueFormatted}&nbsp;/an
{@render children?.({
lawOrRevaluationValue: showRevaluationValue
? revaluationValue
: lawValue,
})}
</li>
{/if}
{#if showLoader && runningCalculationNames.includes("bill")}
<li class="animate-pulse-2 bg-le-rouge-bill px-1 text-black blur-xs">
<span class="text-white blur">value €</span>&nbsp;/an
</li>
{:else if showBillValue}
<li
class="text-le-rouge-bill"
class:line-through-amendment={showAmendmentValue}
>
{billValueFormatted}&nbsp;/an
</li>
{/if}
{#if showLoader && runningCalculationNames.includes("amendment") && modificationsAmendmentCount > 0}
<li class="animate-pulse-2 bg-le-jaune px-1 text-black blur-xs">
<span class="text-white blur">value €</span>&nbsp;/an
</li>
{:else if showAmendmentValue}
<li class="bg-le-jaune px-1 text-black">
{amendmentValueFormatted}&nbsp;/an
</li>
{/if}
</ul>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment