Skip to content
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

enhance: context menu on custom reports page #3776

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
63 changes: 44 additions & 19 deletions packages/desktop-client/src/components/reports/ReportCard.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, {
useRef,
useState,
type ComponentProps,
type ReactNode,
type CSSProperties,
} from 'react';

import { useContextMenu } from '../../hooks/useContextMenu';
import { useIsInViewport } from '../../hooks/useIsInViewport';
import { useNavigate } from '../../hooks/useNavigate';
import { theme } from '../../style';
Expand Down Expand Up @@ -119,10 +119,21 @@ type LayoutProps = {

function Layout({ children, isEditing, menuItems, onMenuSelect }: LayoutProps) {
const triggerRef = useRef(null);
const [menuOpen, setMenuOpen] = useState(false);
const viewRef = useRef(null);

const {
setMenuOpen,
menuOpen,
handleContextMenu,
resetPosition,
position,
asContextMenu,
} = useContextMenu();

return (
<View
ref={viewRef}
onContextMenu={handleContextMenu}
style={{
display: 'block',
height: '100%',
Expand All @@ -135,32 +146,46 @@ function Layout({ children, isEditing, menuItems, onMenuSelect }: LayoutProps) {
},
}}
>
{menuItems && isEditing && (
<View
className={[
menuOpen ? undefined : 'hover-visible',
NON_DRAGGABLE_AREA_CLASS_NAME,
].join(' ')}
style={{
position: 'absolute',
top: 7,
right: 3,
zIndex: 1,
}}
>
<MenuButton ref={triggerRef} onPress={() => setMenuOpen(true)} />
{menuItems && (
<>
{isEditing && (
<View
className={[
menuOpen ? undefined : 'hover-visible',
NON_DRAGGABLE_AREA_CLASS_NAME,
].join(' ')}
UnderKoen marked this conversation as resolved.
Show resolved Hide resolved
style={{
position: 'absolute',
top: 7,
right: 3,
zIndex: 1,
}}
>
<MenuButton
ref={triggerRef}
onPress={() => {
resetPosition();
setMenuOpen(true);
}}
/>
</View>
)}

<Popover
triggerRef={triggerRef}
isOpen={menuOpen}
triggerRef={asContextMenu ? viewRef : triggerRef}
isOpen={Boolean(menuOpen)}
onOpenChange={() => setMenuOpen(false)}
isNonModal
placement={asContextMenu ? 'bottom start' : 'bottom end'}
{...position}
>
<Menu
className={NON_DRAGGABLE_AREA_CLASS_NAME}
onMenuSelect={onMenuSelect}
items={menuItems}
/>
</Popover>
</View>
</>
)}

{children}
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/3776.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [UnderKoen]
---

Add context menus to custom reports dashboard
Loading