Skip to content

Commit

Permalink
fix: source title and link required
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreiffers committed Oct 25, 2023
1 parent f0de7b6 commit 286db13
Showing 1 changed file with 56 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ import { Relation } from '../../../types/enums';
import { getRevisions } from '../../../api/concept-catalog-api';
import { compareVersion } from '../../../utils/version';

const isvalidurl = url => {
try {
url(url);
} catch (e) {
return false;
}
return true;
};

const tekstMedSpraakKodeArray = Yup.object()
.nullable()
.shape({
Expand All @@ -13,6 +22,41 @@ const tekstMedSpraakKodeArray = Yup.object()
en: Yup.array().of(Yup.string()).nullable()
});

const kilde = Yup.array()
.of(
Yup.object().shape({
tekst: Yup.string()
.nullable()
.test({
test(value) {
const isRequired = this.parent.forholdTilKilde !== 'egendefinert';

if (isRequired && (!value || value.length < 2)) {
return this.createError({
message: localization.validationMin2
});
}
return true;
}
}),
uri: Yup.string()
.nullable()
.test({
test(value) {
const isRequired = this.parent.forholdTilKilde !== 'egendefinert';

if (isRequired && !isvalidurl(value)) {
return this.createError({
message: localization.validationUrl
});
}
return true;
}
})
})
)
.nullable();

export const schema = Yup.object().shape({
anbefaltTerm: Yup.object().shape({
navn: Yup.object().shape({
Expand Down Expand Up @@ -95,58 +139,25 @@ export const schema = Yup.object().shape({
}
})
}),
kildebeskrivelse: Yup.object()
.nullable()
.shape({
forholdTilKilde: Yup.string().nullable(),
kilde: Yup.array()
.of(
Yup.object().shape({
tekst: Yup.string()
.nullable()
.min(2, localization.validationMin2),
uri: Yup.string().nullable().url(localization.validationUrl)
})
)
.nullable()
})
kildebeskrivelse: Yup.object().nullable().shape({
forholdTilKilde: Yup.string().nullable(),
kilde
})
}),
definisjonForAllmennheten: Yup.object()
.shape({
kildebeskrivelse: Yup.object()
.nullable()
.shape({
forholdTilKilde: Yup.string().nullable(),
kilde: Yup.array()
.of(
Yup.object().shape({
tekst: Yup.string()
.nullable()
.min(2, localization.validationMin2),
uri: Yup.string().nullable().url(localization.validationUrl)
})
)
.nullable()
})
kildebeskrivelse: Yup.object().nullable().shape({
forholdTilKilde: Yup.string().nullable(),
kilde
})
})
.nullable(),
definisjonForSpesialister: Yup.object()
.shape({
kildebeskrivelse: Yup.object()
.nullable()
.shape({
forholdTilKilde: Yup.string().nullable(),
kilde: Yup.array()
.of(
Yup.object().shape({
tekst: Yup.string()
.nullable()
.min(2, localization.validationMin2),
uri: Yup.string().nullable().url(localization.validationUrl)
})
)
.nullable()
})
kildebeskrivelse: Yup.object().nullable().shape({
forholdTilKilde: Yup.string().nullable(),
kilde
})
})
.nullable(),
fagområde: tekstMedSpraakKodeArray,
Expand Down

0 comments on commit 286db13

Please sign in to comment.