Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Site Editor: Add View Link #57153

Merged
merged 3 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions packages/edit-post/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ import FullscreenModeClose from './fullscreen-mode-close';
import HeaderToolbar from './header-toolbar';
import MoreMenu from './more-menu';
import PostPublishButtonOrToggle from './post-publish-button-or-toggle';
import ViewLink from '../view-link';
import MainDashboardButton from './main-dashboard-button';
import { store as editPostStore } from '../../store';
import { unlock } from '../../lock-unlock';

const { PreviewDropdown } = unlock( editorPrivateApis );
const { PostViewLink, PreviewDropdown } = unlock( editorPrivateApis );

const slideY = {
hidden: { y: '-50px' },
Expand Down Expand Up @@ -189,7 +188,7 @@ function Header( {
className="edit-post-header__post-preview-button"
forceIsAutosaveable={ hasActiveMetaboxes }
/>
<ViewLink />
<PostViewLink showIconLabels={ showIconLabels } />
<PostPublishButtonOrToggle
forceIsDirty={ hasActiveMetaboxes }
setEntitiesSavedStatesCallback={
Expand Down
3 changes: 2 additions & 1 deletion packages/edit-site/src/components/header-edit-mode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import {
import { unlock } from '../../lock-unlock';
import { FOCUSABLE_ENTITIES } from '../../utils/constants';

const { PreviewDropdown } = unlock( editorPrivateApis );
const { PostViewLink, PreviewDropdown } = unlock( editorPrivateApis );

export default function HeaderEditMode( { setListViewToggleElement } ) {
const {
Expand Down Expand Up @@ -217,6 +217,7 @@ export default function HeaderEditMode( { setListViewToggleElement } ) {
/>
</div>
) }
<PostViewLink showIconLabels={ showIconLabels } />
<SaveButton />
{ ! isDistractionFree && (
<PinnedItems.Slot scope="core/edit-site" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
import { __ } from '@wordpress/i18n';
import { Button } from '@wordpress/components';
import { external } from '@wordpress/icons';
import { store as editorStore } from '@wordpress/editor';
import { store as coreStore } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import { store as editPostStore } from '../../store';
import { store as editorStore } from '../../store';

export default function ViewLink() {
const { permalink, isPublished, label, showIconLabels } = useSelect(
export default function PostViewLink( { showIconLabels } ) {
const { hasLoaded, permalink, isPublished, label } = useSelect(
( select ) => {
// Grab post type to retrieve the view_item label.
const postTypeSlug = select( editorStore ).getCurrentPostType();
Expand All @@ -24,15 +23,14 @@ export default function ViewLink() {
permalink: select( editorStore ).getPermalink(),
isPublished: select( editorStore ).isCurrentPostPublished(),
label: postType?.labels.view_item,
showIconLabels:
select( editPostStore ).isFeatureActive( 'showIconLabels' ),
hasLoaded: !! postType,
};
},
[]
);

// Only render the view button if the post is published and has a permalink.
if ( ! isPublished || ! permalink ) {
if ( ! isPublished || ! permalink || ! hasLoaded ) {
return null;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/private-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { lock } from './lock-unlock';
import { EntitiesSavedStatesExtensible } from './components/entities-saved-states';
import useBlockEditorSettings from './components/provider/use-block-editor-settings';
import PostPanelRow from './components/post-panel-row';
import PostViewLink from './components/post-view-link';
import PreviewDropdown from './components/preview-dropdown';
import PluginPostExcerpt from './components/post-excerpt/plugin';

Expand All @@ -16,6 +17,7 @@ lock( privateApis, {
ExperimentalEditorProvider,
EntitiesSavedStatesExtensible,
PostPanelRow,
PostViewLink,
PreviewDropdown,
PluginPostExcerpt,

Expand Down
Loading