Skip to content

Commit

Permalink
Editor: Fix duplicate save panels
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Jun 26, 2024
1 parent 913ebe0 commit 0e8039b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 28 deletions.
6 changes: 6 additions & 0 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
useHasEditorCanvasContainer,
} from '../editor-canvas-container';
import SaveButton from '../save-button';
import SavePanel from '../save-panel';
import SiteEditorMoreMenu from '../more-menu';
import SiteIcon from '../site-icon';
import useEditorIframeProps from '../block-editor/use-editor-iframe-props';
Expand Down Expand Up @@ -199,6 +200,11 @@ export default function EditSiteEditor( { isLoading } ) {
customSaveButton={
_isPreviewingTheme && <SaveButton size="compact" />
}
customSavePanel={
( _isPreviewingTheme || canvasMode === 'view' ) && (
<SavePanel />
)
}
forceDisableBlockTools={ ! hasDefaultEditorCanvasView }
title={ title }
icon={ icon }
Expand Down
3 changes: 0 additions & 3 deletions packages/edit-site/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import { store as editSiteStore } from '../../store';
import SiteHub from '../site-hub';
import ResizableFrame from '../resizable-frame';
import { unlock } from '../../lock-unlock';
import SavePanel from '../save-panel';
import KeyboardShortcutsRegister from '../keyboard-shortcuts/register';
import KeyboardShortcutsGlobal from '../keyboard-shortcuts/global';
import { useIsSiteEditorLoading } from './hooks';
Expand Down Expand Up @@ -236,8 +235,6 @@ export default function Layout( { route } ) {
</div>
) }
</div>

<SavePanel />
</div>
</>
);
Expand Down
5 changes: 3 additions & 2 deletions packages/editor/src/components/editor-interface/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default function EditorInterface( {
disableIframe,
autoFocus,
customSaveButton,
customSavePanel,
forceDisableBlockTools,
title,
icon,
Expand Down Expand Up @@ -214,7 +215,7 @@ export default function EditorInterface( {
)
}
actions={
! isPreviewMode ? (
customSavePanel || (
<SavePublishPanels
closeEntitiesSavedStates={ closeEntitiesSavedStates }
isEntitiesSavedStatesOpen={
Expand All @@ -225,7 +226,7 @@ export default function EditorInterface( {
}
forceIsDirtyPublishPanel={ forceIsDirty }
/>
) : undefined
)
}
shortcuts={ {
previous: previousShortcut,
Expand Down
53 changes: 30 additions & 23 deletions packages/editor/src/components/save-publish-panels/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,25 @@ export default function SavePublishPanels( {
} ) {
const { closePublishSidebar, togglePublishSidebar } =
useDispatch( editorStore );
const {
publishSidebarOpened,
hasNonPostEntityChanges,
hasPostMetaChanges,
} = useSelect(
( select ) => ( {
publishSidebarOpened:
select( editorStore ).isPublishSidebarOpened(),
hasNonPostEntityChanges:
select( editorStore ).hasNonPostEntityChanges(),
hasPostMetaChanges: unlock(
select( editorStore )
).hasPostMetaChanges(),
} ),
const { publishSidebarOpened, isPublishable, isDirty } = useSelect(
( select ) => {
const {
isPublishSidebarOpened,
isEditedPostPublishable,
isCurrentPostPublished,
isEditedPostDirty,
hasNonPostEntityChanges: _hasNonPostEntityChanges,
} = select( editorStore );
return {
publishSidebarOpened: isPublishSidebarOpened(),
isPublishable:
! isCurrentPostPublished() && isEditedPostPublishable(),
isDirty:
_hasNonPostEntityChanges() ||
isEditedPostDirty() ||
unlock( select( editorStore ) ).hasPostMetaChanges(),
};
},
[]
);

Expand All @@ -62,29 +67,31 @@ export default function SavePublishPanels( {
PostPublishExtension={ PluginPostPublishPanel.Slot }
/>
);
} else if ( hasNonPostEntityChanges || hasPostMetaChanges ) {
} else if ( isPublishable ) {
unmountableContent = (
<div className="editor-layout__toggle-entities-saved-states-panel">
<div className="editor-layout__toggle-publish-panel">
<Button
variant="secondary"
className="editor-layout__toggle-entities-saved-states-panel-button"
onClick={ openEntitiesSavedStates }
className="editor-layout__toggle-publish-panel-button"
onClick={ togglePublishSidebar }
aria-expanded={ false }
>
{ __( 'Open save panel' ) }
{ __( 'Open publish panel' ) }
</Button>
</div>
);
} else {
unmountableContent = (
<div className="editor-layout__toggle-publish-panel">
<div className="editor-layout__toggle-entities-saved-states-panel">
<Button
variant="secondary"
className="editor-layout__toggle-publish-panel-button"
onClick={ togglePublishSidebar }
className="editor-layout__toggle-entities-saved-states-panel-button"
onClick={ openEntitiesSavedStates }
aria-expanded={ false }
disabled={ ! isDirty }
__experimentalIsFocusable
>
{ __( 'Open publish panel' ) }
{ __( 'Open save panel' ) }
</Button>
</div>
);
Expand Down

0 comments on commit 0e8039b

Please sign in to comment.