Skip to content

Commit

Permalink
Feat: add zod to concepts (#903)
Browse files Browse the repository at this point in the history
* delete unused file

* fix validation for links

* unecessary return

* unfinished

* delete unused folder

* fix validation

* fix double check on scopenote

* fix: improve zod validation for concept

* improve zod once again

* add and reshape tests

* fix test

* add messages to notes and set title to red if scopenote too long

* fix error messages for codelists

---------

Co-authored-by: Emmanuel <[email protected]>
  • Loading branch information
PierreVasseur and EmmanuelDemey authored Sep 2, 2024
1 parent 09b92aa commit 89caff6
Show file tree
Hide file tree
Showing 22 changed files with 381 additions and 1,360 deletions.
1 change: 0 additions & 1 deletion .husky/pre-commit

This file was deleted.

25 changes: 0 additions & 25 deletions .kubernetes/deployment.yml

This file was deleted.

18 changes: 0 additions & 18 deletions .kubernetes/ingress.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .kubernetes/service.yml

This file was deleted.

55 changes: 33 additions & 22 deletions src/packages/components/note-edition/index.tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,56 @@
import NoteOneLangEdition from './note-one-lang-edition';
import D from '../../deprecated-locales';
import { ClientSideError } from '../errors-bloc';

type NoteEditionTypes = {
noteLg1: string;
notes: any;
noteLg1Name: string;
noteLg2Name: string;
handleChangeLg1: (value: string) => void;
noteLg2: string;
handleChangeLg2: (value: string) => void;
maxLength: number;
errorMessage: { errorMessage: string[]; fields: any };
};
export const NoteEdition = ({
noteLg1,
notes,
noteLg1Name,
noteLg2Name,
handleChangeLg1,
noteLg2,
handleChangeLg2,
maxLength,
errorMessage,
}: Readonly<NoteEditionTypes>) => {
const noteLg1 = notes[noteLg1Name];
const noteLg2 = notes[noteLg2Name];
return (
<div>
<div className="row">
<div className="col-md-6">
<NoteOneLangEdition
note={noteLg1}
handleChange={handleChangeLg1}
maxLength={maxLength}
/>
<>
<NoteOneLangEdition
note={noteLg1}
handleChange={handleChangeLg1}
maxLength={maxLength}
/>
<ClientSideError
id="note-lg1-error"
error={errorMessage?.fields[noteLg1Name]}
></ClientSideError>
</>
</div>
<div className="col-md-6">
<NoteOneLangEdition
note={noteLg2}
handleChange={handleChangeLg2}
maxLength={maxLength}
/>
<>
<NoteOneLangEdition
note={noteLg2}
handleChange={handleChangeLg2}
maxLength={maxLength}
/>
<ClientSideError
id="note-lg2-error"
error={errorMessage?.fields[noteLg2Name]}
></ClientSideError>
</>
</div>
</div>
{maxLength && (
<div className="row">
<div className="row text-center boldRed">
{maxLength} {D.scopeNoteChar}
</div>
</div>
)}
</div>
);
};
13 changes: 11 additions & 2 deletions src/packages/components/note-edition/note-edition.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@ describe('note-edition', () => {
it('renders without crashing', () => {
render(
<NoteEdition
noteLg1="noteLg1"
noteLg2="noteLg2"
notes={{
scopeNoteLg1: 'scopeNote1',
scopeNoteLg2: 'scopeNote2',
definitionLg1: 'definitionLg1',
}}
noteLg1Name="noteLg1Name"
noteLg2Name="noteLg2Name"
handleChangeLg1={jest.fn()}
handleChangeLg2={jest.fn()}
maxLength={0}
errorMessage={{
errorMessage: ['error'],
fields: { field: 'error' },
}}
/>
);
});
Expand Down
12 changes: 12 additions & 0 deletions src/packages/modules-codelists/i18n/dictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,26 @@ const dictionary = {
fr: 'Uri Liste : commence par http://rdf.insee.fr/codes/',
en: 'Uri Liste : starts with http://rdf.insee.fr/codes/',
},
lastListUriSegmentTitleShort: {
fr: 'Uri Liste',
en: 'Uri Liste',
},
lastCodeUriSegmentTitle: {
fr: "Uri des codes, singulier de l'URI de la liste : commence par http://rdf.insee.fr/codes/",
en: 'Uri of codes, singular from list URI : starts with http://rdf.insee.fr/codes/',
},
lastCodeUriSegmentTitleShort: {
fr: 'Uri des codes',
en: 'Uri of codes',
},
lastClassUriSegmentTitle: {
fr: 'Uri class owl : commence par http://rdf.insee.fr/codes/concept/',
en: 'Uri class owl : starts with http://rdf.insee.fr/codes/concept/',
},
lastClassUriSegmentTitleShort: {
fr: 'Uri class owl',
en: 'Uri class owl',
},
codelistsSearchTitle: {
fr: 'Listes de codes - Recherche',
en: 'Code lists - Search',
Expand Down
17 changes: 8 additions & 9 deletions src/packages/modules-codelists/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ export const formatLabel = (component) => {
const CodesList = z.object({
lastListUriSegment: z
.string({
required_error: D.mandatoryProperty(D.lastListUriSegmentTitle),
required_error: D.mandatoryProperty(D.lastListUriSegmentTitleShort),
})
.trim()
.min(1, { message: D.mandatoryProperty(D.lastListUriSegmentTitle) }),
.min(1, { message: D.mandatoryProperty(D.lastListUriSegmentTitleShort) }),
lastCodeUriSegment: z
.string({
required_error: D.mandatoryProperty(D.lastCodeUriSegmentTitle),
required_error: D.mandatoryProperty(D.lastCodeUriSegmentTitleShort),
})
.trim()
.min(1, { message: D.mandatoryProperty(D.lastCodeUriSegmentTitle) }),
.min(1, { message: D.mandatoryProperty(D.lastCodeUriSegmentTitleShort) }),
lastClassUriSegment: z
.string({
required_error: D.mandatoryProperty(D.lastClassUriSegmentTitle),
required_error: D.mandatoryProperty(D.lastClassUriSegmentTitleShort),
})
.trim()
.min(1, { message: D.mandatoryProperty(D.lastClassUriSegmentTitle) }),
.min(1, { message: D.mandatoryProperty(D.lastClassUriSegmentTitleShort) }),
id: z
.string({ required_error: D.mandatoryProperty(D.idTitle) })
.trim()
Expand Down Expand Up @@ -105,9 +105,8 @@ const Code = (shouldCheckDuplicate, codes) =>
.trim()
.min(1, { message: D.mandatoryProperty(D.idTitle) })
.refine(
(value) => {
return !shouldCheckDuplicate || !codes.find((c) => c.code === value);
},
(value) =>
!shouldCheckDuplicate || !codes.find((c) => c.code === value),
{
message: D.ErrorDoubleCode,
}
Expand Down
12 changes: 6 additions & 6 deletions src/packages/modules-codelists/utils/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ describe('validateCodelist', () => {
const result = validateCodelist(codelist);

expect(result.errorMessage).toContain(
D.mandatoryProperty(D.lastListUriSegmentTitle)
D.mandatoryProperty(D.lastListUriSegmentTitleShort)
);
expect(result.errorMessage).toContain(
D.mandatoryProperty(D.lastCodeUriSegmentTitle)
D.mandatoryProperty(D.lastCodeUriSegmentTitleShort)
);
expect(result.errorMessage).toContain(
D.mandatoryProperty(D.lastClassUriSegmentTitle)
D.mandatoryProperty(D.lastClassUriSegmentTitleShort)
);
expect(result.errorMessage).toContain(D.mandatoryProperty(D.idTitle));
expect(result.errorMessage).toContain(D.mandatoryProperty(D1.labelTitle));
Expand All @@ -30,13 +30,13 @@ describe('validateCodelist', () => {
);

expect(result.fields.lastListUriSegment).toBe(
D.mandatoryProperty(D.lastListUriSegmentTitle)
D.mandatoryProperty(D.lastListUriSegmentTitleShort)
);
expect(result.fields.lastCodeUriSegment).toBe(
D.mandatoryProperty(D.lastCodeUriSegmentTitle)
D.mandatoryProperty(D.lastCodeUriSegmentTitleShort)
);
expect(result.fields.lastClassUriSegment).toBe(
D.mandatoryProperty(D.lastClassUriSegmentTitle)
D.mandatoryProperty(D.lastClassUriSegmentTitleShort)
);
expect(result.fields.id).toBe(D.mandatoryProperty(D.idTitle));
expect(result.fields.labelLg1).toBe(D.mandatoryProperty(D1.labelTitle));
Expand Down
Loading

0 comments on commit 89caff6

Please sign in to comment.