Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working on saving pivots #103

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ Changelog
##### 0.1.1-beta
* Removes react-md
* Adds jest and some tests

##### 0.2.0-beta
* Adds row totals as an optional prop enabled by default
* Updates React/React-DOM from 15.6.1 to 16.1.0
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ You can also use a global-friendly UMD build:
* rowHeaders: all the parent row headers above the current clicked row header cell and at the current cell
* `onLeftHeaderCellClick`
* A function that is fired when clicking on the top left most cell (above the row headers and to the left of the column headers)
* `rowTotals`
* A boolean that when false will not display row totals in the table. Totals are turned on by default.
* `selectedAggregationDimension`
* Sets the default aggregation dimension in the Drawer.

## Example usage with optional props
```js
Expand Down Expand Up @@ -185,6 +189,8 @@ function onLeftHeaderCellClick() {
onLeftGridCellClick={onLeftGridCellClick}
onGridHeaderCellClick={onGridHeaderCellClick}
onLeftHeaderCellClick={onLeftHeaderCellClick}
rowTotals={true}
selectedAggregationDimension={'age'}
/>
```

Expand Down
27 changes: 13 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-virtualized-pivot",
"version": "0.1.1-beta",
"version": "0.2.0-beta",
"description": "React Virtualized Pivot",
"main": "dist/es/index.js",
"module": "dist/es/index.js",
Expand Down Expand Up @@ -49,11 +49,16 @@
"verbose": true
},
"dependencies": {
"babel-runtime": "^6.26.0",
"quick-pivot": "^2.2.6",
"react-draggable": "^2.2.6",
"react-select": "^1.0.0-rc.5",
"react-virtualized": "^9.9.0"
"enzyme-adapter-react-16": "^1.1.0",
"quick-pivot": "^2.3.1",
"react": "^16.1.0",
"react-dom": "^16.1.0",
"react-draggable": "^3.0.3",
"react-select": "^1.0.0-rc.10",
"react-sortablejs": "^1.3.5",
"react-test-renderer": "^16.1.1",
"react-virtualized": "^9.12.0",
"sortablejs": "^1.7.0"
},
"devDependencies": {
"autoprefixer": "^7.1.2",
Expand All @@ -72,9 +77,10 @@
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"babel-runtime": "^6.26.0",
"cross-env": "^5.0.5",
"css-loader": "0.26.1",
"enzyme": "^2.8.2",
"enzyme": "^3.2.0",
"eslint": "^4.4.1",
"eslint-loader": "1.1.0",
"eslint-plugin-import": "^2.7.0",
Expand All @@ -94,9 +100,6 @@
"pre-commit": "^1.2.2",
"prop-types": "^15.5.10",
"raf": "^3.3.2",
"react": "^15.6.1",
"react-addons-test-utils": "^15.5.1",
"react-dom": "^15.6.1",
"react-hot-loader": "^3.0.0-beta.7",
"rimraf": "^2.6.1",
"sass-loader": "^6.0.6",
Expand All @@ -107,9 +110,5 @@
"webpack-dashboard": "^0.3.0",
"webpack-dev-server": "^2.4.1",
"webpack-node-externals": "^1.6.0"
},
"peerDependencies": {
"react": "^15.6.1",
"react-dom": "^15.6.1"
}
}
43 changes: 42 additions & 1 deletion src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,24 @@ export default class App extends React.Component {
gridBorders: '#e0e0e0',
icons: '#ccc',
},
colFields: ['name'],
rowFields: ['gender'],
onLeftGridCellClick: () => console.log('clicking leftHeader'), // eslint-disable-line no-console
pivotOnChangeEnabled: true,
pivotOnChangeFunction: (prevState) => {
/* eslint-disable */
const newState = prevState;
newState.colFields=["name","house"];
newState.filters={name: ["Cersei"]};
console.log('new state', newState)
return newState
}
};

this.handleFileSelect = this.handleFileSelect.bind(this);
this.onSelectData = this.onSelectData.bind(this);
this.onSelectColorPack = this.onSelectColorPack.bind(this);
this.onButtonClick = this.onButtonClick.bind(this);
}

handleFileSelect(evt) {
Expand All @@ -63,6 +76,16 @@ export default class App extends React.Component {
data: data.smallData,
isLoaded: true,
selectedAggregationDimension: 'age',
colFields: [],
rowFields: [],
pivotOnChangeFunction: (prevState) => {
/* eslint-disable */
const newState = prevState;
newState.colFields=["name","house"];
newState.filters={name: ["Cersei"]};
console.log('new state', newState)
return newState
},
});
}
if (dataSize.value === 'medium') {
Expand All @@ -71,6 +94,9 @@ export default class App extends React.Component {
data: data.mediumData,
isLoaded: true,
selectedAggregationDimension: 'Quantity',
colFields: [],
rowFields: [],
pivotOnChangeFunction: undefined,
});
}
if (dataSize.value === 'large') {
Expand All @@ -86,12 +112,21 @@ export default class App extends React.Component {
data: results.data,
selectedAggregationDimension: 'Amount Requested',
isLoaded: true,
colFields: [],
rowFields: [],
pivotOnChangeFunction: undefined,
});
},
});
}
}

onButtonClick() {
this.setState({
onLeftHeaderCellClick: function(){console.log('Changes OnClick')},
});
}

