From 73ac3f7c47da2a6a1a8796f89a0afeb5f498c717 Mon Sep 17 00:00:00 2001 From: Nils Ove Tendenes Date: Tue, 10 Dec 2024 11:27:44 +0100 Subject: [PATCH] Revert "fix: remove edit page dependency on erSistPublisert" This reverts commit 730007d7a3a4a356db62573990d804d4ba494383. --- src/components/form-control/index.tsx | 3 ++- src/lib/concept/index.ts | 9 ++++++--- .../form-concept/form-concept.schema.ts | 7 ++----- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/components/form-control/index.tsx b/src/components/form-control/index.tsx index f6cf4019..2d8ff109 100644 --- a/src/components/form-control/index.tsx +++ b/src/components/form-control/index.tsx @@ -59,6 +59,7 @@ const FormControl = ({ const dispatch = useAppDispatch(); const conceptForm = useAppSelector(state => state.conceptForm); const { concept } = conceptForm; + const erSistPublisert = concept?.erSistPublisert ?? false; const published = concept?.erPublisert ?? false; const isSaving = conceptForm.isSaving ?? false; const justChangedStatus = conceptForm.justChangedStatus ?? false; @@ -108,7 +109,7 @@ const FormControl = ({ return concept ? ( - {isFormDirty && published && ( + {isFormDirty && published && erSistPublisert && ( {localization.saveDraft} diff --git a/src/lib/concept/index.ts b/src/lib/concept/index.ts index 8f2c10d6..6b8ffb97 100644 --- a/src/lib/concept/index.ts +++ b/src/lib/concept/index.ts @@ -1,9 +1,12 @@ -import {Concept} from '../../types'; +import { Concept } from '../../types'; export const isConceptEditable = (concept: Concept | undefined) => { if (concept == null) { return false; } - const { id, erPublisert } = concept; - return id == null || !erPublisert; + const { id, erPublisert, erSistPublisert, revisjonAvSistPublisert } = concept; + const editable = + id == null || (erPublisert && erSistPublisert) || revisjonAvSistPublisert; + + return editable; }; 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 a206897b..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 @@ -240,11 +240,8 @@ export const schema = Yup.object().shape({ context.parent.id ? getRevisions(context.parent.id) .then(revisions => { - const latestPublishedRevision = revisions.reduce( - (prev, current) => - compareVersion(prev.versjonsnr, current.versjonsnr) < 0 - ? prev - : current + const latestPublishedRevision = revisions.find( + rev => rev.erSistPublisert ); return ( compareVersion(