-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1114 from InseeFr/1108-le-tableau-des-codes-nest-…
…pas-mis-à-jour-dans-le-formulaire-de-modification 1108 le tableau des codes nest pas mis à jour dans le formulaire de modification
- Loading branch information
Showing
5 changed files
with
161 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/packages/modules-codelists/components/codelist-detail/codes/table.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { vi } from 'vitest'; | ||
|
||
import { Table, TableTypes } from './table'; | ||
|
||
const mockData = [ | ||
{ | ||
code: '001', | ||
labelLg1: 'Label 1', | ||
labelLg2: 'Étiquette 1', | ||
broader: 'Parent 1', | ||
narrower: 'Child 1', | ||
iri: 'iri 1', | ||
closeMatch: 'Close Match 1', | ||
actions: <button>Action 1</button>, | ||
}, | ||
{ | ||
code: '002', | ||
labelLg1: 'Label 2', | ||
labelLg2: 'Étiquette 2', | ||
broader: 'Parent 2', | ||
narrower: 'Child 2', | ||
iri: 'iri 2', | ||
|
||
closeMatch: 'Close Match 2', | ||
actions: <button>Action 2</button>, | ||
}, | ||
]; | ||
|
||
describe('Table Component', () => { | ||
it('renders the table with data', () => { | ||
render( | ||
<Table | ||
loading={false} | ||
codesWithActions={mockData as unknown as TableTypes['codesWithActions']} | ||
total={2} | ||
state={{ first: 0, rows: 10 }} | ||
onPage={vi.fn()} | ||
/>, | ||
); | ||
|
||
screen.getByText('Label 1'); | ||
screen.getByText('Étiquette 1'); | ||
screen.getByText('Parent 1'); | ||
screen.getByText('Child 1'); | ||
screen.getByText('Close Match 1'); | ||
|
||
screen.getByText('Label 2'); | ||
screen.getByText('Étiquette 2'); | ||
screen.getByText('Parent 2'); | ||
screen.getByText('Child 2'); | ||
screen.getByText('Close Match 2'); | ||
}); | ||
|
||
it('renders loading state', () => { | ||
const { container } = render( | ||
<Table | ||
loading={true} | ||
codesWithActions={[] as unknown as TableTypes['codesWithActions']} | ||
total={0} | ||
state={{ first: 0, rows: 10 }} | ||
onPage={vi.fn()} | ||
/>, | ||
); | ||
|
||
expect(container.querySelector('.p-datatable-loading-icon')).not.toBeNull(); | ||
}); | ||
}); |
60 changes: 60 additions & 0 deletions
60
src/packages/modules-codelists/components/codelist-detail/codes/table.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Code } from '@model/CodesList'; | ||
import { Column } from 'primereact/column'; | ||
import { DataTableStateEvent } from 'primereact/datatable'; | ||
|
||
import { DataTable } from '@components/datatable'; | ||
|
||
import { D1, D2 } from '../../../i18n/build-dictionary'; | ||
|
||
export interface TableTypes { | ||
loading: boolean; | ||
codesWithActions: Omit<Code, 'broader' | 'narrower' | 'closeMatch'> & | ||
{ | ||
broader: string; | ||
narrower: string; | ||
closeMatch: string; | ||
actions: JSX.Element; | ||
}[]; | ||
total: number; | ||
state: { | ||
first: number; | ||
rows: number; | ||
}; | ||
onPage: (event: DataTableStateEvent) => void; | ||
} | ||
|
||
export const Table = ({ | ||
codesWithActions, | ||
loading, | ||
state, | ||
total, | ||
onPage, | ||
}: Readonly<TableTypes>) => { | ||
return ( | ||
<DataTable | ||
loading={loading} | ||
lazy | ||
first={state.first} | ||
rows={state.rows} | ||
withPagination={total > 10} | ||
rowsPerPageOptions={[10]} | ||
totalRecords={total} | ||
value={codesWithActions} | ||
onPage={onPage} | ||
> | ||
<Column field="code" header={D1.codeTitle}></Column> | ||
|
||
<Column field="labelLg1" header={D1.codeLabel}></Column> | ||
|
||
<Column field="labelLg2" header={D2.codeLabel}></Column> | ||
|
||
<Column field="broader" header={D1.codelistBroader}></Column> | ||
|
||
<Column field="narrower" header={D1.codelistNarrower}></Column> | ||
|
||
<Column field="closeMatch" header={D1.codelistCloseMatch}></Column> | ||
|
||
<Column field="actions" header=""></Column> | ||
</DataTable> | ||
); | ||
}; |