-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Remove ReactDataGrid dependency from addons bundle #1272
Changes from 3 commits
5134c89
955d673
be93dad
a189f4a
24a0e7d
3560fb5
12764bf
0f5bdeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as CellNavigationMode from './CellNavigationMode'; | ||
import * as EventTypes from './EventTypes'; | ||
import keyMirror from 'keymirror'; | ||
|
||
|
||
const UpdateActions = keyMirror({ | ||
CELL_UPDATE: null, | ||
COLUMN_FILL: null, | ||
COPY_PASTE: null, | ||
CELL_DRAG: null | ||
}); | ||
|
||
const DragItemTypes = { | ||
Column: 'column' | ||
}; | ||
|
||
const CellExpand = { | ||
DOWN_TRIANGLE: String.fromCharCode('9660'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
RIGHT_TRIANGLE: String.fromCharCode('9654') | ||
}; | ||
|
||
|
||
export { | ||
CellNavigationMode, | ||
EventTypes, | ||
UpdateActions, | ||
CellExpand, | ||
DragItemTypes | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default { | ||
CELL_MASK: 5, | ||
EDITOR_CONTAINER: 10, | ||
FROZEN_CELL_MASK: 15, | ||
FROZEN_EDITOR_CONTAINER: 20 | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can use individual exports for better error checking, treeshaking
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would agree but it is a very small file, and I think it is clearer to reference |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,18 @@ | ||
import ColumnMetrics from './ColumnMetrics'; | ||
|
||
export const shouldRowUpdate = (nextProps, currentProps) => { | ||
return !(ColumnMetrics.sameColumns(currentProps.columns, nextProps.columns, ColumnMetrics.sameColumn)) || | ||
nextProps.row !== currentProps.row || | ||
currentProps.colOverscanStartIdx !== nextProps.colOverscanStartIdx || | ||
currentProps.colOverscanEndIdx !== nextProps.colOverscanEndIdx || | ||
currentProps.colVisibleStartIdx !== nextProps.colVisibleStartIdx || | ||
currentProps.colVisibleEndIdx !== nextProps.colVisibleEndIdx || | ||
currentProps.isSelected !== nextProps.isSelected || | ||
currentProps.isScrolling !== nextProps.isScrolling || | ||
nextProps.height !== currentProps.height || | ||
currentProps.isOver !== nextProps.isOver || | ||
currentProps.expandedRows !== nextProps.expandedRows || | ||
currentProps.canDrop !== nextProps.canDrop || | ||
currentProps.forceUpdate === true || | ||
currentProps.extraClasses !== nextProps.extraClasses; | ||
}; | ||
|
||
export default shouldRowUpdate; | ||
export const shouldRowUpdate = (nextProps, currentProps) => { | ||
return currentProps.columns !== nextProps.columns || | ||
nextProps.row !== currentProps.row || | ||
currentProps.colOverscanStartIdx !== nextProps.colOverscanStartIdx || | ||
currentProps.colOverscanEndIdx !== nextProps.colOverscanEndIdx || | ||
currentProps.colVisibleStartIdx !== nextProps.colVisibleStartIdx || | ||
currentProps.colVisibleEndIdx !== nextProps.colVisibleEndIdx || | ||
currentProps.isSelected !== nextProps.isSelected || | ||
currentProps.isScrolling !== nextProps.isScrolling || | ||
nextProps.height !== currentProps.height || | ||
currentProps.isOver !== nextProps.isOver || | ||
currentProps.expandedRows !== nextProps.expandedRows || | ||
currentProps.canDrop !== nextProps.canDrop || | ||
currentProps.forceUpdate === true || | ||
currentProps.extraClasses !== nextProps.extraClasses; | ||
}; | ||
|
||
export default shouldRowUpdate; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I usually prefer the following but I am fine with either
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module.exports = function isColumnsImmutable(columns: Array<Column>) { | ||
export default function isColumnsImmutable(columns) { | ||
return (typeof Immutable !== 'undefined' && (columns instanceof Immutable.List)); | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
const isEmptyArray = (obj) => { | ||
return Array.isArray(obj) && obj.length === 0; | ||
}; | ||
|
||
module.exports = isEmptyArray; | ||
const isEmptyArray = (obj) => { | ||
return Array.isArray(obj) && obj.length === 0; | ||
}; | ||
export default isEmptyArray; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
function isEmpty(obj) { | ||
export default function isEmpty(obj) { | ||
return Object.keys(obj).length === 0 && obj.constructor === Object; | ||
} | ||
|
||
module.exports = isEmpty; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we just combine these functions in a single |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
/* @flow */ | ||
|
||
const isFunction = function(functionToCheck: any): boolean { | ||
export default function isFunction(functionToCheck) { | ||
let getType = {}; | ||
return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]'; | ||
}; | ||
|
||
module.exports = isFunction; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Iterable } from 'immutable'; | ||
|
||
export default function isImmutableCollection(objToVerify) { | ||
return Iterable.isIterable(objToVerify); | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
const getMixedTypeValueRetriever = (isImmutable) => { | ||
export default function getMixedTypeValueRetriever(isImmutable) { | ||
let retObj = {}; | ||
const retriever = (item, key) => { return item[key]; }; | ||
const immutableRetriever = (immutable, key) => { return immutable.get(key); }; | ||
|
||
retObj.getValue = isImmutable ? immutableRetriever : retriever; | ||
|
||
return retObj; | ||
}; | ||
|
||
module.exports = getMixedTypeValueRetriever; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { DragSource, DropTarget } from 'react-dnd'; | ||
import { HeaderCell } from 'react-data-grid'; | ||
|
||
class DraggableHeaderCell extends React.Component { | ||
render() { | ||
|
@@ -26,7 +25,7 @@ class DraggableHeaderCell extends React.Component { | |
style={{ width: 0, cursor: 'move', opacity }} | ||
className={isOver && canDrop ? 'rdg-can-drop' : ''} | ||
> | ||
<HeaderCell {...this.props} /> | ||
{this.props.renderHeaderCell(this.props)} | ||
</div> | ||
) | ||
); | ||
|
@@ -84,7 +83,8 @@ DraggableHeaderCell.propTypes = { | |
connectDropTarget: PropTypes.func.isRequired, | ||
isDragging: PropTypes.bool.isRequired, | ||
isOver: PropTypes.bool, | ||
canDrop: PropTypes.bool | ||
canDrop: PropTypes.bool, | ||
renderHeaderCell: PropTypes.fund | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs to be fixed |
||
}; | ||
|
||
DraggableHeaderCell = DropTarget('Column', target, targetCollect)( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,14 @@ import { shallow } from 'enzyme'; | |
|
||
import DraggableContainer from '../DraggableContainer'; | ||
import DraggableHeaderCell from '../DraggableHeaderCell'; | ||
import { HeaderCell } from 'react-data-grid'; | ||
|
||
const HeaderCell = () => <div/>; | ||
|
||
describe('<DraggableHeaderCell />', () => { | ||
it('should render grid HeaderCell wrapper with cursor: move ', () => { | ||
const wrapper = shallow( | ||
<DraggableContainer> | ||
<DraggableHeaderCell /> | ||
<DraggableHeaderCell renderHeaderCell={() => HeaderCell}/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this correct? Should it be |
||
</DraggableContainer> | ||
); | ||
expect(wrapper.find(HeaderCell)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
import { DragSource } from 'react-dnd'; | ||
import React, {Component} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { _constants, HeaderCell } from 'react-data-grid'; | ||
const { DragItemTypes } = _constants; | ||
import { DragItemTypes } from 'common/constants'; | ||
|
||
class DraggableHeaderCell extends Component { | ||
|
||
|
@@ -26,14 +25,15 @@ class DraggableHeaderCell extends Component { | |
if (isDragging) { | ||
return null; | ||
} | ||
return connectDragSource(<div style={{cursor: 'move'}}><HeaderCell {...this.props}/></div>); | ||
return connectDragSource(<div style={{cursor: 'move'}}>{this.props.renderHeaderCell(this.props)}</div>); | ||
} | ||
} | ||
|
||
DraggableHeaderCell.propTypes = { | ||
connectDragSource: PropTypes.func.isRequired, | ||
connectDragPreview: PropTypes.func.isRequired, | ||
isDragging: PropTypes.bool.isRequired | ||
isDragging: PropTypes.bool.isRequired, | ||
renderHeaderCell: PropTypes.func | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, should it be a required prop? Or we can add a |
||
}; | ||
|
||
function collect(connect, monitor) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets change the require statement to ES6 import