From 74bab823bf32a2873835e3df879b28191f2085ed Mon Sep 17 00:00:00 2001 From: Antoine Dauchez Date: Fri, 10 Nov 2023 10:08:01 +0100 Subject: [PATCH 1/2] [DSM] Add 'mixed' capability to checkboxes in TableRow --- .../src/components/Table/Table.stories.mdx | 4 ++-- .../components/Table/TableRow/TableRow.tsx | 6 +++--- .../Table/TableRow/TableRow.unit.tsx | 21 ------------------- 3 files changed, 5 insertions(+), 26 deletions(-) diff --git a/front-packages/akeneo-design-system/src/components/Table/Table.stories.mdx b/front-packages/akeneo-design-system/src/components/Table/Table.stories.mdx index 4e7917bd591f..26bba1b2f0df 100644 --- a/front-packages/akeneo-design-system/src/components/Table/Table.stories.mdx +++ b/front-packages/akeneo-design-system/src/components/Table/Table.stories.mdx @@ -376,7 +376,7 @@ To compare information, for example how many products are completed versus how m {args => { - const [selectedLines, setSelectedLines] = useState([2]); + const [selectedLines, setSelectedLines] = useState([2, 3]); const handleToggleSelected = lineId => { if (selectedLines.indexOf(lineId) === -1) { setSelectedLines([...selectedLines, lineId]); @@ -410,7 +410,7 @@ To compare information, for example how many products are completed versus how m key={row.id} onClick={() => handleClick(row.id)} onSelectToggle={() => handleToggleSelected(row.id)} - isSelected={selectedLines.indexOf(row.id) !== -1} + isSelected={selectedLines.indexOf(row.id) !== -1 ? (row.id == 3 ? 'mixed' : true) : false} > The alt diff --git a/front-packages/akeneo-design-system/src/components/Table/TableRow/TableRow.tsx b/front-packages/akeneo-design-system/src/components/Table/TableRow/TableRow.tsx index 29d5ef8b5ed8..913b958f43f4 100644 --- a/front-packages/akeneo-design-system/src/components/Table/TableRow/TableRow.tsx +++ b/front-packages/akeneo-design-system/src/components/Table/TableRow/TableRow.tsx @@ -132,7 +132,7 @@ type TableRowProps = Override< /** * Define if the row is selected, required when table is selectable */ - isSelected?: boolean; + isSelected?: boolean| 'mixed'; /** * Define if the row has a warning @@ -165,7 +165,7 @@ const TableRow = forwardRef( ( { rowIndex = 0, - isSelected, + isSelected = false, level, onSelectToggle, onClick, @@ -228,7 +228,7 @@ const TableRow = forwardRef( onClick={handleCheckboxChange} > { handleCheckboxChange(e); }} diff --git a/front-packages/akeneo-design-system/src/components/Table/TableRow/TableRow.unit.tsx b/front-packages/akeneo-design-system/src/components/Table/TableRow/TableRow.unit.tsx index da595e09469f..8b97579f6853 100644 --- a/front-packages/akeneo-design-system/src/components/Table/TableRow/TableRow.unit.tsx +++ b/front-packages/akeneo-design-system/src/components/Table/TableRow/TableRow.unit.tsx @@ -75,27 +75,6 @@ test('it throws when onSelectToggle is not given on selectable table', () => { mockConsole.mockRestore(); }); -test('it throws when isSelected is not given on selectable table', () => { - const mockConsole = jest.spyOn(console, 'error').mockImplementation(); - - const onSelectToggle = jest.fn(); - const cellRender = () => - render( - - - - A value - Another value - - -
- ); - - expect(cellRender).toThrowError(); - - mockConsole.mockRestore(); -}); - test('Table.Row supports forwardRef', () => { const ref = {current: null}; render( From e94514db0495154319d080e8794697c5c1e63d6b Mon Sep 17 00:00:00 2001 From: Antoine Dauchez Date: Fri, 10 Nov 2023 10:51:30 +0100 Subject: [PATCH 2/2] Fix lint check --- .../src/components/Table/TableRow/TableRow.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front-packages/akeneo-design-system/src/components/Table/TableRow/TableRow.tsx b/front-packages/akeneo-design-system/src/components/Table/TableRow/TableRow.tsx index 913b958f43f4..90df869dcfcf 100644 --- a/front-packages/akeneo-design-system/src/components/Table/TableRow/TableRow.tsx +++ b/front-packages/akeneo-design-system/src/components/Table/TableRow/TableRow.tsx @@ -132,7 +132,7 @@ type TableRowProps = Override< /** * Define if the row is selected, required when table is selectable */ - isSelected?: boolean| 'mixed'; + isSelected?: boolean | 'mixed'; /** * Define if the row has a warning