|
| 1 | +// TODO: Remove fake announcement data before shipping |
| 2 | +if (!window.__TANGLE_ANNOUNCEMENTS__) { |
| 3 | + window.__TANGLE_ANNOUNCEMENTS__ = [ |
| 4 | + { |
| 5 | + id: "dashboard-beta-welcome", |
| 6 | + title: "Welcome to the new Dashboard (Beta)", |
| 7 | + body: "We're rolling out new features — favorites, recently viewed, and more. Expect changes as we iterate.", |
| 8 | + variant: "info", |
| 9 | + dismissible: true, |
| 10 | + }, |
| 11 | + ]; |
| 12 | +} |
| 13 | + |
| 14 | +import { Link } from "@tanstack/react-router"; |
| 15 | +import { GitBranch, Play } from "lucide-react"; |
| 16 | + |
| 17 | +import { RunSection } from "@/components/Home/RunSection/RunSection"; |
| 18 | +import { AnnouncementBanners } from "@/components/shared/AnnouncementBanners"; |
| 19 | +import { Icon } from "@/components/ui/icon"; |
| 20 | +import { BlockStack, InlineStack } from "@/components/ui/layout"; |
| 21 | +import { Paragraph, Text } from "@/components/ui/typography"; |
| 22 | +import { type FavoriteItem, useFavorites } from "@/hooks/useFavorites"; |
| 23 | +import { |
| 24 | + type RecentlyViewedItem, |
| 25 | + useRecentlyViewed, |
| 26 | +} from "@/hooks/useRecentlyViewed"; |
| 27 | +import { APP_ROUTES, EDITOR_PATH, RUNS_BASE_PATH } from "@/routes/router"; |
| 28 | + |
| 29 | +const PREVIEW_COUNT = 5; |
| 30 | + |
| 31 | +function formatRelativeTime(viewedAt: number): string { |
| 32 | + const diff = Date.now() - viewedAt; |
| 33 | + const minutes = Math.floor(diff / 60_000); |
| 34 | + if (minutes < 1) return "just now"; |
| 35 | + if (minutes < 60) return `${minutes}m ago`; |
| 36 | + const hours = Math.floor(minutes / 60); |
| 37 | + if (hours < 24) return `${hours}h ago`; |
| 38 | + const days = Math.floor(hours / 24); |
| 39 | + return `${days}d ago`; |
| 40 | +} |
| 41 | + |
| 42 | +function getRecentlyViewedUrl(item: RecentlyViewedItem): string { |
| 43 | + if (item.type === "pipeline") return `${EDITOR_PATH}/${item.id}`; |
| 44 | + if (item.type === "run") return `${RUNS_BASE_PATH}/${item.id}`; |
| 45 | + return "/"; |
| 46 | +} |
| 47 | + |
| 48 | +function getFavoriteUrl(item: FavoriteItem): string { |
| 49 | + if (item.type === "pipeline") return `${EDITOR_PATH}/${item.id}`; |
| 50 | + return `${RUNS_BASE_PATH}/${item.id}`; |
| 51 | +} |
| 52 | + |
| 53 | +const TypePill = ({ type }: { type: "pipeline" | "run" | "component" }) => ( |
| 54 | + <span |
| 55 | + className={`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-xs font-semibold shrink-0 ${ |
| 56 | + type === "pipeline" |
| 57 | + ? "bg-violet-100 text-violet-700" |
| 58 | + : "bg-emerald-100 text-emerald-700" |
| 59 | + }`} |
| 60 | + > |
| 61 | + {type === "pipeline" ? ( |
| 62 | + <GitBranch className="h-3 w-3" /> |
| 63 | + ) : ( |
| 64 | + <Play className="h-3 w-3" /> |
| 65 | + )} |
| 66 | + {type === "pipeline" ? "Pipeline" : type === "run" ? "Run" : "Component"} |
| 67 | + </span> |
| 68 | +); |
| 69 | + |
| 70 | +const SectionHeader = ({ |
| 71 | + title, |
| 72 | + viewAllTo, |
| 73 | + viewAllLabel = "View all", |
| 74 | +}: { |
| 75 | + title: string; |
| 76 | + viewAllTo: string; |
| 77 | + viewAllLabel?: string; |
| 78 | +}) => ( |
| 79 | + <InlineStack gap="3" blockAlign="center"> |
| 80 | + <Text as="h2" size="lg" weight="semibold"> |
| 81 | + {title} |
| 82 | + </Text> |
| 83 | + <Link |
| 84 | + to={viewAllTo} |
| 85 | + className="text-xs text-muted-foreground hover:text-foreground" |
| 86 | + > |
| 87 | + {viewAllLabel} → |
| 88 | + </Link> |
| 89 | + </InlineStack> |
| 90 | +); |
| 91 | + |
| 92 | +// ─── Favorites ───────────────────────────────────────────────────────────────── |
| 93 | + |
| 94 | +const FavoritesPreview = () => { |
| 95 | + const { favorites, removeFavorite } = useFavorites(); |
| 96 | + const preview = favorites.slice(-PREVIEW_COUNT).reverse(); |
| 97 | + |
| 98 | + return ( |
| 99 | + <BlockStack gap="3"> |
| 100 | + <SectionHeader |
| 101 | + title="Favorites" |
| 102 | + viewAllTo={APP_ROUTES.DASHBOARD_FAVORITES} |
| 103 | + /> |
| 104 | + <div className="border border-border rounded-lg overflow-hidden"> |
| 105 | + {preview.length === 0 ? ( |
| 106 | + <div className="px-4 py-3"> |
| 107 | + <Paragraph tone="subdued" size="sm"> |
| 108 | + No favorites yet. Star a pipeline or run to pin it here. |
| 109 | + </Paragraph> |
| 110 | + </div> |
| 111 | + ) : ( |
| 112 | + preview.map((item, i) => ( |
| 113 | + <Link |
| 114 | + key={`${item.type}-${item.id}`} |
| 115 | + to={getFavoriteUrl(item)} |
| 116 | + className={`group flex items-center gap-3 px-4 py-2.5 hover:bg-muted/50 no-underline ${ |
| 117 | + i < preview.length - 1 ? "border-b border-border" : "" |
| 118 | + }`} |
| 119 | + > |
| 120 | + <TypePill type={item.type} /> |
| 121 | + <Text size="sm" className="flex-1 truncate"> |
| 122 | + {item.name} |
| 123 | + </Text> |
| 124 | + <button |
| 125 | + onClick={(e) => { |
| 126 | + e.preventDefault(); |
| 127 | + e.stopPropagation(); |
| 128 | + removeFavorite(item.type, item.id); |
| 129 | + }} |
| 130 | + className="shrink-0 p-0.5 rounded opacity-0 group-hover:opacity-100 hover:bg-muted text-muted-foreground hover:text-foreground cursor-pointer" |
| 131 | + aria-label="Remove from favorites" |
| 132 | + > |
| 133 | + <Icon name="X" size="sm" /> |
| 134 | + </button> |
| 135 | + </Link> |
| 136 | + )) |
| 137 | + )} |
| 138 | + </div> |
| 139 | + </BlockStack> |
| 140 | + ); |
| 141 | +}; |
| 142 | + |
| 143 | +// ─── Recently Viewed ─────────────────────────────────────────────────────────── |
| 144 | + |
| 145 | +const RecentlyViewedPreview = () => { |
| 146 | + const { recentlyViewed } = useRecentlyViewed(); |
| 147 | + const preview = recentlyViewed.slice(0, PREVIEW_COUNT); |
| 148 | + |
| 149 | + return ( |
| 150 | + <BlockStack gap="3"> |
| 151 | + <SectionHeader |
| 152 | + title="Recently Viewed" |
| 153 | + viewAllTo={APP_ROUTES.DASHBOARD_RECENTLY_VIEWED} |
| 154 | + /> |
| 155 | + <div className="border border-border rounded-lg overflow-hidden"> |
| 156 | + {preview.length === 0 ? ( |
| 157 | + <div className="px-4 py-3"> |
| 158 | + <Paragraph tone="subdued" size="sm"> |
| 159 | + Nothing viewed yet. Open a pipeline or run to see it here. |
| 160 | + </Paragraph> |
| 161 | + </div> |
| 162 | + ) : ( |
| 163 | + preview.map((item, i) => ( |
| 164 | + <Link |
| 165 | + key={`${item.type}-${item.id}`} |
| 166 | + to={getRecentlyViewedUrl(item)} |
| 167 | + className={`flex items-center gap-3 px-4 py-2.5 hover:bg-muted/50 no-underline ${ |
| 168 | + i < preview.length - 1 ? "border-b border-border" : "" |
| 169 | + }`} |
| 170 | + > |
| 171 | + <TypePill type={item.type} /> |
| 172 | + <Text size="sm" className="flex-1 truncate"> |
| 173 | + {item.name} |
| 174 | + </Text> |
| 175 | + <Text size="xs" className="text-muted-foreground shrink-0"> |
| 176 | + {formatRelativeTime(item.viewedAt)} |
| 177 | + </Text> |
| 178 | + </Link> |
| 179 | + )) |
| 180 | + )} |
| 181 | + </div> |
| 182 | + </BlockStack> |
| 183 | + ); |
| 184 | +}; |
| 185 | + |
| 186 | +// ─── My Dashboard ────────────────────────────────────────────────────────────── |
| 187 | + |
| 188 | +export function DashboardHomeView() { |
| 189 | + return ( |
| 190 | + <BlockStack gap="6"> |
| 191 | + <AnnouncementBanners /> |
| 192 | + |
| 193 | + {/* Favorites + Recently Viewed side by side */} |
| 194 | + <div className="grid grid-cols-2 gap-6"> |
| 195 | + <FavoritesPreview /> |
| 196 | + <RecentlyViewedPreview /> |
| 197 | + </div> |
| 198 | + |
| 199 | + {/* My Runs — full table with created_by:me filter */} |
| 200 | + <BlockStack gap="3"> |
| 201 | + <SectionHeader |
| 202 | + title="My Runs" |
| 203 | + viewAllTo={APP_ROUTES.DASHBOARD_RUNS} |
| 204 | + viewAllLabel="View all runs" |
| 205 | + /> |
| 206 | + <RunSection hideFilters forcedFilter="created_by:me" maxItems={5} /> |
| 207 | + </BlockStack> |
| 208 | + </BlockStack> |
| 209 | + ); |
| 210 | +} |
0 commit comments