Skip to content

Commit 3349a4c

Browse files
authored
fix: schedule publish allowed before saving draft (#10461)
### What? In the scheduled publish feature, it is possible to open the modal to schedule publishing a document even before you have saved a draft. This change removes the option to open the drawer to even attempt this. This also fixes an issue if you do not have permission to publish, you cannot schedule publish either. ### Why? There were numerous problems: 1. The schedule publish events would show all other publish events for the collection without an ID in the query 2. Scheduling a publish would not work without an ID for a document to publish ### How? Removes the Schedule Publish menu item and drawer if you are on a collection without an ID or you do not have permission to publish. Without an ID: ![Screenshot 2025-01-08 162850](https://github.com/user-attachments/assets/fae0b8d4-6dac-45d7-a565-63fede7aa372) With an ID: ![Screenshot 2025-01-08 162918](https://github.com/user-attachments/assets/c1f4d4f5-1321-43c1-991d-29747db1685d) Perviously, you would always have the option to Schedule Publish.
1 parent 81c1e47 commit 3349a4c

File tree

1 file changed

+11
-7
lines changed
  • packages/ui/src/elements/PublishButton

1 file changed

+11
-7
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,21 @@ export const PublishButton: React.FC<{ label?: string }> = ({ label: labelProp }
5959
}
6060
}, [collectionSlug, globalSlug, config])
6161

62-
const scheduledPublishEnabled =
63-
typeof entityConfig?.versions?.drafts === 'object' &&
64-
entityConfig?.versions?.drafts.schedulePublish
65-
6662
const hasNewerVersions = unpublishedVersionCount > 0
6763

6864
const canPublish =
6965
hasPublishPermission &&
7066
(modified || hasNewerVersions || !hasPublishedDoc) &&
7167
uploadStatus !== 'uploading'
7268

69+
const scheduledPublishEnabled =
70+
typeof entityConfig?.versions?.drafts === 'object' &&
71+
entityConfig?.versions?.drafts.schedulePublish
72+
73+
const canSchedulePublish = Boolean(
74+
scheduledPublishEnabled && hasPublishPermission && (globalSlug || (collectionSlug && id)),
75+
)
76+
7377
const operation = useOperation()
7478

7579
const disabled = operation === 'update' && !modified
@@ -173,11 +177,11 @@ export const PublishButton: React.FC<{ label?: string }> = ({ label: labelProp }
173177
onClick={publish}
174178
size="medium"
175179
SubMenuPopupContent={
176-
localization || scheduledPublishEnabled
180+
localization || canSchedulePublish
177181
? ({ close }) => {
178182
return (
179183
<React.Fragment>
180-
{scheduledPublishEnabled && (
184+
{canSchedulePublish && (
181185
<PopupList.ButtonGroup key="schedule-publish">
182186
<PopupList.Button onClick={() => [toggleModal(drawerSlug), close()]}>
183187
{t('version:schedulePublish')}
@@ -220,7 +224,7 @@ export const PublishButton: React.FC<{ label?: string }> = ({ label: labelProp }
220224
>
221225
{label}
222226
</FormSubmit>
223-
{scheduledPublishEnabled && isModalOpen(drawerSlug) && <ScheduleDrawer slug={drawerSlug} />}
227+
{canSchedulePublish && isModalOpen(drawerSlug) && <ScheduleDrawer slug={drawerSlug} />}
224228
</React.Fragment>
225229
)
226230
}

0 commit comments

Comments
 (0)