Skip to content

Commit 264c5cf

Browse files
committed
feat: условное отображение полей настроек плагинов
Добавлена логика условного отображения полей настроек: - Поля с ключами, начинающимися на "enable", показываются только если actionsPreset === 'custom' - Это позволяет скрывать переключатели отдельных действий когда выбран готовый пресет, улучшая UX Реализовано в обоих компонентах: - PluginSettingsForm.jsx - PluginSettingsDialog.jsx
1 parent fe6cfb3 commit 264c5cf

2 files changed

Lines changed: 56 additions & 29 deletions

File tree

frontend/src/components/PluginSettingsDialog.jsx

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,16 @@ export default function PluginSettingsDialog({ bot, plugin, onOpenChange, onSave
384384
}
385385
};
386386

387+
// Определяем, какие поля показывать на основе условий
388+
const shouldShowField = (key, config) => {
389+
// Если есть поле actionsPreset, то поля enable* показываем только при custom
390+
const actionsPresetValue = settings?.actionsPreset;
391+
if (actionsPresetValue !== undefined && key.startsWith('enable')) {
392+
return actionsPresetValue === 'custom';
393+
}
394+
return true;
395+
};
396+
387397
const renderSettings = () => {
388398
if (settings === null) return <div className="text-center p-4"><Loader2 className="h-6 w-6 animate-spin mx-auto"/></div>;
389399
if (Object.keys(manifestSettings).length === 0) return <p className="text-muted-foreground p-4 text-center">У этого плагина нет настроек.</p>;
@@ -395,16 +405,19 @@ export default function PluginSettingsDialog({ bot, plugin, onOpenChange, onSave
395405
<AccordionItem key={categoryKey} value={categoryKey} className="border rounded-lg bg-muted/20 px-4">
396406
<AccordionTrigger className="text-base font-semibold hover:no-underline">{categoryConfig.label}</AccordionTrigger>
397407
<AccordionContent className="pt-4 border-t space-y-4">
398-
{Object.entries(categoryConfig).filter(([key]) => key !== 'label').map(([key, config]) => (
399-
<SettingField
400-
key={key}
401-
settingKey={key}
402-
config={config}
403-
value={settings[key]}
404-
onChange={handleSettingChange}
405-
readOnly={readOnly}
406-
/>
407-
))}
408+
{Object.entries(categoryConfig)
409+
.filter(([key]) => key !== 'label')
410+
.filter(([key, config]) => shouldShowField(key, config))
411+
.map(([key, config]) => (
412+
<SettingField
413+
key={key}
414+
settingKey={key}
415+
config={config}
416+
value={settings[key]}
417+
onChange={handleSettingChange}
418+
readOnly={readOnly}
419+
/>
420+
))}
408421
</AccordionContent>
409422
</AccordionItem>
410423
))}
@@ -414,16 +427,18 @@ export default function PluginSettingsDialog({ bot, plugin, onOpenChange, onSave
414427

415428
return (
416429
<div className="space-y-4">
417-
{Object.entries(manifestSettings).map(([key, config]) => (
418-
<SettingField
419-
key={key}
420-
settingKey={key}
421-
config={config}
422-
value={settings[key]}
423-
onChange={handleSettingChange}
424-
readOnly={readOnly}
425-
/>
426-
))}
430+
{Object.entries(manifestSettings)
431+
.filter(([key, config]) => shouldShowField(key, config))
432+
.map(([key, config]) => (
433+
<SettingField
434+
key={key}
435+
settingKey={key}
436+
config={config}
437+
value={settings[key]}
438+
onChange={handleSettingChange}
439+
readOnly={readOnly}
440+
/>
441+
))}
427442
</div>
428443
);
429444
};

frontend/src/components/PluginSettingsForm.jsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,17 +257,29 @@ export default function PluginSettingsForm({ plugin, onSettingsChange }) {
257257
onSettingsChange(plugin.id, newSettings);
258258
};
259259

260+
// Определяем, какие поля показывать на основе условий
261+
const shouldShowField = (key, config) => {
262+
// Если есть поле actionsPreset, то поля enable* показываем только при custom
263+
const actionsPresetValue = plugin.settings.actionsPreset;
264+
if (actionsPresetValue !== undefined && key.startsWith('enable')) {
265+
return actionsPresetValue === 'custom';
266+
}
267+
return true;
268+
};
269+
260270
return (
261271
<div className="space-y-6">
262-
{Object.entries(plugin.manifest.settings).map(([key, config]) => (
263-
<SettingField
264-
key={key}
265-
settingKey={key}
266-
config={config}
267-
value={plugin.settings[key]}
268-
onChange={handleFieldChange}
269-
/>
270-
))}
272+
{Object.entries(plugin.manifest.settings)
273+
.filter(([key, config]) => shouldShowField(key, config))
274+
.map(([key, config]) => (
275+
<SettingField
276+
key={key}
277+
settingKey={key}
278+
config={config}
279+
value={plugin.settings[key]}
280+
onChange={handleFieldChange}
281+
/>
282+
))}
271283
</div>
272284
);
273285
}

0 commit comments

Comments
 (0)