Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: mark UTC timestamps MAASENG-1315 #5384

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions cypress/e2e/with-users/subnets/add.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,27 @@ context("Subnets - Add", () => {
});

it("can add and delete a new subnet", () => {
const fabricName = `cy-fabric-${generateId()}`;
const fabric = `cy-fabric-${generateId()}`;
const spaceName = `cy-space-${generateId()}`;
const vid = generateVid();
const vlanName = `cy-vlan-${vid}`;
const vlan = `cy-vlan-${vid}`;
const cidr = "192.168.122.18";
const subnetName = `cy-subnet-${generateId()}`;

completeForm("Fabric", fabricName);
completeForm("Fabric", fabric);
completeForm("Space", spaceName);
completeAddVlanForm(vid, vlanName, fabricName, spaceName);
cy.addSubnet(subnetName, cidr, fabricName, vid, vlanName);
completeAddVlanForm(vid, vlan, fabric, spaceName);
cy.addSubnet({ subnetName, cidr, fabric, vid, vlan });

cy.findAllByRole("link", { name: fabricName }).should("have.length", 2);
cy.findAllByRole("link", { name: fabric }).should("have.length", 2);

// Check it groups items added to the same fabric correctly
cy.findAllByRole("row", { name: fabricName })
cy.findAllByRole("row", { name: fabric })
.eq(1)
.within(() => {
cy.findAllByRole("gridcell")
.eq(1)
.should("have.text", `${vid} (${vlanName})`);
.should("have.text", `${vid} (${vlan})`);
cy.findAllByRole("gridcell").eq(3).should("contain.text", subnetName);
cy.findAllByRole("gridcell").eq(5).should("have.text", spaceName);
});
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"cypress-open": "yarn cypress open",
"cypress-run-a11y": "yarn cypress run --config specPattern=cypress/e2e/accessibility/**/*.ts",
"cypress-run": "yarn cypress run",
"lint": "npmPkgJsonLint . && eslint src cypress && tsc --project tsconfig.json",
"lint": "npmPkgJsonLint . && eslint src cypress && tsc --project tsconfig.json --noEmit && tsc --project cypress/tsconfig.json --noEmit",
"link-components": "yarn link \"@canonical/react-components\" && yarn link \"react\" && yarn install",
"percy": "./cypress/percy.sh",
"release": "yarn clean && yarn install && CI=true yarn test && yarn build && yarn version --new-version",
Expand Down Expand Up @@ -52,6 +52,7 @@
"classnames": "2.5.1",
"clone-deep": "4.0.1",
"date-fns": "2.30.0",
"date-fns-tz": "2.0.1",
"fast-deep-equal": "3.1.3",
"formik": "2.4.5",
"history": "5.3.0",
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
isUpgradeNotification,
} from "@/app/store/notification/utils";
import type { RootState } from "@/app/store/root/types";
import { formatUtcDatetime } from "@/app/utils/time";

type Props = {
className?: string | null;
Expand All @@ -31,6 +32,7 @@ const NotificationGroupNotification = ({
const notification = useSelector((state: RootState) =>
notificationSelectors.getById(state, id)
);
const createdTimestamp = formatUtcDatetime(notification?.created);
if (!notification) {
return null;
}
Expand Down Expand Up @@ -59,7 +61,7 @@ const NotificationGroupNotification = ({
: undefined
}
severity={severity}
timestamp={showDate ? notification.created : null}
timestamp={showDate ? createdTimestamp : null}
>
<span
dangerouslySetInnerHTML={{ __html: notification.message }}
Expand Down
28 changes: 14 additions & 14 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(""),
next_sync: factory.timestamp(""),
}),
];

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 All @@ -198,7 +198,7 @@ it("displays last image sync timestamp for a rack or region+rack controller", ()
renderWithMockStore(<StatusBar />, { state });

expect(screen.getByTestId("status-bar-status")).toHaveTextContent(
`Last image sync: ${controller.last_image_sync}`
`Last image sync: Thu, 02 Jun. 2022 00:48:41 (UTC)`
);
});

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 { UtcDatetime } from "@/app/store/types/model";
import { NodeStatus } from "@/app/store/types/node";
import { getTimeDistanceString } from "@/app/utils/time";
import { formatUtcDatetime, 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: UtcDatetime) => {
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: ${formatUtcDatetime(
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 { formatUtcDatetime } 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: formatUtcDatetime(result.updated),
},
{
className: "runtime-col",
Expand Down
Loading
Loading