-
-
Notifications
You must be signed in to change notification settings - Fork 62
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 #98 from komarovalexander/dev
Add column.visible property
- Loading branch information
Showing
18 changed files
with
270 additions
and
74 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
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 ColumnSettingsDemo from './ColumnSettingsDemo'; | ||
|
||
it('renders without crashing', () => { | ||
const div = document.createElement('div'); | ||
ReactDOM.render(<ColumnSettingsDemo />, 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,96 @@ | ||
import React, { useState } from 'react'; | ||
|
||
import { ITableAllProps, ITableProps, kaReducer, Table } from '../../lib'; | ||
import { hideColumn, showColumn } from '../../lib/actionCreators'; | ||
import CellEditorBoolean from '../../lib/Components/CellEditorBoolean/CellEditorBoolean'; | ||
import { ActionType, DataType, EditingMode, SortingMode } from '../../lib/enums'; | ||
import { DispatchFunc } from '../../lib/types'; | ||
|
||
const dataArray = Array(10).fill(undefined).map( | ||
(_, index) => ({ | ||
column1: `column:1 row:${index}`, | ||
column2: `column:2 row:${index}`, | ||
column3: `column:3 row:${index}`, | ||
column4: `column:4 row:${index}`, | ||
column5: `column:5 row:${index}`, | ||
column6: `column:6 row:${index}`, | ||
id: index, | ||
}), | ||
); | ||
|
||
const tablePropsInit: ITableProps = { | ||
columns: [ | ||
{ key: 'column1', title: 'Column 1', dataType: DataType.String }, | ||
{ key: 'column2', title: 'Column 2', dataType: DataType.String }, | ||
{ key: 'column3', title: 'Column 3', dataType: DataType.String, visible: false }, | ||
{ key: 'column4', title: 'Column 4', dataType: DataType.String }, | ||
{ key: 'column5', title: 'Column 5', dataType: DataType.String }, | ||
{ key: 'column6', title: 'Column 6', dataType: DataType.String }, | ||
], | ||
data: dataArray, | ||
editingMode: EditingMode.Cell, | ||
rowKeyField: 'id', | ||
sortingMode: SortingMode.Single, | ||
}; | ||
|
||
const ColumnSettings: React.FC<ITableAllProps> = (tableProps: ITableAllProps) => { | ||
const columnsSettingsProps: ITableProps = { | ||
data: tableProps.columns.map(c => ({...c, visible: c.visible !== false })), | ||
rowKeyField: 'key', | ||
columns: [{ | ||
key: 'title', | ||
isEditable: false, | ||
title: 'Field', | ||
dataType: DataType.String | ||
}, { | ||
key: 'visible', | ||
title: 'Visible', | ||
isEditable: false, | ||
style: { width: 45 }, | ||
dataType: DataType.Boolean | ||
}], | ||
editingMode: EditingMode.None, | ||
} | ||
const dispatchSettings: DispatchFunc = (action) => { | ||
if (action.type === ActionType.UpdateCellValue){ | ||
tableProps.dispatch(action.value ? showColumn(action.rowKeyValue) : hideColumn(action.rowKeyValue)); | ||
} | ||
}; | ||
return ( | ||
<Table | ||
{...columnsSettingsProps} | ||
childComponents={{ | ||
rootDiv: { elementAttributes: () => ({style: {width: 400, marginBottom: 20}})}, | ||
cell: { | ||
content: (props) => { | ||
switch (props.column.key){ | ||
case 'visible': return <CellEditorBoolean {...props}/>; | ||
} | ||
} | ||
} | ||
}} | ||
dispatch={dispatchSettings} | ||
/> | ||
); | ||
} | ||
|
||
const ColumnSettingsDemo: React.FC = () => { | ||
const [tableProps, changeTableProps] = useState<ITableProps>(tablePropsInit); | ||
const dispatch: DispatchFunc = (action) => { | ||
changeTableProps((prevState: ITableProps) => kaReducer(prevState, action)); | ||
}; | ||
return ( | ||
<div className='column-settings-demo'> | ||
<ColumnSettings | ||
{...tableProps} | ||
dispatch={dispatch} | ||
/> | ||
<Table | ||
{...tableProps} | ||
dispatch={dispatch} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ColumnSettingsDemo; |
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
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.