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
Add pre-publish sidebar #44331
Merged
Merged
Add pre-publish sidebar #44331
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
519a84f
Add prepublish sidebar
octaedro ed9e310
Add openPrepublishSidebar to store
octaedro 8a4a70c
Add changelog
octaedro d2c6132
Rename modal and small refactor
octaedro f259ff5
Add feature flag
octaedro e8cbf8f
Move prepublish sidebar
octaedro b924ed0
change import path
octaedro 9edb35c
Rename classes
octaedro 18e0c42
Fix width
octaedro 69e80d5
Fix styles
octaedro 6a1ed97
Rename prepublish panel
octaedro f65cf26
Rename div class
octaedro 45fed90
Remove onSuccess from PublishButton
octaedro f4f3eed
Fix panel position
octaedro 9ae966b
Use actions instead of sidebar
octaedro 54d8199
Add wc-admin changelog
octaedro 1554447
Move changelog
octaedro 6ce7d48
Fix lint
octaedro File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
packages/js/product-editor/changelog/add-43704_prepublish_sidebar_modal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: add | ||
|
||
Add prepublish panel #44331 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/js/product-editor/src/components/prepublish-panel/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './prepublish-button'; | ||
export * from './prepublish-panel'; | ||
export * from './types'; |
65 changes: 65 additions & 0 deletions
65
packages/js/product-editor/src/components/prepublish-panel/prepublish-button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { Button } from '@wordpress/components'; | ||
import { createElement } from '@wordpress/element'; | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
import type { Product } from '@woocommerce/data'; | ||
import { recordEvent } from '@woocommerce/tracks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as productEditorUiStore } from '../../store/product-editor-ui'; | ||
import { PrepublishButtonProps } from './types'; | ||
import { useValidations } from '../../contexts/validation-context'; | ||
import { TRACKS_SOURCE } from '../../constants'; | ||
|
||
export function PrepublishButton( { | ||
productId, | ||
productType = 'product', | ||
}: PrepublishButtonProps ) { | ||
const { openPrepublishPanel } = useDispatch( productEditorUiStore ); | ||
const { isValidating } = useValidations< Product >(); | ||
const { isSaving, isDirty } = useSelect( | ||
( select ) => { | ||
const { | ||
// @ts-expect-error There are no types for this. | ||
isSavingEntityRecord, | ||
// @ts-expect-error There are no types for this. | ||
hasEditsForEntityRecord, | ||
} = select( 'core' ); | ||
|
||
return { | ||
isSaving: isSavingEntityRecord< boolean >( | ||
'postType', | ||
productType, | ||
productId | ||
), | ||
isDirty: hasEditsForEntityRecord( | ||
'postType', | ||
productType, | ||
productId | ||
), | ||
}; | ||
}, | ||
[ productId, productType ] | ||
); | ||
|
||
const isBusy = isSaving || isValidating; | ||
const isDisabled = isBusy || ! isDirty; | ||
|
||
return ( | ||
<Button | ||
onClick={ () => { | ||
recordEvent( 'product_prepublish', { source: TRACKS_SOURCE } ); | ||
openPrepublishPanel(); | ||
} } | ||
isBusy={ isBusy } | ||
aria-disabled={ isDisabled } | ||
children={ __( 'Add', 'woocommerce' ) } | ||
variant={ 'primary' } | ||
/> | ||
); | ||
} |
62 changes: 62 additions & 0 deletions
62
packages/js/product-editor/src/components/prepublish-panel/prepublish-panel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { createElement } from '@wordpress/element'; | ||
import { Button } from '@wordpress/components'; | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
import { recordEvent } from '@woocommerce/tracks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { PublishButton } from '../header/publish-button'; | ||
import { PrepublishPanelProps } from './types'; | ||
import { store as productEditorUiStore } from '../../store/product-editor-ui'; | ||
import { TRACKS_SOURCE } from '../../constants'; | ||
|
||
export function PrepublishPanel( { | ||
productId, | ||
productType = 'product', | ||
title = __( 'Are you ready to add this product?', 'woocommerce' ), | ||
description = __( | ||
'Double-check your settings before sharing this product with customers.', | ||
'woocommerce' | ||
), | ||
}: PrepublishPanelProps ) { | ||
const lastPersistedProduct = useSelect( | ||
( select ) => { | ||
const { getEntityRecord } = select( 'core' ); | ||
return getEntityRecord( 'postType', productType, productId ); | ||
}, | ||
[ productType, productId ] | ||
); | ||
|
||
const { closePrepublishPanel } = useDispatch( productEditorUiStore ); | ||
|
||
return ( | ||
<div className="woocommerce-product-publish-panel"> | ||
<div className="woocommerce-product-publish-panel__header"> | ||
<PublishButton | ||
productType={ productType } | ||
productStatus={ lastPersistedProduct?.status } | ||
/> | ||
<Button | ||
variant={ 'secondary' } | ||
onClick={ () => { | ||
recordEvent( 'product_prepublish_cancel', { | ||
source: TRACKS_SOURCE, | ||
} ); | ||
closePrepublishPanel(); | ||
} } | ||
> | ||
{ __( 'Cancel', 'woocommerce' ) } | ||
</Button> | ||
</div> | ||
<div className="woocommerce-product-publish-panel__title"> | ||
<h4>{ title }</h4> | ||
<span>{ description }</span> | ||
</div> | ||
</div> | ||
); | ||
} |
56 changes: 56 additions & 0 deletions
56
packages/js/product-editor/src/components/prepublish-panel/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
.woocommerce-product-publish-panel { | ||
right: 0; | ||
left: 0; | ||
overflow: auto; | ||
position: fixed; | ||
|
||
@include break-medium() { | ||
left: auto; | ||
width: $sidebar-width + $border-width + 6px; | ||
transform: translateX(+100%); | ||
animation: product-publish-panel__slide-in-animation 0.1s forwards; | ||
@include reduce-motion("animation"); | ||
|
||
body.is-fullscreen-mode & { | ||
top: 0; | ||
} | ||
|
||
// Keep it open on focus to avoid conflict with navigate-regions animation. | ||
[role="region"]:focus & { | ||
transform: translateX(0%); | ||
} | ||
} | ||
|
||
&__header { | ||
background: $white; | ||
height: $header-height + $border-width; | ||
display: flex; | ||
align-items: center; | ||
gap: 8px; | ||
padding: 0 $grid-unit-20; | ||
|
||
> button { | ||
flex: 1; | ||
} | ||
|
||
.components-button { | ||
width: 100%; | ||
justify-content: center; | ||
} | ||
} | ||
|
||
&__title { | ||
padding: $grid-unit-20; | ||
h4 { | ||
font-size: 14px; | ||
line-height: 20px; | ||
margin: 8px 0; | ||
} | ||
} | ||
} | ||
|
||
@keyframes product-publish-panel__slide-in-animation { | ||
100% { | ||
transform: translateX(0%); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/js/product-editor/src/components/prepublish-panel/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export type PrepublishPanelProps = { | ||
productId: number; | ||
productType: string; | ||
title?: string; | ||
description?: string; | ||
}; | ||
|
||
export type PrepublishButtonProps = { | ||
productId: number; | ||
productType: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears that
sidebar
is used for the actual collapsable sidebar, we may want to use theactions
input here, similar to GB. And if we do add an actual expandable/collapsable sidebar we can add it here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call! I did it in the commit 9ae966b