Skip to content

Commit 849dc4e

Browse files
Copilotsteverydz
andauthored
fix: address review comments - align query params, make props optional, fix effect guard, remove extra fetch in ModelNav
Agent-Logs-Url: https://github.com/canonical/snapcraft.io/sessions/db108129-dfdc-4dc5-9474-7c53386f2475 Co-authored-by: steverydz <501889+steverydz@users.noreply.github.com>
1 parent 62e2dc2 commit 849dc4e

5 files changed

Lines changed: 27 additions & 30 deletions

File tree

static/js/publisher/hooks/__tests__/useSerialLogs.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ describe("useSerialLogs", () => {
176176
({ request }) => {
177177
const url = new URL(request.url);
178178

179-
expect(url.searchParams.get("next-page")).toBe("nextpagecursor");
179+
expect(url.searchParams.get("page")).toBe("nextpagecursor");
180180
return HttpResponse.json({
181181
data: serialLogsResponse,
182182
success: true,
@@ -218,7 +218,7 @@ describe("useSerialLogs", () => {
218218
"2026-03-28T04:00:23.875000",
219219
);
220220
expect(url.searchParams.get("page-size")).toBe("10");
221-
expect(url.searchParams.get("next-page")).toBe("nextpagecursor");
221+
expect(url.searchParams.get("page")).toBe("nextpagecursor");
222222
return HttpResponse.json({
223223
data: serialLogsResponse,
224224
success: true,

static/js/publisher/hooks/useSerialLogs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const useSerialLogs = (
3131
}
3232

3333
if (page) {
34-
url.searchParams.set("next-page", page);
34+
url.searchParams.set("page", page);
3535
}
3636
}
3737

static/js/publisher/layouts/ModelDetailsPageLayout/ModelNav.tsx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { Link, useParams } from "react-router-dom";
22
import { useAtomValue } from "jotai";
33

4-
import { useRemodels, useSerialLogs } from "../../hooks";
4+
import { useRemodels } from "../../hooks";
55
import { brandIdState } from "../../state/brandStoreState";
66

77
function ModelNav({ sectionName }: { sectionName: string }): React.JSX.Element {
88
const { id, modelId } = useParams();
99
const brandId = useAtomValue(brandIdState);
1010
const { data: remodelsData } = useRemodels(brandId);
11-
const { data: serialLogsData } = useSerialLogs(brandId, modelId);
1211

1312
return (
1413
<nav className="p-tabs">
@@ -45,18 +44,16 @@ function ModelNav({ sectionName }: { sectionName: string }): React.JSX.Element {
4544
</Link>
4645
</li>
4746
)}
48-
{serialLogsData?.success && (
49-
<li className="p-tabs__item">
50-
<Link
51-
to={`/admin/${id}/models/${modelId}/serial-log`}
52-
className="p-tabs__link"
53-
aria-selected={sectionName === "serial-log"}
54-
role="tab"
55-
>
56-
Serial log
57-
</Link>
58-
</li>
59-
)}
47+
<li className="p-tabs__item">
48+
<Link
49+
to={`/admin/${id}/models/${modelId}/serial-log`}
50+
className="p-tabs__link"
51+
aria-selected={sectionName === "serial-log"}
52+
role="tab"
53+
>
54+
Serial log
55+
</Link>
56+
</li>
6057
</ul>
6158
</nav>
6259
);

static/js/publisher/pages/SerialLog/SerialLog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function SerialLog(): React.JSX.Element {
7171
: setPageTitle("Serial logs");
7272

7373
useEffect(() => {
74-
if (isLoading && isError) {
74+
if (isLoading || isError) {
7575
return;
7676
}
7777

static/js/publisher/pages/SerialLog/SerialLogTable.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ import { serialLogsListState } from "../../state/serialLogsState";
1212
import type { SerialLog } from "../../types/shared";
1313

1414
type Props = {
15-
handlePageForward: () => void;
16-
handlePageBack: () => void;
17-
handlePageSizeChange: (arg: number) => void;
18-
forwardDisabled: boolean;
19-
backDisabled: boolean;
20-
pageSize: number;
15+
handlePageForward?: () => void;
16+
handlePageBack?: () => void;
17+
handlePageSizeChange?: (arg: number) => void;
18+
forwardDisabled?: boolean;
19+
backDisabled?: boolean;
20+
pageSize?: number;
2121
};
2222

2323
function SerialLogTable({
24-
handlePageForward,
25-
handlePageBack,
26-
handlePageSizeChange,
27-
forwardDisabled,
28-
backDisabled,
29-
pageSize,
24+
handlePageForward = () => {},
25+
handlePageBack = () => {},
26+
handlePageSizeChange = () => {},
27+
forwardDisabled = true,
28+
backDisabled = true,
29+
pageSize = 10,
3030
}: Props): React.JSX.Element {
3131
const { id } = useParams();
3232
const serialLogs = useAtomValue(serialLogsListState);

0 commit comments

Comments
 (0)