Skip to content

Commit 63fe5c7

Browse files
authored
fix(ui): scroll to cron run history
1 parent 15fc881 commit 63fe5c7

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

ui/src/ui/views/cron.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,4 +900,42 @@ describe("cron view", () => {
900900
"cron-thinking-suggestions",
901901
]);
902902
});
903+
904+
it("scrolls the run history card into view when History is clicked", () => {
905+
vi.stubGlobal("requestAnimationFrame", (callback: FrameRequestCallback) => {
906+
callback(0);
907+
return 1;
908+
});
909+
const container = document.createElement("div");
910+
document.body.append(container);
911+
try {
912+
const onLoadRuns = vi.fn();
913+
render(
914+
renderCron(
915+
createProps({
916+
jobs: [createJob("job-1")],
917+
onLoadRuns,
918+
}),
919+
),
920+
container,
921+
);
922+
923+
const runHistory = getElement(container, "[data-run-history]", HTMLElement);
924+
const scrollIntoView = vi.fn();
925+
Object.defineProperty(runHistory, "scrollIntoView", {
926+
configurable: true,
927+
value: scrollIntoView,
928+
});
929+
930+
getButtonByText(container, "History").dispatchEvent(
931+
new MouseEvent("click", { bubbles: true }),
932+
);
933+
934+
expect(onLoadRuns).toHaveBeenCalledWith("job-1");
935+
expect(scrollIntoView).toHaveBeenCalledWith({ behavior: "smooth", block: "start" });
936+
} finally {
937+
container.remove();
938+
vi.unstubAllGlobals();
939+
}
940+
});
903941
});

ui/src/ui/views/cron.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ export function renderCron(props: CronProps) {
629629
: nothing}
630630
</section>
631631
632-
<section class="card">
632+
<section class="card" data-run-history>
633633
<div
634634
class="row"
635635
style="justify-content: space-between; align-items: flex-start; gap: 12px;"
@@ -1691,6 +1691,15 @@ function renderJob(job: CronJob, props: CronProps) {
16911691
@click=${(event: Event) => {
16921692
event.stopPropagation();
16931693
props.onLoadRuns(job.id);
1694+
requestAnimationFrame(() => {
1695+
const runHistory = document.querySelector("[data-run-history]");
1696+
if (
1697+
runHistory instanceof HTMLElement &&
1698+
typeof runHistory.scrollIntoView === "function"
1699+
) {
1700+
runHistory.scrollIntoView({ behavior: "smooth", block: "start" });
1701+
}
1702+
});
16941703
}}
16951704
>
16961705
${t("cron.jobList.history")}

0 commit comments

Comments
 (0)