-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
46 lines (43 loc) · 1.13 KB
/
index.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
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { useState } from '@wordpress/element';
import { store as blockEditorStore } from '@wordpress/block-editor';
/**
* Internal dependencies
*/
import QueryContent from './query-content';
import QueryPlaceholder from './query-placeholder';
import { PatternSelectionModal } from './pattern-selection';
const QueryEdit = ( props ) => {
const { clientId, attributes } = props;
const [ isPatternSelectionModalOpen, setIsPatternSelectionModalOpen ] =
useState( false );
const hasInnerBlocks = useSelect(
( select ) =>
!! select( blockEditorStore ).getBlocks( clientId ).length,
[ clientId ]
);
const Component = hasInnerBlocks ? QueryContent : QueryPlaceholder;
return (
<>
<Component
{ ...props }
openPatternSelectionModal={ () =>
setIsPatternSelectionModalOpen( true )
}
/>
{ isPatternSelectionModalOpen && (
<PatternSelectionModal
clientId={ clientId }
attributes={ attributes }
setIsPatternSelectionModalOpen={
setIsPatternSelectionModalOpen
}
/>
) }
</>
);
};
export default QueryEdit;