import { __ } from '@wordpress/i18n'; import { compose } from '@wordpress/compose'; import { withSelect, withDispatch } from '@wordpress/data'; import { PluginSidebar, PluginSidebarMoreMenuItem } from '@wordpress/editor'; import { useEntityProp } from '@wordpress/core-data'; import Section from './Section'; const JVIcon = () => ( ); const SidePanel = ( { postType, metaFields, setMetaFields } ) => { const { fields, sections } = window.jvbFieldConfig || {}; const [meta, setMeta] = useEntityProp('postType', postType, 'meta'); if (!fields || !fields.length) return null; return ( <> } > Additional Fields } title="Additional Fields" > { Object.values(sections).map((section, index) => { return
; }) } ) } const applyWithSelect = withSelect( ( select ) => { return { metaFields: select( 'core/editor' ).getEditedPostAttribute( 'meta' ), postType: select( 'core/editor' ).getCurrentPostType() }; } ); const applyWithDispatch = withDispatch( ( dispatch ) => { return { setMetaFields ( newValue ) { dispatch('core/editor').editPost( { meta: newValue } ) } } } ); const filterFields = ({section, fields}) => { return fields.filter(item => section.fields.includes(item.name)) }; const testOpen = (index) => { return index === 0; }; export default compose([ applyWithSelect, applyWithDispatch ])(SidePanel);