From cbef75ea14662a9ba38710577169f0ac53a55300 Mon Sep 17 00:00:00 2001 From: Samer Salameh Date: Thu, 19 Nov 2026 17:39:45 +0300 Subject: [PATCH] Grid copy buttons and text selection, fix activating blocked users Co-Authored-By: Claude Sonnet 5.5 --- src/components/EntityGrid.tsx | 38 ++++++++++++++++++++++++++++---- src/features/view/EntityView.tsx | 3 +++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/components/EntityGrid.tsx b/src/components/EntityGrid.tsx index 51b6605..d9f2697 100644 --- a/src/components/EntityGrid.tsx +++ b/src/components/EntityGrid.tsx @@ -1,7 +1,8 @@ -import { useEffect, useMemo, useState } from 'react'; +import { useEffect, useMemo, useRef, useState } from 'react'; import { keepPreviousData, useQuery } from '@tanstack/react-query'; import { useNavigate } from 'react-router-dom'; import DOMPurify from 'dompurify'; +import ContentCopyOutlined from '@mui/icons-material/ContentCopyOutlined'; import EditOutlined from '@mui/icons-material/EditOutlined'; import VisibilityOutlined from '@mui/icons-material/VisibilityOutlined'; import MoreVertOutlined from '@mui/icons-material/MoreVertOutlined'; @@ -92,6 +93,7 @@ export function EntityGrid({ entity, filter, canEdit, onTotal, onFilterRequired, const ui = useUi(); const nav = useNavigate(); const notify = useNotify(); + const navTimer = useRef(0); const [menu, setMenu] = useState<{ el: HTMLElement; actions: RowAction[] } | null>(null); const [confirmAction, setConfirmAction] = useState(null); const [withdrawId, setWithdrawId] = useState(null); @@ -168,9 +170,28 @@ export function EntityGrid({ entity, filter, canEdit, onTotal, onFilterRequired, if (c.name === 'ACTION_ICONS') return null; if (entity === 'USERS' && (c.name === 'JOB_TITLE' || fields[c.index] === 'JOB_TITLE')) return roleLabel(v, t, lab, isRtl(lang)) || '—'; if (c.name.toUpperCase() === 'STATUS_CODE') return = 0 ? String(r[statusIdx] ?? '') : v} caption={v} />; - if (PLATE.test(c.name)) return ; if (HTML_COLUMNS.test(c.name)) return ; - return v || '—'; + if (!v) return '—'; + // a small copy button appears on hover, so a value can be copied without selecting it by hand + return ( + + {PLATE.test(c.name) ? : {v}} + + { + e.stopPropagation(); + void navigator.clipboard?.writeText(v); + }} + > + + + + + ); }; return ( @@ -236,7 +257,16 @@ export function EntityGrid({ entity, filter, canEdit, onTotal, onFilterRequired, ))} {!loading && list.map((r, ri) => ( - alpha(t.palette.primary.main, t.palette.mode === 'dark' ? 0.09 : 0.05) } }} onClick={noView ? undefined : () => nav(`/e/${entity}/view/${rowId(r)}`)}> + alpha(t.palette.primary.main, t.palette.mode === 'dark' ? 0.09 : 0.05) } }} + // selecting text in a cell (to copy it) must not open the record: a drag-select ends in a click on the row + onClick={noView ? undefined : (e) => { + if (window.getSelection()?.toString()) return; + // a double-click (select a word) must not open the record: wait a moment and cancel if a second click follows + const to = `/e/${entity}/view/${rowId(r)}`; + if (e.detail > 1) { window.clearTimeout(navTimer.current); return; } + window.clearTimeout(navTimer.current); + navTimer.current = window.setTimeout(() => { if (!window.getSelection()?.toString()) nav(to); }, 250); + }}> {selectable && ( e.stopPropagation()}> {