Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions examples/kendo-react-redux-undo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
**/kendo-ui-license**

npm-debug.log*
yarn-debug.log*
yarn-error.log*

# package-lock file
package-lock.json
21 changes: 21 additions & 0 deletions examples/kendo-react-redux-undo/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Telerik

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
13 changes: 13 additions & 0 deletions examples/kendo-react-redux-undo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# kendo-react-redux-undo
Kendo UI Grid using [Redux](https://redux.js.org/) for state management and [Redux Undo](https://github.com/omnidan/redux-undo) for history management.

## Build Setup

```bash
# install dependencies
npm install
# serve with hot reload at localhost:3000
npm start
# build for production with minification
npm run build

33 changes: 33 additions & 0 deletions examples/kendo-react-redux-undo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "kendo-redux-timetravel-editing",
"version": "0.1.0",
"private": true,
"dependencies": {
"@progress/kendo-data-query": "^1.7.1",
"@progress/kendo-drawing": "^1.21.2",
"@progress/kendo-react-dateinputs": "^11.0.0",
"@progress/kendo-react-dropdowns": "^11.0.0",
"@progress/kendo-react-grid": "^11.0.0",
"@progress/kendo-react-inputs": "^11.0.0",
"@progress/kendo-react-intl": "^11.0.0",
"@progress/kendo-react-pdf": "^11.0.0",
"@progress/kendo-react-data-tools": "^11.0.0",
"@progress/kendo-theme-default": "^11.0.2",
"react": "^18",
"react-dom": "^18",
"react-redux": "^9.2.0",
"react-scripts": "5.0.1",
"redux": "^5.0.1",
"@redux-devtools/extension": "^3.3.0",
"@reduxjs/toolkit": "^2.8.2",
"redux-thunk": "^3.1.0",
"redux-undo": "^1.1.0",
"prop-types": "15.8.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
Binary file not shown.
40 changes: 40 additions & 0 deletions examples/kendo-react-redux-undo/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
15 changes: 15 additions & 0 deletions examples/kendo-react-redux-undo/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": "./index.html",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
28 changes: 28 additions & 0 deletions examples/kendo-react-redux-undo/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.App {
text-align: center;
}

.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 80px;
}

.App-header {
background-color: #222;
height: 150px;
padding: 20px;
color: white;
}

.App-title {
font-size: 1.5em;
}

.App-intro {
font-size: large;
}

@keyframes App-logo-spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
17 changes: 17 additions & 0 deletions examples/kendo-react-redux-undo/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import './App.css';
import GridContainer from './components/GridContainer';
import '@progress/kendo-theme-default/dist/all.css';

class App extends Component {
render() {
return (
<div className="App">
<GridContainer/>
</div>
);
}
}

export default connect()(App);
10 changes: 10 additions & 0 deletions examples/kendo-react-redux-undo/src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';

it('renders without crashing', () => {
const div = document.createElement('div');
const root = ReactDOM.createRoot(div);
root.render(<App />);
root.unmount();
});
23 changes: 23 additions & 0 deletions examples/kendo-react-redux-undo/src/actions/actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export const ADD_PRODUCT = 'ADD_PRODUCT'
export const UPDATE_PRODUCT = 'UPDATE_PRODUCT'
export const DELETE_PRODUCT = 'DELETE_PRODUCT'
export const CHANGE_EDIT = 'CHANGE_EDIT'

export const DATASTATE_CHANGE = 'DATASTATE_CHANGE'

export function addProduct(payload) {
return { type: ADD_PRODUCT, payload }
}
export function updateProduct(payload) {
return { type: UPDATE_PRODUCT, payload }
}
export function deleteProduct(payload) {
return { type: DELETE_PRODUCT, payload }
}
export function changeEdit(payload) {
return { type: CHANGE_EDIT, payload }
}

export function datastateChange(payload) {
return { type: DATASTATE_CHANGE, payload }
}
110 changes: 110 additions & 0 deletions examples/kendo-react-redux-undo/src/components/GridContainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import React from 'react';
import { connect } from 'react-redux';
import { ActionCreators as UndoActionCreators } from 'redux-undo';
import { addProduct, updateProduct, deleteProduct, changeEdit, datastateChange } from '../actions/actions';
import { Grid, GridColumn as Column, GridToolbar, GridToolbarSort, GridToolbarFilter } from '@progress/kendo-react-grid';
import { Button } from '@progress/kendo-react-buttons';
import { gearIcon } from '@progress/kendo-svg-icons';
import { process } from '@progress/kendo-data-query'
import MyCommandCell from './MyCommandCell'

class GridContainer extends React.Component {
constructor(props) {
super(props);
this.CommandCell = MyCommandCell(this.remove);
}

addItem = () => {
this.props.addProduct();
}

handleItemChange = (dataItem) => {
this.props.updateProduct(dataItem)
}

handleStateChange = (event) => {
this.props.datastateChange(event)
}

remove = (dataItem) => {
this.props.deleteProduct(dataItem);
}

rowClick = (event) => {
this.props.changeEdit(event.dataItem);
}

render() {
const processedProducts = process(this.props.products, this.props.dataState)
console.log(this.props.products.length)
return (
<div className="grid-container">
<Grid
adaptive={true}
dataItemKey="ProductID"
autoProcessData={true}
navigatable={true}
sortable={{ mode: 'multiple' }}
onRowClick={this.rowClick}
onItemChange={this.handleItemChange}
data={processedProducts}
onDataStateChange={this.handleStateChange}
{...this.props.dataState}>
<GridToolbar>
<GridToolbarSort icon="gear" />
<GridToolbarFilter svgIcon={gearIcon} />
<Button
title="Add new"
className="k-button k-primary"
onClick={this.addItem}>
Add new
</Button>
<Button
title="Undo"
className="k-button button-right"
disabled={!this.props.canUndo}
onClick={this.props.onUndo}>
Back
</Button>
<Button
title="Redo"
className="k-button button-right"
disabled={!this.props.canRedo}
onClick={this.props.onRedo}>
Forward
</Button>
</GridToolbar>
<Column field="ProductID" title="ID" editable={false} filter="numeric"/>
<Column field="ProductName" title="Name"/>
<Column field="UnitPrice" title="Price" editor="numeric" filter="numeric"/>
<Column field="UnitsInStock" title="In stock" editor="numeric" filter="numeric"/>
<Column cell={this.CommandCell}/>
</Grid>
</div>
);
}
}

const mapDispatchToProps = dispatch => {
return {
onUndo: () => dispatch(UndoActionCreators.undo()),
onRedo: () => dispatch(UndoActionCreators.redo()),
addProduct: () => dispatch(addProduct()),
updateProduct: (dataItem) => dispatch(updateProduct(dataItem)),
deleteProduct: (dataItem) => dispatch(deleteProduct(dataItem)),
changeEdit: (row) => dispatch(changeEdit(row)),
datastateChange: (event) => dispatch(datastateChange(event))
}
}

function mapStateToProps(state) {
return {
products: state.products.present.products,
dataState: state.dataState.present,
canUndo: state.products.past.length > 0,
canRedo: state.products.future.length > 0,
dataState: state.dataState.present
}
}

export default connect(mapStateToProps, mapDispatchToProps)(GridContainer);
17 changes: 17 additions & 0 deletions examples/kendo-react-redux-undo/src/components/MyCommandCell.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';

export default function MyCommandCell(remove) {
return class extends React.Component {
render() {
return (
<td>
<button
className="k-button k-grid-remove-command"
onClick={(e) => window.confirm('Confirm deleting: ' + this.props.dataItem.ProductName) && remove(this.props.dataItem)}>
Remove
</button>
</td>
);
}
}
};
Loading