Skip to content

Commit

Permalink
fix: merknad and eksempel type should be string
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreiffers committed Sep 22, 2023
1 parent de8cdb7 commit 8170d98
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/app/reducers/conceptMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ function mapCsvTextToConcept(
tekst: mapRowToLanguageValue(csvMap, 'definisjon'),
kildebeskrivelse: mapKilde(csvMap)
},
merknad: mapRowToLanguageValueList(csvMap, 'merknad'),
eksempel: mapRowToLanguageValueList(csvMap, 'eksempel'),
merknad: mapRowToLanguageValue(csvMap, 'merknad'),
eksempel: mapRowToLanguageValue(csvMap, 'eksempel'),
fagområde: mapRowToLanguageValueList(csvMap, 'fagområde'),
gyldigFom: mapToSingleValue(csvMap, 'gyldigfom'),
gyldigTom: mapToSingleValue(csvMap, 'gyldigtom'),
Expand Down
10 changes: 5 additions & 5 deletions src/mock/concepts.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
},
"kilde": "Forskrift om tinglysing § 11 tredje ledd og § 16 annet ledd bokstav e). _Forskrift 3. november 1995 nr. 875 om tinglysing_ https://lovdata.no/forskrift/1995-11-03-875",
"merknad": {
"nb": ["Lorem"],
"nn": ["Lorem NN"]
"nb": "Lorem",
"nn": "Lorem NN"
},
"ansvarligVirksomhet": {
"uri": "http://data.brreg.no/enhetsregisteret/enhet/910244132",
Expand All @@ -36,9 +36,9 @@
"prefLabel": "Brønnøysundregistrene"
},
"eksempel": {
"nb": ["Eksempel lorem ipsum."],
"nn": ["Eksempel lorem ipsum NN."],
"en": ["Eksempel lorem ipsum EN."]
"nb": "Eksempel lorem ipsum.",
"nn": "Eksempel lorem ipsum NN.",
"en": "Eksempel lorem ipsum EN."
},
"fagområde": {
"nb": ["Dokument"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,9 @@ exports[`should render ConceptList 1`] = `
},
},
"eksempel": {
"en": [
"Eksempel lorem ipsum EN.",
],
"nb": [
"Eksempel lorem ipsum.",
],
"nn": [
"Eksempel lorem ipsum NN.",
],
"en": "Eksempel lorem ipsum EN.",
"nb": "Eksempel lorem ipsum.",
"nn": "Eksempel lorem ipsum NN.",
},
"fagområde": {
"en": [
Expand Down Expand Up @@ -74,12 +68,8 @@ exports[`should render ConceptList 1`] = `
"harTelefon": "12345678",
},
"merknad": {
"nb": [
"Lorem",
],
"nn": [
"Lorem NN",
],
"nb": "Lorem",
"nn": "Lorem NN",
},
"omfang": {
"tekst": "Tekst for omfang",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,9 @@ exports[`should render ConceptList 1`] = `
},
},
"eksempel": {
"en": [
"Eksempel lorem ipsum EN.",
],
"nb": [
"Eksempel lorem ipsum.",
],
"nn": [
"Eksempel lorem ipsum NN.",
],
"en": "Eksempel lorem ipsum EN.",
"nb": "Eksempel lorem ipsum.",
"nn": "Eksempel lorem ipsum NN.",
},
"fagområde": {
"en": [
Expand Down Expand Up @@ -74,12 +68,8 @@ exports[`should render ConceptList 1`] = `
"harTelefon": "12345678",
},
"merknad": {
"nb": [
"Lorem",
],
"nn": [
"Lorem NN",
],
"nb": "Lorem",
"nn": "Lorem NN",
},
"omfang": {
"tekst": "Tekst for omfang",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,82 @@ export const schema = Yup.object().shape({
})
})
.nullable(),
merknad: tekstMedSpraakKodeArray,
eksempel: tekstMedSpraakKodeArray,
merknad: Yup.object().shape({
nb: Yup.string().test({
test() {
const { nb, nn, en } = this.parent;
if (!nb && !nn && !en) {
return this.createError({
message: localization.validationRequired,
path: this.path
});
}
return true;
}
}),
nn: Yup.string().test({
test() {
const { nb, nn, en } = this.parent;
if (!nb && !nn && !en) {
return this.createError({
message: localization.validationRequired,
path: this.path
});
}
return true;
}
}),
en: Yup.string().test({
test() {
const { nb, nn, en } = this.parent;
if (!nb && !nn && !en) {
return this.createError({
message: localization.validationRequired,
path: this.path
});
}
return true;
}
})
}),
eksempel: Yup.object().shape({
nb: Yup.string().test({
test() {
const { nb, nn, en } = this.parent;
if (!nb && !nn && !en) {
return this.createError({
message: localization.validationRequired,
path: this.path
});
}
return true;
}
}),
nn: Yup.string().test({
test() {
const { nb, nn, en } = this.parent;
if (!nb && !nn && !en) {
return this.createError({
message: localization.validationRequired,
path: this.path
});
}
return true;
}
}),
en: Yup.string().test({
test() {
const { nb, nn, en } = this.parent;
if (!nb && !nn && !en) {
return this.createError({
message: localization.validationRequired,
path: this.path
});
}
return true;
}
})
}),
fagområde: tekstMedSpraakKodeArray,
statusURI: Yup.string().nullable(),
omfang: Yup.object()
Expand Down
7 changes: 5 additions & 2 deletions src/pages/concept-registration-page/form-concept/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ import { InternalInfo } from './internal-info';
import { getConfig } from '../../../config';
import { setValidationError } from '../../../features/conceptForm';

export const validateWithPreProcess = (values, { dispatch }) => {
export const validateWithPreProcess = (
values,
{ concept, dispatch }: { concept: Concept; dispatch: any }
) => {
const processedValues = preProcessValues(
values.ansvarligVirksomhet.id,
concept.ansvarligVirksomhet.id,
values
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export const preProcessValues = (
}
) => ({
...conceptValues,
merknad: merknad ? stringsToArray(merknad) : null,
eksempel: eksempel ? stringsToArray(eksempel) : null,
merknad,
eksempel,
fagområde: fagområde ? stringsToArray(fagområde) : null,
omfang: pruneEmptyProperties(omfang),
kontaktpunkt: pruneEmptyProperties(kontaktpunkt),
Expand Down
4 changes: 2 additions & 2 deletions src/types/domain.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ export interface Concept {
definisjonForAllmennheten?: Definisjon;
definisjonForSpesialister?: Definisjon;
ansvarligVirksomhet: { id: string };
merknad?: Record<string, string[]>;
eksempel?: Record<string, string[]>;
merknad?: Record<string, string>;
eksempel?: Record<string, string>;
fagområde?: Record<string, string[]>;
fagområdeKoder?: string[];
omfang?: UriText | null;
Expand Down

0 comments on commit 8170d98

Please sign in to comment.