Peter Makowski has proposed merging ~petermakowski/maas-site-manager:add-total_machines-key into maas-site-manager:main.
Commit message: add total_machines key Requested reviews: MAAS Committers (maas-committers) For more details, see: https://code.launchpad.net/~petermakowski/maas-site-manager/+git/site-manager/+merge/442742 -- Your team MAAS Committers is requested to review the proposed merge of ~petermakowski/maas-site-manager:add-total_machines-key into maas-site-manager:main.
diff --git a/frontend/src/api/types.ts b/frontend/src/api/types.ts index 248c6ac..1c6dd36 100644 --- a/frontend/src/api/types.ts +++ b/frontend/src/api/types.ts @@ -8,6 +8,7 @@ export type Stats = { deployed_machines: number; ready_machines: number; error_machines: number; + total_machines: number; last_seen: string; // <ISO 8601 date string> connection: "stable" | "lost" | "unknown"; }; diff --git a/frontend/src/components/SitesList/SitesTable/AggregatedStatus/AggregatedStatus.tsx b/frontend/src/components/SitesList/SitesTable/AggregatedStatus/AggregatedStatus.tsx index 6cc474b..dd9eb15 100644 --- a/frontend/src/components/SitesList/SitesTable/AggregatedStatus/AggregatedStatus.tsx +++ b/frontend/src/components/SitesList/SitesTable/AggregatedStatus/AggregatedStatus.tsx @@ -1,10 +1,9 @@ import type { Stats } from "@/api/types"; import Meter, { color } from "@/components/Meter"; import Popover from "@/components/Popover/Popover"; -import { getAllMachines } from "@/utils"; const AggregatedStatus = ({ stats }: { stats: Stats }) => { - const { deployed_machines, allocated_machines, ready_machines, error_machines } = stats; + const { deployed_machines, allocated_machines, ready_machines, error_machines, total_machines } = stats; return ( <> <div> @@ -51,7 +50,7 @@ const AggregatedStatus = ({ stats }: { stats: Stats }) => { { color: color.link, value: allocated_machines }, { color: color.linkFaded, value: ready_machines }, ]} - label={`${deployed_machines} of ${getAllMachines(stats)} deployed`} + label={`${deployed_machines} of ${total_machines} deployed`} labelClassName="u-text--muted" small /> diff --git a/frontend/src/components/SitesList/SitesTable/SitesTable.tsx b/frontend/src/components/SitesList/SitesTable/SitesTable.tsx index f368905..6045ccf 100644 --- a/frontend/src/components/SitesList/SitesTable/SitesTable.tsx +++ b/frontend/src/components/SitesList/SitesTable/SitesTable.tsx @@ -21,7 +21,7 @@ import TooltipButton from "@/components/base/TooltipButton/TooltipButton"; import { isDev } from "@/constants"; import { useAppContext } from "@/context"; import type { UseSitesQueryResult } from "@/hooks/react-query"; -import { getAllMachines, getCountryName, getTimezoneUTCString, getTimeInTimezone } from "@/utils"; +import { getCountryName, getTimezoneUTCString, getTimeInTimezone } from "@/utils"; const createAccessor = <T, K extends keyof T>(keys: K[] | K) => @@ -173,7 +173,7 @@ const SitesTable = ({ ), cell: ({ getValue }) => { const { stats } = getValue(); - return stats ? getAllMachines(stats) : null; + return stats ? stats.total_machines : null; }, }, { diff --git a/frontend/src/mocks/factories.ts b/frontend/src/mocks/factories.ts index 741be81..c23383e 100644 --- a/frontend/src/mocks/factories.ts +++ b/frontend/src/mocks/factories.ts @@ -10,11 +10,15 @@ export const connections: Stats["connection"][] = ["stable", "lost", "unknown"]; export const statsFactory = Factory.define<Stats>(({ sequence }) => { const chance = new Chance(`maas-${sequence}`); const now = new Date(); - return { + const machines = { deployed_machines: chance.integer({ min: 0, max: 500 }), allocated_machines: chance.integer({ min: 0, max: 500 }), ready_machines: chance.integer({ min: 0, max: 500 }), error_machines: chance.integer({ min: 0, max: 500 }), + }; + return { + ...machines, + total_machines: Object.values(machines).reduce((acc, val) => acc + val, 0), last_seen: new Date(chance.date({ min: sub(now, { minutes: 15 }), max: now })).toISOString(), connection: connectionFactory.build(), }; diff --git a/frontend/src/utils.ts b/frontend/src/utils.ts index 5e3be93..dc47165 100644 --- a/frontend/src/utils.ts +++ b/frontend/src/utils.ts @@ -74,8 +74,3 @@ export const copyToClipboard = (text: string, callback?: (text: string) => void) Sentry.captureException(new Error("copy to clipboard failed", { cause: error })); }); }; - -export const getAllMachines = (stats: Stats) => { - if (!stats) return null; - return stats.deployed_machines + stats.allocated_machines + stats.ready_machines + stats.error_machines; -};
-- Mailing list: https://launchpad.net/~sts-sponsors Post to : sts-sponsors@lists.launchpad.net Unsubscribe : https://launchpad.net/~sts-sponsors More help : https://help.launchpad.net/ListHelp