mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-13 02:14:32 +00:00
fix(ui): improve cliproxy dashboard layout and dropdown styling
This commit is contained in:
1 parent
4dc17fac4f
commit
10d05502f3
3 files changed
+161
-124
No files matched your search
@@ -44,6 +44,7 @@ export function CliproxyTable({ data }: CliproxyTableProps) {
|
|||||||
{
|
{
|
||||||
accessorKey: 'name',
|
accessorKey: 'name',
|
||||||
header: 'Name',
|
header: 'Name',
|
||||||
|
cell: ({ row }) => <span className="font-medium">{row.original.name}</span>,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: 'provider',
|
accessorKey: 'provider',
|
||||||
@@ -56,11 +57,11 @@ export function CliproxyTable({ data }: CliproxyTableProps) {
|
|||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const account = row.original.account;
|
const account = row.original.account;
|
||||||
if (!account) {
|
if (!account) {
|
||||||
return <span className="text-muted-foreground text-xs">default</span>;
|
return <span className="text-muted-foreground text-xs italic">default</span>;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<Badge variant="secondary" className="text-xs font-normal">
|
<Badge variant="secondary" className="text-xs font-normal">
|
||||||
<User className="w-3 h-3 mr-1" />
|
<User className="w-3 h-3 mr-1 opacity-70" />
|
||||||
{account}
|
{account}
|
||||||
</Badge>
|
</Badge>
|
||||||
);
|
);
|
||||||
@@ -69,27 +70,35 @@ export function CliproxyTable({ data }: CliproxyTableProps) {
|
|||||||
{
|
{
|
||||||
accessorKey: 'settings',
|
accessorKey: 'settings',
|
||||||
header: 'Settings Path',
|
header: 'Settings Path',
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<code className="text-[10px] bg-muted px-1.5 py-0.5 rounded text-muted-foreground">
|
||||||
|
{row.original.settings || `config.cliproxy.${row.original.name}`}
|
||||||
|
</code>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'actions',
|
id: 'actions',
|
||||||
header: 'Actions',
|
header: 'Actions',
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => (
|
||||||
<DropdownMenu>
|
<div className="flex justify-end">
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenu>
|
||||||
<Button variant="ghost" size="sm">
|
<DropdownMenuTrigger asChild>
|
||||||
<MoreHorizontal className="w-4 h-4" />
|
<Button variant="ghost" size="sm" className="h-8 w-8 p-0">
|
||||||
</Button>
|
<span className="sr-only">Open menu</span>
|
||||||
</DropdownMenuTrigger>
|
<MoreHorizontal className="w-4 h-4" />
|
||||||
<DropdownMenuContent align="end">
|
</Button>
|
||||||
<DropdownMenuItem
|
</DropdownMenuTrigger>
|
||||||
className="text-red-600"
|
<DropdownMenuContent align="end" className="bg-white dark:bg-zinc-950">
|
||||||
onClick={() => deleteMutation.mutate(row.original.name)}
|
<DropdownMenuItem
|
||||||
>
|
className="text-red-600 focus:text-red-600 focus:bg-red-50 dark:focus:bg-red-950/30"
|
||||||
<Trash2 className="w-4 h-4 mr-2" />
|
onClick={() => deleteMutation.mutate(row.original.name)}
|
||||||
Delete
|
>
|
||||||
</DropdownMenuItem>
|
<Trash2 className="w-4 h-4 mr-2" />
|
||||||
</DropdownMenuContent>
|
Delete
|
||||||
</DropdownMenu>
|
</DropdownMenuItem>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
</div>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -103,16 +112,19 @@ export function CliproxyTable({ data }: CliproxyTableProps) {
|
|||||||
|
|
||||||
if (data.length === 0) {
|
if (data.length === 0) {
|
||||||
return (
|
return (
|
||||||
<div className="text-center py-8 text-muted-foreground">
|
<div className="text-center py-12 border rounded-lg bg-muted/5 border-dashed">
|
||||||
No CLIProxy variants found. Create one to use OAuth-based providers.
|
<div className="text-muted-foreground text-sm">No CLIProxy variants found.</div>
|
||||||
|
<div className="text-xs text-muted-foreground mt-1">
|
||||||
|
Create one to use OAuth-based providers with specific account configurations.
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="border rounded-md">
|
<div className="border rounded-md overflow-hidden bg-card">
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader>
|
<TableHeader className="bg-muted/50">
|
||||||
{table.getHeaderGroups().map((headerGroup) => (
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
<TableRow key={headerGroup.id}>
|
<TableRow key={headerGroup.id}>
|
||||||
{headerGroup.headers.map((header) => (
|
{headerGroup.headers.map((header) => (
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ function DropdownMenuContent({
|
|||||||
data-slot="dropdown-menu-content"
|
data-slot="dropdown-menu-content"
|
||||||
sideOffset={sideOffset}
|
sideOffset={sideOffset}
|
||||||
className={cn(
|
className={cn(
|
||||||
'bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md',
|
'bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md bg-white dark:bg-zinc-950',
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
|
|||||||
+126
-101
@@ -7,12 +7,12 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { Card, CardContent } from '@/components/ui/card';
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
DropdownMenuSeparator,
|
|
||||||
} from '@/components/ui/dropdown-menu';
|
} from '@/components/ui/dropdown-menu';
|
||||||
import { Plus, Check, X, User, ChevronDown, Star, Trash2 } from 'lucide-react';
|
import { Plus, Check, X, User, ChevronDown, Star, Trash2 } from 'lucide-react';
|
||||||
import { CliproxyTable } from '@/components/cliproxy-table';
|
import { CliproxyTable } from '@/components/cliproxy-table';
|
||||||
@@ -40,10 +40,10 @@ function AccountBadge({
|
|||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
<button
|
<button
|
||||||
className={`inline-flex items-center gap-1.5 px-2 py-1 text-xs rounded-md border transition-colors hover:bg-muted/50 ${
|
className={`inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-full border transition-colors hover:bg-muted/80 ${
|
||||||
account.isDefault
|
account.isDefault
|
||||||
? 'border-primary/30 bg-primary/5 text-primary'
|
? 'border-primary/30 bg-primary/10 text-primary font-medium'
|
||||||
: 'border-muted bg-muted/20'
|
: 'border-muted bg-muted/40'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<User className="w-3 h-3" />
|
<User className="w-3 h-3" />
|
||||||
@@ -52,16 +52,15 @@ function AccountBadge({
|
|||||||
<ChevronDown className="w-3 h-3 opacity-50" />
|
<ChevronDown className="w-3 h-3 opacity-50" />
|
||||||
</button>
|
</button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent align="start" className="w-48">
|
<DropdownMenuContent align="start" className="w-56">
|
||||||
<div className="px-2 py-1.5 text-xs text-muted-foreground">
|
<div className="px-2 py-1.5 text-xs text-muted-foreground bg-muted/30 -mx-1 -mt-1 mb-1 border-b">
|
||||||
{account.email || account.id}
|
<div className="font-medium text-foreground mb-0.5 truncate">
|
||||||
|
{account.email || account.id}
|
||||||
|
</div>
|
||||||
{account.lastUsedAt && (
|
{account.lastUsedAt && (
|
||||||
<div className="mt-0.5">
|
<div>Last used: {new Date(account.lastUsedAt).toLocaleDateString()}</div>
|
||||||
Last used: {new Date(account.lastUsedAt).toLocaleDateString()}
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<DropdownMenuSeparator />
|
|
||||||
{!account.isDefault && (
|
{!account.isDefault && (
|
||||||
<DropdownMenuItem onClick={onSetDefault}>
|
<DropdownMenuItem onClick={onSetDefault}>
|
||||||
<Star className="w-4 h-4 mr-2" />
|
<Star className="w-4 h-4 mr-2" />
|
||||||
@@ -69,7 +68,7 @@ function AccountBadge({
|
|||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
)}
|
)}
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
className="text-red-600 focus:text-red-600"
|
className="text-red-600 focus:text-red-600 focus:bg-red-50 dark:focus:bg-red-950/30"
|
||||||
onClick={onRemove}
|
onClick={onRemove}
|
||||||
disabled={isRemoving}
|
disabled={isRemoving}
|
||||||
>
|
>
|
||||||
@@ -81,7 +80,7 @@ function AccountBadge({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ProviderCard({
|
function ProviderRow({
|
||||||
status,
|
status,
|
||||||
setDefaultMutation,
|
setDefaultMutation,
|
||||||
removeMutation,
|
removeMutation,
|
||||||
@@ -91,79 +90,85 @@ function ProviderCard({
|
|||||||
removeMutation: ReturnType<typeof useRemoveAccount>;
|
removeMutation: ReturnType<typeof useRemoveAccount>;
|
||||||
}) {
|
}) {
|
||||||
const accounts = status.accounts || [];
|
const accounts = status.accounts || [];
|
||||||
const hasMultipleAccounts = accounts.length > 1;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div className="flex flex-col sm:flex-row sm:items-center justify-between p-4 border-b last:border-0 hover:bg-muted/5 transition-colors gap-4">
|
||||||
className={`p-4 rounded-lg border ${
|
<div className="flex items-center gap-4 min-w-[180px]">
|
||||||
status.authenticated ? 'border-green-500/30 bg-green-500/5' : 'border-muted bg-muted/5'
|
<div
|
||||||
}`}
|
className={`flex items-center justify-center w-8 h-8 rounded-full ${
|
||||||
>
|
status.authenticated
|
||||||
<div className="flex items-center justify-between">
|
? 'bg-green-500/10 text-green-600 dark:text-green-400'
|
||||||
<div className="flex items-center gap-2">
|
: 'bg-muted text-muted-foreground'
|
||||||
{status.authenticated ? (
|
}`}
|
||||||
<Check className="w-4 h-4 text-green-500" />
|
>
|
||||||
) : (
|
{status.authenticated ? <Check className="w-5 h-5" /> : <X className="w-5 h-5" />}
|
||||||
<X className="w-4 h-4 text-muted-foreground" />
|
|
||||||
)}
|
|
||||||
<span className="font-medium">{status.displayName}</span>
|
|
||||||
</div>
|
</div>
|
||||||
{accounts.length > 0 && (
|
<div>
|
||||||
<Badge variant="secondary" className="text-xs">
|
<div className="font-medium flex items-center gap-2">
|
||||||
{accounts.length} account{accounts.length !== 1 ? 's' : ''}
|
{status.displayName}
|
||||||
</Badge>
|
{accounts.length > 0 && (
|
||||||
|
<Badge variant="secondary" className="text-[10px] h-5 px-1.5 font-normal">
|
||||||
|
{accounts.length}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="text-xs text-muted-foreground mt-0.5">{status.provider}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex-1 flex items-center gap-2 flex-wrap">
|
||||||
|
{status.authenticated && accounts.length > 0 ? (
|
||||||
|
accounts.map((account) => (
|
||||||
|
<AccountBadge
|
||||||
|
key={account.id}
|
||||||
|
account={account}
|
||||||
|
onSetDefault={() =>
|
||||||
|
setDefaultMutation.mutate({
|
||||||
|
provider: status.provider,
|
||||||
|
accountId: account.id,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
onRemove={() =>
|
||||||
|
removeMutation.mutate({
|
||||||
|
provider: status.provider,
|
||||||
|
accountId: account.id,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
isRemoving={removeMutation.isPending}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<div className="text-sm text-muted-foreground italic">
|
||||||
|
{status.authenticated
|
||||||
|
? 'Authenticated (No specific accounts tracked)'
|
||||||
|
: 'Not authenticated'}
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{status.authenticated ? (
|
<div className="flex items-center gap-2">
|
||||||
<div className="mt-2">
|
{!status.authenticated && (
|
||||||
{accounts.length > 0 ? (
|
<div className="text-xs font-mono bg-muted px-2 py-1 rounded text-muted-foreground select-all">
|
||||||
<div className="flex flex-wrap gap-1.5">
|
ccs {status.provider} --auth
|
||||||
{accounts.map((account) => (
|
|
||||||
<AccountBadge
|
|
||||||
key={account.id}
|
|
||||||
account={account}
|
|
||||||
onSetDefault={() =>
|
|
||||||
setDefaultMutation.mutate({
|
|
||||||
provider: status.provider,
|
|
||||||
accountId: account.id,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
onRemove={() =>
|
|
||||||
removeMutation.mutate({
|
|
||||||
provider: status.provider,
|
|
||||||
accountId: account.id,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
isRemoving={removeMutation.isPending}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className="text-sm text-muted-foreground">
|
|
||||||
Authenticated
|
|
||||||
{status.lastAuth && (
|
|
||||||
<span className="ml-1">({new Date(status.lastAuth).toLocaleDateString()})</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{hasMultipleAccounts && (
|
|
||||||
<div className="mt-2 text-xs text-muted-foreground">
|
|
||||||
Click account to manage. Star = default.
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<div className="mt-2 text-xs text-muted-foreground">
|
|
||||||
Add account: <code className="bg-muted px-1 rounded">ccs {status.provider} --auth</code>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)}
|
||||||
) : (
|
{status.authenticated && (
|
||||||
<div className="mt-1 text-sm text-muted-foreground">
|
<Button
|
||||||
Not authenticated
|
variant="outline"
|
||||||
<span className="block text-xs mt-1">
|
size="sm"
|
||||||
Run: <code className="bg-muted px-1 rounded">ccs {status.provider} --auth</code>
|
className="h-7 text-xs gap-1"
|
||||||
</span>
|
onClick={() => {
|
||||||
</div>
|
// This is a placeholder since we can't actually run the auth command from UI easily without a terminal
|
||||||
)}
|
// But we can show the command to run
|
||||||
|
navigator.clipboard.writeText(`ccs ${status.provider} --auth`);
|
||||||
|
}}
|
||||||
|
title="Copy auth command"
|
||||||
|
>
|
||||||
|
<Plus className="w-3 h-3" />
|
||||||
|
Add Account
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -176,12 +181,12 @@ export function CliproxyPage() {
|
|||||||
const removeMutation = useRemoveAccount();
|
const removeMutation = useRemoveAccount();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 space-y-6">
|
<div className="p-6 max-w-6xl mx-auto space-y-8">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-2xl font-bold">CLIProxy</h1>
|
<h1 className="text-2xl font-bold tracking-tight">CLIProxy</h1>
|
||||||
<p className="text-sm text-muted-foreground mt-1">
|
<p className="text-sm text-muted-foreground mt-1">
|
||||||
Manage OAuth-based provider variants with multi-account support
|
Manage OAuth-based provider variants and multi-account configurations
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<Button onClick={() => setDialogOpen(true)}>
|
<Button onClick={() => setDialogOpen(true)}>
|
||||||
@@ -191,27 +196,47 @@ export function CliproxyPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Built-in Profiles with Account Management */}
|
{/* Built-in Profiles with Account Management */}
|
||||||
<div>
|
<div className="space-y-4">
|
||||||
<h2 className="text-lg font-semibold mb-3">Built-in Profiles & Accounts</h2>
|
<div>
|
||||||
{authLoading ? (
|
<h2 className="text-lg font-semibold tracking-tight">Built-in Providers</h2>
|
||||||
<div className="text-muted-foreground">Loading auth status...</div>
|
<p className="text-sm text-muted-foreground">
|
||||||
) : (
|
Manage authentication status and accounts for built-in providers.
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3">
|
</p>
|
||||||
{authData?.authStatus.map((status) => (
|
</div>
|
||||||
<ProviderCard
|
|
||||||
key={status.provider}
|
<Card>
|
||||||
status={status}
|
<CardContent className="p-0">
|
||||||
setDefaultMutation={setDefaultMutation}
|
{authLoading ? (
|
||||||
removeMutation={removeMutation}
|
<div className="p-8 text-center text-muted-foreground">
|
||||||
/>
|
Loading authentication status...
|
||||||
))}
|
</div>
|
||||||
</div>
|
) : (
|
||||||
)}
|
<div className="flex flex-col">
|
||||||
|
{authData?.authStatus.map((status) => (
|
||||||
|
<ProviderRow
|
||||||
|
key={status.provider}
|
||||||
|
status={status}
|
||||||
|
setDefaultMutation={setDefaultMutation}
|
||||||
|
removeMutation={removeMutation}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Custom Variants */}
|
{/* Custom Variants */}
|
||||||
<div>
|
<div className="space-y-4">
|
||||||
<h2 className="text-lg font-semibold mb-3">Custom Variants</h2>
|
<div className="flex items-center justify-between">
|
||||||
|
<div>
|
||||||
|
<h2 className="text-lg font-semibold tracking-tight">Custom Variants</h2>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Create custom aliases for providers with specific accounts.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
<div className="text-muted-foreground">Loading variants...</div>
|
<div className="text-muted-foreground">Loading variants...</div>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
Reference in new issue
Block a user