Skip to content

Commit 17f6d41

Browse files
committed
Refactor OrgHomePage by removing unused components and functions, streamlining imports, and enhancing code clarity.
1 parent 228694f commit 17f6d41

1 file changed

Lines changed: 0 additions & 119 deletions

File tree

  • apps/mesh/src/web/routes/orgs/home

apps/mesh/src/web/routes/orgs/home/page.tsx

Lines changed: 0 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* Supports graph view toggle in header.
66
*/
77

8-
import { createToolCaller } from "@/tools/client";
98
import { ChatProvider, useChat } from "@/web/components/chat/chat-context";
109
import { ChatInput } from "@/web/components/chat/chat-input";
1110
import { DecoChatSkeleton } from "@/web/components/chat/deco-chat-skeleton";
@@ -20,16 +19,13 @@ import {
2019
import { NoLlmBindingEmptyState } from "@/web/components/chat/no-llm-binding-empty-state";
2120
import { ThreadHistoryPopover } from "@/web/components/chat/thread-history-popover";
2221
import { ErrorBoundary } from "@/web/components/error-boundary";
23-
import { IntegrationIcon } from "@/web/components/integration-icon.tsx";
24-
import type { MonitoringLogsWithGatewayResponse } from "@/web/components/monitoring/index";
2522
import { useConnections } from "@/web/hooks/collections/use-connection";
2623
import { useGateways } from "@/web/hooks/collections/use-gateway";
2724
import { useBindingConnections } from "@/web/hooks/use-binding";
2825
import { useThreads } from "@/web/hooks/use-chat-store";
2926
import { useInvalidateCollectionsOnToolCall } from "@/web/hooks/use-invalidate-collections-on-tool-call";
3027
import { useLocalStorage } from "@/web/hooks/use-local-storage";
3128
import { usePersistedChat } from "@/web/hooks/use-persisted-chat";
32-
import { useToolCall } from "@/web/hooks/use-tool-call";
3329
import { authClient } from "@/web/lib/auth-client";
3430
import { LOCALSTORAGE_KEYS } from "@/web/lib/localstorage-keys";
3531
import { useProjectContext } from "@/web/providers/project-context-provider";
@@ -38,7 +34,6 @@ import { ViewModeToggle } from "@deco/ui/components/view-mode-toggle.tsx";
3834
import type { Metadata } from "@deco/ui/types/chat-metadata.ts";
3935
import { useNavigate, useRouterState } from "@tanstack/react-router";
4036
import {
41-
CpuChip02,
4237
GitBranch01,
4338
Loading01,
4439
MessageChatSquare,
@@ -103,62 +98,6 @@ function useStoredSelection<TState, TItem>(
10398

10499
type HomeViewMode = "chat" | "graph";
105100

106-
// ---------- Date Range Helper ----------
107-
108-
function getLast24HoursDateRange() {
109-
const now = Date.now();
110-
const fiveMinutes = 5 * 60 * 1000;
111-
const roundedNow = Math.floor(now / fiveMinutes) * fiveMinutes;
112-
const endDate = new Date(roundedNow);
113-
const startDate = new Date(roundedNow - 24 * 60 * 60 * 1000);
114-
return {
115-
startDate: startDate.toISOString(),
116-
endDate: endDate.toISOString(),
117-
};
118-
}
119-
120-
function aggregateGatewayToolCalls(
121-
logs: Array<{ gatewayId?: string | null }>,
122-
): Map<string, number> {
123-
const counts = new Map<string, number>();
124-
for (const log of logs) {
125-
if (!log.gatewayId) continue;
126-
counts.set(log.gatewayId, (counts.get(log.gatewayId) ?? 0) + 1);
127-
}
128-
return counts;
129-
}
130-
131-
// ---------- Hub Cards Grid ----------
132-
133-
const MAX_HUB_CARDS = 6;
134-
135-
interface HubCardProps {
136-
icon: string | null | undefined;
137-
title: string;
138-
onClick: () => void;
139-
}
140-
141-
function HubCard({ icon, title, onClick }: HubCardProps) {
142-
return (
143-
<button
144-
type="button"
145-
onClick={onClick}
146-
className="flex items-center gap-2 p-3 rounded-xl border border-border hover:bg-accent/50 transition-colors text-left cursor-pointer"
147-
>
148-
<IntegrationIcon
149-
icon={icon}
150-
name={title}
151-
size="sm"
152-
fallbackIcon={<CpuChip02 size={16} />}
153-
className="shrink-0"
154-
/>
155-
<span className="text-sm font-medium text-foreground truncate">
156-
{title}
157-
</span>
158-
</button>
159-
);
160-
}
161-
162101
// ---------- Main Content ----------
163102

164103
function HomeContent() {
@@ -509,11 +448,6 @@ function HomeContent() {
509448
</ChatInput>
510449
</div>
511450

512-
{/* Hub Cards Grid - sorted by tool calls */}
513-
<TopHubsGrid
514-
gateways={gateways}
515-
onSelectGateway={handleGatewayChange}
516-
/>
517451
</div>
518452
</div>
519453
)}
@@ -522,59 +456,6 @@ function HomeContent() {
522456
);
523457
}
524458

525-
// ---------- Top Hubs Grid Component ----------
526-
527-
function TopHubsGrid({
528-
gateways,
529-
onSelectGateway,
530-
}: {
531-
gateways: ReturnType<typeof useGateways>;
532-
onSelectGateway: (gatewayId: string) => void;
533-
}) {
534-
const { locator } = useProjectContext();
535-
const toolCaller = createToolCaller();
536-
const dateRange = getLast24HoursDateRange();
537-
538-
const { data: logsData } = useToolCall<
539-
{ startDate: string; endDate: string; limit: number; offset: number },
540-
MonitoringLogsWithGatewayResponse
541-
>({
542-
toolCaller,
543-
toolName: "MONITORING_LOGS_LIST",
544-
toolInputParams: { ...dateRange, limit: 1000, offset: 0 },
545-
scope: locator,
546-
staleTime: 30_000,
547-
});
548-
549-
const logs = logsData?.logs ?? [];
550-
const toolCallCounts = aggregateGatewayToolCalls(logs);
551-
552-
// Sort gateways by tool call count (descending), take max 6
553-
const sortedGateways = [...gateways]
554-
.sort((a, b) => {
555-
const countA = toolCallCounts.get(a.id) ?? 0;
556-
const countB = toolCallCounts.get(b.id) ?? 0;
557-
return countB - countA;
558-
})
559-
.slice(0, MAX_HUB_CARDS);
560-
561-
if (sortedGateways.length === 0) return null;
562-
563-
return (
564-
<div className="w-full">
565-
<div className="grid grid-cols-3 gap-2">
566-
{sortedGateways.map((gateway) => (
567-
<HubCard
568-
key={gateway.id}
569-
icon={gateway.icon}
570-
title={gateway.title}
571-
onClick={() => onSelectGateway(gateway.id)}
572-
/>
573-
))}
574-
</div>
575-
</div>
576-
);
577-
}
578459

579460
export default function OrgHomePage() {
580461
// Force remount on navigation to reset chat view

0 commit comments

Comments
 (0)