-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: QUV-2455 New table rowGroupingRenderer preset
- Loading branch information
santiago.trigo
committed
Aug 6, 2024
1 parent
babed5b
commit 0af7f76
Showing
12 changed files
with
155 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { TColDef } from '../declarations'; | ||
import { RowGroupingRenderer } from '../renderers'; | ||
|
||
export const rowGrouping: TColDef = { | ||
id: 'rowGrouping', | ||
cellRenderer: RowGroupingRenderer, | ||
minWidth: 50, | ||
headerOnFilterPosition: true, | ||
}; |
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,8 @@ | ||
import * as React from 'react'; | ||
|
||
export type TRowGroupingContext = { | ||
onRowGroupingChange?: ( | ||
rowIndex: number, | ||
event: React.FormEvent<Element>, | ||
) => void; | ||
}; |
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 @@ | ||
export * from './RowGroupingContext'; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './Action'; | ||
export * from './Bulk'; | ||
export * from './Options'; | ||
export * from './RowGrouping'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as React from 'react'; | ||
|
||
export const useRowGrouping = ({ data, initialSelection = [] }) => { | ||
const [rowSelection, setRowSelection] = React.useState(initialSelection); | ||
|
||
const toggle = React.useCallback( | ||
(index: number) => { | ||
setRowSelection(() => | ||
data.map((d, i) => { | ||
if (index === i) { | ||
d.rowGrouping = !d.rowGrouping; | ||
} | ||
return d; | ||
}), | ||
); | ||
}, | ||
[data], | ||
); | ||
return { rowSelection, toggle }; | ||
}; |
17 changes: 17 additions & 0 deletions
17
packages/table/src/renderers/RowGroupingRenderer/RowGroupingRenderer.stories.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,17 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { RowGroupingRenderer } from './RowGroupingRenderer'; | ||
|
||
const meta: Meta<typeof RowGroupingRenderer> = { | ||
title: 'Components/Layout/Table/Renderers/rowGroupingRenderer', | ||
component: RowGroupingRenderer, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof RowGroupingRenderer>; | ||
|
||
export const Base: Story = { | ||
args: { | ||
value: false, | ||
}, | ||
}; |
25 changes: 25 additions & 0 deletions
25
packages/table/src/renderers/RowGroupingRenderer/RowGroupingRenderer.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,25 @@ | ||
import * as React from 'react'; | ||
|
||
import { IconButtonCollapse } from '@devoinc/genesys-ui'; | ||
|
||
import type { TCellRenderer } from '../../declarations'; | ||
import { TRowGroupingContext } from '../../facade'; | ||
|
||
export const RowGroupingRenderer: React.FC<TCellRenderer> = ({ | ||
value, | ||
rowIndex, | ||
colDef, | ||
}) => { | ||
const context = colDef?.context as TRowGroupingContext; | ||
|
||
return ( | ||
<IconButtonCollapse | ||
onClick={(event) => { | ||
if (context?.onRowGroupingChange) { | ||
context.onRowGroupingChange(rowIndex, event); | ||
} | ||
}} | ||
state={value ? 'expanded' : 'enabled'} | ||
/> | ||
); | ||
}; |
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 @@ | ||
export * from './RowGroupingRenderer'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import * as React from 'react'; | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { Flex } from '@devoinc/genesys-ui'; | ||
|
||
import { | ||
orderDataByOrderStruct, | ||
RowGroupingRenderer, | ||
Table, | ||
TColDef, | ||
TextRenderer, | ||
useOrderStruct, | ||
useRowGrouping, | ||
} from '../src'; | ||
|
||
const meta: Meta<typeof Table> = { | ||
title: 'Components/Layout/Table/RowGrouping', | ||
component: Table, | ||
parameters: { | ||
layout: 'fullscreen', | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof Table>; | ||
|
||
const initialData = Array.from({ length: 10 }).map((_, index) => ({ | ||
rowGrouping: false, | ||
text: `text ${index}`, | ||
})); | ||
|
||
const BulkExample = () => { | ||
const { orderStruct, onSort } = useOrderStruct([ | ||
{ id: 'text', sort: 'desc' }, | ||
]); | ||
const dataOrdered = [...initialData].sort(orderDataByOrderStruct(orderStruct)); | ||
|
||
const { rowSelection, toggle } = useRowGrouping({ data: dataOrdered, initialSelection: [] }); | ||
|
||
return ( | ||
<Flex flexDirection="column" gap="cmp-md"> | ||
<Flex.Item> | ||
<Table | ||
data={dataOrdered} | ||
onSort={(colDef: TColDef) => { | ||
onSort(colDef.id); | ||
}} | ||
colDefs={[ | ||
{ | ||
id: 'rowGrouping', | ||
cellRenderer: RowGroupingRenderer, | ||
width: 46, | ||
context: { | ||
rowSelection, | ||
onRowGroupingChange: (rowIndex) => { | ||
toggle(rowIndex); | ||
}, | ||
} | ||
}, | ||
{ id: 'text', cellRenderer: TextRenderer, headerName: 'Text', sortable: true }, | ||
]} | ||
/> | ||
</Flex.Item> | ||
</Flex> | ||
); | ||
}; | ||
|
||
export const Base: Story = { | ||
render: () => <BulkExample />, | ||
}; |