Grid copy buttons and text selection, fix activating blocked users
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e435a51989
commit
cbef75ea14
|
|
@ -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 { keepPreviousData, useQuery } from '@tanstack/react-query';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import DOMPurify from 'dompurify';
|
import DOMPurify from 'dompurify';
|
||||||
|
import ContentCopyOutlined from '@mui/icons-material/ContentCopyOutlined';
|
||||||
import EditOutlined from '@mui/icons-material/EditOutlined';
|
import EditOutlined from '@mui/icons-material/EditOutlined';
|
||||||
import VisibilityOutlined from '@mui/icons-material/VisibilityOutlined';
|
import VisibilityOutlined from '@mui/icons-material/VisibilityOutlined';
|
||||||
import MoreVertOutlined from '@mui/icons-material/MoreVertOutlined';
|
import MoreVertOutlined from '@mui/icons-material/MoreVertOutlined';
|
||||||
|
|
@ -92,6 +93,7 @@ export function EntityGrid({ entity, filter, canEdit, onTotal, onFilterRequired,
|
||||||
const ui = useUi();
|
const ui = useUi();
|
||||||
const nav = useNavigate();
|
const nav = useNavigate();
|
||||||
const notify = useNotify();
|
const notify = useNotify();
|
||||||
|
const navTimer = useRef(0);
|
||||||
const [menu, setMenu] = useState<{ el: HTMLElement; actions: RowAction[] } | null>(null);
|
const [menu, setMenu] = useState<{ el: HTMLElement; actions: RowAction[] } | null>(null);
|
||||||
const [confirmAction, setConfirmAction] = useState<RowAction | null>(null);
|
const [confirmAction, setConfirmAction] = useState<RowAction | null>(null);
|
||||||
const [withdrawId, setWithdrawId] = useState<string | null>(null);
|
const [withdrawId, setWithdrawId] = useState<string | null>(null);
|
||||||
|
|
@ -168,9 +170,28 @@ export function EntityGrid({ entity, filter, canEdit, onTotal, onFilterRequired,
|
||||||
if (c.name === 'ACTION_ICONS') return null;
|
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 (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 <StatusChip status={statusIdx >= 0 ? String(r[statusIdx] ?? '') : v} caption={v} />;
|
if (c.name.toUpperCase() === 'STATUS_CODE') return <StatusChip status={statusIdx >= 0 ? String(r[statusIdx] ?? '') : v} caption={v} />;
|
||||||
if (PLATE.test(c.name)) return <PlateBadge text={v} />;
|
|
||||||
if (HTML_COLUMNS.test(c.name)) return <Box dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(v) }} />;
|
if (HTML_COLUMNS.test(c.name)) return <Box dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(v) }} />;
|
||||||
return v || '—';
|
if (!v) return '—';
|
||||||
|
// a small copy button appears on hover, so a value can be copied without selecting it by hand
|
||||||
|
return (
|
||||||
|
<Box sx={{ display: 'inline-flex', alignItems: 'center', gap: 0.25, '& .copy-btn': { opacity: 0 }, '&:hover .copy-btn': { opacity: 1 } }}>
|
||||||
|
{PLATE.test(c.name) ? <PlateBadge text={v} /> : <span>{v}</span>}
|
||||||
|
<Tooltip title={ui('copy')}>
|
||||||
|
<IconButton
|
||||||
|
className="copy-btn"
|
||||||
|
size="small"
|
||||||
|
aria-label={ui('copy')}
|
||||||
|
sx={{ p: 0.25 }}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
void navigator.clipboard?.writeText(v);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ContentCopyOutlined sx={{ fontSize: 14 }} />
|
||||||
|
</IconButton>
|
||||||
|
</Tooltip>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -236,7 +257,16 @@ export function EntityGrid({ entity, filter, canEdit, onTotal, onFilterRequired,
|
||||||
))}
|
))}
|
||||||
{!loading &&
|
{!loading &&
|
||||||
list.map((r, ri) => (
|
list.map((r, ri) => (
|
||||||
<TableRow key={String(rowId(r)) + ri} hover={!noView} sx={{ cursor: noView ? 'default' : 'pointer', '&:nth-of-type(even)': { bgcolor: (t) => alpha(t.palette.primary.main, t.palette.mode === 'dark' ? 0.09 : 0.05) } }} onClick={noView ? undefined : () => nav(`/e/${entity}/view/${rowId(r)}`)}>
|
<TableRow key={String(rowId(r)) + ri} hover={!noView} sx={{ cursor: noView ? 'default' : 'pointer', '& td': { userSelect: 'text' }, '&:nth-of-type(even)': { bgcolor: (t) => 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 && (
|
{selectable && (
|
||||||
<TableCell padding="checkbox" onClick={(e) => e.stopPropagation()}>
|
<TableCell padding="checkbox" onClick={(e) => e.stopPropagation()}>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
|
|
|
||||||
|
|
@ -158,6 +158,9 @@ export function EntityView({ entity, id }: { entity: string; id: string }) {
|
||||||
for (const k of Object.keys(payload)) if (/DATE/.test(k)) delete payload[k];
|
for (const k of Object.keys(payload)) if (/DATE/.test(k)) delete payload[k];
|
||||||
if (values.EVENT_DATE_GRID) payload.EVENT_DATE_GRID = values.EVENT_DATE_GRID;
|
if (values.EVENT_DATE_GRID) payload.EVENT_DATE_GRID = values.EVENT_DATE_GRID;
|
||||||
}
|
}
|
||||||
|
// users: the backend's activate / deactivate read every posted key from the user record, and it has no LOCATION_IDS
|
||||||
|
// property ("method getLOCATION_IDS was not found"), so the old form never posted the (empty) area list with these actions
|
||||||
|
if (entity === 'USERS') delete payload.LOCATION_IDS;
|
||||||
return runAction(entity, v.a.ACTION_NAME, payload, id, [], v.reason);
|
return runAction(entity, v.a.ACTION_NAME, payload, id, [], v.reason);
|
||||||
},
|
},
|
||||||
onSuccess: (res, v) => {
|
onSuccess: (res, v) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue