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

fix: handle publish locale with autosave enabled and close dropdown #8719

Merged
merged 4 commits into from
Nov 6, 2024
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
2 changes: 1 addition & 1 deletion packages/next/src/views/Version/Restore/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const Restore: React.FC<Props> = ({
className={[canRestoreAsDraft && `${baseClass}__button`].filter(Boolean).join(' ')}
onClick={() => toggleModal(modalSlug)}
size="small"
SubMenuPopupContent={
SubMenuPopupContent={() =>
canRestoreAsDraft && (
<PopupList.ButtonGroup>
<PopupList.Button onClick={() => [setDraft(true), toggleModal(modalSlug)]}>
Expand Down
12 changes: 7 additions & 5 deletions packages/payload/src/collections/operations/updateByID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,12 @@ export const updateByIDOperation = async <TSlug extends CollectionSlug>(
}

if (publishSpecificLocale) {
publishedDocWithLocales = await getLatestCollectionVersion({
versionSnapshotResult = await beforeChange({
...beforeChangeArgs,
docWithLocales,
})

const lastPublished = await getLatestCollectionVersion({
id,
config: collectionConfig,
payload,
Expand All @@ -305,10 +310,7 @@ export const updateByIDOperation = async <TSlug extends CollectionSlug>(
req,
})

versionSnapshotResult = await beforeChange({
...beforeChangeArgs,
docWithLocales,
})
publishedDocWithLocales = lastPublished ? lastPublished : {}
}

let result = await beforeChange({
Expand Down
5 changes: 2 additions & 3 deletions packages/ui/src/elements/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,10 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, Props>((
className={disabled ? `${baseClass}--popup-disabled` : ''}
horizontalAlign="right"
noBackground
render={({ close }) => SubMenuPopupContent({ close: () => close() })}
size="large"
verticalAlign="bottom"
>
{SubMenuPopupContent}
</Popup>
/>
</div>
)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/elements/Button/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type Props = {
round?: boolean
secondaryActions?: secondaryAction | secondaryAction[]
size?: 'large' | 'medium' | 'small'
SubMenuPopupContent?: React.ReactNode
SubMenuPopupContent?: (props: { close: () => void }) => React.ReactNode
to?: string
tooltip?: string
type?: 'button' | 'submit'
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/elements/PublishButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const DefaultPublishButton: React.FC<{ label?: string }> = ({ label: labe
disabled={!canPublish}
onClick={publish}
size="medium"
SubMenuPopupContent={
SubMenuPopupContent={({ close }) =>
localization
? localization.locales.map((locale) => {
const formattedLabel =
Expand All @@ -139,7 +139,7 @@ export const DefaultPublishButton: React.FC<{ label?: string }> = ({ label: labe
if (isActive) {
return (
<PopupList.ButtonGroup key={locale.code}>
<PopupList.Button onClick={() => publishSpecificLocale(locale.code)}>
<PopupList.Button onClick={() => [publishSpecificLocale(locale.code), close()]}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The array is a bit strange, probably should be avoided. I'd expect it to be onClick={() => { publishSpecificLocale(locale.code); close(); }}> or similar.

{t('version:publishIn', { locale: formattedLabel || locale.code })}
</PopupList.Button>
</PopupList.ButtonGroup>
Expand Down