diff --git a/src/packages/modules-operations/document/edition/edition.jsx b/src/packages/modules-operations/document/edition/edition.jsx index 455190a39..a813d35f3 100644 --- a/src/packages/modules-operations/document/edition/edition.jsx +++ b/src/packages/modules-operations/document/edition/edition.jsx @@ -154,7 +154,11 @@ const OperationsDocumentationEdition = (props) => { saveDocument(document, type, files) .then( (id = document.id) => { - goBack(`/operations/${type}/${id}`, isCreation); + if (props.onSave) { + props.onSave(id); + } else { + goBack(`/operations/${type}/${id}`, isCreation); + } }, (err) => { setServerSideError(err); @@ -219,7 +223,11 @@ const OperationsDocumentationEdition = (props) => { /> )} - goBack('/operations/documents')} /> + + props.onCancel ? props.onCancel() : goBack('/operations/documents') + } + /> 0} diff --git a/src/packages/modules-operations/msd/documents/documents-bloc/index.jsx b/src/packages/modules-operations/msd/documents/documents-bloc/index.jsx index bb50a096b..1b57125b8 100644 --- a/src/packages/modules-operations/msd/documents/documents-bloc/index.jsx +++ b/src/packages/modules-operations/msd/documents/documents-bloc/index.jsx @@ -1,7 +1,7 @@ import D, { D1, D2 } from '../../../../deprecated-locales'; import { useState, useEffect } from 'react'; import './style.scss'; -import { isDocument, isLink } from '../../../document/utils'; +import { DOCUMENT, isDocument, isLink, LINK } from '../../../document/utils'; import { getBaseURI } from '../../../../sdk'; import { sortArray } from '../../../../utils/array-utils'; import { getLang } from '../../../../utils/dictionnary'; @@ -43,7 +43,7 @@ export function DocumentsBloc({ addHandler, objectType, }) { - const documentStores = useDocumentsStoreContext(); + const { documentStores, openLateralPanelOpened } = useDocumentsStoreContext(); /** * @param {import('js/types').SimsDocuments} document @@ -127,7 +127,7 @@ export function DocumentsBloc({ )} {editMode && ( -
+
+
{panelStatus && (
diff --git a/src/packages/modules-operations/msd/documents/documents-bloc/index.spec.jsx b/src/packages/modules-operations/msd/documents/documents-bloc/index.spec.jsx index 368924058..23b6aaf3d 100644 --- a/src/packages/modules-operations/msd/documents/documents-bloc/index.spec.jsx +++ b/src/packages/modules-operations/msd/documents/documents-bloc/index.spec.jsx @@ -44,7 +44,9 @@ const documents = [ export const renderWithStore = (component) => { return render( - + {component} ); diff --git a/src/packages/modules-operations/msd/documents/documents-bloc/style.scss b/src/packages/modules-operations/msd/documents/documents-bloc/style.scss index 2946b8922..d81e90268 100644 --- a/src/packages/modules-operations/msd/documents/documents-bloc/style.scss +++ b/src/packages/modules-operations/msd/documents/documents-bloc/style.scss @@ -23,3 +23,15 @@ flex: 2 1 auto; } } + +.documentblock__picker { + .panel-heading { + display: flex; + justify-content: space-between; + + .btn { + background-color: transparent; + } + } + +} diff --git a/src/packages/modules-operations/msd/index.jsx b/src/packages/modules-operations/msd/index.jsx index 6865fe5f5..5c34d4f22 100644 --- a/src/packages/modules-operations/msd/index.jsx +++ b/src/packages/modules-operations/msd/index.jsx @@ -17,9 +17,7 @@ import { getOperationsCodesList } from '../../redux/operations/selector'; import { useParams } from 'react-router-dom'; import { getOperationsSimsCurrent } from '../../redux/selectors'; -import { GeneralApi } from '../../sdk/general-api'; import { OperationsApi } from '../../sdk/operations-api'; -import { sortArray } from '../../utils/array-utils'; import { useOrganizations } from '../../utils/hooks/organizations'; import { useGoBack } from '../../utils/hooks/useGoBack'; import { SimsContextProvider } from './context'; @@ -27,6 +25,7 @@ import './msd.scss'; import { DocumentsStoreProvider } from './pages/sims-creation/documents-store-context'; import { isEssentialRubricKo } from './sims-field-title'; import { getParentId, getParentType } from './utils'; +import { useDocumentsList } from './pages/sims-creation/useDocumentsList'; export const HELP = 'HELP'; export const CREATE = 'CREATE'; @@ -263,10 +262,7 @@ const MSDContainerWithParent = (props) => { const { idParent, parentType } = props; const [parent, setParent] = useState(props.parent); const [loading, setLoading] = useState(true); - const [documentStores, setDocumentStores] = useState({ - lg1: [], - lg2: [], - }); + const { documentStores, setDocumentStores } = useDocumentsList(); const goBack = useGoBack(); @@ -297,25 +293,20 @@ const MSDContainerWithParent = (props) => { } }, [idParent, parentType]); - useEffect(() => { - GeneralApi.getDocumentsList().then((results) => { - const unSortedDocuments = results.map((document) => { - return { - ...document, - id: document.uri.substr(document.uri.lastIndexOf('/') + 1), - }; - }); - setDocumentStores({ - lg1: sortArray('labelLg1')(unSortedDocuments), - lg2: sortArray('labelLg2')(unSortedDocuments), - }); - }); - }, []); + const [lateralPanelOpened, setLateralPanelOpened] = useState(); if (loading) return ; return ( - + setLateralPanelOpened(undefined), + openLateralPanelOpened: (type) => setLateralPanelOpened(type), + }} + > void; +}; +export const DocumentFormPanel = ({ + opened, + onHide, +}: Readonly) => { + const langOptions = useCodesList('ISO-639'); + const { lateralPanelOpened, onLateralPanelHide, updateDocumentStores } = + useDocumentsStoreContext(); + const [saving, setSaving] = useState(false); + + const onSave = () => { + setSaving(true); + getDocumentsList() + .then((result) => updateDocumentStores(result)) + .then(() => { + setSaving(false); + if (onLateralPanelHide) { + onLateralPanelHide(); + } + }); + }; + + return ( + + {saving ? ( + + ) : ( + + )} + + ); +}; diff --git a/src/packages/modules-operations/msd/pages/sims-creation/documents-store-context.tsx b/src/packages/modules-operations/msd/pages/sims-creation/documents-store-context.tsx index 80fd288a7..dcf3ded47 100644 --- a/src/packages/modules-operations/msd/pages/sims-creation/documents-store-context.tsx +++ b/src/packages/modules-operations/msd/pages/sims-creation/documents-store-context.tsx @@ -1,10 +1,18 @@ import { createContext, useContext } from 'react'; import { Document } from '../../../../model/operations/document'; +import { DOCUMENT, LINK } from '../../../document/utils'; -export type DocumentsStoreContextType = { +export type DocumentsStoreObject = { lg1: Document[]; lg2: Document[]; }; +export type DocumentsStoreContextType = { + documentStores: DocumentsStoreObject; + updateDocumentStores: (store: DocumentsStoreObject) => void; + lateralPanelOpened?: typeof DOCUMENT | typeof LINK; + onLateralPanelHide?: () => void; + openLateralPanelOpened?: (type: typeof DOCUMENT | typeof LINK) => void; +}; const DocumentsStoreContext = createContext< DocumentsStoreContextType | undefined >(undefined); diff --git a/src/packages/modules-operations/msd/pages/sims-creation/index.jsx b/src/packages/modules-operations/msd/pages/sims-creation/index.jsx index 7abebd283..66e73113e 100644 --- a/src/packages/modules-operations/msd/pages/sims-creation/index.jsx +++ b/src/packages/modules-operations/msd/pages/sims-creation/index.jsx @@ -25,6 +25,8 @@ import { flattenTree, rangeType } from '../../../utils/msd'; import { RubricEssentialMsg } from '../../rubric-essantial-msg'; import './sims-creation.scss'; import { useBlocker } from 'react-router-dom'; +import { DocumentFormPanel } from './document-form-panel'; +import { useDocumentsStoreContext } from './documents-store-context'; const { RICH_TEXT } = rangeType; @@ -255,6 +257,9 @@ const SimsCreation = ({ }); }; }; + + const { lateralPanelOpened, onLateralPanelHide } = useDocumentsStoreContext(); + if (loading) return ; if (saving) return ; @@ -267,6 +272,11 @@ const SimsCreation = ({ + + {Object.values(metadataStructure).map((msd, index) => { return (
diff --git a/src/packages/modules-operations/msd/pages/sims-creation/sims-document-field.tsx b/src/packages/modules-operations/msd/pages/sims-creation/sims-document-field.tsx index 594aff289..c68cf0a27 100644 --- a/src/packages/modules-operations/msd/pages/sims-creation/sims-document-field.tsx +++ b/src/packages/modules-operations/msd/pages/sims-creation/sims-document-field.tsx @@ -43,7 +43,6 @@ export const SimsDocumentField = ({ return ( <> - {' '}
.panel-default > .panel-heading { padding: 5px 15px; background-color: var(--color-2); color: white; diff --git a/src/packages/modules-operations/msd/pages/sims-creation/useDocumentsList.ts b/src/packages/modules-operations/msd/pages/sims-creation/useDocumentsList.ts new file mode 100644 index 000000000..f6053b423 --- /dev/null +++ b/src/packages/modules-operations/msd/pages/sims-creation/useDocumentsList.ts @@ -0,0 +1,31 @@ +import { sortArray } from '../../../../utils/array-utils'; +import { GeneralApi } from '../../../../sdk/general-api'; +import { useEffect, useState } from 'react'; + +export const useDocumentsList = () => { + const [documentStores, setDocumentStores] = useState({ + lg1: [], + lg2: [], + }); + + useEffect(() => { + getDocumentsList().then((result: any) => setDocumentStores(result)); + }, []); + + return { documentStores, setDocumentStores }; +}; + +export const getDocumentsList = () => { + return GeneralApi.getDocumentsList().then((results: any) => { + const unSortedDocuments = results.map((document: any) => { + return { + ...document, + id: document.uri.substr(document.uri.lastIndexOf('/') + 1), + }; + }); + return { + lg1: sortArray('labelLg1')(unSortedDocuments), + lg2: sortArray('labelLg2')(unSortedDocuments), + }; + }); +}; diff --git a/src/packages/modules-operations/msd/pages/sims-visualisation/index.jsx b/src/packages/modules-operations/msd/pages/sims-visualisation/index.jsx index f0db7fec2..b98a309fe 100644 --- a/src/packages/modules-operations/msd/pages/sims-visualisation/index.jsx +++ b/src/packages/modules-operations/msd/pages/sims-visualisation/index.jsx @@ -43,7 +43,7 @@ export default function SimsVisualisation({ missingDocuments, owners = [], }) { - const documentStores = useDocumentsStoreContext(); + const { documentStores } = useDocumentsStoreContext(); const [secondLang] = useSecondLang(); const [modalOpened, setModalOpened] = useState(false); const [exportModalOpened, setExportModalOpened] = useState(false); diff --git a/src/packages/modules-operations/msd/pages/sims-visualisation/sims-block-richtext.spec.jsx b/src/packages/modules-operations/msd/pages/sims-visualisation/sims-block-richtext.spec.jsx index 7edcd4de5..a286cc607 100644 --- a/src/packages/modules-operations/msd/pages/sims-visualisation/sims-block-richtext.spec.jsx +++ b/src/packages/modules-operations/msd/pages/sims-visualisation/sims-block-richtext.spec.jsx @@ -4,7 +4,7 @@ import { DocumentsStoreProvider } from '../sims-creation/documents-store-context export const renderWithStore = (component) => { return render( - + {component} );