Skip to content

Commit

Permalink
Merge pull request #878 from InseeFr/fix/rewrite-new
Browse files Browse the repository at this point in the history
feat: migrate 2 components
  • Loading branch information
PierreVasseur authored Aug 2, 2024
2 parents 26a8a8d + 2ca2613 commit 278d315
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react';
import { useHistory } from 'react-router-dom';
import { Table, NumberResult } from '@inseefr/wilco';
import DatePickerRmes from '../../../../../../applications/shared/date-picker-rmes';
import { DatePicker } from '../../../../../../new-architecture/components';
import D from '../../../../../../i18n';
import { rowParams } from './data';
import dayjs from 'dayjs';
Expand Down Expand Up @@ -36,7 +36,7 @@ const CollectionsCreationsModifications = ({ collectionsData, type }) => {
<div className="row" style={{ marginTop: '2%' }}>
<div className="form-group col-md-4 col-md-offset-4 text-center">
<label>{D.dashboardConceptsListPickerTitle(typeByLang)}</label>
<DatePickerRmes
<DatePicker
value={dateFilter}
onChange={setDateFilter}
placement="top"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react';
import { useHistory } from 'react-router-dom';
import { Table, NumberResult } from '@inseefr/wilco';
import DatePickerRmes from '../../../../../../applications/shared/date-picker-rmes';
import { DatePicker } from '../../../../../../new-architecture/components';
import D from '../../../../../../i18n';
import { rowParams } from './data';
import dayjs from 'dayjs';
Expand Down Expand Up @@ -37,7 +37,7 @@ const ConceptsCreationsModifications = ({ conceptsData, type }) => {
<div className="row" style={{ marginTop: '2%' }}>
<div className="form-group col-md-4 col-md-offset-4 text-center">
<label>{D.dashboardConceptsListPickerTitle(typeByLang)}</label>
<DatePickerRmes
<DatePicker
value={dateFilter}
onChange={setDateFilter}
placement="top"
Expand Down
9 changes: 4 additions & 5 deletions src/js/applications/administration/dashboard/concepts/home.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { PageTitle } from '../../../../new-architecture/components';
import { PageTitle, Tabs } from '../../../../new-architecture/components';
import Controls from './controls';
import TabsRmes from '../../../../applications/shared/tabs-rmes/tabs-rmes';
import ConceptsSummary from './concepts/summary';
import ConceptsCreationsModifications from './concepts/creations-modifications';
import CollectionsSummary from './collections/summary';
Expand Down Expand Up @@ -59,14 +58,14 @@ function ConceptsDashboard({ conceptsData, collectionsData }) {
},
];
const tabs = [
{ title: D.conceptsTitle, content: <TabsRmes tabs={tabsConcepts} /> },
{ title: D.collectionsTitle, content: <TabsRmes tabs={tabsCollections} /> },
{ title: D.conceptsTitle, content: <Tabs tabs={tabsConcepts} /> },
{ title: D.collectionsTitle, content: <Tabs tabs={tabsCollections} /> },
];
return (
<div className="container">
<PageTitle title={D.dashboardConceptsTitle} />
<Controls />
<TabsRmes tabs={tabs} />
<Tabs tabs={tabs} />
</div>
);
}
Expand Down
15 changes: 9 additions & 6 deletions src/js/applications/concepts/advanced-search/home.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Link, useHistory } from 'react-router-dom';
import { NumberResult } from '@inseefr/wilco';
import { PageTitle, TextInput } from '../../../new-architecture/components';
import {
PageTitle,
TextInput,
DatePicker,
} from '../../../new-architecture/components';

