-
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
Context menu upgrade from v1.6.2 to v2.9.2 #1081
Conversation
@@ -48,6 +48,7 @@ const Canvas = createReactClass({ | |||
rowScrollTimeout: PropTypes.number, | |||
scrollToRowIndex: PropTypes.number, | |||
contextMenu: PropTypes.element, | |||
contextMenuId: PropTypes.string, |
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.
Does grid need to specify contextMenuId
prop. id
can be specified while creating contextMenu
element so the context menu example can be written as
<ReactDataGrid
contextMenu={<MyContextMenu
id="myContextMenu" // ContextMenu ID
onRowDelete={this.deleteRow}
onRowInsertAbove={this.insertRowAbove}
onRowInsertBelow={this.insertRowBelow} />}
....
This way contextMenuId
prop does not need to pass down from ReactDataGrid
to RowsContainer
Thoughts?
class RowsContainer extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.plugins = props.window ? props.window.ReactDataGridPlugins : window.ReactDataGridPlugins; | ||
this.hasContextMenu = this.hasContextMenu.bind(this); | ||
this.renderRowsWithContextMenu = this.renderRowsWithContextMenu.bind(this); | ||
this.getContextMenuContainer = this.getContextMenuContainer.bind(this); | ||
this.state = {ContextMenuContainer: this.getContextMenuContainer(props)}; | ||
this.validateContextMenu = this.validateContextMenu.bind(this); |
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.
These methods are not used as event handlers and do not need to be bound. They are used in the constructor and in the render method where this
value would be correct
@@ -333,6 +334,7 @@ const Canvas = createReactClass({ | |||
width={this.props.width} | |||
rows={rows} | |||
contextMenu={this.props.contextMenu} | |||
contextMenuId={this.props.contextMenuId} |
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.
Based on the above comment contextMenuId
prop can be removed from all the components
this.state = {ContextMenuContainer: this.getContextMenuContainer(props)}; | ||
this.validateContextMenu = this.validateContextMenu.bind(this); | ||
|
||
this.validateContextMenu(); |
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.
I wonder if constructor
is the right place for validation. Did not find any recommendation on where to throw the errors but I think render
method would probably be a better place. It is recommended to avoid any side effects in constructor
https://reactjs.org/docs/react-component.html#constructor
render() {
if (this.hasContextMenu()) {
if (!this.plugins) { throw new Error('...') }
return this.renderRowsWithContextMenu();
}
return <SimpleRowsContainer {...this.props} />;
}
@malonecj @diogofcunha thoughts?
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.
@amanmahajan7 we shouldn't add any side effects in the constructor even when not using react, creating a new object should never affect other parts of an application, you are correct, in react the constructor is used only to set the initial state
export const getNewContextMenuProps = ({ contextMenuId, rowIdx, idx }) => ({ | ||
rowIdx, idx, id: contextMenuId || DEFAULT_CONTEXT_MENU_ID | ||
}); | ||
|
||
class RowsContainer extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.plugins = props.window ? props.window.ReactDataGridPlugins : window.ReactDataGridPlugins; |
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.
This is an old code but is there a use case of props.window
? I wonder if anyone is actually using it, I do not think it can even be populated. This can be cleaned up (probably in a separate PR)
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.
@amanmahajan7 can it be server side rendering?
I think this was added back in the days due to IE8 support problems, having the context menu added directly would break IE8 apart
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.
I am not sure but that does seem like a workaround for SSR. We can revisit this code once RDG officially supports server side rendering.
|
||
it('should throw exception for no context menu plugin', () => { | ||
const newProp = Object.assign({}, props, { window: {}}); | ||
try { |
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.
toThrow/toThrowError
can be used instead
expect(shallow(<RowsContainer {...newProp} />)).toThrow()
@amanmahajan7 |
} | ||
|
||
render() { | ||
return this.hasContextMenu() ? this.renderRowsWithContextMenu() : <SimpleRowsContainer {...this.props} />; | ||
return this.getRowsContainer(); |
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.
getRowsContainer
method is probably not required and the render
method can just return the container
render () {
if (this.hasContextMenu()) {
this.validatePlugin();
return this.renderRowsWithContextMenu();
}
return <SimpleRowsContainer {...this.props} />;
}
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.
Just a small change, rest looks good
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.
Looks good to me
This upgrade is also required to support |
Should we fix the conflicts on this and get it merged? Makes sense to merge it |
@hutber |
What is the breaking change? Can this PR address it? |
@sontek |
@qili26 Ahh, is that all there is? I understand that upgrade is backwards incompatible but I think a version bump would suffice. Or are you taking extra steps to make it compatible? |
Description
A few sentences describing the overall goals of the pull request's commits.
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (check one with "x")
What is the current behavior? (You can also link to an open issue here)
react data grid + react v16 + current react context menu v1.6.2 doesn't display context menu.
What is the new behavior?
the context menu will be displayed.
Does this PR introduce a breaking change? (check one with "x")
If this PR contains a breaking change, please describe the impact and migration path for existing applications:
Some css has to be changed due to react context menu upgrade (breaking changes were introduced from react-contextmenu)
Original
ContextMenuLayer
HoC is converted toContextMenuTrigger
as a component. Hence the export (wrapper of context menu in RDG) has to be updated as well.Other information: