Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIM-1077] Improved user feedback on PIF calculator #2271

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions src/main/resources/react4xp/_entries/PifCalculator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { X } from 'react-feather'

function PifCalculator(props) {
const validMaxYear = props.lastUpdated.year
const { pifErrorMarket, pifErrorProduct, calculatorValidateAmountNumber, pifValidateYear } = props.phrases
const { pifErrorProduct, calculatorValidateAmountNumber, pifValidateYear } = props.phrases
const [scopeCode, setScopeCode] = useState({
error: false,
errorMsg: pifErrorMarket,
errorMsg: '',
value: '',
})
const [productGroup, setProductGroup] = useState({
Expand All @@ -29,8 +29,7 @@ function PifCalculator(props) {
errorMsg: props.lastNumberText,
value: '',
})
// Differentiate validMinYear based on selected market
const validMinYear = scopeCode.value === '3' ? 1926 : 1977
const validMinYear = getStartYearRelevantDataset()
const validMinYearPhrase = pifValidateYear.replaceAll('{0}', validMinYear)
const validYearErrorMsg = `${validMinYearPhrase} ${validMaxYear}`
const [startYear, setStartYear] = useState({
Expand Down Expand Up @@ -141,8 +140,31 @@ function PifCalculator(props) {
})
}

function getStartYearRelevantDataset() {
// Datasets available from 1977 for home market
if (scopeCode.value === '2') return 1977
// Datasets available from 1953 for home and import market with spesific product type
if (scopeCode.value === '3' && productGroup.value && productGroup.value !== 'SITCT') return 1953
// Datasets available from 1926 for home and import market and product type 'all'
return 1926
}

function isFormValid() {
return isStartValueValid() && isStartYearValid() && isStartMonthValid() && isEndYearValid() && isEndMonthValid()
return (
haveDatasetForChosenProductGroup() &&
isStartValueValid() &&
isStartYearValid() &&
isStartMonthValid() &&
isEndYearValid() &&
isEndMonthValid()
)
}

function haveDatasetForChosenProductGroup(scopeCodeValue, productGroupValue) {
// Dataset not available for pifProductOil (SITC4) for home market
const productGroupChosen = productGroupValue || productGroup.value
const scopeCodeChosen = scopeCodeValue || scopeCode.value
return !(productGroupChosen === 'SITC4' && scopeCodeChosen === '2')
}

function isStartValueValid(value) {
Expand Down Expand Up @@ -235,12 +257,17 @@ function PifCalculator(props) {
...scopeCode,
value: value,
})
setProductGroup({
...productGroup,
error: !haveDatasetForChosenProductGroup(value, productGroup.value),
})
break
}
case 'product-group': {
setProductGroup({
...productGroup,
value: value.id,
error: !haveDatasetForChosenProductGroup(scopeCode.value, value.id),
})
break
}
Expand Down Expand Up @@ -359,6 +386,8 @@ function PifCalculator(props) {
}}
items={props.productGroups}
ariaLabel={props.phrases.pifProductTypeHeader}
error={productGroup.error}
errorMessage={productGroup.errorMsg}
/>
)
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/resources/site/i18n/phrases.properties
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ calculatorMonthAverageFrontpage = Alle
pifServiceValidateStartMonth = Startmåned er ikke gyldig for denne utregningen
pifServiceValidateEndMonth = Sluttmåned er ikke gyldig for denne utregningen
pifValidateMonth = Finnes ikke data for tidspunkt. For inneværende år må måned velges.
pifValidateYear = Du kan kun skrive inn årstall fra {0} til
pifValidateYear = Data kun tilgjengelig fra {0} til
pifAmountEqualled = Beløpet tilsvarer
pifCalculatorInfoTitle = Merk!
pifCalculatorInfoText = Beregningene viser utviklingen i kroneverdi når en tar utgangspunktet i konsumprisindeksen. Kalkulatoren viser ikke hva enkeltvarer bør eller skal koste når prisen reguleres med konsumprisindeksen.
Expand All @@ -296,9 +296,7 @@ pifProductManufactured = Bearbeidde varer gruppert etter materiale
pifProductMachine = Maskiner og transportmidler
pifProductOther = Forskjellige ferdige varer
pifProductPriceHeader = Hva var prisen for varen?
pifErrorMarket = Feil markedskode
pifErrorProduct = Feil produktgruppe

pifErrorProduct = Mangler data for kombinasjonen av marked og produktgruppe
bkibolAmount = Beløp
bkibolAmountInclude = Omfatter
bkibolTitle = Beregn endringer i byggekostnader
Expand Down
6 changes: 2 additions & 4 deletions src/main/resources/site/i18n/phrases_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ calculatorMonthAverageFrontpage = All
pifServiceValidateStartMonth = Start month is not valid for this calculation
pifServiceValidateEndMonth = End month is not valid for this calculation
pifValidateMonth = No data for the selected time. For the present year you must choose a month
pifValidateYear = You can only enter years from {0} to
pifValidateYear = Data only available from {0} to
pifAmountEqualled = The amount equals
pifCalculatorInfoTitle = Notice!
pifCalculatorInfoText = The calculations show the development in NOK when you take the consumer price index as a starting point. The calculator does not show what individual items should or will cost when the price is regulated with the consumer price index.
Expand All @@ -296,9 +296,7 @@ pifProductManufactured = Manufactured goods classified by material
pifProductMachine = Machinery and transport equipment
pifProductOther = Miscellaneous manufactures articles
pifProductPriceHeader = Amount in NOK
pifErrorMarket = Invalid market code
pifErrorProduct = Invalid commodity group

pifErrorProduct = Missing data for combination of market and commodity group
bkibolAmount = Amount
bkibolAmountInclude = Includes
bkibolTitle = Building costs calculator
Expand Down
6 changes: 2 additions & 4 deletions src/main/resources/site/i18n/phrases_nn.properties
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ calculatorMonthAverageFrontpage = Alle
pifServiceValidateStartMonth = Startmåned er ikke gyldig for denne utregningen
pifServiceValidateEndMonth = Sluttmåned er ikke gyldig for denne utregningen
pifValidateMonth = Finnes ikke data for tidspunkt. For inneværende år må måned velges.
pifValidateYear = Du kan kun skrive inn årstall fra {0} til
pifValidateYear = Data kun tilgjengelig fra {0} til
pifAmountEqualled = Beløpet tilsvarer
pifCalculatorInfoTitle = Merk!
pifCalculatorInfoText = Beregningene viser utviklingen i kroneverdi når en tar utgangspunktet i konsumprisindeksen. Kalkulatoren viser ikke hva enkeltvarer bør eller skal koste når prisen reguleres med konsumprisindeksen.
Expand All @@ -289,9 +289,7 @@ pifProductManufactured = Bearbeidde varer grupperte etter materiale
pifProductMachine = Maskinar og transportmiddel
pifProductOther = Forskjellige ferdige varer
pifProductPriceHeader = Kor mykje kosta varen?
pifErrorMarket = Feil markedskode
pifErrorProduct = Feil produktgruppe

pifErrorProduct = Mangler data for kombinasjonen av marked og produktgruppe
bkibolAmount = Beløp
bkibolAmountInclude= Omfattar
bkibolTitle = Berekn endring i byggekostnader
Expand Down