Skip to content

Commit 2300c7b

Browse files
committed
Make page for serial log
1 parent 587da5e commit 2300c7b

4 files changed

Lines changed: 77 additions & 3 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ function ModelDetailsPageLayout() {
88
pathname.endsWith("policies") || pathname.endsWith("policies/create");
99
const isRemodel =
1010
pathname.endsWith("remodel") || pathname.endsWith("remodel/configure");
11-
const isSerialLog = pathname.endsWith("serial-log");
11+
const isSerialLog =
12+
pathname.endsWith("serial-log") || pathname.includes("/serial-log/");
1213

1314
const getSectionName = () => {
1415
if (isPolicies) {
Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,76 @@
1+
import { useAtomValue } from "jotai";
2+
import { useParams } from "react-router-dom";
3+
import { format } from "date-fns";
4+
import { Row, Col, Icon } from "@canonical/react-components";
5+
6+
import { useSerialLog } from "../../hooks";
7+
import { brandIdState, brandStoreState } from "../../state/brandStoreState";
8+
import { setPageTitle } from "../../utils";
9+
10+
import type { UseQueryResult } from "react-query";
11+
import type { SerialLog as SerialLogType } from "../../types/shared";
12+
113
function SerialLog() {
2-
return <h1>Hi</h1>;
14+
const { id, modelId, serial } = useParams();
15+
const brandId = useAtomValue(brandIdState);
16+
const { isLoading, isError, data }: UseQueryResult<SerialLogType[], Error> =
17+
useSerialLog(brandId, modelId, serial);
18+
const brandStore = useAtomValue(brandStoreState(id));
19+
20+
brandStore
21+
? setPageTitle(`Serial logs for ${modelId} in ${brandStore.name}`)
22+
: setPageTitle("Serial logs");
23+
24+
return (
25+
<>
26+
<h1>{serial}</h1>
27+
{isLoading && (
28+
<p>
29+
<Icon name="spinner" className="u-animation--spin" />
30+
&nbsp;Fetching serial logs...
31+
</p>
32+
)}
33+
{!isLoading && !isError && data && (
34+
<>
35+
<Row>
36+
<Col size={4}>
37+
<p>Serial:</p>
38+
</Col>
39+
<Col size={8}>
40+
<p>{data[0].serial}</p>
41+
</Col>
42+
</Row>
43+
<Row>
44+
<Col size={4}>
45+
<p>Created at:</p>
46+
</Col>
47+
<Col size={8}>
48+
<p>
49+
{format(
50+
new Date(data[0]["created-at"]),
51+
"dd/MM/yyyy 'at' HH:mm",
52+
)}
53+
</p>
54+
</Col>
55+
</Row>
56+
<Row>
57+
<Col size={4}>
58+
<p>serial-sign-key-sha3-384:</p>
59+
</Col>
60+
<Col size={8}>
61+
<p>{data[0]["serial-sign-key-sha3-384"]}</p>
62+
</Col>
63+
</Row>
64+
<Row>
65+
<Col size={4}>
66+
<p>Serial assertion:</p>
67+
</Col>
68+
</Row>
69+
<pre>{data[0]["serial-assertion"]}</pre>
70+
</>
71+
)}
72+
</>
73+
);
374
}
475

576
export default SerialLog;

static/js/publisher/pages/SerialLogs/SerialLogs.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useEffect } from "react";
12
import { useAtomValue, useSetAtom } from "jotai";
23
import { useParams, useSearchParams } from "react-router-dom";
34
import { Notification, Icon, Row, Col } from "@canonical/react-components";
@@ -15,7 +16,6 @@ import SerialLogsTable from "./SerialLogsTable";
1516

1617
import type { UseQueryResult } from "react-query";
1718
import type { SerialLog } from "../../types/shared";
18-
import { useEffect } from "react";
1919

2020
function SerialLogs() {
2121
const { id, modelId } = useParams();

static/js/publisher/types/shared.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,6 @@ export type SerialLog = {
194194
"created-at": string;
195195
"model-name": string;
196196
serial: string;
197+
"serial-assertion"?: string;
198+
"serial-sign-key-sha3-384"?: string;
197199
};

0 commit comments

Comments
 (0)