-
-
Notifications
You must be signed in to change notification settings - Fork 57
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 #164 from alexander-dryannov/feature/group-summary…
…-render Group Summary
- Loading branch information
Showing
17 changed files
with
410 additions
and
15 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
10 changes: 10 additions & 0 deletions
10
src/Demos/GroupingSummaryDemo/GroupingSummaryDemo.test.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,10 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
import GroupingSummaryDemo from './GroupingSummaryDemo'; | ||
|
||
it('renders without crashing', () => { | ||
const div = document.createElement('div'); | ||
ReactDOM.render(<GroupingSummaryDemo />, div); | ||
ReactDOM.unmountComponentAtNode(div); | ||
}); |
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,51 @@ | ||
import React, { useState } from 'react'; | ||
|
||
import { ITableProps, kaReducer, Table } from '../../lib'; | ||
import { DataType } from '../../lib/enums'; | ||
import { DispatchFunc } from '../../lib/types'; | ||
|
||
const dataArray = [ | ||
{ id: 1, type: 'Cat', name: 'Kas', country: 'Czech Republic', age: 2 }, | ||
{ id: 2, type: 'Dog', name: 'Rex', country: 'Montenegro', age: 6 }, | ||
{ id: 3, type: 'Cat', name: 'Simba', country: 'France', age: 12 }, | ||
{ id: 4, type: 'Dog', name: 'Beethoven', country: 'Czech Republic', age: 3 }, | ||
{ id: 5, type: 'Cat', name: 'Hash', country: 'Czech Republic', age: 8 }, | ||
]; | ||
|
||
const tablePropsInit: ITableProps = { | ||
columns: [ | ||
{ key: 'type', title: 'TYPE', dataType: DataType.String }, | ||
{ key: 'name', title: 'NAME', dataType: DataType.String }, | ||
{ key: 'country', title: 'COUNTRY', dataType: DataType.String }, | ||
{ key: 'age', title: 'AGE', dataType: DataType.Number, style: { width: '50%' } }, | ||
], | ||
data: dataArray, | ||
groups: [{ columnKey: 'country', enableSummary: false }, { columnKey: 'type', enableSummary: true }], | ||
rowKeyField: 'id', | ||
}; | ||
|
||
const GroupingSummaryDemo: React.FC = () => { | ||
const [tableProps, changeTableProps] = useState(tablePropsInit); | ||
const dispatch: DispatchFunc = (action) => { | ||
changeTableProps((prevState: ITableProps) => kaReducer(prevState, action)); | ||
}; | ||
return ( | ||
<Table | ||
{...tableProps} | ||
childComponents={{ | ||
groupSummaryCell: { | ||
content: ({ groupData, column }) => { | ||
switch (column.key) { | ||
case 'age': return ( | ||
<b>Max age: {Math.max.apply(Math, groupData.map((o) => o.age))}</b> | ||
); | ||
} | ||
} | ||
} | ||
}} | ||
dispatch={dispatch} | ||
/> | ||
); | ||
}; | ||
|
||
export default GroupingSummaryDemo; |
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,21 @@ | ||
import * as React from 'react'; | ||
|
||
import defaultOptions from '../../defaultOptions'; | ||
import { IGroupSummaryCellProps } from '../../props'; | ||
import { getElementCustomization } from '../../Utils/ComponentUtils'; | ||
|
||
export const GroupSummaryCell: React.FunctionComponent<IGroupSummaryCellProps> = (props) => { | ||
const { | ||
column: { style }, | ||
childComponents | ||
} = props; | ||
const { elementAttributes, content } = getElementCustomization({ | ||
className: defaultOptions.css.groupSummaryCell, | ||
style | ||
}, props, childComponents?.groupSummaryCell); | ||
return ( | ||
<td {...elementAttributes}> | ||
{content} | ||
</td> | ||
); | ||
}; |
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,28 @@ | ||
import * as React from 'react'; | ||
import defaultOptions from '../../defaultOptions'; | ||
import { IGroupSummaryRowProps } from '../../props'; | ||
import { getElementCustomization } from '../../Utils/ComponentUtils'; | ||
import EmptyCells from '../EmptyCells/EmptyCells'; | ||
import { GroupSummaryCell } from '../GroupSummaryCell/GroupSummaryCell'; | ||
|
||
export const GroupSummaryRow: React.FunctionComponent<IGroupSummaryRowProps> = (props) => { | ||
const { | ||
childComponents, | ||
columns, | ||
groupColumnsCount | ||
} = props; | ||
|
||
const { elementAttributes, content } = getElementCustomization({ | ||
className: defaultOptions.css.groupSummaryRow, | ||
}, props, childComponents?.groupSummaryRow); | ||
return ( | ||
<tr {...elementAttributes}> | ||
{content || ( | ||
<> | ||
<EmptyCells count={groupColumnsCount}/> | ||
{columns.map((column) => <GroupSummaryCell key={column.key} {...props} column={column} />)} | ||
</> | ||
)} | ||
</tr> | ||
); | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
|
||
export class Group { | ||
public columnKey!: string; | ||
public enableSummary?: boolean; | ||
} |
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
Oops, something went wrong.