Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/channel-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,4 @@ export function ChannelDialog({ mode = "create", channel }: ChannelDialogProps)
</DialogContent>
</Dialog>
)
}
}
35 changes: 27 additions & 8 deletions components/endpoint-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ import {
FormMessage,
} from "@/components/ui/form"
import { Plus, Loader2 } from "lucide-react"
import { useState } from "react"
import React, { useState } from "react"
import { useForm } from "react-hook-form"
import { zodResolver } from "@hookform/resolvers/zod"
import { insertEndpointSchema } from "@/lib/db/schema/endpoints"
import { Endpoint, NewEndpoint } from "@/lib/db/schema/endpoints"
import { useToast } from "@/components/ui/use-toast"
import { DropdownMenuItem } from "@/components/ui/dropdown-menu"
import { Channel, ChannelType } from "@/lib/channels"
import { CHANNEL_TEMPLATES } from "@/lib/channels"
import { CHANNEL_TEMPLATES, CHANNEL_LABELS } from "@/lib/channels"
import { TemplateFields } from "@/components/template-fields"
import { createEndpoint, updateEndpoint } from "@/lib/services/endpoints"
import { SelectGroup, SelectLabel } from "@/components/ui/select"

interface EndpointDialogProps {
mode?: "create" | "edit"
Expand Down Expand Up @@ -182,11 +183,29 @@ export function EndpointDialog({
</SelectTrigger>
</FormControl>
<SelectContent>
{channels.map((channel) => (
<SelectItem key={channel.id} value={channel.id}>
{channel.name}
</SelectItem>
))}
{(() => {
// 按渠道类型分组
const groupedChannels: Record<string, Channel[]> = {}
channels.forEach(channel => {
if (!groupedChannels[channel.type]) {
groupedChannels[channel.type] = []
}
groupedChannels[channel.type].push(channel)
})

return Object.entries(groupedChannels).map(([type, channels]) => (
<React.Fragment key={type}>
<SelectGroup>
<SelectLabel>{CHANNEL_LABELS[type as ChannelType]}</SelectLabel>
{channels.map(channel => (
<SelectItem key={channel.id} value={channel.id}>
{channel.name}
</SelectItem>
))}
</SelectGroup>
</React.Fragment>
))
})()}
</SelectContent>
</Select>
<FormMessage />
Expand Down Expand Up @@ -275,4 +294,4 @@ export function EndpointDialog({
</DialogContent>
</Dialog>
)
}
}
8 changes: 5 additions & 3 deletions components/endpoint-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
AlertDialogTitle,
} from "@/components/ui/alert-dialog"
import { STATUS_LABELS, STATUS_COLORS } from "@/lib/constants/endpoints"
import { Channel } from "@/lib/channels"
import { Channel, CHANNEL_LABELS } from "@/lib/channels"
import { EndpointExample } from "@/components/endpoint-example"
import { useRouter } from "next/navigation"
import { deleteEndpoint, toggleEndpointStatus, testEndpoint } from "@/lib/services/endpoints"
Expand Down Expand Up @@ -211,6 +211,7 @@ export function EndpointTable({
<TableHead className="w-[50px]"></TableHead>
<TableHead>ID</TableHead>
<TableHead>名称</TableHead>
<TableHead>渠道类型</TableHead>
<TableHead>推送渠道</TableHead>
<TableHead>消息模版</TableHead>
<TableHead>状态</TableHead>
Expand All @@ -221,7 +222,7 @@ export function EndpointTable({
<TableBody>
{filteredEndpoints.length === 0 ? (
<TableRow>
<TableCell colSpan={8} className="h-24 text-center text-muted-foreground">
<TableCell colSpan={9} className="h-24 text-center text-muted-foreground">
{searchQuery ? "未找到匹配的接口" : "暂无接口"}
</TableCell>
</TableRow>
Expand All @@ -238,6 +239,7 @@ export function EndpointTable({
</TableCell>
<TableCell className="font-mono">{endpoint.id}</TableCell>
<TableCell>{endpoint.name}</TableCell>
<TableCell>{channel && CHANNEL_LABELS[channel.type]}</TableCell>
<TableCell>{channel?.name}</TableCell>
<TableCell>
<Popover>
Expand Down Expand Up @@ -357,4 +359,4 @@ export function EndpointTable({
/>
</div>
)
}
}
2 changes: 1 addition & 1 deletion components/ui/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const SelectLabel = React.forwardRef<
>(({ className, ...props }, ref) => (
<SelectPrimitive.Label
ref={ref}
className={cn("px-2 py-1.5 text-sm font-semibold", className)}
className={cn("px-2 py-1.5 text-sm text-muted-foreground", className)}
{...props}
/>
))
Expand Down