mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-04 12:07:09 +00:00
replay ui fix (#56)
* refactor: rename inspect to replay across the codebase Renames inspect-ui/ to replay-ui/, internal/inspect/ to internal/replay/, the CLI subcommand from `sanderling inspect` to `sanderling replay`, and updates all references in docs, Makefile, README, and Go comments. * feat(replay-ui): show spec filename with full path on hover RunList and RunDetail now render the basename of spec_path (e.g. login.spec.ts) with the full path available as a title tooltip.
This commit is contained in:
71 files changed
+104
-92
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import { useEffect } from "react";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
|
||||
export interface UseStepResult {
|
||||
runId: string;
|
||||
stepIndex: number;
|
||||
goTo: (index: number) => void;
|
||||
}
|
||||
|
||||
export function useStep(maxIndex: number | undefined): UseStepResult {
|
||||
const navigate = useNavigate();
|
||||
const { id, step } = useParams<{ id: string; step: string }>();
|
||||
const runId = id ?? "";
|
||||
const parsed = Number(step ?? "1");
|
||||
const stepIndex = Number.isFinite(parsed) && parsed > 0 ? parsed : 1;
|
||||
|
||||
const clamped = clampIndex(stepIndex, maxIndex);
|
||||
|
||||
useEffect(() => {
|
||||
if (clamped !== stepIndex && runId !== "") {
|
||||
navigate(`/runs/${runId}/steps/${clamped}`, { replace: true });
|
||||
}
|
||||
}, [clamped, stepIndex, runId, navigate]);
|
||||
|
||||
const goTo = (index: number) => {
|
||||
const target = clampIndex(index, maxIndex);
|
||||
if (target !== stepIndex && runId !== "") {
|
||||
navigate(`/runs/${runId}/steps/${target}`);
|
||||
}
|
||||
};
|
||||
|
||||
return { runId, stepIndex: clamped, goTo };
|
||||
}
|
||||
|
||||
function clampIndex(index: number, maxIndex: number | undefined): number {
|
||||
if (index < 1) {
|
||||
return 1;
|
||||
}
|
||||
if (maxIndex !== undefined && index > maxIndex) {
|
||||
return maxIndex;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
Reference in new issue
Block a user