Skip to content

Commit 2052e10

Browse files
committed
chore: add kendo-react-graphql app
1 parent 56313e9 commit 2052e10

File tree

20 files changed

+816
-0
lines changed

20 files changed

+816
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Kendo UI for React Grid Integration with GraphQL.
2+
3+
> This application shows an example of how one can use editable Kendo UI for React Grid with GraphQL queries.
4+
5+
## Build Setup
6+
7+
### Server setup
8+
9+
All of these commands have to be executed inside the server folder.
10+
11+
```bash
12+
# install dependencies
13+
npm install
14+
# start the server at localhost:4000
15+
node app.js
16+
```
17+
18+
### Client setup
19+
20+
All of these commands have to be executed inside the client folder.
21+
Ensure that the server is running on port 4000 before starting the client application.
22+
23+
```bash
24+
# install dependencies
25+
npm install
26+
# serve with hot reload at localhost:3000
27+
npm start
28+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
**/kendo-ui-license**
21+
22+
npm-debug.log*
23+
yarn-debug.log*
24+
yarn-error.log*
25+
26+
# package-lock file
27+
package-lock.json
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "client",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"@progress/kendo-data-query": "^1.3.1",
7+
"@progress/kendo-drawing": "^1.5.6",
8+
"@progress/kendo-react-dateinputs": "^1.1.0",
9+
"@progress/kendo-react-dropdowns": "^1.1.0",
10+
"@progress/kendo-react-grid": "^1.1.0",
11+
"@progress/kendo-react-inputs": "^1.1.0",
12+
"@progress/kendo-react-intl": "^1.1.0",
13+
"@progress/kendo-react-pdf": "^1.1.0",
14+
"@progress/kendo-theme-default": "^2.54.0",
15+
"apollo-boost": "^0.1.10",
16+
"bootstrap": "^4.1.1",
17+
"cldr-data": "^32.0.1",
18+
"graphql": "^0.13.2",
19+
"jquery": "^3.3.1",
20+
"popper.js": "^1.14.3",
21+
"react": "^16.4.1",
22+
"react-apollo": "^2.1.6",
23+
"react-dom": "^16.4.1",
24+
"react-scripts": "1.1.4"
25+
},
26+
"scripts": {
27+
"start": "react-scripts start",
28+
"build": "react-scripts build",
29+
"test": "react-scripts test --env=jsdom",
30+
"eject": "react-scripts eject"
31+
}
32+
}
3.78 KB
Binary file not shown.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6+
<meta name="theme-color" content="#000000">
7+
<!--
8+
manifest.json provides metadata used when your web app is added to the
9+
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
10+
-->
11+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
12+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
13+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
14+
crossorigin="anonymous">
15+
<!--
16+
Notice the use of %PUBLIC_URL% in the tags above.
17+
It will be replaced with the URL of the `public` folder during the build.
18+
Only files inside the `public` folder can be referenced from the HTML.
19+
20+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
21+
work correctly both with client-side routing and a non-root public URL.
22+
Learn how to configure a non-root public URL by running `npm run build`.
23+
-->
24+
<title>React App</title>
25+
</head>
26+
<body>
27+
<noscript>
28+
You need to enable JavaScript to run this app.
29+
</noscript>
30+
<div id="root"></div>
31+
<!--
32+
This HTML file is a template.
33+
If you open it directly in the browser, you will see an empty page.
34+
35+
You can add webfonts, meta tags, or analytics to this file.
36+
The build step will place the bundled scripts into the <body> tag.
37+
38+
To begin the development, run `npm start` or `yarn start`.
39+
To create a production bundle, use `npm run build` or `yarn build`.
40+
-->
41+
</body>
42+
</html>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"short_name": "React App",
3+
"name": "Create React App Sample",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "64x64 32x32 24x24 16x16",
8+
"type": "image/x-icon"
9+
}
10+
],
11+
"start_url": "./index.html",
12+
"display": "standalone",
13+
"theme_color": "#000000",
14+
"background_color": "#ffffff"
15+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.header {
2+
position: relative;
3+
}
4+
.header h5 {
5+
color: #888888;
6+
display: inline-block;
7+
position: relative;
8+
margin: 0 0 10px;
9+
padding: 0 10px 0 0;
10+
background: #fff;
11+
text-transform: uppercase;
12+
}
13+
.header:before {
14+
content: "";
15+
display: block;
16+
position: absolute;
17+
left: 20px;
18+
right: 20px;
19+
bottom: 18px;
20+
border-top: 1px solid #e8ecef;
21+
}
22+
.k-grid {
23+
margin-bottom: 20px;
24+
}
25+
.k-form fieldset {
26+
border-top-width: 0;
27+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import React, { Component } from 'react';
2+
import '@progress/kendo-theme-default/dist/all.css';
3+
import 'bootstrap';
4+
import './App.css';
5+
import GridContainer from './components/GridContainer'
6+
import ProductsForm from './components/ProductForm'
7+
import ApolloClient from 'apollo-boost';
8+
import { ApolloProvider } from 'react-apollo';
9+
10+
11+
// apollo client setup
12+
const client = new ApolloClient({
13+
uri: 'http://localhost:4000/graphql'
14+
})
15+
16+
class App extends Component {
17+
18+
constructor(props){
19+
super(props)
20+
this.state = {
21+
selectedItem: {},
22+
inEdit: false
23+
}
24+
}
25+
26+
changeRowSelection = (row) =>{
27+
this.setState({
28+
inEdit: true,
29+
selectedItem: row
30+
})
31+
}
32+
33+
addItem = () =>{
34+
this.setState({
35+
inEdit: false
36+
})
37+
}
38+
39+
render() {
40+
return (
41+
<ApolloProvider client={client}>
42+
<div className="App row m-2">
43+
<ProductsForm selectedItem={this.state.selectedItem} inEdit={this.state.inEdit} addItem={this.addItem}/>
44+
<GridContainer changeRowSelection={this.changeRowSelection} addItem={this.addItem} inEdit={this.state.inEdit}/>
45+
</div>
46+
</ApolloProvider>
47+
);
48+
}
49+
}
50+
51+
export default App;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import App from './App';
4+
5+
it('renders without crashing', () => {
6+
const div = document.createElement('div');
7+
ReactDOM.render(<App />, div);
8+
ReactDOM.unmountComponentAtNode(div);
9+
});
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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

Comments
 (0)