🐛 fix: Simplify protocol enable checks by removing unnecessary false comparisons

This commit is contained in:
web 2025-09-28 09:19:54 -07:00
parent 35e1cef18e
commit 4828700776
3 changed files with 5 additions and 6 deletions

View File

@ -155,9 +155,7 @@ export default function ServersPage() {
accessorKey: 'protocols',
header: t('protocols'),
cell: ({ row }) => {
const list = row.original.protocols.filter(
(p) => p.enable !== false,
) as API.Protocol[];
const list = row.original.protocols.filter((p) => p.enable) as API.Protocol[];
if (!list.length) return '—';
return (
<div className='flex flex-col gap-1'>

View File

@ -492,7 +492,7 @@ export default function ServerForm(props: {
PROTOCOLS.findIndex((t) => t === type),
);
const current = (protocolsValues[i] || {}) as Record<string, any>;
const isEnabled = current?.enable !== false;
const isEnabled = current?.enable;
const fields = PROTOCOL_FIELDS[type] || [];
return (
<AccordionItem key={type} value={type} className='mb-2 rounded-lg border'>
@ -529,7 +529,8 @@ export default function ServerForm(props: {
checked={!!isEnabled}
disabled={Boolean(
initialValues?.id &&
isProtocolUsedInNodes(initialValues?.id || 0, type),
isProtocolUsedInNodes(initialValues?.id || 0, type) &&
isEnabled,
)}
onCheckedChange={(checked) => {
form.setValue(`protocols.${i}.enable`, checked);

View File

@ -65,7 +65,7 @@ export const useServerStore = create<ServerState>((set, get) => ({
getServerEnabledProtocols: (serverId: number) => {
const server = get().servers.find((s) => s.id === serverId);
return server?.protocols?.filter((p) => p.enable !== false) || [];
return server?.protocols?.filter((p) => p.enable) || [];
},
getProtocolPort: (serverId?: number, protocol?: string) => {