diff --git a/src/main/resources/lib/ssb/parts/simpleStatbank.ts b/src/main/resources/lib/ssb/parts/simpleStatbank.ts index 2ac8d74c9..53ef0aee8 100644 --- a/src/main/resources/lib/ssb/parts/simpleStatbank.ts +++ b/src/main/resources/lib/ssb/parts/simpleStatbank.ts @@ -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( @@ -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) { @@ -44,7 +41,6 @@ export function getStatbankApiData( } export interface SimpleStatbankResult { - time: string data: DimensionData[] } @@ -52,4 +48,5 @@ interface DimensionData { displayName: string dataCode: string value: (string | number)[] + time: string } diff --git a/src/main/resources/site/parts/simpleStatbank/simpleStatbank.jsx b/src/main/resources/site/parts/simpleStatbank/simpleStatbank.jsx index 748e44589..4b8bea71f 100644 --- a/src/main/resources/site/parts/simpleStatbank/simpleStatbank.jsx +++ b/src/main/resources/site/parts/simpleStatbank/simpleStatbank.jsx @@ -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 = return (