-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bbce3f9
upgrade react context menu to v2.9
6ff153f
Merge branch 'master' into ql-context-menu-upgrade
874819f
add unit tests
c9f0e55
update unit test
c792018
remove unecessary id set
5045270
remove unnecessary function
19c825d
update migration doc
c82e21a
catchup master
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import {MenuItem, monitor, SubMenu, connect, ContextMenuLayer} from 'react-contextmenu'; | ||
import ContextMenu from './ContextMenu'; | ||
import {ContextMenu, MenuItem, monitor, SubMenu, connect, ContextMenuTrigger} from 'react-contextmenu'; | ||
import MenuHeader from './MenuHeader'; | ||
|
||
export {ContextMenu, MenuHeader, MenuItem, monitor, SubMenu, connect, ContextMenuLayer}; | ||
export {ContextMenu, MenuHeader, MenuItem, monitor, SubMenu, connect, ContextMenuTrigger}; |
59 changes: 45 additions & 14 deletions
59
packages/react-data-grid-examples/src/assets/css/react-context-menu.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,78 @@ | ||
.react-context-menu { | ||
.react-contextmenu { | ||
min-width: 160px; | ||
padding: 5px 0; | ||
margin: 2px 0 0; | ||
font-size: 14px; | ||
font-size: 16px; | ||
color: #373a3c; | ||
text-align: left; | ||
background-color: #fff; | ||
-webkit-background-clip: padding-box; | ||
background-clip: padding-box; | ||
border: 1px solid rgba(0,0,0,.15); | ||
border-radius: .25rem; | ||
outline: none; | ||
opacity: 0; | ||
pointer-events: none; | ||
transition: opacity 250ms ease !important; | ||
} | ||
|
||
.react-context-menu-link { | ||
display: inline-block; | ||
width: 100%; | ||
.react-contextmenu.react-contextmenu--visible { | ||
opacity: 1; | ||
pointer-events: auto; | ||
} | ||
|
||
.react-contextmenu-item { | ||
padding: 3px 20px; | ||
clear: both; | ||
font-weight: 400; | ||
line-height: 1.5; | ||
color: #373a3c; | ||
text-align: inherit; | ||
white-space: nowrap; | ||
background: 0 0; | ||
border: 0; | ||
cursor: pointer; | ||
} | ||
|
||
.react-context-menu-link.active, | ||
.react-context-menu-link:hover { | ||
.react-contextmenu-item.react-contextmenu-item--active, | ||
.react-contextmenu-item.react-contextmenu-item--selected { | ||
color: #fff; | ||
background-color: #0275d8; | ||
border-color: #0275d8; | ||
background-color: #20a0ff; | ||
border-color: #20a0ff; | ||
text-decoration: none; | ||
} | ||
|
||
.react-context-menu-item.submenu > a { | ||
padding-right: 27px; | ||
.react-contextmenu-item.react-contextmenu-item--disabled, | ||
.react-contextmenu-item.react-contextmenu-item--disabled:hover { | ||
color: #878a8c; | ||
background-color: transparent; | ||
border-color: rgba(0,0,0,.15); | ||
} | ||
|
||
.react-contextmenu-item--divider { | ||
margin-bottom: 3px; | ||
padding: 2px 0; | ||
border-bottom: 1px solid rgba(0,0,0,.15); | ||
cursor: inherit; | ||
} | ||
.react-contextmenu-item--divider:hover { | ||
background-color: transparent; | ||
border-color: rgba(0,0,0,.15); | ||
} | ||
|
||
.react-context-menu-item.submenu > a:after { | ||
.react-contextmenu-item.react-contextmenu-submenu { | ||
padding: 0; | ||
} | ||
|
||
.react-contextmenu-item.react-contextmenu-submenu > .react-contextmenu-item { | ||
} | ||
|
||
.react-contextmenu-item.react-contextmenu-submenu > .react-contextmenu-item:after { | ||
content: "▶"; | ||
display: inline-block; | ||
position: absolute; | ||
right: 7px; | ||
} | ||
|
||
.example-multiple-targets::after { | ||
content: attr(data-count); | ||
display: block; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 52 additions & 7 deletions
59
packages/react-data-grid/src/__tests__/RowsContainer.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,62 @@ | ||
import { shallow } from 'enzyme'; | ||
import React from 'react'; | ||
import ReactTestUtils from 'react-dom/test-utils'; | ||
import RowsContainer from '../RowsContainer'; | ||
import RowsContainer, { getNewContextMenuProps, SimpleRowsContainer, DEFAULT_CONTEXT_MENU_ID } from '../RowsContainer'; | ||
|
||
const FakeContextMenuTrigger = () => <div id="fakeContextMenuTrigger" />; | ||
|
||
const FakeContextMenu = () => <div />; | ||
|
||
const ReactDataGridPlugins = { | ||
Menu: { | ||
ContextMenuTrigger: FakeContextMenuTrigger | ||
} | ||
}; | ||
|
||
const contextMenuId = 'fakeContextMenu'; | ||
const props = { | ||
contextMenu: <FakeContextMenu id={contextMenuId} />, | ||
rowIdx: 5, | ||
idx: 8, | ||
window: { ReactDataGridPlugins }, | ||
rows: [ | ||
{ id: 'row_1' }, | ||
{ id: 'row_2' } | ||
] | ||
}; | ||
|
||
describe('Rows Container', () => { | ||
describe('without context menu', () => { | ||
let componentWithoutContextMenu = {}; | ||
describe('getNewContextMenuProps()', () => { | ||
it('should populate correct newProps for contextMenu with customized menu id', () => { | ||
const newProps = getNewContextMenuProps(props); | ||
expect(newProps.id).toBe(contextMenuId); | ||
}); | ||
|
||
beforeEach(() => { | ||
componentWithoutContextMenu = ReactTestUtils.renderIntoDocument(<RowsContainer window={{ ReactDataGridPlugins: undefined }} />); | ||
it('should populate correct newProps for contextMenu with default menu id', () => { | ||
const newProps = getNewContextMenuProps(Object.assign({}, props, { contextMenu: <FakeContextMenu /> })); | ||
expect(newProps.id).toBe(DEFAULT_CONTEXT_MENU_ID); | ||
}); | ||
}); | ||
|
||
describe('with context menu', () => { | ||
it('should create a new RowsContainer instance', () => { | ||
expect(componentWithoutContextMenu).toBeDefined(); | ||
const wrapper = shallow(<RowsContainer {...props} />); | ||
expect(wrapper.find(FakeContextMenuTrigger).length).toBe(1); | ||
}); | ||
|
||
it('should throw exception for no context menu plugin when rendering', () => { | ||
const newProp = Object.assign({}, props, { window: {}}); | ||
expect(() => { shallow(<RowsContainer {...newProp} />); }).toThrowError('You need to include ReactDataGrid UiPlugins in order to initialise context menu'); | ||
}); | ||
}); | ||
|
||
describe('without context menu', () => { | ||
it('should create a SimpleRowsContainer', () => { | ||
const newProps = Object.assign({}, props, { | ||
contextMenu: undefined | ||
}); | ||
const wrapper = shallow(<RowsContainer {...newProps}/>); | ||
expect(wrapper.find(SimpleRowsContainer).length).toBe(1); | ||
expect(wrapper.find(FakeContextMenuTrigger).length).toBe(0); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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)https://github.com/adazzle/react-data-grid/blob/master/packages/react-data-grid/src/Canvas.js#L284
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.