initial commit

This commit is contained in:
Alex Holliday committed 2025-11-13 13:47:26 -08:00
1 parent 7cb985116e
commit 75acf7b38f
955 files changed
+37333 -87054

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
import axios from "axios";
import type { AxiosError } from "axios";
import type { AxiosRequestConfig, AxiosResponse } from "axios";
const BASE_URL = import.meta.env.VITE_APP_API_BASE_URL;
const api = axios.create({
baseURL: BASE_URL || "http://localhost:55555/api/v2",
withCredentials: true,
});
const onSuccess = (response: AxiosResponse) => response;
const onError = (error: AxiosError) => {
if (error.response?.status === 401) {
window.location.href = "/login";
}
return Promise.reject(error);
};
api.interceptors.response.use(onSuccess, onError);
export const get = <T>(
url: string,
config: AxiosRequestConfig = {}
): Promise<AxiosResponse<T>> => api.get<T>(url, config);
export const post = <T>(
url: string,
data: any,
config: AxiosRequestConfig = {}
): Promise<AxiosResponse<T>> => api.post<T>(url, data, config);
export const patch = <T>(
url: string,
data: any,
config: AxiosRequestConfig = {}
): Promise<AxiosResponse<T>> => api.patch<T>(url, data, config);
export const deleteOp = <T>(
url: string,
config: AxiosRequestConfig = {}
): Promise<AxiosResponse<T>> => api.delete<T>(url, config);
export default api;
+41
View File
@@ -0,0 +1,41 @@
const MIN_OUT = 10;
const MAX_OUT = 100;
export const normalizeResponseTimes = <
T extends Record<K, number>,
K extends keyof T
>(
checks: T[],
key: K
): (T & { normalResponseTime: number })[] => {
if (!Array.isArray(checks) || checks.length === 0)
return checks as (T & {
normalResponseTime: number;
})[];
if (checks.length === 1) {
return [
{
...checks[0],
normalResponseTime: 50,
},
];
}
const { min, max } = checks.reduce(
(acc, check) => {
if (check[key] > acc.max) acc.max = check[key];
if (check[key] < acc.min) acc.min = check[key];
return acc;
},
{ max: -Infinity, min: Infinity }
);
const range = max - min || 1;
return checks.map((check) => ({
...check,
normalResponseTime:
MIN_OUT + ((check[key] - min) * (MAX_OUT - MIN_OUT)) / range,
}));
};
+88
View File
@@ -0,0 +1,88 @@
import type { MonitorStatus } from "@/types/monitor";
import type { IMonitor } from "@/types/monitor";
import type { PaletteKey } from "@/theme/theme";
import type { ValueType } from "@/components/design-elements/StatusLabel";
export const getStatusPalette = (status: MonitorStatus): PaletteKey => {
const paletteMap: Record<MonitorStatus, PaletteKey> = {
up: "success",
down: "error",
initializing: "warning",
};
return paletteMap[status];
};
export const getValuePalette = (value: ValueType): PaletteKey => {
const paletteMap: Record<ValueType, PaletteKey> = {
positive: "success",
negative: "error",
neutral: "warning",
};
return paletteMap[value];
};
export const getStatusColor = (status: MonitorStatus, theme: any): string => {
const statusColors: Record<MonitorStatus, string> = {
up: theme.palette.success.lowContrast,
down: theme.palette.error.lowContrast,
initializing: theme.palette.warning.lowContrast,
};
return statusColors[status];
};
export const getResponseTimeColor = (responseTime: number): PaletteKey => {
if (responseTime < 200) {
return "success";
} else if (responseTime < 300) {
return "warning";
} else {
return "error";
}
};
export const getInfraGaugeColor = (val: number, theme: any) => {
if (val < 50) {
return theme.palette.success.main;
} else if (val < 80) {
return theme.palette.warning.lowContrast;
} else {
return theme.palette.error.lowContrast;
}
};
export const getPageSpeedPalette = (score: number): PaletteKey => {
if (score >= 90) return "success";
else if (score >= 50) return "warning";
else return "error";
};
export const formatUrl = (url: string, maxLength: number = 55) => {
if (!url) return "";
const strippedUrl = url.replace(/^https?:\/\//, "");
return strippedUrl.length > maxLength
? `${strippedUrl.slice(0, maxLength)}…`
: strippedUrl;
};
export interface IStatusPageHeaderConfig {
paletteKey: PaletteKey;
message: string;
}
export const getStatusPageHeaderConfig = (
monitors: IMonitor[]
): IStatusPageHeaderConfig => {
if (!monitors || monitors.length === 0) {
return { paletteKey: "error", message: "No monitors available" };
}
const allUp = monitors.every((monitor) => monitor.status === "up");
const anyDown = monitors.some((monitor) => monitor.status === "down");
const allDown = monitors.every((monitor) => monitor.status === "down");
if (allUp)
return { paletteKey: "success", message: "All systems operational" };
if (allDown) return { paletteKey: "error", message: "All systems down" };
if (anyDown)
return { paletteKey: "warning", message: "Partial system outage" };
return { paletteKey: "warning", message: "Partial system outage" };
};
+56
View File
@@ -0,0 +1,56 @@
import dayjs from "dayjs";
import duration from "dayjs/plugin/duration";
import utc from "dayjs/plugin/utc";
import timezone from "dayjs/plugin/timezone";
import customParseFormat from "dayjs/plugin/customParseFormat";
dayjs.extend(utc);
dayjs.extend(timezone);
dayjs.extend(customParseFormat);
dayjs.extend(duration);
export const MS_PER_SECOND = 1000;
export const MS_PER_MINUTE = 60 * MS_PER_SECOND;
export const MS_PER_HOUR = 60 * MS_PER_MINUTE;
export const MS_PER_DAY = 24 * MS_PER_HOUR;
export const MS_PER_WEEK = MS_PER_DAY * 7;
export const formatDateWithTz = (
timestamp: string,
format: string,
timezone: string
) => {
if (!timestamp) {
return "Unknown time";
}
const formattedDate = dayjs(timestamp).tz(timezone).format(format);
return formattedDate;
};
export const tickDateFormatLookup = (range: string) => {
const tickFormatLookup: Record<string, string> = {
"2h": "h:mm A",
"24h": "h:mm A",
"7d": "MM/D, h:mm A",
"30d": "ddd. M/D",
};
const format = tickFormatLookup[range];
if (format === undefined) {
return "";
}
return format;
};
export const tooltipDateFormatLookup = (range: string) => {
const dateFormatLookup: Record<string, string> = {
"2h": "ddd. MMMM D, YYYY, hh:mm A",
"24h": "ddd. MMMM D, YYYY, hh:mm A",
"7d": "ddd. MMMM D, YYYY, hh:mm A",
"30d": "ddd. MMMM D, YYYY",
};
const format = dateFormatLookup[range];
if (format === undefined) {
return "";
}
return format;
};
+42
View File
@@ -0,0 +1,42 @@
import i18n from "i18next";
import { initReactI18next } from "react-i18next";
type TranslationModule = {
default?: Record<string, any>;
[key: string]: any;
};
const primaryLanguage = "en";
// Load all translation files eagerly
const translations = import.meta.glob<TranslationModule>("../locales/*.json", {
eager: true,
});
const resources: Record<string, any> = {};
Object.keys(translations).forEach((path) => {
const match = path.match(/\/([^/]+)\.json$/);
if (!match) {
console.warn(`Skipping invalid translation file path: ${path}`);
return;
}
const langCode = match[1];
resources[langCode] = {
translation: translations[path].default || translations[path],
};
});
i18n.use(initReactI18next).init({
resources,
lng: primaryLanguage,
fallbackLng: primaryLanguage,
debug: import.meta.env.MODE === "development",
ns: ["translation"],
defaultNS: "translation",
interpolation: {
escapeValue: false,
},
returnEmptyString: false,
});
export default i18n;
File diff suppressed because it is too large. Load diff