/** * One settings tab: the fields that belong to it, grouped into sections. * * Two tabs carry something that is not a setting: Appearance shows the preview, * because seeing the result answers the question faster than reading about it, * and Advanced offers to replace the encryption secrets, because that is an * action and belongs where somebody would look for it. */ import { Card, CardBody, CardHeader } from '@wordpress/components'; import Field, { isVisible } from './Field'; import Preview from './Preview'; import Secrets from './Secrets'; const APPEARANCE_TAB = 'appearance'; const ADVANCED_TAB = 'advanced'; export default function SettingsTab( { tab, fields, values, onChange, rotatedAt, isNetwork = false, } ) { const forThisTab = fields.filter( ( field ) => field.tab === tab && isVisible( field, values ) ); // Sections keep their order of first appearance in the schema, so the // schema file reads in the same order as the screen. const sections = []; forThisTab.forEach( ( field ) => { const existing = sections.find( ( section ) => section.title === field.section ); if ( existing ) { existing.fields.push( field ); } else { sections.push( { title: field.section, fields: [ field ] } ); } } ); return (
{ /* Neither belongs on the network defaults: the preview renders with THIS site's secret and settings, and the secrets are per site by design -- there is no network-wide one to replace. */ } { tab === APPEARANCE_TAB && ! isNetwork && ( ) } { sections.map( ( section ) => (

{ section.title }

{ section.fields.map( ( field ) => (
) ) }
) ) } { tab === ADVANCED_TAB && ! isNetwork && ( ) }
); }