-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
component(ContextMenuViewport): move to ui-next with theme support #6008
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
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { ContextMenu } from '@ohif/ui'; | ||
| import { ContextMenuViewport } from '@ohif/ui-next'; | ||
|
|
||
| export default { | ||
| 'ui.contextMenu': ContextMenu, | ||
| 'ui.contextMenu': ContextMenuViewport, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import React from 'react'; | ||
| import { Icons } from '../Icons'; | ||
|
|
||
| interface ContextMenuViewportProps { | ||
| items?: Array<{ | ||
| label: string; | ||
| action: (item: any, props: any) => void; | ||
| iconRight?: string; | ||
| [key: string]: unknown; | ||
| }>; | ||
| defaultPosition?: { x: number; y: number }; | ||
| [key: string]: unknown; | ||
| } | ||
|
|
||
| const ContextMenuViewport = ({ items, ...props }: ContextMenuViewportProps) => { | ||
| if (!items) { | ||
| return null; | ||
| } | ||
|
Comment on lines
+16
to
+18
Contributor
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.
The guard Prompt To Fix With AIThis is a comment left during a code review.
Path: platform/ui-next/src/components/ContextMenuViewport/ContextMenuViewport.tsx
Line: 16-18
Comment:
**Empty array bypasses the early-return guard**
The guard `if (!items)` returns `null` only when `items` is `undefined` or `null`. If `ContextMenuItemsBuilder.getMenuItems` returns `[]`, the controller's own `if (!items) return` also passes through, and the component renders an empty container div — a small invisible-but-present box at the calculated position. Adding `|| items.length === 0` to the guard would prevent this; note the old component has the same behavior so this is not a regression introduced by this PR.
How can I resolve this? If you propose a fix, please make it concise.
Collaborator
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. Since it is not a regression let's leave it. |
||
|
|
||
| return ( | ||
| <div | ||
| data-cy="context-menu" | ||
| className="bg-popover text-popover-foreground animate-in fade-in-0 zoom-in-95 relative z-50 w-48 overflow-hidden rounded-md border border-input p-1 shadow-md" | ||
| onContextMenu={e => e.preventDefault()} | ||
| > | ||
| {items.map((item, index) => ( | ||
| <div | ||
| key={index} | ||
| data-cy="context-menu-item" | ||
| onClick={() => item.action(item, props)} | ||
| className="hover:bg-accent hover:text-accent-foreground flex cursor-default select-none items-center justify-between rounded-sm px-2 py-1.5 text-base outline-none" | ||
|
dan-rukas marked this conversation as resolved.
|
||
| > | ||
| <span>{item.label}</span> | ||
| {item.iconRight && ( | ||
| <Icons.ByName | ||
| name={item.iconRight} | ||
| className="inline" | ||
| /> | ||
| )} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default ContextMenuViewport; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default as ContextMenuViewport } from './ContextMenuViewport'; |
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.
defaultPositionis declared in the interface but never read in the component body. Since the dialog service handles positioning externally viauiDialogService.show({ defaultPosition }), this prop will never be forwarded to the component as a prop, making the declaration dead code.Prompt To Fix With AI
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 think @greptileai is correct here. Please update.
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.
Agreed — here's the fix. Just drop the
defaultPositionline; the index signature already handles any extra props passed through:That removes the dead declaration while keeping the interface flexible for anything else the dialog service might forward.