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 11 commits into
base: master
Choose a base branch
from
72 changes: 53 additions & 19 deletions packages/desktop-client/src/components/reports/ReportCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import React, {
type CSSProperties,
} from 'react';

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

function Layout({ children, isEditing, menuItems, onMenuSelect }: LayoutProps) {
const triggerRef = useRef(null);
const [menuOpen, setMenuOpen] = useState(false);
const viewRef = useRef(null);
const [menuOpen, setMenuOpen] = useState<null | 'context' | 'button'>(null);
const [crossOffset, setCrossOffset] = useState(0);
const [offset, setOffset] = useState(0);
const reportBudgetEnabled = useFeatureFlag('reportBudget');
UnderKoen marked this conversation as resolved.
Show resolved Hide resolved
const contextMenusEnabled =
useFeatureFlag('contextMenus') && reportBudgetEnabled;
matt-fidd marked this conversation as resolved.
Show resolved Hide resolved

const isContextMenu = menuOpen === 'context';

return (
<View
ref={viewRef}
onContextMenu={e => {
if (!contextMenusEnabled) return;
e.preventDefault();
setMenuOpen('context');
const rect = e.currentTarget.getBoundingClientRect();
setCrossOffset(e.clientX - rect.left);
setOffset(e.clientY - rect.bottom);
}}
UnderKoen marked this conversation as resolved.
Show resolved Hide resolved
style={{
display: 'block',
height: '100%',
Expand All @@ -135,32 +153,48 @@ 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={() => {
setCrossOffset(0);
setOffset(0);
setMenuOpen('button');
}}
/>
</View>
)}

<Popover
triggerRef={triggerRef}
isOpen={menuOpen}
onOpenChange={() => setMenuOpen(false)}
triggerRef={isContextMenu ? viewRef : triggerRef}
isOpen={Boolean(menuOpen)}
onOpenChange={() => setMenuOpen(null)}
isNonModal
placement={isContextMenu ? 'bottom start' : 'bottom end'}
crossOffset={crossOffset}
offset={offset}
>
<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 menu's to custom reports dashboard
UnderKoen marked this conversation as resolved.
Show resolved Hide resolved