import Select from 'react-select';
import Controls from './controls';
import DatePickerRmes from '../../../applications/shared/date-picker-rmes';
import D from '../../../i18n';
import { filterKeyDate } from '../../../new-architecture/utils/array-utils';
import {
Expand Down Expand Up @@ -176,7 +179,7 @@ const ConceptSearchList = ({
<label>{D.conceptsCreationDateMessage}</label>
</div>
<div className="col-md-4">
<DatePickerRmes
<DatePicker
value={dateCreatedStart}
onChange={(value) => handleChange('dateCreatedStart', value)}
placement="bottom"
Expand All @@ -186,7 +189,7 @@ const ConceptSearchList = ({
<label>{D.conceptsTransitionDateMessage}</label>
</div>
<div className="col-md-4">
<DatePickerRmes
<DatePicker
value={dateCreatedEnd}
onChange={(value) => handleChange('dateCreatedEnd', value)}
placement="bottom"
Expand All @@ -198,7 +201,7 @@ const ConceptSearchList = ({
<label>{D.conceptsUpdateDateMessage}</label>
</div>
<div className="col-md-4">
<DatePickerRmes
<DatePicker
value={dateModifiedStart}
onChange={(value) => handleChange('dateModifiedStart', value)}
placement="bottom"
Expand All @@ -208,7 +211,7 @@ const ConceptSearchList = ({
<label>{D.conceptsTransitionDateMessage}</label>
</div>
<div className="col-md-4">
<DatePickerRmes
<DatePicker
value={dateModifiedEnd}
onChange={(value) => handleChange('dateModifiedEnd', value)}
placement="bottom"
Expand Down
8 changes: 2 additions & 6 deletions src/js/applications/concepts/edition-creation/general.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import D, { D1, D2 } from '../../../i18n';
import DatePickerRmes from '../../../applications/shared/date-picker-rmes';
import InputRmes from '../../../applications/shared/input-rmes';
import InputMultiRmes from '../../../applications/shared/input-multi-rmes';
import { fields as generalFields } from '../../../utils/concepts/general';
Expand All @@ -9,6 +8,7 @@ import {
DisseminationStatusInput,
ClientSideError,
RequiredIcon,
DatePicker,
} from '../../../new-architecture/components';
import Select from './../../../utils/components/select-rmes';

Expand Down Expand Up @@ -125,11 +125,7 @@ function ConceptGeneralEdition({
</div>
<div className="form-group">
<label>{D1.validDateTitle}</label>
<DatePickerRmes
value={valid}
onChange={handlers.valid}
placement="top"
/>
<DatePicker value={valid} onChange={handlers.valid} placement="top" />
</div>
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions src/js/applications/operations/document/edition/edition.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
ActionToolbar,
LabelRequired,
} from '@inseefr/wilco';
import DatePickerRmes from '../../../../applications/shared/date-picker-rmes';
import api from '../../../../remote-api/api';
import Modal from 'react-modal';
import {
Expand All @@ -22,6 +21,7 @@ import {
ErrorBloc,
GlobalClientSideErrorBloc,
ClientSideError,
DatePicker,
} from '../../../../new-architecture/components';
import Select from '../../../../utils/components/select-rmes';

Expand Down Expand Up @@ -338,7 +338,7 @@ const OperationsDocumentationEdition = (props) => {
<Row>
<div className="col-md-12 form-group">
<LabelRequired>{D1.titleUpdatedDate}</LabelRequired>
<DatePickerRmes
<DatePicker
value={updatedDate}
onChange={(date) => {
const value = date && date.split('T')[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PureComponent } from 'react';
import D from '../../../../../i18n';
import { rangeType } from '../../../../../utils/msd/';
import DatePickerRmes from '../../../../../applications/shared/date-picker-rmes';
import { DatePicker } from '../../../../../new-architecture/components';
import InputRmes from '../../../../../applications/shared/input-rmes';
import {
EditorMarkdownToolbar,
Expand Down Expand Up @@ -162,7 +162,7 @@ class SimsField extends PureComponent {
/>
)}
{msd.rangeType === DATE && (
<DatePickerRmes
<DatePicker
aria-label={D.simsValue}
id={msd.idMas}
colMd={12}
Expand Down
20 changes: 0 additions & 20 deletions src/js/applications/shared/date-picker-rmes/index.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { render } from '@testing-library/react';
import DatePickerRmes from './';
import { DatePicker } from './';

describe('date-picker', () => {
it('renders without crashing', () => {
render(<DatePickerRmes />);
render(<DatePicker />);
});
});
30 changes: 30 additions & 0 deletions src/js/new-architecture/components/date-picker/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// @ts-ignore
import BootstrapDatePicker from 'react-16-bootstrap-date-picker';
import { D1, D2 } from '../../../i18n';

type DatePickerTypes = {
value: string;
onChange: (value: string) => void;
placement: string;
secondLang?: boolean;
};
export const DatePicker = ({
value,
onChange,
placement,
secondLang = false,
}: DatePickerTypes) => {
const days = secondLang ? D2.calendarDays : D1.calendarDays;
const months = secondLang ? D2.calendarMonths : D1.calendarMonths;

return (
<BootstrapDatePicker
value={value}
calendarPlacement={placement}
onChange={onChange}
weekStartsOn={1}
dayLabels={days}
monthLabels={months}
/>
);
};
2 changes: 2 additions & 0 deletions src/js/new-architecture/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './data/conditional-display';
export * from './data/creators';
export * from './contributors/contributors';
export * from './date-picker';
export * from './dissemination-status/disseminationStatus';
export * from './errors-bloc/index';
export * from './creators-input';
Expand All @@ -10,5 +11,6 @@ export * from './loading/loading';
export * from './new-button';
export * from './required-icon';
export * from './status';
export * from './tabs/tabs';
export * from './page-title';
export * from './validationButton';
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render, fireEvent, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import TabsRmes from './tabs-rmes';
import { Tabs } from './tabs';

describe('TabsRmes Component', () => {
const tabsMock = [
Expand All @@ -10,19 +10,19 @@ describe('TabsRmes Component', () => {
];

it('should render correctly with initial active tab', () => {
render(<TabsRmes tabs={tabsMock} />);
render(<Tabs tabs={tabsMock} />);
expect(screen.getByText('Content 1')).toBeVisible();
});

it('should switch tabs on click', () => {
render(<TabsRmes tabs={tabsMock} />);
render(<Tabs tabs={tabsMock} />);
const secondTab = screen.getByRole('tab', { name: 'Tab 2' });
fireEvent.click(secondTab);
expect(screen.getByText('Content 2')).toBeVisible();
});

it('should not switch to disabled tab', () => {
render(<TabsRmes tabs={tabsMock} />);
render(<Tabs tabs={tabsMock} />);
const disabledTab = screen.getByRole('tab', { name: 'Tab 3' });
fireEvent.click(disabledTab);
expect(screen.getByText('Content 1')).toBeVisible();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
import { useId, useState } from 'react';
import { Tabs, Tab } from 'react-bootstrap';
import { Tabs as BootstrapTabs, Tab as BootstrapTab } from 'react-bootstrap';

const TabsRmes = ({ tabs }) => {
export const Tabs = ({
tabs,
}: {
tabs: { title: string; disabled: boolean; content: unknown }[];
}) => {
const [activeTab, setActiveTab] = useState(0);
const id = useId();
return (
<ul className="nav nav-tabs nav-justified">
<Tabs
<BootstrapTabs
id={id}
defaultActiveKey={0}
onSelect={(index) => setActiveTab(index)}
onSelect={(index: number) => setActiveTab(index)}
justified
>
{tabs.map((t, i) => (
<Tab
<BootstrapTab
key={`tab${i}`}
eventKey={i}
title={t.title}
disabled={t.disabled}
>
{activeTab === i && t.content}
</Tab>
</BootstrapTab>
))}
</Tabs>
</BootstrapTabs>
</ul>
);
};

export default TabsRmes;
3 changes: 3 additions & 0 deletions src/react-app-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/// <reference types="react-scripts" />

declare module 'react-16-bootstrap-date-picker';
declare module 'react-bootstrap';

declare module '@inseefr/wilco';

0 comments on commit 278d315

Please sign in to comment.