diff --git a/src/packages/components/page-title-block/index.tsx b/src/packages/components/page-title-block/index.tsx index 9526e3f94..1f25147c5 100644 --- a/src/packages/components/page-title-block/index.tsx +++ b/src/packages/components/page-title-block/index.tsx @@ -1,5 +1,5 @@ type PageTitleBlockTypes = { - titleLg1: string; + titleLg1?: string; titleLg2?: string; secondLang?: boolean; }; diff --git a/src/packages/model/operations/family.ts b/src/packages/model/operations/family.ts new file mode 100644 index 000000000..c0e5130d4 --- /dev/null +++ b/src/packages/model/operations/family.ts @@ -0,0 +1,8 @@ +import { ValidationState } from '../../components'; + +export type Family = { + id: string; + prefLabelLg1?: string; + prefLabelLg2?: string; + validationState: ValidationState; +}; diff --git a/src/packages/modules-classifications/item/client.js b/src/packages/modules-classifications/item/client.js index e82e46daa..9919d1612 100644 --- a/src/packages/modules-classifications/item/client.js +++ b/src/packages/modules-classifications/item/client.js @@ -13,7 +13,7 @@ export const fetchingPreviousLevels = (classificationId, general) => { general.broaderURI.lastIndexOf('/') ); const previousLevel = - levels[levels.findIndex((level) => level.indexOf(currentLevel) === 0)]; + levels[levels.findIndex((level) => level.startsWith(currentLevel))]; if (!!previousLevel) { return ClassificationsApi.getClassificationLevelMembers( diff --git a/src/packages/modules-operations/families/visualization/index.js b/src/packages/modules-operations/families/visualization/index.tsx similarity index 50% rename from src/packages/modules-operations/families/visualization/index.js rename to src/packages/modules-operations/families/visualization/index.tsx index 50bd82168..10ec67658 100644 --- a/src/packages/modules-operations/families/visualization/index.js +++ b/src/packages/modules-operations/families/visualization/index.tsx @@ -1,32 +1,27 @@ import D from '../../../deprecated-locales'; import { useSelector } from 'react-redux'; import { useParams } from 'react-router-dom'; -import { Button, ActionToolbar, ReturnButton } from '@inseefr/wilco'; import { Loading, ErrorBloc, - ValidationButton, PageTitleBlock, CheckSecondLang, } from '../../../components'; -import { useGoBack } from '../../../utils/hooks/useGoBack'; - import { useCallback, useEffect, useState } from 'react'; import OperationsFamilyVisualization from '../../../modules-operations/families/visualization/visualization'; -import { containUnsupportedStyles } from '../../../utils/html-utils'; import { getLocales } from '../../../redux/selectors'; import { getSecondLang } from '../../../redux/second-lang'; import { OperationsApi } from '../../../sdk/operations-api'; -import Auth from '../../../auth/components/auth'; -import { ADMIN } from '../../../auth/roles'; -const Family = () => { - const { id } = useParams(); - const langs = useSelector((state) => getLocales(state)); - const secondLang = useSelector((state) => getSecondLang(state)); - const goBack = useGoBack(); +import { Menu } from './menu'; +import { Family } from '../../../model/operations/family'; + +const FamilyView = () => { + const { id } = useParams<{ id: string }>(); + const langs = useSelector(getLocales); + const secondLang = useSelector(getSecondLang); - const [family, setFamily] = useState({}); + const [family, setFamily] = useState(); const [serverSideError, setServerSideError] = useState(); const [publishing, setPublishing] = useState(false); @@ -41,18 +36,13 @@ const Family = () => { .then(() => { return OperationsApi.getFamilyById(id).then(setFamily); }) - .catch((error) => setServerSideError(error)) + .catch((error: any) => setServerSideError(error)) .finally(() => setPublishing(false)); }, [family, id]); - if (!family.id) return ; - if (publishing) return ; + if (!family) return ; + if (publishing) return ; - /* - * The publication button should be enabled only if RICH_TEXT value do not - * have unsupported styles like STRIKETHROUGH, color or background color - */ - const publicationDisabled = containUnsupportedStyles(family); return (
{ titleLg2={family.prefLabelLg2} secondLang={secondLang} /> - - goBack('/operations/families')} /> - - - - - -
); }; -export default Family; +export default FamilyView; diff --git a/src/packages/modules-operations/families/visualization/menu.spec.tsx b/src/packages/modules-operations/families/visualization/menu.spec.tsx new file mode 100644 index 000000000..a9cae4d5b --- /dev/null +++ b/src/packages/modules-operations/families/visualization/menu.spec.tsx @@ -0,0 +1,31 @@ +import { render, screen } from '@testing-library/react'; +import { Menu } from './menu'; +import { RBACMock } from '../../../tests-utils/rbac'; +import { ADMIN } from '../../../auth/roles'; +import { Family } from '../../../model/operations/family'; + +describe('Family Home Page Menu', () => { + it('an admin can update and publish a family', () => { + render( + + + + ); + + screen.getByText('Update'); + screen.getByText('Publish'); + screen.getByText('Back'); + }); + + it('a user without Admin cannot create or publish a family', () => { + render( + + + + ); + + expect(screen.queryByText('Update')).toBeNull(); + expect(screen.queryByText('Publish')).toBeNull(); + screen.getByText('Back'); + }); +}); diff --git a/src/packages/modules-operations/families/visualization/menu.tsx b/src/packages/modules-operations/families/visualization/menu.tsx new file mode 100644 index 000000000..2f442c50a --- /dev/null +++ b/src/packages/modules-operations/families/visualization/menu.tsx @@ -0,0 +1,43 @@ +import { Family } from '../../../model/operations/family'; +import { ActionToolbar, Button, ReturnButton } from '@inseefr/wilco'; +import Auth from '../../../auth/components/auth'; +import { ADMIN } from '../../../auth/roles'; +import { ValidationButton } from '../../../components'; +import D from '../../../deprecated-locales/build-dictionary'; +import { containUnsupportedStyles } from '../../../utils/html-utils'; +import { useGoBack } from '../../../utils/hooks/useGoBack'; + +type MenuTypes = { + family: Family; + publish: () => void; +}; + +export const Menu = ({ family, publish }: Readonly) => { + const goBack = useGoBack(); + + /* + * The publication button should be enabled only if RICH_TEXT value do not + * have unsupported styles like STRIKETHROUGH, color or background color + */ + const publicationDisabled = containUnsupportedStyles(family); + + return ( + + goBack('/operations/families')} /> + + + + + +