Skip to content
Snippets Groups Projects
Commit b667c9cc authored by Emmanuel Raviart's avatar Emmanuel Raviart Committed by Dorine Lambinet
Browse files

Fix display of references in parameter view when parameter is a value.

parent a1107e71
No related branches found
No related tags found
1 merge request!21Fusion commits ui parametres
......@@ -19,6 +19,7 @@
import ReferencesView from "$lib/components/parameters/ReferencesView.svelte"
import ScaleView from "$lib/components/parameters/ScaleView.svelte"
import {
buildInstantReferencesAndValueArray,
labelFromScaleType,
labelFromUnit,
labelFromValueType,
......@@ -167,10 +168,12 @@
</tr>
</thead>
<tbody>
{#each Object.entries(parameter.values).sort( ([instant1], [instant2]) => instant2.localeCompare(instant1), ) as [instant, valueAtInstant]}
{#each buildInstantReferencesAndValueArray(parameter) as { instant, references, valueAtInstant }}
<tr>
<td class="border p-1 font-serif text-center">{instant}</td>
{#if valueAtInstant === "expected"}
{#if valueAtInstant === undefined}
<td class="border italic p-1 text-center" colspan="2" />
{:else if valueAtInstant === "expected"}
<td class="border italic p-1 text-center" colspan="3"
>valeur attendue</td
>
......@@ -186,16 +189,21 @@
? labelFromUnit(metadata, parameter.unit)
: ""}</td
>
{/if}
{#if valueAtInstant !== "expected"}
<td class="border p-1 text-center"
>{#if valueAtInstant.reference !== undefined}
>{#if references.length > 0}
<ul>
{#each valueAtInstant.reference as { href, title }}
{#each references as { href, note, title }}
<li>
{#if href === undefined}{title}{:else}<a
class="link"
{href}
target="_blank">{title ?? "source"}</a
>{/if}
{#if note}
<p>{note}</p>
{/if}
</li>
{/each}
</ul>{/if}</td
......
......@@ -12,19 +12,17 @@
import ValueAtInstantEdit from "$lib/components/parameters/ValueAtInstantEdit.svelte"
import { errorAsKeyValueDictionary, iterArrayWithErrors } from "$lib/errors"
import { iterToLimit } from "$lib/iterators"
import { labelFromValueType, labelFromUnit } from "$lib/parameters"
import {
buildInstantReferencesAndValueArray,
labelFromValueType,
labelFromUnit,
} from "$lib/parameters"
let globalErrors: { [key: string]: unknown }
export { globalErrors as errors }
export let parameter: ValueParameter
export let showErrors: boolean
interface InstantReferencesAndValue {
instant: string
references: Reference[]
valueAtInstant?: ValueAtInstant
}
let errors = globalErrors
let instantReferencesAndValueArray =
buildInstantReferencesAndValueArray(parameter)
......@@ -45,36 +43,6 @@
updateParameter()
}
function buildInstantReferencesAndValueArray(
parameter: ValueParameter,
): InstantReferencesAndValue[] {
const instantReferencesAndValueByInstant: {
[instant: string]: InstantReferencesAndValue
} = Object.fromEntries(
Object.entries(parameter.values ?? {}).map(
([instant, valueAtInstant]) => [
instant,
{ instant, references: [], valueAtInstant },
],
),
)
if (parameter.reference !== undefined) {
for (const [instant, references] of Object.entries(parameter.reference)) {
if (instantReferencesAndValueByInstant[instant] === undefined) {
instantReferencesAndValueByInstant[instant] = {
instant,
references,
}
} else {
instantReferencesAndValueByInstant[instant].references = references
}
}
}
return Object.entries(instantReferencesAndValueByInstant)
.sort(([instant1], [instant2]) => instant2.localeCompare(instant1))
.map(([_instant, instantReferencesAndValue]) => instantReferencesAndValue)
}
function changeInstant(index, { target }: Event) {
const { value: instant } = target as HTMLInputElement
const [validInstant, error] = auditDateIso8601String(laxAudit, instant)
......
import type { Metadata } from "@openfisca/ast"
import type {
Metadata,
Reference,
ValueAtInstant,
ValueParameter,
} from "@openfisca/ast"
import {
AmountUnit,
ParameterClass,
......@@ -8,6 +13,40 @@ import {
ValueType,
} from "@openfisca/ast"
export interface InstantReferencesAndValue {
instant: string
references: Reference[]
valueAtInstant?: ValueAtInstant
}
export function buildInstantReferencesAndValueArray(
parameter: ValueParameter,
): InstantReferencesAndValue[] {
const instantReferencesAndValueByInstant: {
[instant: string]: InstantReferencesAndValue
} = Object.fromEntries(
Object.entries(parameter.values ?? {}).map(([instant, valueAtInstant]) => [
instant,
{ instant, references: [], valueAtInstant },
]),
)
if (parameter.reference !== undefined) {
for (const [instant, references] of Object.entries(parameter.reference)) {
if (instantReferencesAndValueByInstant[instant] === undefined) {
instantReferencesAndValueByInstant[instant] = {
instant,
references,
}
} else {
instantReferencesAndValueByInstant[instant].references = references
}
}
}
return Object.entries(instantReferencesAndValueByInstant)
.sort(([instant1], [instant2]) => instant2.localeCompare(instant1))
.map(([_instant, instantReferencesAndValue]) => instantReferencesAndValue)
}
export function labelFromParameterClass(
parameterClass: ParameterClass | string,
): string {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment