From b6fe874bdfe477f5d60afed23662b734f1783e08 Mon Sep 17 00:00:00 2001 From: Hege Aalvik <48259307+hegeaal@users.noreply.github.com> Date: Fri, 26 Jan 2024 08:11:30 +0100 Subject: [PATCH] feat: add replace by unpusblished concept field in form (#628) --- src/l10n/helptexts.nb.ts | 1 + src/l10n/nb.ts | 1 + .../form-concept/form-concept.schema.ts | 1 + .../form-concept/index.tsx | 5 +- .../validity/validity.component.tsx | 101 +++++++++++++++++- src/types/domain.d.ts | 1 + 6 files changed, 106 insertions(+), 4 deletions(-) diff --git a/src/l10n/helptexts.nb.ts b/src/l10n/helptexts.nb.ts index 02a0ba2e..e02619f5 100644 --- a/src/l10n/helptexts.nb.ts +++ b/src/l10n/helptexts.nb.ts @@ -143,6 +143,7 @@ Se mer om ‘kontaktinformasjon’ i [veileder for begrepsbeskrivelser](https:// assignUserAbstract: "Velg personen som skal ha ansvaret for å følge opp begrepet.", replacedByAbstract: "Referanse til begrep som erstatter gjeldende begrep.", + replacedByUnpublishedAbstract: "Referanse til upubliserte begrep i egen katalog som erstatter gjeldende begrep.", relationsTitle: "Relasjoner", relationsTitleUnpublished: "Relasjoner - upublisert", descriptionTitle: "Beskrivelse", diff --git a/src/l10n/nb.ts b/src/l10n/nb.ts index d68434bc..ddfa324a 100644 --- a/src/l10n/nb.ts +++ b/src/l10n/nb.ts @@ -100,6 +100,7 @@ export const nb = { internalInfo: "Interne opplysninger", internalSubText: "Opplysningene under er til intern bruk og vil ikke publiseres ut i Felles datakatalog.", replacedBy: 'Erstattes av', + replacedByNotPublished: 'Erstattes av - upublisert', relation: 'Relasjon', relationType: 'Nivå', description: 'Beskrivelse', diff --git a/src/pages/concept-registration-page/form-concept/form-concept.schema.ts b/src/pages/concept-registration-page/form-concept/form-concept.schema.ts index 64bdce7e..851925dd 100644 --- a/src/pages/concept-registration-page/form-concept/form-concept.schema.ts +++ b/src/pages/concept-registration-page/form-concept/form-concept.schema.ts @@ -216,6 +216,7 @@ export const schema = Yup.object().shape({ seOgså: Yup.array().of(Yup.string().nullable()).nullable(), internSeOgså: Yup.array().of(Yup.string().nullable()).nullable(), erstattesAv: Yup.array().of(Yup.string().nullable()).nullable(), + internErstattesAv: Yup.array().of(Yup.string().nullable()).nullable(), begrepsRelasjon: Yup.array() .of( Yup.object().shape({ diff --git a/src/pages/concept-registration-page/form-concept/index.tsx b/src/pages/concept-registration-page/form-concept/index.tsx index 7704da7b..21c1e4d0 100644 --- a/src/pages/concept-registration-page/form-concept/index.tsx +++ b/src/pages/concept-registration-page/form-concept/index.tsx @@ -79,6 +79,7 @@ export type FormValues = Pick< | 'seOgså' | 'internSeOgså' | 'erstattesAv' + | 'internErstattesAv' | 'assignedUser' | 'abbreviatedLabel' | 'begrepsRelasjon' @@ -269,7 +270,7 @@ export const FormConceptPure: FC = ({ title={localization.formValidity} showInitially={expandAll} > - + = { seOgså = [], internSeOgså = [], erstattesAv = [], + internErstattesAv = [], assignedUser = '', abbreviatedLabel = null, begrepsRelasjon = [], @@ -344,6 +346,7 @@ const formikConfig: WithFormikConfig = { seOgså, internSeOgså, erstattesAv, + internErstattesAv, assignedUser, abbreviatedLabel, begrepsRelasjon, diff --git a/src/pages/concept-registration-page/form-concept/validity/validity.component.tsx b/src/pages/concept-registration-page/form-concept/validity/validity.component.tsx index f495dd87..357b410f 100644 --- a/src/pages/concept-registration-page/form-concept/validity/validity.component.tsx +++ b/src/pages/concept-registration-page/form-concept/validity/validity.component.tsx @@ -11,20 +11,32 @@ import { getTranslateText } from '../../../../lib/translateText'; import { useAppDispatch, useAppSelector } from '../../../../app/redux/hooks'; import { fetchConceptSuggestions, - selectAllConceptSuggestions + fetchInternalConceptSuggestions, + selectAllConceptSuggestions, + selectAllInternalConceptSuggestions } from '../../../../features/concept-suggestions'; import { fetchConcepts, - selectAllConceptEntities + fetchInternalConcepts, + selectAllConceptEntities, + selectAllInternalConceptEntities } from '../../../../features/concepts'; -export const Validity: FC = () => { +interface Props { + catalogId: string; +} + +export const Validity: FC = ({ catalogId }) => { const [gyldigFomField] = useField('gyldigFom'); const [gyldigTomField] = useField('gyldigTom'); const [erstattesAv] = useField('erstattesAv'); + const [internErstattesAv] = useField('internErstattesAv'); const dispatch = useAppDispatch(); const relatedConcepts = useAppSelector(selectAllConceptEntities); const conceptSuggestions = useAppSelector(selectAllConceptSuggestions); + const relatedInternalConcepts = useAppSelector( + selectAllInternalConceptEntities + ); useEffect(() => { if (erstattesAv.value?.length > 0) { @@ -36,10 +48,29 @@ export const Validity: FC = () => { dispatch(fetchConceptSuggestions({ q })); }; + const executeInternalConceptSuggestionSearch = ( + query: string, + publisherId: string + ) => { + dispatch(fetchInternalConceptSuggestions({ query, publisherId })); + }; + useEffect(() => { executeConceptSuggestionSearch(''); + executeInternalConceptSuggestionSearch('', catalogId); }, []); + useEffect(() => { + if (internErstattesAv.value?.length > 0) { + dispatch( + fetchInternalConcepts({ + catalogId, + values: internErstattesAv.value + }) + ); + } + }, [internErstattesAv.value]); + const conceptSuggestionsMap = conceptSuggestions.map( ({ identifier, prefLabel, definition, publisher }) => ({ @@ -59,6 +90,39 @@ export const Validity: FC = () => { option?.value && dispatch(fetchConcepts([option.value])); }; + const extractListOfOriginaltBegrepIds = (values: OptionProps[]): string[] => { + const originaltBegreps: string[] = []; + + values && + values.forEach(value => { + const originaltBegrep = value.value; + originaltBegrep && originaltBegreps.push(originaltBegrep); + }); + return originaltBegreps; + }; + + const addRelatedInternalConcept = (form, fieldName, option): void => { + form.setFieldValue( + fieldName, + option.map(item => item.value) + ); + const values = extractListOfOriginaltBegrepIds(option); + option?.values && dispatch(fetchInternalConcepts({ catalogId, values })); + }; + + const internalConceptSuggestions = useAppSelector( + selectAllInternalConceptSuggestions + ); + + const internalConceptSuggestionsMap = internalConceptSuggestions.map( + ({ anbefaltTerm, definisjon, originaltBegrep }) => + ({ + value: originaltBegrep, + label: getTranslateText(anbefaltTerm?.navn), + description: getTranslateText(definisjon?.tekst) + } as any) + ); + return (
@@ -115,6 +179,37 @@ export const Validity: FC = () => { )} />
+
+ + ( + form.setFieldValue(internErstattesAv.name, '')} + onChange={addRelatedInternalConcept} + onInputChange={value => + executeInternalConceptSuggestionSearch(value, catalogId) + } + defaultValue={form?.values?.internErstattesAv?.map(item => ({ + value: item, + label: + getTranslateText( + relatedInternalConcepts[item]?.anbefaltTerm?.navn + ) ?? 'default' + }))} + isMulti + /> + )} + /> +
); }; diff --git a/src/types/domain.d.ts b/src/types/domain.d.ts index c6eb3024..f75e399f 100644 --- a/src/types/domain.d.ts +++ b/src/types/domain.d.ts @@ -157,6 +157,7 @@ export interface Concept { begrepsRelasjon?: Relasjon[]; internBegrepsRelasjon?: Relasjon[]; interneFelt?: Record; + internErstattesAv?: string[]; } export interface SkosConcept {