Skip to content

Commit

Permalink
Edit Post: Refactor 'MetaBoxVisibility' component (#67265)
Browse files Browse the repository at this point in the history
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: ntsekouras <[email protected]>
  • Loading branch information
3 people authored Nov 25, 2024
1 parent b1b77f3 commit 66d117f
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions packages/edit-post/src/components/meta-boxes/meta-box-visibility.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { withSelect } from '@wordpress/data';
import { useEffect } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import { store as editorStore } from '@wordpress/editor';

class MetaBoxVisibility extends Component {
componentDidMount() {
this.updateDOM();
}

componentDidUpdate( prevProps ) {
if ( this.props.isVisible !== prevProps.isVisible ) {
this.updateDOM();
}
}

updateDOM() {
const { id, isVisible } = this.props;
export default function MetaBoxVisibility( { id } ) {
const isVisible = useSelect(
( select ) => {
return select( editorStore ).isEditorPanelEnabled(
`meta-box-${ id }`
);
},
[ id ]
);

useEffect( () => {
const element = document.getElementById( id );
if ( ! element ) {
return;
Expand All @@ -29,13 +26,7 @@ class MetaBoxVisibility extends Component {
} else {
element.classList.add( 'is-hidden' );
}
}
}, [ id, isVisible ] );

render() {
return null;
}
return null;
}

export default withSelect( ( select, { id } ) => ( {
isVisible: select( editorStore ).isEditorPanelEnabled( `meta-box-${ id }` ),
} ) )( MetaBoxVisibility );

1 comment on commit 66d117f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 66d117f.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12006963598
📝 Reported issues:

Please sign in to comment.