Skip to content

Commit

Permalink
fix(ui): stale doc status when publishing, reverting and unpublishing (
Browse files Browse the repository at this point in the history
…#10405)

### What?
The status indicator was not updating properly when users were clicking
"unpublish" and "revert changes"

### Why?
hasPublishedDoc, unpublishedVersionCount and
mostRecentVersionIsAutosaved states were not being updated properly.

### How?
This PR updates the variables when interacting with the status actions
and sets mostRecentVersionIsAutosaved to false when the publish button
is clicked.

Fixes #9531
  • Loading branch information
JarrodMFlesch authored Jan 8, 2025
1 parent 9701fc6 commit 17e7ee2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/ui/src/elements/Autosave/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const Autosave: React.FC<Props> = ({ id, collection, global: globalDoc })
mostRecentVersionIsAutosaved,
setLastUpdateTime,
setMostRecentVersionIsAutosaved,
setUnpublishedVersionCount,
} = useDocumentInfo()
const queueRef = useRef([])
const isProcessingRef = useRef(false)
Expand Down Expand Up @@ -177,6 +178,7 @@ export const Autosave: React.FC<Props> = ({ id, collection, global: globalDoc })
if (!mostRecentVersionIsAutosaved) {
incrementVersionCount()
setMostRecentVersionIsAutosaved(true)
setUnpublishedVersionCount((prev) => prev + 1)
}
} else {
return res.json()
Expand Down
10 changes: 9 additions & 1 deletion packages/ui/src/elements/PublishButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const PublishButton: React.FC<{ label?: string }> = ({ label: labelProp }
hasPublishedDoc,
hasPublishPermission,
setHasPublishedDoc,
setMostRecentVersionIsAutosaved,
setUnpublishedVersionCount,
unpublishedVersionCount,
uploadStatus,
Expand Down Expand Up @@ -124,8 +125,15 @@ export const PublishButton: React.FC<{ label?: string }> = ({ label: labelProp }
})

setUnpublishedVersionCount(0)
setMostRecentVersionIsAutosaved(false)
setHasPublishedDoc(true)
}, [setHasPublishedDoc, submit, setUnpublishedVersionCount, uploadStatus])
}, [
setHasPublishedDoc,
submit,
setUnpublishedVersionCount,
uploadStatus,
setMostRecentVersionIsAutosaved,
])

const publishSpecificLocale = useCallback(
(locale) => {
Expand Down
19 changes: 15 additions & 4 deletions packages/ui/src/elements/Status/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export const Status: React.FC = () => {
globalSlug,
hasPublishedDoc,
incrementVersionCount,
setHasPublishedDoc,
setMostRecentVersionIsAutosaved,
setUnpublishedVersionCount,
unpublishedVersionCount,
} = useDocumentInfo()
const { toggleModal } = useModal()
Expand Down Expand Up @@ -110,8 +113,14 @@ export const Status: React.FC = () => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
resetForm(data)
toast.success(json.message)

incrementVersionCount()
setMostRecentVersionIsAutosaved(false)

if (action === 'unpublish') {
setHasPublishedDoc(false)
} else if (action === 'revert') {
setUnpublishedVersionCount(0)
}
} else {
toast.error(t('error:unPublishingDocument'))
}
Expand All @@ -128,17 +137,19 @@ export const Status: React.FC = () => {
[
api,
collectionSlug,
incrementVersionCount,
globalSlug,
i18n.language,
id,
i18n.language,
incrementVersionCount,
locale,
resetForm,
revertModalSlug,
serverURL,
setUnpublishedVersionCount,
t,
toggleModal,
revertModalSlug,
unPublishModalSlug,
setHasPublishedDoc,
],
)

Expand Down

0 comments on commit 17e7ee2

Please sign in to comment.