Public Access
feat(audit): undo button for merges, hide manual games
The audit log shows Undo on a merge row for 30 days, with a confirm dialog and clear errors. The details page follows a merged key to the kept game. Hide and Show now work for manual games too. de/en texts.
This commit is contained in:
1 parent
0c300c455d
commit
ae904d946a
9 files changed
+189
-57
No files matched your search
@@ -1,17 +1,18 @@
|
||||
import {useCallback, useEffect, useState} from 'react';
|
||||
import {Link} from 'react-router-dom';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {ChevronLeft, ChevronRight, Loader2} from 'lucide-react';
|
||||
import {ChevronLeft, ChevronRight, Loader2, Undo2} from 'lucide-react';
|
||||
|
||||
import {Button} from '@/components/ui/button';
|
||||
import {Card, CardContent, CardHeader, CardTitle} from '@/components/ui/card';
|
||||
import {Select, SelectContent, SelectItem, SelectTrigger, SelectValue} from '@/components/ui/select';
|
||||
import PageContainer from '../components/PageContainer.jsx';
|
||||
import {fetchAuditLog} from '../utils/links.js';
|
||||
import {toast} from 'sonner';
|
||||
import {fetchAuditLog, undoMerge} from '../utils/links.js';
|
||||
import {formatDateTime} from '../utils/format.js';
|
||||
|
||||
const PAGE_SIZE = 20;
|
||||
const ACTIONS = ['GAME_MERGE', 'GAME_LINK', 'GAME_UNLINK', 'GAME_LINK_DISMISS', 'GAME_CORRECT',
|
||||
const ACTIONS = ['GAME_MERGE', 'GAME_MERGE_UNDO', 'GAME_LINK', 'GAME_UNLINK', 'GAME_LINK_DISMISS', 'GAME_CORRECT',
|
||||
'GAME_CORRECTION_RESET'];
|
||||
const ALL = 'ALL';
|
||||
|
||||
@@ -29,6 +30,7 @@ export default function AuditLogPage() {
|
||||
const [page, setPage] = useState(0);
|
||||
const [result, setResult] = useState({content: [], totalPages: 0});
|
||||
const [status, setStatus] = useState('loading');
|
||||
const [undoing, setUndoing] = useState(false);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
try {
|
||||
@@ -54,6 +56,30 @@ export default function AuditLogPage() {
|
||||
load();
|
||||
}, [load]);
|
||||
|
||||
const onUndo = async (entry) => {
|
||||
// The merged key has no catalog row any more; its name is the first one in the detail.
|
||||
const name = entry.gameName ?? /^"(.*?)" into "/.exec(entry.detail ?? '')?.[1] ?? entry.appid;
|
||||
const other = entry.targetGameName ?? entry.targetAppid;
|
||||
if (!window.confirm(t('AUDIT.UNDO.CONFIRM', {name, other}))) return;
|
||||
setUndoing(true);
|
||||
try {
|
||||
const response = await undoMerge(entry.id);
|
||||
if (response.status === 401) return;
|
||||
if (response.ok) {
|
||||
toast.success(t('AUDIT.UNDO.DONE'));
|
||||
} else {
|
||||
const data = await response.json().catch(() => ({}));
|
||||
toast.error(t(`AUDIT.UNDO.ERROR_CODES.${data.code}`, {defaultValue: t('AUDIT.UNDO.ERROR')}));
|
||||
}
|
||||
await load();
|
||||
} catch (err) {
|
||||
console.error('Undo merge error:', err);
|
||||
toast.error(t('INFO.ERROR.NETWORK_FAILURE'));
|
||||
} finally {
|
||||
setUndoing(false);
|
||||
}
|
||||
};
|
||||
|
||||
const onActionChange = (value) => {
|
||||
setAction(value);
|
||||
setPage(0);
|
||||
@@ -100,6 +126,12 @@ export default function AuditLogPage() {
|
||||
<GameRef appid={entry.targetAppid} name={entry.targetGameName} fallback={entry.targetAppid}/>
|
||||
</p>
|
||||
{entry.detail && <p className="break-words text-xs text-muted-foreground">{entry.detail}</p>}
|
||||
{entry.action === 'GAME_MERGE' && entry.undoable && (
|
||||
<Button type="button" variant="outline" size="sm" disabled={undoing}
|
||||
onClick={() => onUndo(entry)}>
|
||||
<Undo2/>{t('AUDIT.UNDO.BUTTON')}
|
||||
</Button>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
Reference in new issue
Block a user