Skip to content

Commit

Permalink
MIM-1723:Fixed data i dimensionCode is Tid
Browse files Browse the repository at this point in the history
  • Loading branch information
ssb-cgn committed Jan 22, 2024
1 parent 6a8b174 commit 0d94bfe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
21 changes: 9 additions & 12 deletions src/main/resources/lib/ssb/parts/simpleStatbank.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-ignore
import JSONstat from 'jsonstat-toolkit/import.mjs'
import { type Dataset, type Data, type Dimension } from '/lib/types/jsonstat-toolkit'
import { type Dataset, type Data, type Dimension, Category } from '/lib/types/jsonstat-toolkit'
import { fetchStatbankApiDataQuery } from '/lib/ssb/dataset/statbankApi/statbankApi'

export function getStatbankApiData(
Expand All @@ -17,24 +17,21 @@ export function getStatbankApiData(

try {
const result: DimensionData[] = dataDimensions.map(function (dataDimension: string) {
const values = timeDimensions.map((timeDimension) => {
const data: Data | null = dataset?.Data({
[dimensionCode]: dataDimension,
Tid: timeDimension,
}) as Data
const data: Data | null = dataset?.Data({
[dimensionCode]: dataDimension,
}) as Data

return data.value ?? data.status
})
const filterCategory: Category | null = filterDimensionCode?.Category(dataDimension) as Category | null

return {
displayName: filterDimensionCode?.Category(dataDimension)?.label,
displayName: filterCategory ? filterCategory.label : '',
dataCode: dataDimension, // Hvis vi må ta høyde for at de dytter inn mer enn en dimensjon her må det hånderes
value: values[0], // Forventer at dette arryayet kun har et element (kun en tidsserie)
value: data.value ?? data.status, // Forventer at dette arryayet kun har et element (kun en tidsserie)
time: dimensionCode === 'Tid' ? dataDimension : timeDimensions[0],
}
})

return {
time: timeDimensions[0],
data: result,
}
} catch (error) {
Expand All @@ -44,12 +41,12 @@ export function getStatbankApiData(
}

export interface SimpleStatbankResult {
time: string
data: DimensionData[]
}

interface DimensionData {
displayName: string
dataCode: string
value: (string | number)[]
time: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function SimpleStatbank(props) {
function renderResult() {
if (selectedValue) {
const result = Number(selectedValue.value) > 0 ? selectedValue.value : '-'
const resultView = resultLayout.replace('{value}', result).replace('{time}', statbankApiData.time)
const resultView = resultLayout.replace('{value}', result).replace('{time}', selectedValue.time)
const textResult = <span dangerouslySetInnerHTML={{ __html: resultView }} />
return (
<div>
Expand All @@ -49,6 +49,7 @@ function SimpleStatbank(props) {
id: element.dataCode,
title: selectDisplay == 'text' ? element.displayName : `${element.dataCode}: ${element.displayName}`,
value: element.value,
time: element.time,
}))
: []
return (
Expand Down Expand Up @@ -91,7 +92,6 @@ SimpleStatbank.propTypes = {
urlOrId: PropTypes.string,
selectDisplay: PropTypes.string,
statbankApiData: PropTypes.objectOf({
time: PropTypes.string,
data: PropTypes.object,
}),
}
Expand Down

0 comments on commit 0d94bfe

Please sign in to comment.