Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/migrate all operations menu #907

Merged
merged 11 commits into from
Sep 2, 2024
1 change: 0 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
npm test
5 changes: 3 additions & 2 deletions src/packages/auth/components/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ export const mapStateToProps = (state: ReduxModel) => {
const mapDispatchToProps = {
loadUserStamp: loadUserStamp,
};

export type RoleCheck = string | [string, (value: string) => boolean];
export type RoleChecks = Array<RoleCheck>;
type AuthDumbTypes = {
userRoles?: string[];
userStamp?: string;
roles: Array<string | [string, (value: string) => boolean]>;
roles: RoleChecks;
fallback?: any;
complementaryCheck?: boolean;
loadUserStamp?: any;
Expand Down
6 changes: 6 additions & 0 deletions src/packages/model/Operation.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { Series } from './operations/series';
import { ValidationState } from '../components';

/**
* Type used when fetching all Series
*/
Expand All @@ -7,6 +10,9 @@ export type Operation = {
altLabel: string;
iri: string;
seriesIri: string;
idSims?: string;
series: Series;
validationState: ValidationState;
};

export type SeeAlso = {
Expand Down
8 changes: 8 additions & 0 deletions src/packages/model/Sims.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { ValidationState } from '../components';

export type Rubric = {
idAttribute: string;
};

export type Sims = {
id: string;
creators: string[];
idIndicator?: string;
idOperation?: string;
idSeries?: string;
validationState: ValidationState;
parentsWithoutSims: any[];
};
8 changes: 8 additions & 0 deletions src/packages/model/operations/indicator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ValidationState } from '../../components';

export type Indicator = {
id: string;
idSims: string;
validationState: ValidationState;
creators: string[];
};
10 changes: 10 additions & 0 deletions src/packages/model/operations/series.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ValidationState } from '../../components';
import { Operation } from '../Operation';

export type Series = {
id: string;
creators: string[];
validationState: ValidationState;
idSims?: string;
operations: Operation[];
};
18 changes: 3 additions & 15 deletions src/packages/modules-operations/indicators/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
import { useEffect, useState } from 'react';
import { VerticalMenu } from '@inseefr/wilco';

import D from '../../deprecated-locales';
import {
MasculineButton,
SearchableList,
PageTitle,
Loading,
} from '../../components';
import { SearchableList, PageTitle, Loading } from '../../components';
import { useTitle } from '../../utils/hooks/useTitle';
import { OperationsApi } from '../../sdk/operations-api';
import { sortArray } from '../../utils/array-utils';
import Auth from '../../auth/components/auth';
import { ADMIN } from '../../auth/roles';
import { Menu } from './menu';

function IndicatorsHome() {
useTitle(D.operationsTitle, D.indicatorsTitle);
Expand All @@ -30,11 +22,7 @@ function IndicatorsHome() {
return (
<div className="container">
<div className="row">
<Auth roles={[ADMIN]}>
<VerticalMenu>
<MasculineButton action="/operations/indicator/create" />
</VerticalMenu>
</Auth>
<Menu></Menu>
<div className="col-md-8 text-center pull-right operations-list">
<PageTitle title={D.indicatorsSearchTitle} col={12} offset={0} />
<SearchableList
Expand Down
26 changes: 26 additions & 0 deletions src/packages/modules-operations/indicators/menu.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { render, screen } from '@testing-library/react';
import { Menu } from './menu';
import { RBACMock } from '../../tests-utils/rbac';
import { ADMIN } from '../../auth/roles';

describe('Family Home Page Menu', () => {
it('an admin can update and publish a family', () => {
render(
<RBACMock roles={[ADMIN]}>
<Menu />
</RBACMock>
);

screen.getByText('New');
});

it('a user without Admin cannot create or publish a family', () => {
render(
<RBACMock roles={[]}>
<Menu />
</RBACMock>
);

expect(screen.queryByText('New')).toBeNull();
});
});
14 changes: 14 additions & 0 deletions src/packages/modules-operations/indicators/menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ADMIN } from '../../auth/roles';
import { VerticalMenu } from '@inseefr/wilco';
import { MasculineButton } from '../../components';
import Auth from '../../auth/components/auth';

export const Menu = () => {
return (
<Auth roles={[ADMIN]}>
<VerticalMenu>
<MasculineButton action="/operations/indicator/create" />
</VerticalMenu>
</Auth>
);
};
46 changes: 3 additions & 43 deletions src/packages/modules-operations/indicators/visualization/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,19 @@ import { useParams } from 'react-router-dom';
import D from '../../../deprecated-locales';
import { useSelector } from 'react-redux';
import OperationsIndicatorVisualization from '../../../modules-operations/indicators/visualization/general';
import { Button, ActionToolbar, ReturnButton } from '@inseefr/wilco';
import {
Loading,
ErrorBloc,
ValidationButton,
PageTitleBlock,
CheckSecondLang,
} from '../../../components';
import { useGoBack } from '../../../utils/hooks/useGoBack';

import { CL_FREQ } from '../../../redux/actions/constants/codeList';
import { useCodesList } from '../../../utils/hooks/codeslist';
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, INDICATOR_CONTRIBUTOR } from '../../../auth/roles';
import { Menu } from './menu';
const IndicatorVisualizationContainer = () => {
const { id } = useParams();

Expand All @@ -31,8 +26,6 @@ const IndicatorVisualizationContainer = () => {
(state) => state.operationsOrganisations.results || []
);

const goBack = useGoBack();

const [indicator, setIndicator] = useState({});

const [serverSideError, setServerSideError] = useState();
Expand All @@ -55,48 +48,15 @@ const IndicatorVisualizationContainer = () => {
if (!indicator.id) return <Loading />;
if (publishing) return <Loading text={'publishing'} />;

/*
* 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(indicator);
const checkStamp = (stamp) => indicator.creators.includes(stamp);

return (
<div className="container">
<PageTitleBlock
titleLg1={indicator.prefLabelLg1}
titleLg2={indicator.prefLabelLg2}
secondLang={secondLang}
/>
<ActionToolbar>
<ReturnButton action={() => goBack('/operations/indicators')} />
{indicator.idSims && (
<Button
action={`/operations/sims/${indicator.idSims}`}
label={D.btnSimsVisu}
/>
)}
{!indicator.idSims && (
<Auth roles={[ADMIN, [INDICATOR_CONTRIBUTOR, checkStamp]]}>
<Button
action={`/operations/indicator/${indicator.id}/sims/create`}
label={D.btnSimsCreate}
/>
</Auth>
)}
<Auth roles={[ADMIN, [INDICATOR_CONTRIBUTOR, checkStamp]]}>
<ValidationButton
object={indicator}
callback={publish}
disabled={publicationDisabled}
/>
<Button
action={`/operations/indicator/${indicator.id}/modify`}
label={D.btnUpdate}
/>
</Auth>
</ActionToolbar>
<Menu indicator={indicator} publish={publish} />

{serverSideError && <ErrorBloc error={serverSideError} D={D} />}

<CheckSecondLang />
Expand Down
Loading