refactor: simplify OrganizationStrategy component by removing unused imports and details

This commit is contained in:
Arunavo Ray
2025-06-17 13:12:12 +05:30
parent f07ae220b0
commit 13d4b03541
2 changed files with 169 additions and 207 deletions

View File

@@ -11,7 +11,7 @@ import { githubApi } from "@/lib/api";
import type { GitHubConfig, MirrorOptions, AdvancedOptions } from "@/types/config"; import type { GitHubConfig, MirrorOptions, AdvancedOptions } from "@/types/config";
import { Input } from "../ui/input"; import { Input } from "../ui/input";
import { toast } from "sonner"; import { toast } from "sonner";
import { AlertTriangle, Info } from "lucide-react"; import { Info } from "lucide-react";
import { Alert, AlertDescription } from "../ui/alert"; import { Alert, AlertDescription } from "../ui/alert";
import { GitHubMirrorSettings } from "./GitHubMirrorSettings"; import { GitHubMirrorSettings } from "./GitHubMirrorSettings";
import { Separator } from "../ui/separator"; import { Separator } from "../ui/separator";

View File

@@ -1,9 +1,9 @@
import React, { useState } from "react"; import React from "react";
import { Card } from "@/components/ui/card"; import { Card } from "@/components/ui/card";
import { Input } from "@/components/ui/input"; import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label"; import { Label } from "@/components/ui/label";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
import { Info, GitBranch, FolderTree, Package, Star, Building2, User, ChevronDown, ChevronUp, Globe, Lock, Shield } from "lucide-react"; import { Info, GitBranch, FolderTree, Star, Building2, User, Globe, Lock, Shield } from "lucide-react";
import { Separator } from "@/components/ui/separator"; import { Separator } from "@/components/ui/separator";
import { import {
Tooltip, Tooltip,
@@ -17,11 +17,6 @@ import {
PopoverTrigger, PopoverTrigger,
} from "@/components/ui/popover"; } from "@/components/ui/popover";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from "@/components/ui/collapsible";
import type { GiteaOrgVisibility } from "@/types/config"; import type { GiteaOrgVisibility } from "@/types/config";
export type MirrorStrategy = "preserve" | "single-org" | "flat-user"; export type MirrorStrategy = "preserve" | "single-org" | "flat-user";
@@ -47,11 +42,10 @@ const strategyConfig = {
color: "text-blue-600 dark:text-blue-400", color: "text-blue-600 dark:text-blue-400",
bgColor: "bg-blue-50 dark:bg-blue-950/20", bgColor: "bg-blue-50 dark:bg-blue-950/20",
borderColor: "border-blue-200 dark:border-blue-900", borderColor: "border-blue-200 dark:border-blue-900",
details: [ repoColors: {
"Personal repos → Your Gitea username", bg: "bg-blue-50 dark:bg-blue-950/30",
"Org repos → Same org name in Gitea", icon: "text-blue-600 dark:text-blue-400"
"Team structure preserved" }
]
}, },
"single-org": { "single-org": {
title: "Consolidate to One Org", title: "Consolidate to One Org",
@@ -60,11 +54,10 @@ const strategyConfig = {
color: "text-purple-600 dark:text-purple-400", color: "text-purple-600 dark:text-purple-400",
bgColor: "bg-purple-50 dark:bg-purple-950/20", bgColor: "bg-purple-50 dark:bg-purple-950/20",
borderColor: "border-purple-200 dark:border-purple-900", borderColor: "border-purple-200 dark:border-purple-900",
details: [ repoColors: {
"All repos in one place", bg: "bg-purple-50 dark:bg-purple-950/30",
"Simplified management", icon: "text-purple-600 dark:text-purple-400"
"Custom organization name" }
]
}, },
"flat-user": { "flat-user": {
title: "Flat User Structure", title: "Flat User Structure",
@@ -73,186 +66,165 @@ const strategyConfig = {
color: "text-green-600 dark:text-green-400", color: "text-green-600 dark:text-green-400",
bgColor: "bg-green-50 dark:bg-green-950/20", bgColor: "bg-green-50 dark:bg-green-950/20",
borderColor: "border-green-200 dark:border-green-900", borderColor: "border-green-200 dark:border-green-900",
details: [ repoColors: {
"All repos under your username", bg: "bg-green-50 dark:bg-green-950/30",
"No organizations needed", icon: "text-green-600 dark:text-green-400"
"Simple and personal" }
]
} }
}; };
const StrategyVisualizer: React.FC<{ const MappingPreview: React.FC<{
strategy: MirrorStrategy; strategy: MirrorStrategy;
config: typeof strategyConfig.preserve;
destinationOrg?: string; destinationOrg?: string;
starredReposOrg?: string; starredReposOrg?: string;
githubUsername?: string; githubUsername?: string;
giteaUsername?: string; giteaUsername?: string;
}> = ({ strategy, destinationOrg, starredReposOrg, githubUsername, giteaUsername }) => { }> = ({ strategy, config, destinationOrg, starredReposOrg, githubUsername, giteaUsername }) => {
const [isOpen, setIsOpen] = useState(false);
const displayGithubUsername = githubUsername || "<username>"; const displayGithubUsername = githubUsername || "<username>";
const displayGiteaUsername = giteaUsername || "<username>"; const displayGiteaUsername = giteaUsername || "<username>";
const isGithubPlaceholder = !githubUsername; const isGithubPlaceholder = !githubUsername;
const isGiteaPlaceholder = !giteaUsername; const isGiteaPlaceholder = !giteaUsername;
const renderPreserveStructure = () => (
<div className="flex items-center justify-between gap-8 p-6">
<div className="flex-1">
<div className="text-sm font-medium text-muted-foreground mb-3">GitHub</div>
<div className="space-y-2">
<div className="flex items-center gap-2 p-2 bg-gray-50 dark:bg-gray-800 rounded">
<User className="h-4 w-4" />
<span className={cn("text-sm", isGithubPlaceholder && "text-muted-foreground italic")}>{displayGithubUsername}/my-repo</span>
</div>
<div className="flex items-center gap-2 p-2 bg-gray-50 dark:bg-gray-800 rounded">
<Building2 className="h-4 w-4" />
<span className="text-sm">my-org/team-repo</span>
</div>
<div className="flex items-center gap-2 p-2 bg-gray-50 dark:bg-gray-800 rounded">
<Star className="h-4 w-4" />
<span className="text-sm">awesome/starred-repo</span>
</div>
</div>
</div>
<div className="flex items-center">
<GitBranch className="h-5 w-5 text-muted-foreground" />
</div>
<div className="flex-1">
<div className="text-sm font-medium text-muted-foreground mb-3">Gitea</div>
<div className="space-y-2">
<div className="flex items-center gap-2 p-2 bg-blue-50 dark:bg-blue-950/30 rounded">
<User className="h-4 w-4 text-blue-600 dark:text-blue-400" />
<span className={cn("text-sm", isGiteaPlaceholder && "text-muted-foreground italic")}>{displayGiteaUsername}/my-repo</span>
</div>
<div className="flex items-center gap-2 p-2 bg-blue-50 dark:bg-blue-950/30 rounded">
<Building2 className="h-4 w-4 text-blue-600 dark:text-blue-400" />
<span className="text-sm">my-org/team-repo</span>
</div>
<div className="flex items-center gap-2 p-2 bg-blue-50 dark:bg-blue-950/30 rounded">
<Building2 className="h-4 w-4 text-blue-600 dark:text-blue-400" />
<span className="text-sm">{starredReposOrg || "starred"}/starred-repo</span>
</div>
</div>
</div>
</div>
);
const renderSingleOrg = () => (
<div className="flex items-center justify-between gap-8 p-6">
<div className="flex-1">
<div className="text-sm font-medium text-muted-foreground mb-3">GitHub</div>
<div className="space-y-2">
<div className="flex items-center gap-2 p-2 bg-gray-50 dark:bg-gray-800 rounded">
<User className="h-4 w-4" />
<span className={cn("text-sm", isGithubPlaceholder && "text-muted-foreground italic")}>{displayGithubUsername}/my-repo</span>
</div>
<div className="flex items-center gap-2 p-2 bg-gray-50 dark:bg-gray-800 rounded">
<Building2 className="h-4 w-4" />
<span className="text-sm">my-org/team-repo</span>
</div>
<div className="flex items-center gap-2 p-2 bg-gray-50 dark:bg-gray-800 rounded">
<Star className="h-4 w-4" />
<span className="text-sm">awesome/starred-repo</span>
</div>
</div>
</div>
<div className="flex items-center">
<GitBranch className="h-5 w-5 text-muted-foreground" />
</div>
<div className="flex-1">
<div className="text-sm font-medium text-muted-foreground mb-3">Gitea</div>
<div className="space-y-2">
<div className="flex items-center gap-2 p-2 bg-purple-50 dark:bg-purple-950/30 rounded">
<Building2 className="h-4 w-4 text-purple-600 dark:text-purple-400" />
<span className="text-sm">{destinationOrg || "github-mirrors"}/my-repo</span>
</div>
<div className="flex items-center gap-2 p-2 bg-purple-50 dark:bg-purple-950/30 rounded">
<Building2 className="h-4 w-4 text-purple-600 dark:text-purple-400" />
<span className="text-sm">{destinationOrg || "github-mirrors"}/team-repo</span>
</div>
<div className="flex items-center gap-2 p-2 bg-purple-50 dark:bg-purple-950/30 rounded">
<Building2 className="h-4 w-4 text-purple-600 dark:text-purple-400" />
<span className="text-sm">{starredReposOrg || "starred"}/starred-repo</span>
</div>
</div>
</div>
</div>
);
const renderFlatUser = () => (
<div className="flex items-center justify-between gap-8 p-6">
<div className="flex-1">
<div className="text-sm font-medium text-muted-foreground mb-3">GitHub</div>
<div className="space-y-2">
<div className="flex items-center gap-2 p-2 bg-gray-50 dark:bg-gray-800 rounded">
<User className="h-4 w-4" />
<span className={cn("text-sm", isGithubPlaceholder && "text-muted-foreground italic")}>{displayGithubUsername}/my-repo</span>
</div>
<div className="flex items-center gap-2 p-2 bg-gray-50 dark:bg-gray-800 rounded">
<Building2 className="h-4 w-4" />
<span className="text-sm">my-org/team-repo</span>
</div>
<div className="flex items-center gap-2 p-2 bg-gray-50 dark:bg-gray-800 rounded">
<Star className="h-4 w-4" />
<span className="text-sm">awesome/starred-repo</span>
</div>
</div>
</div>
<div className="flex items-center">
<GitBranch className="h-5 w-5 text-muted-foreground" />
</div>
<div className="flex-1">
<div className="text-sm font-medium text-muted-foreground mb-3">Gitea</div>
<div className="space-y-2">
<div className="flex items-center gap-2 p-2 bg-green-50 dark:bg-green-950/30 rounded">
<User className="h-4 w-4 text-green-600 dark:text-green-400" />
<span className={cn("text-sm", isGiteaPlaceholder && "text-muted-foreground italic")}>{displayGiteaUsername}/my-repo</span>
</div>
<div className="flex items-center gap-2 p-2 bg-green-50 dark:bg-green-950/30 rounded">
<User className="h-4 w-4 text-green-600 dark:text-green-400" />
<span className={cn("text-sm", isGiteaPlaceholder && "text-muted-foreground italic")}>{displayGiteaUsername}/team-repo</span>
</div>
<div className="flex items-center gap-2 p-2 bg-green-50 dark:bg-green-950/30 rounded">
<Building2 className="h-4 w-4 text-green-600 dark:text-green-400" />
<span className="text-sm">{starredReposOrg || "starred"}/starred-repo</span>
</div>
</div>
</div>
</div>
);
if (strategy === "preserve") {
return ( return (
<div className="mt-3"> <div className="flex items-center justify-between gap-6">
<Collapsible open={isOpen} onOpenChange={setIsOpen}> <div className="flex-1">
<Card className="overflow-hidden"> <div className="text-xs font-medium text-muted-foreground mb-2">GitHub</div>
<CollapsibleTrigger className="w-full"> <div className="space-y-1.5">
<div className="bg-muted/50 p-3 border-b hover:bg-muted/70 transition-colors cursor-pointer"> <div className="flex items-center gap-2 p-1.5 bg-gray-50 dark:bg-gray-800 rounded text-xs">
<h4 className="text-sm font-medium flex items-center justify-between"> <User className="h-3 w-3" />
<span className="flex items-center gap-2"> <span className={cn(isGithubPlaceholder && "text-muted-foreground italic")}>{displayGithubUsername}/my-repo</span>
<Package className="h-4 w-4" /> </div>
Repository Mapping Preview <div className="flex items-center gap-2 p-1.5 bg-gray-50 dark:bg-gray-800 rounded text-xs">
</span> <Building2 className="h-3 w-3" />
{isOpen ? ( <span>my-org/team-repo</span>
<ChevronUp className="h-4 w-4 text-muted-foreground" /> </div>
) : ( <div className="flex items-center gap-2 p-1.5 bg-gray-50 dark:bg-gray-800 rounded text-xs">
<ChevronDown className="h-4 w-4 text-muted-foreground" /> <Star className="h-3 w-3" />
)} <span>awesome/starred-repo</span>
</h4> </div>
</div>
</div>
<div className="flex items-center">
<GitBranch className="h-4 w-4 text-muted-foreground" />
</div>
<div className="flex-1">
<div className="text-xs font-medium text-muted-foreground mb-2">Gitea</div>
<div className="space-y-1.5">
<div className={cn("flex items-center gap-2 p-1.5 rounded text-xs", config.repoColors.bg)}>
<User className={cn("h-3 w-3", config.repoColors.icon)} />
<span className={cn(isGiteaPlaceholder && "text-muted-foreground italic")}>{displayGiteaUsername}/my-repo</span>
</div>
<div className={cn("flex items-center gap-2 p-1.5 rounded text-xs", config.repoColors.bg)}>
<Building2 className={cn("h-3 w-3", config.repoColors.icon)} />
<span>my-org/team-repo</span>
</div>
<div className={cn("flex items-center gap-2 p-1.5 rounded text-xs", config.repoColors.bg)}>
<Building2 className={cn("h-3 w-3", config.repoColors.icon)} />
<span>{starredReposOrg || "starred"}/starred-repo</span>
</div>
</div>
</div> </div>
</CollapsibleTrigger>
<CollapsibleContent>
{strategy === "preserve" && renderPreserveStructure()}
{strategy === "single-org" && renderSingleOrg()}
{strategy === "flat-user" && renderFlatUser()}
</CollapsibleContent>
</Card>
</Collapsible>
</div> </div>
); );
}
if (strategy === "single-org") {
return (
<div className="flex items-center justify-between gap-6">
<div className="flex-1">
<div className="text-xs font-medium text-muted-foreground mb-2">GitHub</div>
<div className="space-y-1.5">
<div className="flex items-center gap-2 p-1.5 bg-gray-50 dark:bg-gray-800 rounded text-xs">
<User className="h-3 w-3" />
<span className={cn(isGithubPlaceholder && "text-muted-foreground italic")}>{displayGithubUsername}/my-repo</span>
</div>
<div className="flex items-center gap-2 p-1.5 bg-gray-50 dark:bg-gray-800 rounded text-xs">
<Building2 className="h-3 w-3" />
<span>my-org/team-repo</span>
</div>
<div className="flex items-center gap-2 p-1.5 bg-gray-50 dark:bg-gray-800 rounded text-xs">
<Star className="h-3 w-3" />
<span>awesome/starred-repo</span>
</div>
</div>
</div>
<div className="flex items-center">
<GitBranch className="h-4 w-4 text-muted-foreground" />
</div>
<div className="flex-1">
<div className="text-xs font-medium text-muted-foreground mb-2">Gitea</div>
<div className="space-y-1.5">
<div className={cn("flex items-center gap-2 p-1.5 rounded text-xs", config.repoColors.bg)}>
<Building2 className={cn("h-3 w-3", config.repoColors.icon)} />
<span>{destinationOrg || "github-mirrors"}/my-repo</span>
</div>
<div className={cn("flex items-center gap-2 p-1.5 rounded text-xs", config.repoColors.bg)}>
<Building2 className={cn("h-3 w-3", config.repoColors.icon)} />
<span>{destinationOrg || "github-mirrors"}/team-repo</span>
</div>
<div className={cn("flex items-center gap-2 p-1.5 rounded text-xs", config.repoColors.bg)}>
<Building2 className={cn("h-3 w-3", config.repoColors.icon)} />
<span>{starredReposOrg || "starred"}/starred-repo</span>
</div>
</div>
</div>
</div>
);
}
if (strategy === "flat-user") {
return (
<div className="flex items-center justify-between gap-6">
<div className="flex-1">
<div className="text-xs font-medium text-muted-foreground mb-2">GitHub</div>
<div className="space-y-1.5">
<div className="flex items-center gap-2 p-1.5 bg-gray-50 dark:bg-gray-800 rounded text-xs">
<User className="h-3 w-3" />
<span className={cn(isGithubPlaceholder && "text-muted-foreground italic")}>{displayGithubUsername}/my-repo</span>
</div>
<div className="flex items-center gap-2 p-1.5 bg-gray-50 dark:bg-gray-800 rounded text-xs">
<Building2 className="h-3 w-3" />
<span>my-org/team-repo</span>
</div>
<div className="flex items-center gap-2 p-1.5 bg-gray-50 dark:bg-gray-800 rounded text-xs">
<Star className="h-3 w-3" />
<span>awesome/starred-repo</span>
</div>
</div>
</div>
<div className="flex items-center">
<GitBranch className="h-4 w-4 text-muted-foreground" />
</div>
<div className="flex-1">
<div className="text-xs font-medium text-muted-foreground mb-2">Gitea</div>
<div className="space-y-1.5">
<div className={cn("flex items-center gap-2 p-1.5 rounded text-xs", config.repoColors.bg)}>
<User className={cn("h-3 w-3", config.repoColors.icon)} />
<span className={cn(isGiteaPlaceholder && "text-muted-foreground italic")}>{displayGiteaUsername}/my-repo</span>
</div>
<div className={cn("flex items-center gap-2 p-1.5 rounded text-xs", config.repoColors.bg)}>
<User className={cn("h-3 w-3", config.repoColors.icon)} />
<span className={cn(isGiteaPlaceholder && "text-muted-foreground italic")}>{displayGiteaUsername}/team-repo</span>
</div>
<div className={cn("flex items-center gap-2 p-1.5 rounded text-xs", config.repoColors.bg)}>
<Building2 className={cn("h-3 w-3", config.repoColors.icon)} />
<span>{starredReposOrg || "starred"}/starred-repo</span>
</div>
</div>
</div>
</div>
);
}
return null;
}; };
export const OrganizationStrategy: React.FC<OrganizationStrategyProps> = ({ export const OrganizationStrategy: React.FC<OrganizationStrategyProps> = ({
@@ -334,17 +306,17 @@ export const OrganizationStrategy: React.FC<OrganizationStrategyProps> = ({
<Info className="h-4 w-4 text-muted-foreground" /> <Info className="h-4 w-4 text-muted-foreground" />
</button> </button>
</PopoverTrigger> </PopoverTrigger>
<PopoverContent side="left" align="center" className="w-64"> <PopoverContent side="left" align="center" className="w-[500px]">
<div className="space-y-2"> <div className="space-y-3">
{config.details.map((detail, idx) => ( <h4 className="font-medium text-sm">Repository Mapping Preview</h4>
<div key={idx} className="flex items-start gap-2"> <MappingPreview
<div className={cn( strategy={key}
"h-1.5 w-1.5 rounded-full mt-1.5 flex-shrink-0", config={config}
"bg-muted-foreground" destinationOrg={destinationOrg}
)} /> starredReposOrg={starredReposOrg}
<span className="text-xs text-muted-foreground">{detail}</span> githubUsername={githubUsername}
</div> giteaUsername={giteaUsername}
))} />
</div> </div>
</PopoverContent> </PopoverContent>
</Popover> </Popover>
@@ -541,16 +513,6 @@ export const OrganizationStrategy: React.FC<OrganizationStrategyProps> = ({
</div> </div>
)} )}
</div> </div>
<Separator className="my-4" />
<StrategyVisualizer
strategy={strategy}
destinationOrg={destinationOrg}
starredReposOrg={starredReposOrg}
githubUsername={githubUsername}
giteaUsername={giteaUsername}
/>
</div> </div>
); );
}; };