11import React , { PureComponent } from 'react'
2- import { DragDropContextProvider } from 'react-dnd' ;
3- import HTML5Backend from 'react-dnd-html5-backend' ;
2+ import { DragDropContextProvider } from 'react-dnd'
3+ import HTML5Backend from 'react-dnd-html5-backend'
44import Select from 'react-select'
55
6- import DataSheet from '../lib' ;
6+ import DataSheet from '../lib'
77import { ENTER_KEY , TAB_KEY } from '../lib/keys'
88
99import {
1010 colDragSource , colDropTarget ,
11- rowDragSource , rowDropTarget ,
12- } from './drag-drop.js' ;
13-
11+ rowDragSource , rowDropTarget
12+ } from './drag-drop.js'
1413
1514const Header = colDropTarget ( colDragSource ( ( props ) => {
1615 const { col, connectDragSource, connectDropTarget, isOver } = props
@@ -22,8 +21,8 @@ const Header = colDropTarget(colDragSource((props) => {
2221} ) )
2322
2423class SheetRenderer extends PureComponent {
25- render ( ) {
26- const { className, columns, onColumnDrop } = this . props ;
24+ render ( ) {
25+ const { className, columns, onColumnDrop } = this . props
2726 return (
2827 < table className = { className } >
2928 < thead >
@@ -45,18 +44,18 @@ class SheetRenderer extends PureComponent {
4544}
4645
4746const RowRenderer = rowDropTarget ( rowDragSource ( ( props ) => {
48- const { isOver, children, connectDropTarget, connectDragPreview, connectDragSource } = props ;
49- const className = isOver ? 'drop-target' : '' ;
47+ const { isOver, children, connectDropTarget, connectDragPreview, connectDragSource } = props
48+ const className = isOver ? 'drop-target' : ''
5049 return connectDropTarget ( connectDragPreview (
5150 < tr className = { className } >
52- { connectDragSource ( < td className = 'cell read-only row-handle' key = '$$actionCell' > </ td > ) }
51+ { connectDragSource ( < td className = 'cell read-only row-handle' key = '$$actionCell' / >) }
5352 { children }
5453 </ tr >
5554 ) )
5655} ) )
5756
5857class SelectEditor extends PureComponent {
59- constructor ( props ) {
58+ constructor ( props ) {
6059 super ( props )
6160 this . handleChange = this . handleChange . bind ( this )
6261 this . handleKeyDown = this . handleKeyDown . bind ( this )
@@ -70,6 +69,7 @@ class SelectEditor extends PureComponent {
7069 }
7170 const { e } = this . state
7271 onCommit ( opt . value , e )
72+ console . log ( 'COMMITTED' , opt . value )
7373 }
7474
7575 handleKeyDown ( e ) {
@@ -82,7 +82,7 @@ class SelectEditor extends PureComponent {
8282 }
8383 }
8484
85- render ( ) {
85+ render ( ) {
8686 return (
8787 < Select
8888 autoFocus
@@ -96,21 +96,21 @@ class SelectEditor extends PureComponent {
9696 { label : '2' , value : 2 } ,
9797 { label : '3' , value : 3 } ,
9898 { label : '4' , value : 4 } ,
99- { label : '5' , value : 5 } ,
99+ { label : '5' , value : 5 }
100100 ] }
101101 />
102102 )
103103 }
104104}
105105
106106class RangeEditor extends PureComponent {
107- constructor ( props ) {
107+ constructor ( props ) {
108108 super ( props )
109109 this . handleChange = this . handleChange . bind ( this )
110110 }
111111
112- componentDidMount ( ) {
113- this . _input . focus ( ) ;
112+ componentDidMount ( ) {
113+ this . _input . focus ( )
114114 }
115115
116116 handleChange ( e ) {
@@ -138,11 +138,10 @@ const FillViewer = props => {
138138 const { value } = props
139139 return (
140140 < div style = { { width : '100%' } } >
141- { [ 1 , 2 , 3 , 4 , 5 ] . map ( v => {
141+ { [ 1 , 2 , 3 , 4 , 5 ] . map ( v => {
142142 const backgroundColor = v > value ? 'transparent' : '#007eff'
143143 return (
144- < div key = { v } style = { { float : 'left' , width : '20%' , height : '17px' , backgroundColor} } >
145- </ div >
144+ < div key = { v } style = { { float : 'left' , width : '20%' , height : '17px' , backgroundColor} } />
146145 )
147146 } ) }
148147 </ div >
@@ -151,7 +150,7 @@ const FillViewer = props => {
151150
152151class CustomRendererSheet extends PureComponent {
153152 constructor ( props ) {
154- super ( props ) ;
153+ super ( props )
155154 this . state = {
156155 columns : [
157156 { label : 'Style' , width : '40%' } ,
@@ -174,7 +173,7 @@ class CustomRendererSheet extends PureComponent {
174173 [ { value : 'Pale Mild Ale' } , { value : '10 - 20' } , { value : '6 - 9' } , { value : 3 , dataEditor : SelectEditor } ] ,
175174 [ { value : 'Dark Mild Ale' } , { value : '10 - 24' } , { value : '17 - 34' } , { value : 3 , dataEditor : SelectEditor } ] ,
176175 [ { value : 'Brown Ale' } , { value : '12 - 25' } , { value : '12 - 17' } , { value : 3 , dataEditor : SelectEditor } ]
177- ]
176+ ] . map ( ( a , i ) => a . map ( ( cell , j ) => Object . assign ( cell , { key : ` ${ i } - ${ j } ` } ) ) )
178177 }
179178
180179 this . handleColumnDrop = this . handleColumnDrop . bind ( this )
@@ -184,24 +183,24 @@ class CustomRendererSheet extends PureComponent {
184183 this . renderRow = this . renderRow . bind ( this )
185184 }
186185
187- handleColumnDrop ( from , to ) {
188- const columns = [ ...this . state . columns ] ;
189- columns . splice ( to , 0 , ...columns . splice ( from , 1 ) ) ;
186+ handleColumnDrop ( from , to ) {
187+ const columns = [ ...this . state . columns ]
188+ columns . splice ( to , 0 , ...columns . splice ( from , 1 ) )
190189 const grid = this . state . grid . map ( r => {
191- const row = [ ...r ] ;
192- row . splice ( to , 0 , ...row . splice ( from , 1 ) ) ;
193- return row ;
194- } ) ;
195- this . setState ( { columns, grid } ) ;
190+ const row = [ ...r ]
191+ row . splice ( to , 0 , ...row . splice ( from , 1 ) )
192+ return row
193+ } )
194+ this . setState ( { columns, grid } )
196195 }
197196
198- handleRowDrop ( from , to ) {
199- const grid = [ ...this . state . grid ] ;
200- grid . splice ( to , 0 , ...grid . splice ( from , 1 ) ) ;
201- this . setState ( { grid } ) ;
197+ handleRowDrop ( from , to ) {
198+ const grid = [ ...this . state . grid ]
199+ grid . splice ( to , 0 , ...grid . splice ( from , 1 ) )
200+ this . setState ( { grid } )
202201 }
203202
204- handleChange ( modifiedCell , i , j , value ) {
203+ handleChange ( modifiedCell , i , j , value ) {
205204 this . setState ( ( prevState ) => {
206205 const grid = [ ...prevState . grid ]
207206 grid [ i ] = [ ...grid [ i ] ]
@@ -219,7 +218,7 @@ class CustomRendererSheet extends PureComponent {
219218 return < RowRenderer rowIndex = { row } onRowDrop = { this . handleRowDrop } { ...rest } />
220219 }
221220
222- render ( ) {
221+ render ( ) {
223222 return (
224223 < DragDropContextProvider backend = { HTML5Backend } >
225224 < DataSheet
@@ -230,7 +229,7 @@ class CustomRendererSheet extends PureComponent {
230229 onChange = { this . handleChange }
231230 />
232231 </ DragDropContextProvider >
233- ) ;
232+ )
234233 }
235234}
236235
0 commit comments