Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,20 @@
* WordPress dependencies
*/
import { useSelect, useDispatch } from '@wordpress/data';
import { useViewportMatch } from '@wordpress/compose';
import { Button } from '@wordpress/components';
import { store as preferencesStore } from '@wordpress/preferences';
import { PinnedItems } from '@wordpress/interface';
import { __, _x } from '@wordpress/i18n';
import { seen } from '@wordpress/icons';
import { store as interfaceStore } from '@wordpress/interface';
import { __, _x, isRTL } from '@wordpress/i18n';
import { drawerLeft, drawerRight, seen } from '@wordpress/icons';

/**
* Internal dependencies
*/
import HeaderSkeleton from '../header/header-skeleton';
import MoreMenu from '../more-menu';
import PostPreviewButton from '../post-preview-button';
import PreviewDropdown from '../preview-dropdown';
import RevisionsSlider from './revisions-slider';
import { store as editorStore } from '../../store';
import {
TEMPLATE_PART_POST_TYPE,
PATTERN_POST_TYPE,
NAVIGATION_POST_TYPE,
} from '../../store/constants';
import { sidebars } from '../sidebar/constants';
import { unlock } from '../../lock-unlock';

/**
Expand All @@ -34,32 +27,24 @@ import { unlock } from '../../lock-unlock';
* @return {React.JSX.Element} The revisions header component.
*/
function RevisionsHeader( { showDiff, onToggleDiff } ) {
const isWideViewport = useViewportMatch( 'large' );
const { postType, showIconLabels, currentRevisionId } = useSelect(
( select ) => {
const { get: getPreference } = select( preferencesStore );
const { getCurrentPostType } = select( editorStore );

return {
postType: getCurrentPostType(),
showIconLabels: getPreference( 'core', 'showIconLabels' ),
currentRevisionId: unlock(
select( editorStore )
).getCurrentRevisionId(),
};
},
[]
);
const { currentRevisionId, sidebarIsOpened } = useSelect( ( select ) => {
return {
currentRevisionId: unlock(
select( editorStore )
).getCurrentRevisionId(),
sidebarIsOpened:
!! select( interfaceStore ).getActiveComplementaryArea(
'core'
),
};
}, [] );

const { setCurrentRevisionId, restoreRevision } = unlock(
useDispatch( editorStore )
);

const disablePreviewOption = [
NAVIGATION_POST_TYPE,
TEMPLATE_PART_POST_TYPE,
PATTERN_POST_TYPE,
].includes( postType );
const { enableComplementaryArea, disableComplementaryArea } =
useDispatch( interfaceStore );

const canRestore = !! currentRevisionId;

Expand All @@ -85,13 +70,26 @@ function RevisionsHeader( { showDiff, onToggleDiff } ) {
center={ <RevisionsSlider /> }
settings={
<>
<PreviewDropdown disabled={ disablePreviewOption } />

<PostPreviewButton className="editor-header__post-preview-button" />

{ ( isWideViewport || ! showIconLabels ) && (
<PinnedItems.Slot scope="core" />
) }
<Button
__next40pxDefaultSize
icon={ isRTL() ? drawerLeft : drawerRight }
label={ _x( 'Settings', 'panel button label' ) }
isPressed={ sidebarIsOpened }
aria-expanded={ sidebarIsOpened }
onClick={ () => {
if ( sidebarIsOpened ) {
disableComplementaryArea( 'core' );
} else {
enableComplementaryArea(
'core',
sidebars.document
);
}
} }
size="compact"
/>

<Button
__next40pxDefaultSize
Expand Down
Loading