Skip to content

Commit

Permalink
feat: mark utc timestamps MAASENG-1315
Browse files Browse the repository at this point in the history
- add branded UtcTimestamp type
  • Loading branch information
petermakowski committed Apr 3, 2024
1 parent 7deb99c commit 68528eb
Show file tree
Hide file tree
Showing 31 changed files with 178 additions and 126 deletions.
8 changes: 4 additions & 4 deletions src/app/base/components/DhcpForm/DhcpForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ describe("DhcpForm", () => {
dhcpsnippet: factory.dhcpSnippetState({
items: [
factory.dhcpSnippet({
created: "Thu, 15 Aug. 2019 06:21:39",
created: factory.timestamp("Thu, 15 Aug. 2019 06:21:39"),
id: 1,
name: "lease",
updated: "Thu, 15 Aug. 2019 06:21:39",
updated: factory.timestamp("Thu, 15 Aug. 2019 06:21:39"),
value: "lease 10",
}),
factory.dhcpSnippet({
created: "Thu, 15 Aug. 2019 06:21:39",
created: factory.timestamp("Thu, 15 Aug. 2019 06:21:39"),
id: 2,
name: "class",
updated: "Thu, 15 Aug. 2019 06:21:39",
updated: factory.timestamp("Thu, 15 Aug. 2019 06:21:39"),
}),
],
loaded: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ describe("DhcpFormFields", () => {
dhcpsnippet: factory.dhcpSnippetState({
items: [
factory.dhcpSnippet({
created: "Thu, 15 Aug. 2019 06:21:39",
created: factory.timestamp("Thu, 15 Aug. 2019 06:21:39"),
id: 1,
name: "lease",
updated: "Thu, 15 Aug. 2019 06:21:39",
updated: factory.timestamp("Thu, 15 Aug. 2019 06:21:39"),
value: "lease 10",
}),
factory.dhcpSnippet({
created: "Thu, 15 Aug. 2019 06:21:39",
created: factory.timestamp("Thu, 15 Aug. 2019 06:21:39"),
id: 2,
name: "class",
updated: "Thu, 15 Aug. 2019 06:21:39",
updated: factory.timestamp("Thu, 15 Aug. 2019 06:21:39"),
}),
],
loaded: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe("NotificationGroupNotification", () => {

it("shows the date for upgrade notifications", () => {
const notification = factory.notification({
created: "Tue, 27 Apr. 2021 00:34:39",
created: factory.timestamp("Tue, 27 Apr. 2021 00:34:39"),
ident: NotificationIdent.UPGRADE_STATUS,
});
const state = factory.rootState({
Expand Down
26 changes: 13 additions & 13 deletions src/app/base/components/StatusBar/StatusBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ it("can show if a machine is currently commissioning", () => {
it("can show if a machine has not been commissioned yet", () => {
state.machine.items = [
factory.machineDetails({
commissioning_start_time: "",
commissioning_start_time: factory.timestamp(""),
fqdn: "test.maas",
system_id: "abc123",
}),
Expand All @@ -67,7 +67,7 @@ it("can show the last time a machine was commissioned", () => {
state.machine.items = [
factory.machineDetails({
enable_hw_sync: false,
commissioning_start_time: "Thu, 31 Dec. 2020 22:59:00",
commissioning_start_time: factory.timestamp("Thu, 31 Dec. 2020 22:59:00"),
fqdn: "test.maas",
status: NodeStatus.DEPLOYED,
system_id: "abc123",
Expand All @@ -85,7 +85,7 @@ it("can handle an incorrectly formatted commissioning timestamp", () => {
state.machine.items = [
factory.machineDetails({
enable_hw_sync: false,
commissioning_start_time: "2020-03-01 09:12:43",
commissioning_start_time: factory.timestamp("2020-03-01 09:12:43"),
fqdn: "test.maas",
status: NodeStatus.DEPLOYED,
system_id: "abc123",
Expand All @@ -102,13 +102,13 @@ it("can handle an incorrectly formatted commissioning timestamp", () => {
it("displays Last and Next sync instead of Last commissioned date for deployed machines with hardware sync enabled ", () => {
state.machine.items = [
factory.machineDetails({
commissioning_start_time: "Thu, 31 Dec. 2020 22:59:00",
commissioning_start_time: factory.timestamp("Thu, 31 Dec. 2020 22:59:00"),
fqdn: "test.maas",
status: NodeStatus.DEPLOYED,
system_id: "abc123",
enable_hw_sync: true,
last_sync: "Thu, 31 Dec. 2020 22:00:00",
next_sync: "Thu, 31 Dec. 2020 23:01:00",
last_sync: factory.timestamp("Thu, 31 Dec. 2020 22:00:00"),
next_sync: factory.timestamp("Thu, 31 Dec. 2020 23:01:00"),
}),
];

Expand All @@ -131,13 +131,13 @@ it("displays Last and Next sync instead of Last commissioned date for deployed m
it("doesn't display last or next sync for deploying machines with hardware sync enabled", () => {
state.machine.items = [
factory.machineDetails({
commissioning_start_time: "Thu, 31 Dec. 2020 22:59:00",
commissioning_start_time: factory.timestamp("Thu, 31 Dec. 2020 22:59:00"),
fqdn: "test.maas",
status: NodeStatus.DEPLOYING,
system_id: "abc123",
enable_hw_sync: true,
last_sync: "Thu, 31 Dec. 2020 22:00:00",
next_sync: "Thu, 31 Dec. 2020 23:01:00",
last_sync: factory.timestamp("Thu, 31 Dec. 2020 22:00:00"),
next_sync: factory.timestamp("Thu, 31 Dec. 2020 23:01:00"),
}),
];

Expand All @@ -159,13 +159,13 @@ it("doesn't display last or next sync for deploying machines with hardware sync
it("displays correct text for machines with hardware sync enabled and no last_sync or next_sync", () => {
state.machine.items = [
factory.machineDetails({
commissioning_start_time: "Thu, 31 Dec. 2020 22:59:00",
commissioning_start_time: factory.timestamp("Thu, 31 Dec. 2020 22:59:00"),
fqdn: "test.maas",
status: NodeStatus.DEPLOYED,
system_id: "abc123",
enable_hw_sync: true,
last_sync: "",
next_sync: "",
last_sync: factory.timestamp("Thu, 31 Dec. 2020 22:00:00"),
next_sync: factory.timestamp("Thu, 31 Dec. 2020 23:01:00"),
}),
];

Expand All @@ -189,7 +189,7 @@ it("displays correct text for machines with hardware sync enabled and no last_sy

it("displays last image sync timestamp for a rack or region+rack controller", () => {
const controller = factory.controllerDetails({
last_image_sync: "Thu, 02 Jun. 2022 00:48:41",
last_image_sync: factory.timestamp("Thu, 02 Jun. 2022 00:48:41"),
node_type: NodeType.RACK_CONTROLLER,
});
state.controller.active = controller.system_id;
Expand Down
9 changes: 6 additions & 3 deletions src/app/base/components/StatusBar/StatusBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import {
isDeployedWithHardwareSync,
isMachineDetails,
} from "@/app/store/machine/utils";
import type { UtcTimestamp } from "@/app/store/types/model";
import { NodeStatus } from "@/app/store/types/node";
import { getTimeDistanceString } from "@/app/utils/time";
import { getUtcTimestamp, getTimeDistanceString } from "@/app/utils/time";

const getLastCommissionedString = (machine: MachineDetails) => {
if (machine.status === NodeStatus.COMMISSIONING) {
Expand All @@ -37,7 +38,7 @@ const getLastCommissionedString = (machine: MachineDetails) => {
}
};

const getSyncStatusString = (syncStatus: string) => {
const getSyncStatusString = (syncStatus: UtcTimestamp) => {
if (syncStatus === "") {
return "Never";
}
Expand Down Expand Up @@ -87,7 +88,9 @@ export const StatusBar = (): JSX.Element | null => {
isControllerDetails(activeController) &&
(isRack(activeController) || isRegionAndRack(activeController))
) {
status = `Last image sync: ${activeController.last_image_sync}`;
status = `Last image sync: ${getUtcTimestamp(
activeController.last_image_sync
)}`;
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe("EventLogs", () => {
state.event.items.push(
factory.eventRecord({
node_id: 1,
created: "Tue, 16 Mar. 2021 03:04:00",
created: factory.timestamp("Tue, 16 Mar. 2021 03:04:00"),
})
);
}
Expand Down Expand Up @@ -116,7 +116,7 @@ describe("EventLogs", () => {
state.event.items.push(
factory.eventRecord({
node_id: 1,
created: "Tue, 16 Mar. 2021 03:04:00",
created: factory.timestamp("Tue, 16 Mar. 2021 03:04:00"),
})
);
}
Expand Down Expand Up @@ -156,11 +156,11 @@ describe("EventLogs", () => {
it("orders the rows by most recent first", () => {
state.event.items = [
factory.eventRecord({
created: "Tue, 16 Mar. 2021 03:04:00",
created: factory.timestamp("Tue, 16 Mar. 2021 03:04:00"),
node_id: 1,
}),
factory.eventRecord({
created: "Tue, 17 Mar. 2021 03:04:00",
created: factory.timestamp("Tue, 17 Mar. 2021 03:04:00"),
node_id: 1,
}),
];
Expand Down Expand Up @@ -221,7 +221,7 @@ describe("EventLogs", () => {
state.event.items.push(
factory.eventRecord({
node_id: 1,
created: "Tue, 16 Mar. 2021 03:04:00",
created: factory.timestamp("Tue, 16 Mar. 2021 03:04:00"),
})
);
}
Expand All @@ -239,7 +239,7 @@ describe("EventLogs", () => {
state.event.items.push(
factory.eventRecord({
node_id: 1,
created: "Tue, 16 Mar. 2021 03:04:00",
created: factory.timestamp("Tue, 16 Mar. 2021 03:04:00"),
})
);
}
Expand Down Expand Up @@ -273,7 +273,7 @@ describe("EventLogs", () => {
state.event.items.push(
factory.eventRecord({
node_id: 1,
created: "Tue, 16 Mar. 2021 03:04:00",
created: factory.timestamp("Tue, 16 Mar. 2021 03:04:00"),
})
);
}
Expand All @@ -292,7 +292,7 @@ describe("EventLogs", () => {
state.event.items.push(
factory.eventRecord({
node_id: 1,
created: "Tue, 16 Mar. 2021 03:04:00",
created: factory.timestamp("Tue, 16 Mar. 2021 03:04:00"),
})
);
}
Expand All @@ -311,7 +311,7 @@ describe("EventLogs", () => {
state.event.items.push(
factory.eventRecord({
node_id: 1,
created: "Tue, 16 Mar. 2021 03:04:00",
created: factory.timestamp("Tue, 16 Mar. 2021 03:04:00"),
})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type { ScriptResult } from "@/app/store/scriptresult/types";
import { ScriptResultType } from "@/app/store/scriptresult/types";
import { canBeSuppressed } from "@/app/store/scriptresult/utils";
import { nodeIsMachine } from "@/app/store/utils";
import { getUtcTimestamp } from "@/app/utils/time";

export enum ScriptResultAction {
VIEW_METRICS = "viewMetrics",
Expand Down Expand Up @@ -131,7 +132,7 @@ const NodeTestsTable = ({ node, scriptResults }: Props): JSX.Element => {
},
{
className: "date-col",
content: result.updated,
content: getUtcTimestamp(result.updated),
},
{
className: "runtime-col",
Expand Down
18 changes: 9 additions & 9 deletions src/app/images/components/ImagesTable/ImagesTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ it("renders the correct status for a downloaded image that is not selected", ()
});

it("renders the time of last update", () => {
const lastUpdate = "Mon, 30 Jan. 2023 15:54:44";
const lastUpdate = factory.timestamp("Mon, 30 Jan. 2023 15:54:44");
const resource = factory.bootResource({
arch: "amd64",
complete: true,
Expand Down Expand Up @@ -304,7 +304,7 @@ it("disables delete action for images being downloaded", async () => {
});

it("displays a correct last deployed time and machine count", () => {
const lastDeployed = "Fri, 18 Nov. 2022 09:55:21";
const lastDeployed = factory.timestamp("Fri, 18 Nov. 2022 09:55:21");
const resources = [
factory.bootResource({
arch: "amd64",
Expand Down Expand Up @@ -358,7 +358,7 @@ it("can handle empty string for last deployed time", () => {
factory.bootResource({
arch: "amd64",
name: "ubuntu/focal",
lastDeployed: "",
lastDeployed: factory.timestamp(""),
machineCount: 768,
}),
];
Expand Down Expand Up @@ -403,20 +403,20 @@ it("can sort by last deployed time", async () => {
name: "ubuntu/xenial",
arch: "amd64",
title: "16.04 LTS",
lastDeployed: "Tue, 16 Nov. 2022 09:55:21",
lastDeployed: factory.timestamp("Tue, 16 Nov. 2022 09:55:21"),
}),
factory.bootResource({
arch: "amd64",
name: "ubuntu/focal",
title: "20.04 LTS",
lastDeployed: "Thu, 17 Nov. 2022 09:55:21",
lastDeployed: factory.timestamp("Thu, 17 Nov. 2022 09:55:21"),
machineCount: 768,
}),
factory.bootResource({
name: "ubuntu/bionic",
arch: "i386",
title: "18.04 LTS",
lastDeployed: "Wed, 18 Nov. 2022 08:55:21",
lastDeployed: factory.timestamp("Wed, 18 Nov. 2022 08:55:21"),
}),
];
const state = factory.rootState({
Expand Down Expand Up @@ -465,20 +465,20 @@ it("sorts by release by default", () => {
arch: "amd64",
name: "ubuntu/focal",
title: "20.04 LTS",
lastDeployed: "Thu, 17 Nov. 2022 09:55:21",
lastDeployed: factory.timestamp("Thu, 17 Nov. 2022 09:55:21"),
machineCount: 768,
}),
factory.bootResource({
name: "ubuntu/bionic",
arch: "i386",
title: "18.04 LTS",
lastDeployed: "Wed, 18 Nov. 2022 08:55:21",
lastDeployed: factory.timestamp("Wed, 18 Nov. 2022 08:55:21"),
}),
factory.bootResource({
name: "ubuntu/xenial",
arch: "amd64",
title: "16.04 LTS",
lastDeployed: "Tue, 16 Nov. 2022 09:55:21",
lastDeployed: factory.timestamp("Tue, 16 Nov. 2022 09:55:21"),
}),
];
const state = factory.rootState({
Expand Down
4 changes: 0 additions & 4 deletions src/app/settings/views/Dhcp/DhcpForm/DhcpForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@ describe("DhcpForm", () => {
dhcpsnippet: factory.dhcpSnippetState({
items: [
factory.dhcpSnippet({
created: "Thu, 15 Aug. 2019 06:21:39",
id: 1,
name: "lease",
updated: "Thu, 15 Aug. 2019 06:21:39",
value: "lease 10",
}),
factory.dhcpSnippet({
created: "Thu, 15 Aug. 2019 06:21:39",
id: 2,
name: "class",
updated: "Thu, 15 Aug. 2019 06:21:39",
}),
],
loaded: true,
Expand Down
7 changes: 2 additions & 5 deletions src/app/settings/views/Dhcp/DhcpList/DhcpList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useEffect, useState } from "react";

import { ContentSection } from "@canonical/maas-react-components";
import { Code, Col, Row } from "@canonical/react-components";
import { format, parse } from "date-fns";
import { useDispatch, useSelector } from "react-redux";
import type { Dispatch } from "redux";

Expand Down Expand Up @@ -34,6 +33,7 @@ import type { RootState } from "@/app/store/root/types";
import { subnetActions } from "@/app/store/subnet";
import subnetSelectors from "@/app/store/subnet/selectors";
import type { Subnet } from "@/app/store/subnet/types";
import { formatUtcTimestamp } from "@/app/utils/time";

const getTargetName = (
controllers: Controller[],
Expand Down Expand Up @@ -80,10 +80,7 @@ const generateRows = (
const expanded = expandedId === dhcpsnippet.id;
// Dates are in the format: Thu, 15 Aug. 2019 06:21:39.
const updated = dhcpsnippet.updated
? format(
parse(dhcpsnippet.updated, "E, dd LLL. yyyy HH:mm:ss", new Date()),
"yyyy-LL-dd H:mm"
)
? formatUtcTimestamp(dhcpsnippet.updated)
: "Never";
const enabled = dhcpsnippet.enabled ? "Yes" : "No";
const showDelete = expandedType === "delete";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ describe("RepositoryForm", () => {
const store = mockStore(state);
const repository = {
id: 9,
created: "Tue, 27 Aug. 2019 12:39:12",
updated: "Tue, 27 Aug. 2019 12:39:12",
created: factory.timestamp("Tue, 27 Aug. 2019 12:39:12"),
updated: factory.timestamp("Tue, 27 Aug. 2019 12:39:12"),
name: "name",
url: "http://www.website.com",
distributions: [],
Expand Down
Loading

0 comments on commit 68528eb

Please sign in to comment.