Skip to content

Commit 7dc5256

Browse files
authored
fix: publish locale with autosave enabled and close dropdown (#8719)
1. Fix publish specific locale option when no published versions exist 2. Close the publish locale dropdown on click
1 parent a22c0e6 commit 7dc5256

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

packages/next/src/views/Version/Restore/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const Restore: React.FC<Props> = ({
100100
className={[canRestoreAsDraft && `${baseClass}__button`].filter(Boolean).join(' ')}
101101
onClick={() => toggleModal(modalSlug)}
102102
size="small"
103-
SubMenuPopupContent={
103+
SubMenuPopupContent={() =>
104104
canRestoreAsDraft && (
105105
<PopupList.ButtonGroup>
106106
<PopupList.Button onClick={() => [setDraft(true), toggleModal(modalSlug)]}>

packages/payload/src/collections/operations/updateByID.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,12 @@ export const updateByIDOperation = async <
309309
}
310310

311311
if (publishSpecificLocale) {
312-
publishedDocWithLocales = await getLatestCollectionVersion({
312+
versionSnapshotResult = await beforeChange({
313+
...beforeChangeArgs,
314+
docWithLocales,
315+
})
316+
317+
const lastPublished = await getLatestCollectionVersion({
313318
id,
314319
config: collectionConfig,
315320
payload,
@@ -318,10 +323,7 @@ export const updateByIDOperation = async <
318323
req,
319324
})
320325

321-
versionSnapshotResult = await beforeChange({
322-
...beforeChangeArgs,
323-
docWithLocales,
324-
})
326+
publishedDocWithLocales = lastPublished ? lastPublished : {}
325327
}
326328

327329
let result = await beforeChange({

packages/ui/src/elements/Button/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,10 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, Props>((
183183
className={disabled ? `${baseClass}--popup-disabled` : ''}
184184
horizontalAlign="right"
185185
noBackground
186+
render={({ close }) => SubMenuPopupContent({ close: () => close() })}
186187
size="large"
187188
verticalAlign="bottom"
188-
>
189-
{SubMenuPopupContent}
190-
</Popup>
189+
/>
191190
</div>
192191
)
193192
}

packages/ui/src/elements/Button/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export type Props = {
2323
round?: boolean
2424
secondaryActions?: secondaryAction | secondaryAction[]
2525
size?: 'large' | 'medium' | 'small'
26-
SubMenuPopupContent?: React.ReactNode
26+
SubMenuPopupContent?: (props: { close: () => void }) => React.ReactNode
2727
to?: string
2828
tooltip?: string
2929
type?: 'button' | 'submit'

packages/ui/src/elements/PublishButton/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export const DefaultPublishButton: React.FC<{ label?: string }> = ({ label: labe
126126
disabled={!canPublish}
127127
onClick={publish}
128128
size="medium"
129-
SubMenuPopupContent={
129+
SubMenuPopupContent={({ close }) =>
130130
localization
131131
? localization.locales.map((locale) => {
132132
const formattedLabel =
@@ -139,7 +139,7 @@ export const DefaultPublishButton: React.FC<{ label?: string }> = ({ label: labe
139139
if (isActive) {
140140
return (
141141
<PopupList.ButtonGroup key={locale.code}>
142-
<PopupList.Button onClick={() => publishSpecificLocale(locale.code)}>
142+
<PopupList.Button onClick={() => [publishSpecificLocale(locale.code), close()]}>
143143
{t('version:publishIn', { locale: formattedLabel || locale.code })}
144144
</PopupList.Button>
145145
</PopupList.ButtonGroup>

0 commit comments

Comments
 (0)