-
Notifications
You must be signed in to change notification settings - Fork 30
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
Prevent native context menu from being invoked on webviews #1736
Conversation
// eslint-disable-next-line sonarjs/cognitive-complexity | ||
export const Plots = ({ state }: { state: PlotsWebviewState }) => { | ||
const PlotsContent = ({ state }: PlotsProps) => { |
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.
Function PlotsContent
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
@@ -12,7 +12,7 @@ type CSSVariables = DetailedHTMLProps< | |||
HTMLDivElement | |||
> | |||
|
|||
export const Theme: React.FC = ({ children }) => { | |||
export const useThemeVariables = () => { |
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.
Function useThemeVariables
has 34 lines of code (exceeds 30 allowed). Consider refactoring.
export const Plots = ({ state }: PlotsProps) => { | ||
const variables = useThemeVariables() | ||
|
||
return ( | ||
<div | ||
style={variables} | ||
onContextMenu={e => { | ||
e.preventDefault() | ||
}} | ||
> | ||
<PlotsContent state={state} /> | ||
</div> |
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 container refactor makes it easier to ensure all states are wrapped with click-prevention even with the early-return logic we had before. It could probably use a larger refactor, but that's not the focus of this PR.
export const Theme: React.FC = ({ children }) => { | ||
const variables = useThemeVariables() |
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 kept Theme
for backward-compatibility, but it'd probably be best to use the hook everywhere in the future.
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 don't think backward-compatibility
is the right terminology here. If we are going to use the hook can you please follow up and remove this component. Thank you.
Closes #1723 |
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.
LGTM
(also tested manually)
export const Theme: React.FC = ({ children }) => { | ||
const variables = useThemeVariables() |
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 don't think backward-compatibility
is the right terminology here. If we are going to use the hook can you please follow up and remove this component. Thank you.
…ontext-menu-on-webviews
// eslint-disable-next-line sonarjs/cognitive-complexity | ||
export const Plots = ({ state }: { state: PlotsWebviewState }) => { | ||
const PlotsContent = ({ state }: PlotsProps) => { |
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.
Function PlotsContent
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Code Climate has analyzed commit bf2312a and detected 2 issues on this pull request. Here's the issue category breakdown:
The test coverage on the diff in this pull request is 100.0% (85% is the threshold). This pull request will bring the total coverage in the repository to 96.7% (0.0% change). View more on Code Climate. |
Demo in VSCode:
suppressed-contextmenu-vscode-demo.mp4
Demo in Storybook (proving it works in no-data states):
suppressed-contextmenu-storybook-demo.mp4
This PR suppresses native context menu in both Experiments Table and Plots webviews by adding a wrapper
div
with the proponContextmenu={(e)=>{e.preventDefault()}}
as the outermost component for both webviews.In order to keep unnecessary wrappers to a minimum, I also refactored the
Theme
component's logic out into a hook which can be applied to normaldiv
s so that we can use the same wrapperdiv
for both purposes.