From 2fb79adbe789f75274695ee4b293681bda60c749 Mon Sep 17 00:00:00 2001 From: Jeff Reiffers Date: Fri, 13 Dec 2024 11:15:26 +0100 Subject: [PATCH] fix: new concept --- .../concepts/new/new-page.client.tsx | 40 ++++++++++++ .../[catalogId]/concepts/new/page.tsx | 64 +++++++++++++++++-- .../components/definition-section.tsx | 27 ++++---- .../components/concept-form/index.tsx | 21 +++--- .../concept-form/validation-schema.tsx | 3 +- libs/utils/src/lib/language/nb.ts | 1 + 6 files changed, 125 insertions(+), 31 deletions(-) create mode 100644 apps/concept-catalog/app/catalogs/[catalogId]/concepts/new/new-page.client.tsx diff --git a/apps/concept-catalog/app/catalogs/[catalogId]/concepts/new/new-page.client.tsx b/apps/concept-catalog/app/catalogs/[catalogId]/concepts/new/new-page.client.tsx new file mode 100644 index 000000000..ffa850be5 --- /dev/null +++ b/apps/concept-catalog/app/catalogs/[catalogId]/concepts/new/new-page.client.tsx @@ -0,0 +1,40 @@ +'use client'; + +import { Breadcrumbs, PageBanner } from '@catalog-frontend/ui'; +import { localization, getTranslateText } from '@catalog-frontend/utils'; +import ConceptForm from '../../../../../components/concept-form'; + +export const NewPage = ({ + breadcrumbList, + catalogId, + organization, + concept, + conceptStatuses, + codeListsResult, + fieldsResult, + usersResult, + catalogPortalBaseUri +}) => { + + + return ( + <> + + + + + ); +}; diff --git a/apps/concept-catalog/app/catalogs/[catalogId]/concepts/new/page.tsx b/apps/concept-catalog/app/catalogs/[catalogId]/concepts/new/page.tsx index 40bc41580..29928f7c5 100644 --- a/apps/concept-catalog/app/catalogs/[catalogId]/concepts/new/page.tsx +++ b/apps/concept-catalog/app/catalogs/[catalogId]/concepts/new/page.tsx @@ -1,11 +1,61 @@ -import { RedirectType, redirect } from 'next/navigation'; +import { getAllCodeLists, getConceptStatuses, getFields, getOrganization, getUsers } from '@catalog-frontend/data-access'; +import { BreadcrumbType } from '@catalog-frontend/ui'; +import { localization, prepareStatusList } from '@catalog-frontend/utils'; +import { CodeListsResult, FieldsResult, Organization, UsersResult } from '@catalog-frontend/types'; import { withWriteProtectedPage } from '../../../../../utils/auth'; -export const NewPage = withWriteProtectedPage( - ({ catalogId }) => `/catalogs/${catalogId}/concepts/new`, - async ({ catalogId }) => { - //redirect(`${process.env.CONCEPT_CATALOG_GUI_BASE_URI}/${catalogId}/new`, RedirectType.push); +import { NewPage } from './new-page.client'; + +export default withWriteProtectedPage( + ({ catalogId }) => `/catalogs//${catalogId}/concepts/new`, + async ({ catalogId, session }) => { + const concept = { + ansvarligVirksomhet: { + id: catalogId + } + }; + + const conceptStatuses = await getConceptStatuses() + .then((response) => response.json()) + .then((body) => body?.conceptStatuses ?? []) + .then((statuses) => prepareStatusList(statuses)); + + const organization: Organization = await getOrganization(catalogId).then((response) => response.json()); + const codeListsResult: CodeListsResult = await getAllCodeLists(catalogId, `${session?.accessToken}`).then( + (response) => response.json(), + ); + const fieldsResult: FieldsResult = await getFields(catalogId, `${session?.accessToken}`).then((response) => + response.json(), + ); + const usersResult: UsersResult = await getUsers(catalogId, `${session?.accessToken}`).then((response) => + response.json(), + ); + + const breadcrumbList = catalogId + ? ([ + { + href: `/catalogs/${catalogId}`, + text: localization.catalogType.concept, + }, + { + href: `/catalogs/${catalogId}/concepts/new`, + text: localization.newConcept, + }, + ] as BreadcrumbType[]) + : []; + + return ( + + ); }, ); - -export default NewPage; diff --git a/apps/concept-catalog/components/concept-form/components/definition-section.tsx b/apps/concept-catalog/components/concept-form/components/definition-section.tsx index 99c65e11d..d31ea1f4c 100644 --- a/apps/concept-catalog/components/concept-form/components/definition-section.tsx +++ b/apps/concept-catalog/components/concept-form/components/definition-section.tsx @@ -30,9 +30,9 @@ export const DefinitionSection = () => { ...def, kildebeskrivelse: { forholdTilKilde: def.kildebeskrivelse?.forholdTilKilde ?? 'egendefinert', - kilde: def.kildebeskrivelse?.kilde ?? [] - } - } + kilde: def.kildebeskrivelse?.kilde ?? [], + }, + }; }; return ( @@ -57,13 +57,7 @@ export const DefinitionSection = () => { tagTitle={localization.tag.required} /> } - > - {Object.keys(errors).some((value) => - ['definisjon', 'definisjonForAllmennheten', 'definisjonForSpesialister'].includes(value), - ) && ( - Minst en definisjon må være definert! - )} - + /> {definitions .filter((name) => values[name]) @@ -85,7 +79,7 @@ export const DefinitionSection = () => { setOpen({...open, [index]: false})} + onClose={() => setOpen({ ...open, [index]: false })} placement='top' size='md' variant='default' @@ -94,8 +88,10 @@ export const DefinitionSection = () => { def.kildebeskrivelse?.kilde?.length && setOpen({...open, [index]: true})} - onMouseOut={() => setOpen({...open, [index]: false})} + onMouseEnter={() => + def.kildebeskrivelse?.kilde?.length && setOpen({ ...open, [index]: true }) + } + onMouseOut={() => setOpen({ ...open, [index]: false })} > {`${def.kildebeskrivelse?.kilde?.length ? def.kildebeskrivelse?.kilde.length : 'Ingen'} ${localization.conceptForm.fieldLabel.sources.toLowerCase()}`} @@ -187,6 +183,11 @@ export const DefinitionSection = () => { /> ))} + + {Object.keys(errors).some((value) => + ['definisjon', 'definisjonForAllmennheten', 'definisjonForSpesialister'].includes(value), + ) && Minst en definisjon må være definert!} + ); }; diff --git a/apps/concept-catalog/components/concept-form/index.tsx b/apps/concept-catalog/components/concept-form/index.tsx index bfeb329fb..e2dd4ceaf 100644 --- a/apps/concept-catalog/components/concept-form/index.tsx +++ b/apps/concept-catalog/components/concept-form/index.tsx @@ -5,7 +5,7 @@ import classNames from 'classnames'; import { Formik, Form } from 'formik'; import { useRouter } from 'next/navigation'; import { Alert, Spinner } from '@digdir/designsystemet-react'; -import { localization, trimObjectWhitespace } from '@catalog-frontend/utils'; +import { localization } from '@catalog-frontend/utils'; import { CodeListsResult, Concept, FieldsResult, ReferenceDataCode, UsersResult } from '@catalog-frontend/types'; import { Button, FormLayout, NotificationCarousel } from '@catalog-frontend/ui'; import { createConcept, updateConcept } from '../../app/actions/concept/actions'; @@ -60,7 +60,7 @@ const getNotifications = ({ isValid, hasUnsavedChanges }) => [ ]; const ConceptForm = ({ catalogId, concept, conceptStatuses, codeListsResult, fieldsResult, usersResult }: Props) => { - const [isSubmitted, setIsSubmitted] = useState(false); + const [isSaveButtonClicked, setIsSaveButtonClicked] = useState(false); const [isCanceled, setIsCanceled] = useState(false); const router = useRouter(); @@ -68,9 +68,9 @@ const ConceptForm = ({ catalogId, concept, conceptStatuses, codeListsResult, fie const mapPropsToValues = ({ id, anbefaltTerm = { navn: {} }, - definisjon = { tekst: {}, kildebeskrivelse: undefined }, - definisjonForAllmennheten = { tekst: {}, kildebeskrivelse: undefined }, - definisjonForSpesialister = { tekst: {}, kildebeskrivelse: undefined }, + definisjon = undefined, + definisjonForAllmennheten = undefined, + definisjonForSpesialister = undefined, merknad = {}, merkelapp = [], tillattTerm = {}, @@ -78,7 +78,7 @@ const ConceptForm = ({ catalogId, concept, conceptStatuses, codeListsResult, fie eksempel = {}, fagområde = {}, fagområdeKoder = [], - statusURI = undefined, + statusURI = 'http://publications.europa.eu/resource/authority/concept-status/DRAFT', omfang = undefined, kontaktpunkt = undefined, gyldigFom = undefined, @@ -91,7 +91,7 @@ const ConceptForm = ({ catalogId, concept, conceptStatuses, codeListsResult, fie abbreviatedLabel = undefined, begrepsRelasjon = [], internBegrepsRelasjon = [], - versjonsnr = { major: 0, minor: 0, patch: 0 }, + versjonsnr = { major: 0, minor: 1, patch: 0 }, interneFelt = {}, ...rest }: Concept) => { @@ -156,12 +156,11 @@ const ConceptForm = ({ catalogId, concept, conceptStatuses, codeListsResult, fie { concept.id === null ? await handleCreate(values as Concept) : await handleUpdate(values as Concept); setSubmitting(false); - setIsSubmitted(true); }} > {({ errors, values, dirty, isValid, isSubmitting, isValidating, submitForm }) => { @@ -169,6 +168,7 @@ const ConceptForm = ({ catalogId, concept, conceptStatuses, codeListsResult, fie return ( <>
+ {isSaveButtonClicked ? 'save button clicked' : 'save not clicked'}
{ + setIsSaveButtonClicked(true); submitForm(); }} > diff --git a/apps/concept-catalog/components/concept-form/validation-schema.tsx b/apps/concept-catalog/components/concept-form/validation-schema.tsx index c9ea9bb84..80369fbd7 100644 --- a/apps/concept-catalog/components/concept-form/validation-schema.tsx +++ b/apps/concept-catalog/components/concept-form/validation-schema.tsx @@ -142,7 +142,8 @@ export const definitionSchema = Yup.object() return true; }, }) - .nullable(); + .nullable() + .default(null); export const relationSchema = Yup.object().shape({ relasjon: Yup.string().required('Feltet må fylles ut'), diff --git a/libs/utils/src/lib/language/nb.ts b/libs/utils/src/lib/language/nb.ts index 91fe4fe53..4919bb4d6 100644 --- a/libs/utils/src/lib/language/nb.ts +++ b/libs/utils/src/lib/language/nb.ts @@ -69,6 +69,7 @@ export const nb = { choose: 'Velg', serviceMessageError: 'Kunne ikke laste inn tjenestemeldinger. Vennligst prøv igjen senere.', serviceMessageSeeMore: 'Se detaljert driftsmelding for mer informasjon.', + newConcept: 'Nytt begrep', catalogType: { admin: 'Administrasjonsgrensesnitt',