Enhance dashboard to display data for all Active Directory objects and dynamically generate available fields.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 705f2157-ef97-4fbd-89e4-8c7f2ecaea90
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7ed01c5f-a82d-405a-b728-b2e3d127c60c/3caa578d-3a2c-45ec-a6c0-75313ad18bfb.jpg
This commit is contained in:
alphaeusmote
2025-04-10 00:32:56 +00:00
parent d0748723c3
commit 9d39faf2cf
5 changed files with 874 additions and 58 deletions
+95
View File
@@ -0,0 +1,95 @@
import { DashboardConfig } from "@/components/dashboard/dashboard-layout";
// Interface for snapshot branding options
export interface SnapshotBranding {
logoUrl: string;
companyName: string;
title: string;
description: string;
primaryColor: string;
secondaryColor: string;
showDate: boolean;
showFooter: boolean;
footerText: string;
expiresInDays: number;
}
// Interface for snapshot data
export interface SnapshotData {
dashboard: DashboardConfig;
dataSources: Array<{
id: string;
name: string;
data: any[];
fields: Array<{ name: string; type: string }>;
}>;
branding: SnapshotBranding;
createdAt: string;
expiresAt: string | null;
}
/**
* Generate a snapshot of the dashboard data for sharing
*/
export function generateSnapshot({
dashboard,
dataSources,
branding,
}: {
dashboard: DashboardConfig;
dataSources: Array<{
id: string;
name: string;
data: any[];
fields: Array<{ name: string; type: string }>;
}>;
branding: SnapshotBranding;
}): SnapshotData {
const createdAt = new Date().toISOString();
// Calculate expiry date if applicable
let expiresAt: string | null = null;
if (branding.expiresInDays > 0) {
const expiry = new Date();
expiry.setDate(expiry.getDate() + branding.expiresInDays);
expiresAt = expiry.toISOString();
}
const snapshotData: SnapshotData = {
dashboard,
dataSources,
branding,
createdAt,
expiresAt,
};
return snapshotData;
}
/**
* Checks if a snapshot has expired
*/
export function isSnapshotExpired(snapshot: SnapshotData): boolean {
if (!snapshot.expiresAt) {
return false; // No expiry date means it never expires
}
const expiryDate = new Date(snapshot.expiresAt);
const now = new Date();
return now > expiryDate;
}
/**
* Format a date for display in the snapshot
*/
export function formatSnapshotDate(dateString: string): string {
const date = new Date(dateString);
return date.toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
});
}