fix: displaying valid metrics and removing type assertions
This commit is contained in:
1 parent
5a8d0432ff
commit
0fc013246d
3 files changed
+42
-33
No files matched your search
@@ -3,6 +3,7 @@ import { Gauge } from "@/Components/design-elements";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { Monitor } from "@/Types/Monitor";
|
||||
import type { CheckSnapshot } from "@/Types/Check";
|
||||
import Grid from "@mui/material/Grid";
|
||||
import Box from "@mui/material/Box";
|
||||
import { LAYOUT, SPACING } from "@/Utils/Theme/constants";
|
||||
@@ -15,13 +16,6 @@ interface StatusPageMonitor extends Monitor {
|
||||
checks?: Monitor["recentChecks"];
|
||||
}
|
||||
|
||||
interface PageSpeedCheck {
|
||||
performance: number;
|
||||
accessibility: number;
|
||||
bestPractices: number;
|
||||
seo: number;
|
||||
}
|
||||
|
||||
interface MetricConfig {
|
||||
key: string;
|
||||
label: string;
|
||||
@@ -66,31 +60,29 @@ const MetricItem = ({ label, progress }: MetricConfig) => {
|
||||
);
|
||||
};
|
||||
|
||||
const buildMetrics = (
|
||||
check: PageSpeedCheck,
|
||||
t: (key: string) => string
|
||||
): MetricConfig[] => [
|
||||
{
|
||||
key: "performance",
|
||||
label: t("pages.statusPages.monitorsList.pagespeed.performance"),
|
||||
progress: check.performance,
|
||||
},
|
||||
{
|
||||
key: "accessibility",
|
||||
label: t("pages.statusPages.monitorsList.pagespeed.accessibility"),
|
||||
progress: check.accessibility,
|
||||
},
|
||||
{
|
||||
key: "bestPractices",
|
||||
label: t("pages.statusPages.monitorsList.pagespeed.bestPractices"),
|
||||
progress: check.bestPractices,
|
||||
},
|
||||
{
|
||||
key: "seo",
|
||||
label: t("pages.statusPages.monitorsList.pagespeed.seo"),
|
||||
progress: check.seo,
|
||||
},
|
||||
];
|
||||
const buildMetrics = (check: CheckSnapshot, t: (key: string) => string): MetricConfig[] =>
|
||||
[
|
||||
{
|
||||
key: "performance",
|
||||
label: t("pages.statusPages.monitorsList.pagespeed.performance"),
|
||||
progress: check.performance,
|
||||
},
|
||||
{
|
||||
key: "accessibility",
|
||||
label: t("pages.statusPages.monitorsList.pagespeed.accessibility"),
|
||||
progress: check.accessibility,
|
||||
},
|
||||
{
|
||||
key: "bestPractices",
|
||||
label: t("pages.statusPages.monitorsList.pagespeed.bestPractices"),
|
||||
progress: check.bestPractices,
|
||||
},
|
||||
{
|
||||
key: "seo",
|
||||
label: t("pages.statusPages.monitorsList.pagespeed.seo"),
|
||||
progress: check.seo,
|
||||
},
|
||||
].filter((m): m is MetricConfig => m.progress !== undefined);
|
||||
|
||||
export const PageSpeedMetrics = ({ monitor }: { monitor: StatusPageMonitor }) => {
|
||||
const theme = useTheme();
|
||||
@@ -109,7 +101,7 @@ export const PageSpeedMetrics = ({ monitor }: { monitor: StatusPageMonitor }) =>
|
||||
);
|
||||
}
|
||||
|
||||
const metrics = buildMetrics(latestCheck as PageSpeedCheck, t);
|
||||
const metrics = buildMetrics(latestCheck, t);
|
||||
|
||||
return (
|
||||
<Grid
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import type { Pool } from "pg";
|
||||
|
||||
export const addShowPageSpeedToStatusPages = async (pool: Pool) => {
|
||||
await pool.query(`
|
||||
ALTER TABLE status_pages
|
||||
ADD COLUMN IF NOT EXISTS show_page_speed BOOLEAN DEFAULT FALSE;
|
||||
`);
|
||||
};
|
||||
|
||||
export const dropShowPageSpeedFromStatusPages = async (pool: Pool) => {
|
||||
await pool.query(`
|
||||
ALTER TABLE status_pages
|
||||
DROP COLUMN IF EXISTS show_page_speed;
|
||||
`);
|
||||
};
|
||||
@@ -21,6 +21,7 @@ import { createStatusPages, dropStatusPages } from "./0018_create_status_pages.j
|
||||
import { createAppSettings, dropAppSettings } from "./0019_create_app_settings.js";
|
||||
import { createContinuousAggregates, dropContinuousAggregates } from "./0020_create_continuous_aggregates.js";
|
||||
import { createRetentionCompression, dropRetentionCompression } from "./0021_create_retention_compression.js";
|
||||
import { addShowPageSpeedToStatusPages, dropShowPageSpeedFromStatusPages } from "./0022_add_show_page_speed_to_status_pages.js";
|
||||
|
||||
const SERVICE_NAME = "TimescaleDB Migrations";
|
||||
|
||||
@@ -52,6 +53,7 @@ const migrations: MigrationEntry[] = [
|
||||
{ name: "0019_create_app_settings", up: createAppSettings, down: dropAppSettings },
|
||||
{ name: "0020_create_continuous_aggregates", up: createContinuousAggregates, down: dropContinuousAggregates },
|
||||
{ name: "0021_create_retention_compression", up: createRetentionCompression, down: dropRetentionCompression },
|
||||
{ name: "0022_add_show_page_speed_to_status_pages", up: addShowPageSpeedToStatusPages, down: dropShowPageSpeedFromStatusPages },
|
||||
];
|
||||
|
||||
const ensureMigrationsTable = async (pool: Pool) => {
|
||||
|
||||
Reference in new issue
Block a user