rename frontend-v2 to frontend

This commit is contained in:
mbecker20
2024-01-06 15:16:24 -08:00
parent d46741c5ae
commit 57ed905140
278 changed files with 1208 additions and 11739 deletions

75
frontend/src/lib/utils.ts Normal file
View File

@@ -0,0 +1,75 @@
import { Types } from "@monitor/client";
import { UsableResource } from "@types";
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
export const keys = <T extends object>(o: T): (keyof T)[] =>
Object.keys(o) as (keyof T)[];
export const RESOURCE_TARGETS: UsableResource[] = [
"Alerter",
"Build",
"Builder",
"Deployment",
"Repo",
"Server",
];
export const fmt_update_date = (d: Date) =>
`${d.getDate()}/${d.getMonth() + 1} @ ${d.getHours()}:${d.getMinutes()}`;
export const fmt_verison = (version: Types.Version | undefined) => {
if (!version) return "...";
const { major, minor, patch } = version;
if (major === 0 && minor === 0 && patch === 0) return "latest";
return `v${major}.${minor}.${patch}`;
};
export const fmt_duration = (start_ts: number, end_ts: number) => {
const start = new Date(start_ts);
const end = new Date(end_ts);
const durr = end.getTime() - start.getTime();
const seconds = durr / 1000;
const minutes = Math.floor(seconds / 60);
const remaining_seconds = seconds % 60;
return `${
minutes > 0 ? `${minutes} minute${minutes > 1 ? "s" : ""} ` : ""
}${remaining_seconds.toFixed(minutes > 0 ? 0 : 1)} seconds`;
};
export function env_to_text(envVars: Types.EnvironmentVar[] | undefined) {
return envVars?.reduce(
(prev, { variable, value }) =>
prev + (prev ? "\n" : "") + `${variable}=${value}`,
""
);
}
function keep_line(line: string) {
if (line.length === 0) return false;
let firstIndex = -1;
for (let i = 0; i < line.length; i++) {
if (line[i] !== " ") {
firstIndex = i;
break;
}
}
if (firstIndex === -1) return false;
if (line[firstIndex] === "#") return false;
return true;
}
export function text_to_env(env: string): Types.EnvironmentVar[] {
return env
.split("\n")
.filter((line) => keep_line(line))
.map((entry) => {
const [first, ...rest] = entry.replaceAll('"', "").split("=");
return [first, rest.join("=")];
})
.map(([variable, value]) => ({ variable, value }));
}