Skip to content

Commit 6d2e7fd

Browse files
committed
fix: dynamic content not appearing when not needed
1 parent 7ab870f commit 6d2e7fd

3 files changed

Lines changed: 59 additions & 77 deletions

File tree

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,15 @@
11
/**
22
* WordPress dependencies.
33
*/
4-
import { __ } from '@wordpress/i18n';
5-
6-
import { BlockControls } from '@wordpress/block-editor';
7-
8-
import {
9-
createSlotFill,
10-
DropdownMenu,
11-
ToolbarGroup
12-
} from '@wordpress/components';
13-
14-
import { createHigherOrderComponent } from '@wordpress/compose';
15-
16-
import { select } from '@wordpress/data';
17-
18-
import { Fragment } from '@wordpress/element';
19-
20-
import { addFilter } from '@wordpress/hooks';
4+
import { createSlotFill } from '@wordpress/components';
215

226
/**
237
* Internal dependencies.
248
*/
259
import './editor.scss';
26-
import './value/index.js';
2710
import './link/index.js';
11+
import './value/index.js';
2812
import './media/index.js';
2913

30-
export const { Slot: OtterDynamicContentSlot, Fill: OtterDynamicContentFill } = createSlotFill( 'OtterDynamicContent' );
31-
32-
export const withDynamicContentSlot = createHigherOrderComponent( ( BlockEdit ) => {
33-
return ( props ) => {
34-
return (
35-
<Fragment>
36-
<BlockControls group="other">
37-
<ToolbarGroup>
38-
<DropdownMenu
39-
icon="database"
40-
label={ __( 'Dynamic Content', 'otter-blocks' ) }
41-
className="o-dynamic-button">
42-
{ ( { onClose } ) => (
43-
<>
44-
<OtterDynamicContentSlot fillProps={ { onClose } } />
45-
</>
46-
) }
47-
</DropdownMenu>
48-
</ToolbarGroup>
49-
</BlockControls>
50-
51-
<BlockEdit { ...props } />
52-
</Fragment>
53-
);
54-
};
55-
}, 'withDynamicContentSlot' );
5614

57-
if ( Boolean( window.themeisleGutenberg.isBlockEditor ) && select( 'core/editor' ) ) {
58-
addFilter(
59-
'editor.BlockEdit',
60-
'themeisle-blocks/dynamic-content/with-dynamic-content-slot',
61-
withDynamicContentSlot
62-
);
63-
}
15+
export const { Slot: OtterDynamicContentSlot, Fill: OtterDynamicContentFill } = createSlotFill( 'OtterDynamicContent' );

src/blocks/plugins/dynamic-content/link/edit.js

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ import { link } from '@wordpress/icons';
88
*/
99
import { __ } from '@wordpress/i18n';
1010

11+
import { BlockControls } from '@wordpress/block-editor';
1112

1213
import {
1314
Modal,
14-
MenuItem
15+
MenuItem,
16+
DropdownMenu,
17+
ToolbarGroup
1518
} from '@wordpress/components';
1619

1720
import { useSelect } from '@wordpress/data';
@@ -31,9 +34,9 @@ import {
3134
name,
3235
supportedBlocks
3336
} from './index.js';
34-
import { OtterDynamicContentFill } from '../index.js';
3537
import Fields from './fields.js';
3638
import InlineControls from '../components/inline-controls.js';
39+
import { OtterDynamicContentSlot } from '../index.js';
3740

3841
const Edit = ({
3942
isActive,
@@ -106,20 +109,31 @@ const Edit = ({
106109
return (
107110
<Fragment>
108111
{ Boolean( window.themeisleGutenberg.hasModule.dynamicContent ) && (
109-
<OtterDynamicContentFill>
110-
{ ({ onClose }) => (
111-
<MenuItem
112-
icon={ link }
113-
onClick={ () => {
114-
setOpen( true );
115-
if ( onClose ) { onClose(); }
116-
} }
117-
className="o-dynamic-button"
118-
>
119-
{ __( 'Dynamic Link', 'otter-blocks' ) }
120-
</MenuItem>
121-
)}
122-
</OtterDynamicContentFill>
112+
<BlockControls group="other">
113+
<ToolbarGroup>
114+
<DropdownMenu
115+
icon="database"
116+
label={ __( 'Dynamic Content', 'otter-blocks' ) }
117+
className="o-dynamic-button">
118+
{ ( { onClose } ) => (
119+
<>
120+
<OtterDynamicContentSlot fillProps={ { onClose } } />
121+
122+
<MenuItem
123+
icon={ link }
124+
onClick={ () => {
125+
setOpen( true );
126+
if ( onClose ) { onClose(); }
127+
} }
128+
className="o-dynamic-button"
129+
>
130+
{ __( 'Dynamic Link', 'otter-blocks' ) }
131+
</MenuItem>
132+
</>
133+
) }
134+
</DropdownMenu>
135+
</ToolbarGroup>
136+
</BlockControls>
123137
) }
124138

125139
{ isOpen && (

src/blocks/plugins/dynamic-content/link/index.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import { BlockControls } from '@wordpress/block-editor';
1313
import { registerFormatType } from '@wordpress/rich-text';
1414

1515
import {
16+
MenuItem,
17+
DropdownMenu,
1618
Popover,
17-
ToolbarButton,
1819
ToolbarGroup
1920
} from '@wordpress/components';
2021

@@ -39,6 +40,7 @@ import {
3940
getObjectFromQueryString,
4041
getQueryStringFromObject
4142
} from '../../../helpers/helper-functions.js';
43+
import { OtterDynamicContentSlot } from '../index.js';
4244

4345
export const name = 'themeisle-blocks/dynamic-link';
4446

@@ -134,17 +136,31 @@ const DynamicLinkControl = ({
134136
return (
135137
<Fragment>
136138
{ children }
137-
138-
<BlockControls>
139+
<BlockControls group="other">
139140
<ToolbarGroup>
140-
<ToolbarButton
141-
name="dynamic-link"
142-
icon={ link }
143-
title={ __( 'Dynamic Link', 'otter-blocks' ) }
144-
ref={ buttonRef }
145-
onClick={ () => setOpen( ! isOpen ) }
141+
<DropdownMenu
142+
icon="database"
143+
label={ __( 'Dynamic Content', 'otter-blocks' ) }
146144
className="o-dynamic-button"
147-
/>
145+
ref={ buttonRef }
146+
>
147+
{ ( { onClose } ) => (
148+
<>
149+
<OtterDynamicContentSlot fillProps={ { onClose } } />
150+
151+
<MenuItem
152+
icon={ link }
153+
onClick={ () => {
154+
setOpen( true );
155+
if ( onClose ) { onClose(); }
156+
} }
157+
className="o-dynamic-button"
158+
>
159+
{ __( 'Dynamic Link', 'otter-blocks' ) }
160+
</MenuItem>
161+
</>
162+
) }
163+
</DropdownMenu>
148164
</ToolbarGroup>
149165
</BlockControls>
150166

0 commit comments

Comments
 (0)