Skip to content

Commit

Permalink
Revert "Make order visible if it has a value"
Browse files Browse the repository at this point in the history
This reverts commit 33d0bbf.
  • Loading branch information
jorgefilipecosta committed Jul 16, 2024
1 parent a5898f0 commit 60bb53d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 94 deletions.
2 changes: 1 addition & 1 deletion packages/editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ _Returns_

### PageAttributesOrder

Renders the Page Attributes Order component. A number input in an editor interface for setting the order of a given page.
Renders the Page Attributes Order component. A number input in an editor interface for setting the order of a given page. The component is now not used in core but was kept for backward compatibility.

_Returns_

Expand Down
95 changes: 9 additions & 86 deletions packages/editor/src/components/page-attributes/order.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
/**
* WordPress dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
import { __ } from '@wordpress/i18n';
import {
Button,
Dropdown,
Flex,
FlexBlock,
__experimentalNumberControl as NumberControl,
} from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { useState, useMemo } from '@wordpress/element';
import { __experimentalInspectorPopoverHeader as InspectorPopoverHeader } from '@wordpress/block-editor';
import { useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import PostPanelRow from '../post-panel-row';
import PostTypeSupportCheck from '../post-type-support-check';
import { store as editorStore } from '../../store';

function PageAttributesOrder( { order = 0 } ) {
function PageAttributesOrder() {
const order = useSelect(
( select ) =>
select( editorStore ).getEditedPostAttribute( 'menu_order' ) ?? 0,
[]
);
const { editPost } = useDispatch( editorStore );
const [ orderInput, setOrderInput ] = useState( null );

Expand Down Expand Up @@ -56,6 +57,7 @@ function PageAttributesOrder( { order = 0 } ) {
/**
* Renders the Page Attributes Order component. A number input in an editor interface
* for setting the order of a given page.
* The component is now not used in core but was kept for backward compatibility.
*
* @return {Component} The component to be rendered.
*/
Expand All @@ -66,82 +68,3 @@ export default function PageAttributesOrderWithChecks() {
</PostTypeSupportCheck>
);
}

function PostOrderToggle( { isOpen, onClick } ) {
const order = useSelect(
( select ) =>
select( editorStore ).getEditedPostAttribute( 'menu_order' ) ?? 0,
[]
);
return (
<Button
size="compact"
className="editor-post-order__panel-toggle"
variant="tertiary"
aria-expanded={ isOpen }
// translators: %s: Current post parent.
aria-label={ sprintf( __( 'Change order: %s' ), order ) }
onClick={ onClick }
>
{ order }
</Button>
);
}

export function OrderRow() {
const order = useSelect(
( select ) =>
select( editorStore ).getEditedPostAttribute( 'menu_order' ),
[]
);
// Use internal state instead of a ref to make sure that the component
// re-renders when the popover's anchor updates.
const [ popoverAnchor, setPopoverAnchor ] = useState( null );
// Memoize popoverProps to avoid returning a new object every time.
const popoverProps = useMemo(
() => ( {
// Anchor the popover to the middle of the entire row so that it doesn't
// move around when the label changes.
anchor: popoverAnchor,
placement: 'left-start',
offset: 36,
shift: true,
} ),
[ popoverAnchor ]
);
if ( ! order ) {
return null;
}
return (
<PostPanelRow label={ __( 'Order' ) } ref={ setPopoverAnchor }>
<Dropdown
popoverProps={ popoverProps }
className="editor-post-order__panel-dropdown"
contentClassName="editor-post-order__panel-dialog"
focusOnMount
renderToggle={ ( { isOpen, onToggle } ) => (
<PostOrderToggle isOpen={ isOpen } onClick={ onToggle } />
) }
renderContent={ ( { onClose } ) => (
<div className="editor-post-order">
<InspectorPopoverHeader
title={ __( 'Order' ) }
onClose={ onClose }
/>
<div>
{ __(
'This attribute determines the order of pages in the Pages List block.'
) }
<p>
{ __(
'Pages with the same order value will sorted alphabetically. Negative order values are also supported.'
) }
</p>
</div>
<PageAttributesOrder order={ order } />
</div>
) }
/>
</PostPanelRow>
);
}
8 changes: 1 addition & 7 deletions packages/editor/src/components/page-attributes/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { store as coreStore } from '@wordpress/core-data';
*/
import { store as editorStore } from '../../store';
import PageAttributesCheck from './check';
import { OrderRow } from './order';
import { ParentRow } from './parent';

const PANEL_NAME = 'page-attributes';
Expand All @@ -28,12 +27,7 @@ function AttributesPanel() {
return null;
}

return (
<>
<ParentRow />
<OrderRow />
</>
);
return <ParentRow />;
}

/**
Expand Down

0 comments on commit 60bb53d

Please sign in to comment.