1+ import React , { Component } from 'react' ;
2+ import { Grid , GridColumn , GridToolbar } from '@progress/kendo-react-grid' ;
3+ import MyCommandCell from './MyCommandCell'
4+ import { graphql , compose } from 'react-apollo' ;
5+ import { getProductsQuery , deleteProductMutation } from '../queries/queries' ;
6+
7+
8+ class GridContainer extends Component {
9+
10+ constructor ( props ) {
11+ super ( props )
12+ this . remove = this . remove . bind ( this ) ;
13+ this . CommandCell = MyCommandCell ( this . remove ) ;
14+ }
15+
16+ remove ( dataItem ) {
17+ this . props . deleteProductMutation ( {
18+ variables : {
19+ ProductID : dataItem . ProductID ,
20+ } ,
21+ refetchQueries : [ { query : getProductsQuery } ]
22+ } ) ;
23+ }
24+
25+ handleRowClick = ( event ) => {
26+ this . props . changeRowSelection ( event . dataItem )
27+ }
28+
29+ handleAddItem = ( ) => {
30+ this . props . addItem ( )
31+ }
32+
33+ render ( ) {
34+ return (
35+ < div className = "grid-container col-md-8 col-sm-12 col-xs-12" >
36+ < div className = "header" >
37+ < h5 > Data</ h5 >
38+ </ div >
39+ < Grid data = { this . props . getProductsQuery . loading === true ? [ ] : this . props . getProductsQuery . products }
40+ onRowClick = { this . handleRowClick }
41+ style = { { maxHeight : "600px" } }
42+ >
43+ < GridToolbar >
44+ < button
45+ title = "Add new"
46+ className = "k-button k-primary"
47+ onClick = { this . handleAddItem }
48+ disabled = { ! this . props . inEdit }
49+ > Add new
50+ </ button >
51+ </ GridToolbar >
52+ < GridColumn field = "ProductID" title = "ID" width = "300" />
53+ < GridColumn field = "ProductName" title = "Product Name" />
54+ < GridColumn field = "UnitPrice" title = "Unit Price" width = "150px" />
55+ < GridColumn field = "UnitsInStock" title = "Units in Stock" width = "150px" />
56+ < GridColumn cell = { this . CommandCell } width = "120px" />
57+ </ Grid >
58+ </ div >
59+ ) ;
60+ }
61+ }
62+
63+ export default compose (
64+ graphql ( getProductsQuery , { name : "getProductsQuery" } ) ,
65+ graphql ( deleteProductMutation , { name : "deleteProductMutation" } )
66+ ) ( GridContainer ) ;
0 commit comments