From 4e50070adb085e6864ad1743dc9deec8a986ef14 Mon Sep 17 00:00:00 2001 From: Tasso Evangelista Date: Wed, 30 Oct 2019 14:50:15 -0300 Subject: [PATCH] Implement SettingState --- .../components/admin/settings/GroupState.js | 2 +- client/components/admin/settings/Section.js | 10 ++--- .../settings/{SettingField.js => Setting.js} | 15 +++---- .../components/admin/settings/SettingState.js | 43 +++++++++++++++++++ .../admin/settings/SettingsState.js | 18 -------- package-lock.json | 26 +++++++++++ 6 files changed, 82 insertions(+), 32 deletions(-) rename client/components/admin/settings/{SettingField.js => Setting.js} (90%) create mode 100644 client/components/admin/settings/SettingState.js diff --git a/client/components/admin/settings/GroupState.js b/client/components/admin/settings/GroupState.js index a7c9d04c55e..0194de9523d 100644 --- a/client/components/admin/settings/GroupState.js +++ b/client/components/admin/settings/GroupState.js @@ -13,7 +13,7 @@ export function GroupState({ groupId }) { const group = state.find(({ _id, type }) => _id === groupId && type === 'group'); const settings = state.filter(({ group }) => group === groupId); const changed = settings.some(({ changed }) => changed); - const sections = Array.from(new Set(settings.map(({ section }) => section))); + const sections = Array.from(new Set(settings.map(({ section }) => section || ''))); const saveRef = useRef(save); const cancelRef = useRef(cancel); diff --git a/client/components/admin/settings/Section.js b/client/components/admin/settings/Section.js index f9a8aa48769..30ad33853b6 100644 --- a/client/components/admin/settings/Section.js +++ b/client/components/admin/settings/Section.js @@ -3,14 +3,12 @@ import React from 'react'; import { useTranslation } from '../../providers/TranslationProvider'; import { useSection } from './SectionState'; -import { SettingField } from './SettingField'; -import { useSettingsState } from './SettingsState'; +import { Setting } from './Setting'; +import { SettingState } from './SettingState'; export function Section({ children, hasReset = true, help, solo }) { const section = useSection(); const t = useTranslation(); - const { state } = useSettingsState(); - const settings = state.filter(({ _id }) => section.settings.includes(_id)); const handleResetSectionClick = () => { section.reset(); @@ -20,7 +18,9 @@ export function Section({ children, hasReset = true, help, solo }) { {help && {help}} - {settings.map((setting) => )} + {section.settings.map((setting) => + + )} {hasReset && section.canReset &&