onSelectColorPack(colorPack) {
if (colorPack.value === 'standard') {
this.setState({
Expand Down Expand Up @@ -206,6 +241,7 @@ export default class App extends React.Component {
<div className="inner three"></div>
</div>
<div className="app-menu" style={{ 'width': '100%' }}>
<button onClick={this.onButtonClick}>Pass</button>
<div className='select-container'>
<div
className="title"
Expand Down Expand Up @@ -266,8 +302,12 @@ export default class App extends React.Component {
</div>
</div>
<Pivot
colFields={this.state.colFields}
rowFields={this.state.rowFields}
onChange={this.state.pivotOnChangeFunction}
colorPack={colorPack}
data={data}
filters={{name: ['Arya', 'Jon']}}
onGridCellClick={({
rowIndex,
columnIndex,
Expand Down Expand Up @@ -304,7 +344,8 @@ export default class App extends React.Component {
console.log('childrenData', childrenData); // eslint-disable-line no-console
console.log('rowHeaders', rowHeaders); // eslint-disable-line no-console
}}
onLeftHeaderCellClick={() => console.log('clicking leftHeader')} // eslint-disable-line no-console
onLeftHeaderCellClick={this.state.onLeftHeaderCellClick} // eslint-disable-line no-console
rowTotals={true}
selectedAggregationDimension={selectedAggregationDimension}
/>
</section>
Expand Down
160 changes: 76 additions & 84 deletions src/components/CustomReactSortable/CustomReactSortable.jsx
Original file line number Diff line number Diff line change
@@ -1,110 +1,102 @@
/* eslint-disable */
/* eslint consistent-return: 0 */
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import SortableJS from './CustomSortable';

const store = {
nextSibling: null,
activeComponent: null,
nextSibling: null,
activeComponent: null
};

class Sortable extends Component {
static propTypes = {
options: PropTypes.object,
onChange: PropTypes.func,
tag: PropTypes.string,
style: PropTypes.object,
options: PropTypes.object,
onChange: PropTypes.func,
tag: PropTypes.string,
style: PropTypes.object
};
static defaultProps = {
options: {},
tag: 'div',
style: {},
options: {},
tag: 'div',
style: {}
};
sortable = null;

componentDidMount() {
const options = { ...this.props.options };

[
'onChoose',
'onStart',
'onEnd',
'onAdd',
'onUpdate',
'onSort',
'onRemove',
'onFilter',
'onMove',
'onClone',
].forEach((name) => {
const eventHandler = options[name];

options[name] = (...params) => {
const [evt] = params;

if (name === 'onChoose') {
store.nextSibling = evt.item.nextElementSibling;
store.activeComponent = this;
} else if ((name === 'onAdd' || name === 'onUpdate') &&
this.props.onChange) {
const items = this.sortable.toArray();
const remote = store.activeComponent;
const remoteItems = remote.sortable.toArray();

const referenceNode = (store.nextSibling &&
store.nextSibling.parentNode !== null) ?
store.nextSibling : null;

evt.from.insertBefore(evt.item, referenceNode);
if (remote !== this) {
const remoteOptions = remote.props.options || {};

if ((typeof remoteOptions.group === 'object') &&
(remoteOptions.group.pull === 'clone')) {
// Remove the node with the same data-reactid
evt.item.parentNode.removeChild(evt.item);
}

remote.props.onChange &&
remote.props.onChange(remoteItems, remote.sortable, evt);
}

this.props.onChange &&
this.props.onChange(items, this.sortable, evt);
}

if (evt.type === 'move') {
const [evt, originalEvent] = params;
const canMove = eventHandler ?
eventHandler(evt, originalEvent) : true;

return canMove;
}

setTimeout(() => {
eventHandler && eventHandler(evt);
}, 0);
};
});

this.sortable = SortableJS.create(ReactDOM.findDOMNode(this), options);
const options = { ...this.props.options };

[
'onChoose',
'onStart',
'onEnd',
'onAdd',
'onUpdate',
'onSort',
'onRemove',
'onFilter',
'onMove',
'onClone'
].forEach((name) => {
const eventHandler = options[name];

options[name] = (...params) => {
const [evt] = params;

if (name === 'onChoose') {
store.nextSibling = evt.item.nextElementSibling;
store.activeComponent = this;
} else if ((name === 'onAdd' || name === 'onUpdate') && this.props.onChange) {
const items = this.sortable.toArray();
const remote = store.activeComponent;
const remoteItems = remote.sortable.toArray();

const referenceNode = (store.nextSibling && store.nextSibling.parentNode !== null) ? store.nextSibling : null;
evt.from.insertBefore(evt.item, referenceNode);
if (remote !== this) {
const remoteOptions = remote.props.options || {};

if ((typeof remoteOptions.group === 'object') && (remoteOptions.group.pull === 'clone')) {
// Remove the node with the same data-reactid
evt.item.parentNode.removeChild(evt.item);
}

remote.props.onChange && remote.props.onChange(remoteItems, remote.sortable, evt);
}

this.props.onChange && this.props.onChange(items, this.sortable, evt);
}

if (evt.type === 'move') {
const [evt, originalEvent] = params;
const canMove = eventHandler ? eventHandler(evt, originalEvent) : true;
return canMove;
}

setTimeout(() => {
eventHandler && eventHandler(evt);
}, 0);
};
});

this.sortable = SortableJS.create(ReactDOM.findDOMNode(this), options);
}
componentWillUnmount() {
if (this.sortable) {
this.sortable.destroy();
this.sortable = null;
}
if (this.sortable) {
this.sortable.destroy();
this.sortable = null;
}
}
render() {
const { tag: Component, ...props } = this.props;
const { tag: Component, ...props } = this.props;

delete props.options;
delete props.onChange;
delete props.options;
delete props.onChange;

return (
<Component {...props} />
);
return (
<Component {...props} />
);
}
}

Expand Down
Loading