import { __ } from '@wordpress/i18n';
import { compose } from '@wordpress/compose';
import { withSelect, withDispatch } from '@wordpress/data';
import { PluginSidebar, PluginSidebarMoreMenuItem } from '@wordpress/editor';
import { PanelBody, PanelRow, TextControl, DateTimePicker } from '@wordpress/components';
import { useEntityProp } from '@wordpress/core-data';
import Section from './Section';
const JVIcon = () => (
);
const SidePanel = ( { postType, metaFields, setMetaFields } ) => {
const { content, fields, sections, base } = window.jvbFieldConfig || {};
const [meta, setMeta] = useEntityProp('postType', content, 'meta');
if (!fields || !fields.length) return null;
console.log(fields);
console.log(sections);
return (
<>
}
>
Additional Fields
}
title="Additional Fields"
>
{
Object.values(sections).map((section, index) => (
))
}
>
)
}
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, base}) => {
const sectionFields = section.fields.map(f => base+f);
return fields.filter(item => sectionFields.includes(item.name))
};
const testOpen = (index) => {
return index === 0;
};
export default compose([
applyWithSelect,
applyWithDispatch
])(SidePanel);