Skip to content

Commit

Permalink
Merge pull request #3082 from statisticsnorway/MIM-2092-manual-date-i…
Browse files Browse the repository at this point in the history
…nput-for-keyFigures

[MIM-2092] Mim 2092 manual date input for key figures
  • Loading branch information
Carl-OW authored Jan 10, 2025
2 parents de8cbd4 + a95b090 commit fc90abf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/main/resources/lib/types/partTypes/keyFigure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface KeyFigureProps {
hiddenTitle: string
isInStatisticsPage: boolean
isMacro: boolean
dateInput?: string | undefined
}

export interface KeyFigureData {
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/site/content-types/keyFigure/keyFigure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
<allow-child-content>true</allow-child-content>
<form>
<mixin name="dataSource" />
<input name="dateInput" type="TextLine">
<label>Dato</label>
<occurrences minimum="0" maximum="1" />
<config/>
</input>
<input name="manualSource" type="TextLine">
<label>Manuell verdi</label>
<occurrences minimum="0" maximum="1" />
Expand Down
31 changes: 18 additions & 13 deletions src/main/resources/site/parts/keyFigure/keyFigure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,31 @@ function renderKeyFigure(
config?: KeyFigurePartConfig
): XP.Response {
const draftExist = !!parsedKeyFiguresDraft
const rawDateInput = page.data.dateInput as string | undefined
const dateInput = rawDateInput ? rawDateInput : undefined

const existingTimeValue = parsedKeyFigures.find((keyFigure) => keyFigure.time)?.time

const timeValue = existingTimeValue || dateInput || undefined

if ((parsedKeyFigures && parsedKeyFigures.length > 0) || draftExist) {
const hiddenTitle: Array<string> = parsedKeyFigures.map((keyFigureData) => {
return keyFigureData.title
})

const props: KeyFigureProps = {
displayName: config && config.title,
keyFigures: parsedKeyFigures.map((keyFigureData) => {
return {
...keyFigureData,
glossary: keyFigureData.glossaryText,
}
}),
displayName: config?.title,
keyFigures: parsedKeyFigures.map((keyFigureData) => ({
...keyFigureData,
time: timeValue,
glossary: keyFigureData.glossaryText,
})),
keyFiguresDraft: parsedKeyFiguresDraft
? parsedKeyFiguresDraft.map((keyFigureDraftData) => {
return {
...keyFigureDraftData,
glossary: keyFigureDraftData.glossaryText,
}
})
? parsedKeyFiguresDraft.map((keyFigureDraftData) => ({
...keyFigureDraftData,
time: timeValue,
glossary: keyFigureDraftData.glossaryText,
}))
: undefined,
sourceLabel: getPhrases(page)!.source,
source: config?.source,
Expand Down

0 comments on commit fc90abf

Please sign in to comment.