-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathmeta-boxes-section.js
61 lines (54 loc) · 1.54 KB
/
meta-boxes-section.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* External dependencies
*/
import { filter, map } from 'lodash';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { withSelect } from '@wordpress/data';
import { store as editorStore } from '@wordpress/editor';
import { PreferencesModalSection } from '@wordpress/interface';
/**
* Internal dependencies
*/
import { EnableCustomFieldsOption, EnablePanelOption } from './options';
import { store as editPostStore } from '../../store';
export function MetaBoxesSection( {
areCustomFieldsRegistered,
metaBoxes,
...sectionProps
} ) {
// The 'Custom Fields' meta box is a special case that we handle separately.
const thirdPartyMetaBoxes = filter(
metaBoxes,
( { id } ) => id !== 'postcustom'
);
if ( ! areCustomFieldsRegistered && thirdPartyMetaBoxes.length === 0 ) {
return null;
}
return (
<PreferencesModalSection { ...sectionProps }>
{ areCustomFieldsRegistered && (
<EnableCustomFieldsOption label={ __( 'Custom fields' ) } />
) }
{ map( thirdPartyMetaBoxes, ( { id, title } ) => (
<EnablePanelOption
key={ id }
label={ title }
panelName={ `meta-box-${ id }` }
/>
) ) }
</PreferencesModalSection>
);
}
export default withSelect( ( select ) => {
const { getEditorSettings } = select( editorStore );
const { getAllMetaBoxes } = select( editPostStore );
return {
// This setting should not live in the block editor's store.
areCustomFieldsRegistered:
getEditorSettings().enableCustomFields !== undefined,
metaBoxes: getAllMetaBoxes(),
};
} )( MetaBoxesSection );