Compare commits

...
Author SHA1 Message Date
Ludy87 0bd50d3c6a Sync local settings only when card is collapsed
Updates the useEffect in ProviderCard to set local settings from incoming props only when the card is not expanded. This prevents overwriting local changes while the card is open.
2025-12-20 21:26:15 +01:00
Ludy87 73251fd2fb Sync provider settings with settings.yml in config UI
Updated ProviderCard to keep local settings in sync with incoming settings from settings.yml using useEffect. Also ensured default values are only applied to unset fields, and passed settings to ProviderCard from AdminConnectionsSection to support this behavior.
2025-12-20 21:11:56 +01:00
2 changed files with 12 additions and 3 deletions
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useEffect, useState } from 'react';
import { Paper, Group, Text, Button, Collapse, Stack, TextInput, Textarea, Switch, PasswordInput } from '@mantine/core';
import { useTranslation } from 'react-i18next';
import LocalIcon from '@app/components/shared/LocalIcon';
@@ -25,14 +25,22 @@ export default function ProviderCard({
const [expanded, setExpanded] = useState(false);
const [localSettings, setLocalSettings] = useState<Record<string, any>>(settings);
// Keep local settings in sync with incoming settings (values loaded from settings.yml)
useEffect(() => {
if (!expanded) {
setLocalSettings(settings);
}
}, [settings, expanded]);
// Initialize local settings with defaults when opening an unconfigured provider
const handleConnectToggle = () => {
if (!isConfigured && !expanded) {
// First time opening an unconfigured provider - initialize with defaults
const defaultSettings: Record<string, any> = {};
// while preserving any values already present (from settings.yml)
const defaultSettings: Record<string, any> = { ...settings };
provider.fields.forEach((field) => {
if (field.defaultValue !== undefined) {
defaultSettings[field.key] = field.defaultValue;
defaultSettings[field.key] = defaultSettings[field.key] ?? field.defaultValue;
}
});
setLocalSettings(defaultSettings);
@@ -422,6 +422,7 @@ export default function AdminConnectionsSection() {
key={provider.id}
provider={provider}
isConfigured={false}
settings={getProviderSettings(provider)}
onSave={(providerSettings) => handleProviderSave(provider, providerSettings)}
disabled={!loginEnabled}
/>