From f7f49a81eca8833ed55c466cc9dae869d3b65c09 Mon Sep 17 00:00:00 2001 From: Jeff Reiffers Date: Fri, 27 Oct 2023 14:51:54 +0200 Subject: [PATCH 1/2] feat: remove delete button --- src/components/form-control/index.tsx | 273 ++++++++---------- src/l10n/nb.ts | 4 - .../form-concept/index.tsx | 17 +- 3 files changed, 122 insertions(+), 172 deletions(-) diff --git a/src/components/form-control/index.tsx b/src/components/form-control/index.tsx index 2f560f85..86bfc318 100644 --- a/src/components/form-control/index.tsx +++ b/src/components/form-control/index.tsx @@ -1,6 +1,5 @@ import React, { memo, useEffect, useState } from 'react'; import { useParams } from 'react-router-dom'; -import { Variant } from '@fellesdatakatalog/button'; import { ConceptStatus, TimeFormat } from '../../types/enums'; import { formatTime } from '../../utils/date'; @@ -11,8 +10,6 @@ import { postConceptFromForm } from '../../lib/patchConceptForm'; import { publishConceptFromForm } from '../../lib/publishConceptFromForm'; -import { deleteConcept } from '../../api/concept-catalog-api'; -import ConfirmDialog from '../confirm-dialog'; import SC from './styled'; @@ -20,7 +17,6 @@ interface Props { isFormDirty: boolean; onNewConceptRevision: () => void; onSave: (conceptId) => void; - onDelete: () => void; isInitialInValidForm: boolean; lastPatchedResponse: any; values: V; @@ -30,12 +26,10 @@ const FormControl = ({ isFormDirty, onNewConceptRevision, onSave, - onDelete, isInitialInValidForm, lastPatchedResponse, values }: Props) => { - const [showConfirmDelete, setShowConfirmDelete] = useState(false); const [isSticky, setSticky] = useState(false); const [saveCalled, setSaveCalled] = useState(false); const [newConceptId, setNewConceptId] = useState(null); @@ -61,9 +55,6 @@ const FormControl = ({ }; }, [debounce, handleScroll]); - const toggleShowConfirmDelete = (): void => - setShowConfirmDelete(!showConfirmDelete); - const { conceptId } = useParams<{ conceptId: string; }>(); @@ -111,11 +102,6 @@ const FormControl = ({ : ''; }; - const confirmDelete = async (): Promise => { - await deleteConcept(conceptId); - onDelete(); - }; - useEffect(() => { const id = conceptId === 'new' ? newConceptId : conceptId; if (saveCalled && id && !(isSaving || errorSaving)) { @@ -124,151 +110,130 @@ const FormControl = ({ }, [isSaving, errorSaving, saveCalled, newConceptId, onSave]); return concept ? ( - <> - - - {isFormDirty && published && erSistPublisert && ( - - - {localization.saveDraft} - - )} - {!published && ( - { - setSaveCalled(true); - if (concept?.id) { - patchConceptFromForm(values, { - concept, - dispatch, - lastPatchedResponse, - isSaving - }); - } else { - postConceptFromForm(values, { - concept, - dispatch, - isSaving - })?.then(action => { - setNewConceptId(action.payload); - }); - } - }} - > - {localization.save} - - )} - {!published && ( - { - setSaveCalled(true); - patchConceptFromForm( - { - status: ConceptStatus.HOERING, - ...(concept.versjonsnr?.major === 0 && - concept.versjonsnr?.minor === 0 && - concept.versjonsnr?.patch === 1 && { - versjonsnr: { major: 1, minor: 0, patch: 0 } - }) - }, - { - concept, - dispatch, - lastPatchedResponse: concept, - isSaving - } - ); - }} - > - - {localization.setToHoering} - - )} - {!published && ( - { - setSaveCalled(true); - patchConceptFromForm( - { - status: ConceptStatus.GODKJENT, - ...(concept.versjonsnr?.major === 0 && - concept.versjonsnr?.minor === 0 && - concept.versjonsnr?.patch === 1 && { - versjonsnr: { major: 1, minor: 0, patch: 0 } - }) - }, - { - concept, - dispatch, - lastPatchedResponse: concept, - isSaving - } - ); - }} - > - - {localization.setToApproval} - - )} - {!published && ( - + + {isFormDirty && published && erSistPublisert && ( + + + {localization.saveDraft} + + )} + {!published && ( + { + setSaveCalled(true); + if (concept?.id) { + patchConceptFromForm(values, { + concept, + dispatch, + lastPatchedResponse, + isSaving + }); + } else { + postConceptFromForm(values, { + concept, + dispatch, + isSaving + })?.then(action => { + setNewConceptId(action.payload); + }); } - onClick={() => { - setSaveCalled(true); - publishConceptFromForm({ + }} + > + {localization.save} + + )} + {!published && ( + { + setSaveCalled(true); + patchConceptFromForm( + { + status: ConceptStatus.HOERING, + ...(concept.versjonsnr?.major === 0 && + concept.versjonsnr?.minor === 0 && + concept.versjonsnr?.patch === 1 && { + versjonsnr: { major: 1, minor: 0, patch: 0 } + }) + }, + { concept, dispatch, lastPatchedResponse: concept, isSaving - }); - }} - > - - {localization.publish} - - )} -
- {createMessage()} -
- - {!published && concept?.id && ( - - - {localization.deleteDraft} - - )} -
-
- {showConfirmDelete && ( - - )} - + } + ); + }} + > + + {localization.setToHoering} + + )} + {!published && ( + { + setSaveCalled(true); + patchConceptFromForm( + { + status: ConceptStatus.GODKJENT, + ...(concept.versjonsnr?.major === 0 && + concept.versjonsnr?.minor === 0 && + concept.versjonsnr?.patch === 1 && { + versjonsnr: { major: 1, minor: 0, patch: 0 } + }) + }, + { + concept, + dispatch, + lastPatchedResponse: concept, + isSaving + } + ); + }} + > + + {localization.setToApproval} + + )} + {!published && ( + { + setSaveCalled(true); + publishConceptFromForm({ + concept, + dispatch, + lastPatchedResponse: concept, + isSaving + }); + }} + > + + {localization.publish} + + )} +
+ {createMessage()} +
+ + ) : null; }; diff --git a/src/l10n/nb.ts b/src/l10n/nb.ts index c7cde693..f6d15d81 100644 --- a/src/l10n/nb.ts +++ b/src/l10n/nb.ts @@ -50,9 +50,6 @@ export const nb = { help: 'Hjelp', moreRecomendations: 'Flere anbefalinger', lessRecomendations: 'Færre anbefalinger', - confirmDeleteTitle: 'Bekreft sletting', - confirmDeleteMessage: 'Bekreft at du vil slette dette begrepet.', - cancelDelete: 'Avbryt', requiredFieldsMissing: 'Obligatoriske felt mangler', concept: 'Begrep', conceptCatalog: 'Begrepskatalog', @@ -89,7 +86,6 @@ export const nb = { saveDraft: 'Lagre som nytt utkast', version: 'Versjon', exPublished: 'Ekspublisert', - deleteDraft: 'Slett utkast', confirm: 'Bekreft', cancel: 'Avbryt', unsavedPrompt: 'Endringene er ikke lagret, vil du forkaste endringene?', diff --git a/src/pages/concept-registration-page/form-concept/index.tsx b/src/pages/concept-registration-page/form-concept/index.tsx index ce0d8fe1..6a63712c 100644 --- a/src/pages/concept-registration-page/form-concept/index.tsx +++ b/src/pages/concept-registration-page/form-concept/index.tsx @@ -38,7 +38,6 @@ import { schema as validationSchema } from './form-concept.schema'; import SC from './styled'; import { InternalInfo } from './internal-info'; -import { getConfig } from '../../../config'; import { setValidationError } from '../../../features/conceptForm'; export const validateWithPreProcess = ( @@ -123,11 +122,8 @@ export const FormConceptPure: FC = ({ } = errors; const [showUserPrompt, setShowUserPrompt] = useState(true); const [saveCalled, setSaveCalled] = useState(false); - const [deleteCalled, setDeleteCalled] = useState(false); const [newConceptId, setNewConceptId] = useState(null); - const config = getConfig(); - const languageEntities = useAppSelector(state => state.languages.entities); const appDispatch = useAppDispatch(); @@ -178,20 +174,16 @@ export const FormConceptPure: FC = ({ event.returnValue = ''; }; // if the form is NOT unchanged, then set the onbeforeunload - if (dirty && showUserPrompt && !(saveCalled || deleteCalled)) { + if (dirty && showUserPrompt && !saveCalled) { window.addEventListener('beforeunload', handler); // clean it up, if the dirty state changes return () => { window.removeEventListener('beforeunload', handler); }; } - - if (deleteCalled) { - window.location.href = `${config.conceptCatalogFrontendBaseUri}/${catalogId}`; - } // since this is not dirty, don't do anything return () => {}; - }, [dirty, showUserPrompt, saveCalled, deleteCalled]); + }, [dirty, showUserPrompt, saveCalled]); useEffect(() => { if (saveCalled) { @@ -206,7 +198,7 @@ export const FormConceptPure: FC = ({ return ( = ({ setSaveCalled(true); setNewConceptId(id); }} - onDelete={() => { - setDeleteCalled(true); - }} isInitialInValidForm={!isValid} lastPatchedResponse={lastPatchedResponse} values={values} From 1270c94657f891ee9c740a587f4184a05ddcdd34 Mon Sep 17 00:00:00 2001 From: Jeff Reiffers Date: Wed, 1 Nov 2023 07:26:33 +0100 Subject: [PATCH 2/2] feat: remove status and publishbuttons --- src/components/form-control/index.tsx | 88 --------------------------- 1 file changed, 88 deletions(-) diff --git a/src/components/form-control/index.tsx b/src/components/form-control/index.tsx index 86bfc318..2d8ff109 100644 --- a/src/components/form-control/index.tsx +++ b/src/components/form-control/index.tsx @@ -9,7 +9,6 @@ import { patchConceptFromForm, postConceptFromForm } from '../../lib/patchConceptForm'; -import { publishConceptFromForm } from '../../lib/publishConceptFromForm'; import SC from './styled'; @@ -26,7 +25,6 @@ const FormControl = ({ isFormDirty, onNewConceptRevision, onSave, - isInitialInValidForm, lastPatchedResponse, values }: Props) => { @@ -63,7 +61,6 @@ const FormControl = ({ const { concept } = conceptForm; const erSistPublisert = concept?.erSistPublisert ?? false; const published = concept?.erPublisert ?? false; - const validationError = conceptForm.isValidationError || isInitialInValidForm; const isSaving = conceptForm.isSaving ?? false; const justChangedStatus = conceptForm.justChangedStatus ?? false; const errorSaving = conceptForm.error ?? false; @@ -144,91 +141,6 @@ const FormControl = ({ {localization.save} )} - {!published && ( - { - setSaveCalled(true); - patchConceptFromForm( - { - status: ConceptStatus.HOERING, - ...(concept.versjonsnr?.major === 0 && - concept.versjonsnr?.minor === 0 && - concept.versjonsnr?.patch === 1 && { - versjonsnr: { major: 1, minor: 0, patch: 0 } - }) - }, - { - concept, - dispatch, - lastPatchedResponse: concept, - isSaving - } - ); - }} - > - - {localization.setToHoering} - - )} - {!published && ( - { - setSaveCalled(true); - patchConceptFromForm( - { - status: ConceptStatus.GODKJENT, - ...(concept.versjonsnr?.major === 0 && - concept.versjonsnr?.minor === 0 && - concept.versjonsnr?.patch === 1 && { - versjonsnr: { major: 1, minor: 0, patch: 0 } - }) - }, - { - concept, - dispatch, - lastPatchedResponse: concept, - isSaving - } - ); - }} - > - - {localization.setToApproval} - - )} - {!published && ( - { - setSaveCalled(true); - publishConceptFromForm({ - concept, - dispatch, - lastPatchedResponse: concept, - isSaving - }); - }} - > - - {localization.publish} - - )}
{createMessage()}