Skip to content
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
11 changes: 0 additions & 11 deletions web/actions/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@ import { services } from "@/db/schema";
import { requireDeveloperRole } from "@/lib/auth";
import { inngest } from "@/lib/inngest/client";
import { inngestEvents } from "@/lib/inngest/events";
import { startMigrationInternal } from "@/lib/migrations";

export async function startMigration(
serviceId: string,
targetServerId: string,
) {
await requireDeveloperRole();
await startMigrationInternal(serviceId, targetServerId);
revalidatePath(`/dashboard/projects`);
return { success: true };
}

export async function cancelMigration(serviceId: string) {
await requireDeveloperRole();
Expand Down
6 changes: 1 addition & 5 deletions web/components/auth/device-authorization-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { authClient } from "@/lib/auth-client";

function normalizeUserCode(value: string) {
return value.trim().replace(/-/g, "").toUpperCase();
}

export function DeviceAuthorizationPage() {
const router = useRouter();
const searchParams = useSearchParams();
Expand All @@ -36,7 +32,7 @@ export function DeviceAuthorizationPage() {

const verifyCode = useCallback(
async (code: string) => {
const formatted = normalizeUserCode(code);
const formatted = code.trim().replace(/-/g, "").toUpperCase();
if (!formatted) {
setError("Enter the device code to continue");
return;
Expand Down
8 changes: 2 additions & 6 deletions web/components/github/github-repo-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ const fetcher = (url: string) => fetch(url).then((res) => res.json());

const EMPTY_REPOS: GitHubRepo[] = [];

function getValidGitHubRepoName(url: string) {
const match = url.match(/^https:\/\/github\.com\/([^/]+\/[^/]+)\/?$/);
return match ? match[1] : null;
}

export function GitHubRepoSelector({
value,
onChange,
Expand Down Expand Up @@ -61,7 +56,8 @@ export function GitHubRepoSelector({
}, [repos, search]);

const publicRepoFromSearch = useMemo(() => {
const repoName = getValidGitHubRepoName(search);
const match = search.match(/^https:\/\/github\.com\/([^/]+\/[^/]+)\/?$/);
const repoName = match ? match[1] : null;
if (!repoName) return null;
const alreadyInList = repos.some(
(r) => r.fullName.toLowerCase() === repoName.toLowerCase(),
Expand Down
30 changes: 13 additions & 17 deletions web/components/metrics/metrics-history-charts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ const CHARTS: ChartConfig[] = [
},
];

const CHART_THRESHOLDS = [
{ value: 70, color: "#f59e0b" },
{ value: 90, color: "#f43f5e" },
];

const SERVER_COLORS = [
"#10b981",
"#0ea5e9",
Expand Down Expand Up @@ -284,7 +289,7 @@ function MetricChartCard({
iconType="plainline"
wrapperStyle={{ paddingBottom: 12 }}
/>
{thresholdsForChart().map((threshold) => (
{CHART_THRESHOLDS.map((threshold) => (
<ReferenceLine
key={threshold.value}
y={threshold.value}
Expand Down Expand Up @@ -440,18 +445,16 @@ function buildChartRows(series: ServerMetricsHistory[]): ChartRow[] {
(a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime(),
);
}

function thresholdsForChart() {
return [
{ value: 70, color: "#f59e0b" },
{ value: 90, color: "#f43f5e" },
];
}

function formatTooltipValue(item: TooltipPayload) {
const value = Number(item.value);
if (!Number.isFinite(value)) return "-";
if (isBytesSeries(String(item.dataKey))) return formatBytes(value);
const dataKey = String(item.dataKey);
if (
dataKey.startsWith("memoryUsedBytes:") ||
dataKey.startsWith("diskUsedBytes:")
) {
return formatBytes(value);
}
return `${value.toFixed(1)}%`;
}

Expand All @@ -463,13 +466,6 @@ function getServerColor(index: number) {
return SERVER_COLORS[index % SERVER_COLORS.length];
}

function isBytesSeries(dataKey: string) {
return (
dataKey.startsWith("memoryUsedBytes:") ||
dataKey.startsWith("diskUsedBytes:")
);
}

function formatShortTime(value: string) {
return new Intl.DateTimeFormat(undefined, {
month: "short",
Expand Down
59 changes: 19 additions & 40 deletions web/components/service/details/service-details-overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ function ServiceMetricsPanel({
() => buildServiceMetricSummaryItems(chartMode, stats, chartRows, hasMetricData),
[chartMode, stats, chartRows, hasMetricData],
);
const todayLabel = new Intl.DateTimeFormat(undefined, {
day: "numeric",
month: "short",
}).format(new Date());

return (
<div className="flex h-full min-h-72 flex-col gap-4 p-4">
Expand All @@ -247,7 +251,7 @@ function ServiceMetricsPanel({
)}
</div>
<div className="flex flex-col items-end gap-2">
<p className="text-sm text-muted-foreground">{formatToday()}</p>
<p className="text-sm text-muted-foreground">{todayLabel}</p>
<ServiceChartModeToggle
value={chartMode}
onChange={setChartMode}
Expand Down Expand Up @@ -819,7 +823,10 @@ function getSourceInfo(service: Service): SourceInfo {
if (service.sourceType === "github" && service.githubRepoUrl) {
return {
icon: Github,
label: formatGithubRepo(service.githubRepoUrl),
label: service.githubRepoUrl
.replace(/^https:\/\/github\.com\//, "")
.replace(/^git@github\.com:/, "")
.replace(/\.git$/, ""),
detail: "GitHub",
href: service.githubRepoUrl,
branch: service.githubBranch || "main",
Expand Down Expand Up @@ -877,12 +884,8 @@ function buildStatusSeries(stats?: ServiceMetricsResponse): StatusSeries[] {
}

function getStatusDataKey(status: string): string {
return `${getStatusDataKeyBase(status)}_total`;
}

function getStatusDataKeyBase(status: string): string {
const normalized = status.replace(/[^a-zA-Z0-9]/g, "_");
return `status_${normalized || "unknown"}`;
return `status_${normalized || "unknown"}_total`;
}

function getStatusColor(status: string, index: number): string {
Expand All @@ -895,13 +898,6 @@ function getStatusColor(status: string, index: number): string {
return palette[index % palette.length];
}

function formatGithubRepo(repoUrl: string): string {
return repoUrl
.replace(/^https:\/\/github\.com\//, "")
.replace(/^git@github\.com:/, "")
.replace(/\.git$/, "");
}

function formatResources(service: Service): string {
const cpu = service.resourceCpuLimit;
const memoryMb = service.resourceMemoryLimitMb;
Expand All @@ -917,15 +913,11 @@ function formatResources(service: Service): string {
return `${cpuLabel} · ${memoryLabel}`;
}

function getConfiguredReplicaCount(overview: OverviewData): number {
return overview.serverSummaries.reduce(
function formatInstanceSummary(overview: OverviewData): string {
const configured = overview.serverSummaries.reduce(
(total, server) => total + server.configured,
0,
);
}

function formatInstanceSummary(overview: OverviewData): string {
const configured = getConfiguredReplicaCount(overview);
const serverCount = overview.serverSummaries.length;

if (configured === 0) {
Expand Down Expand Up @@ -953,18 +945,16 @@ function getPrimaryEndpoint(endpoints: EndpointItem[]): EndpointItem {

function formatPortSummary(ports: Service["ports"]): string {
if (ports.length === 0) return "No Ports";
if (ports.length === 1) return formatPortLabel(ports[0]);
if (ports.length === 1) {
const port = ports[0];
const protocol = (port.protocol || "http").toUpperCase();
const external = port.externalPort ? ` -> :${port.externalPort}` : "";
return `${protocol} :${port.port}${external}`;
}

return formatCount(ports.length, "port");
}

function formatPortLabel(port: Service["ports"][number]): string {
const protocol = (port.protocol || "http").toUpperCase();
const external = port.externalPort ? ` -> :${port.externalPort}` : "";

return `${protocol} :${port.port}${external}`;
}

function formatCount(count: number, singular: string): string {
const label = singular
.split(" ")
Expand Down Expand Up @@ -1227,7 +1217,7 @@ function formatAxisTick(value: number, mode: ServiceChartMode): string {
if (mode === "latency") return formatDurationMs(value);
if (mode === "traffic") return formatBytes(value);
if (mode === "resources") return `${formatRateTick(value)}%`;
return formatRequestTick(value);
return formatCompactNumber(value);
}

function formatRateTick(value: number): string {
Expand All @@ -1243,10 +1233,6 @@ function getYAxisMargin(mode: ServiceChartMode): number {
return -20;
}

function formatRequestTick(value: number): string {
return formatCompactNumber(value);
}

function formatRequestCount(value: number): string {
if (!Number.isFinite(value)) return "-";

Expand Down Expand Up @@ -1293,10 +1279,3 @@ function formatTooltipDate(value: string): string {
minute: "2-digit",
}).format(new Date(value));
}

function formatToday(): string {
return new Intl.DateTimeFormat(undefined, {
day: "numeric",
month: "short",
}).format(new Date());
}
Loading
Loading