feat: Test run detail pane (#381)

This commit is contained in:
kimatata
2026-01-12 23:27:34 +09:00
committed by GitHub
parent ab348fc4e5
commit 34135209d9
18 changed files with 564 additions and 339 deletions

View File

@@ -1,9 +1,22 @@
import { useEffect } from 'react';
export const useFormGuard = (isDirty: boolean, confirmText: string) => {
export const useFormGuard = (isDirty: boolean, confirmText: string, ignorePaths?: string[]) => {
useEffect(() => {
const handleClick = (event: MouseEvent) => {
if (isDirty && event.target instanceof Element && event.target.closest('a:not([target="_blank"]')) {
if (!isDirty) return;
if (event.target instanceof Element) {
const anchor = event.target.closest('a:not([target="_blank"])');
if (!anchor) return;
const href = anchor.getAttribute('href');
if (!href) return;
// do not show confirm for ignored paths
if (ignorePaths && ignorePaths.some((path) => href.includes(path))) {
return;
}
if (!window.confirm(confirmText)) {
event.preventDefault();
event.stopPropagation();
@@ -25,5 +38,5 @@ export const useFormGuard = (isDirty: boolean, confirmText: string) => {
window.removeEventListener('beforeunload', handleBeforeUnload);
window.removeEventListener('click', handleClick, true);
};
}, [confirmText, isDirty]);
}, [confirmText, isDirty, ignorePaths]);
};