fix(admin): add publish-date editing - #2201
Conversation
🦋 Changeset detectedLatest commit: 6839ab2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-verification
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
There was a problem hiding this comment.
This is the right change, in the right place. The publish-date field plugs into the existing auxiliary-update path for content metadata, and the backend already has schema and authorization support (publishedAt on contentUpdateBody, gated by content:publish_any in the update route). The frontend correctly limits the control to editor+ users and already-published items, the strings are wrapped for Lingui, the new UI uses logical Tailwind classes, and the added tests cover role gating and the update payload.
I checked the full diff, the backend route (packages/core/src/astro/routes/api/content/[collection]/[id].ts), the content update handler/repository, the Zod schema, the role/permission mapping, and the admin tests. Only one real issue stood out: the isUpdatingPublishedAt flag is derived from the latest variables of a shared updateMutation, so it can flip to false while a publish-date update is still in flight. That clears the input/button disabled state too early and allows duplicate/conflicting submissions when other auxiliary writes (SEO, author, or even a save) happen concurrently.
Overlapping PRsThis PR modifies files that are also changed by other open PRs:
This may cause merge conflicts or duplicated work. A maintainer will coordinate. |
There was a problem hiding this comment.
This is the right change in the right place, and the prior review’s finding is fully addressed. The publish-date field plugs into the existing content update path, the backend already supports publishedAt writes gated by content:publish_any, and the frontend correctly restricts the control to editor+ users on already-published entries.
What I checked:
- Diff coverage:
ContentSettingsPanel,ContentEditor,router.tsx, the admin API client types, the existingdatetime-localhelpers, the changeset, and the added tests. - Backend support:
packages/core/src/astro/routes/api/content/[collection]/[id].tsrequirescontent:publish_anyfor anypublishedAtwrite; thecontentUpdateBodyschema acceptspublishedAt;handleContentUpdatepasses it through toContentRepository.update.content:publish_anymaps to theEDITORrole, which matches the frontend’sROLE_EDITOR = 40check. - Prior issue fixed: The previous problem was that
isUpdatingPublishedAtwas inferred from the latest variables of a sharedupdateMutation, so it could drop tofalsewhile a publish-date update was still in flight if another auxiliary write (SEO, author, etc.) started. The author introduced a dedicatedpublishedAtMutation, andisUpdatingPublishedAtnow trackspublishedAtMutation.isPendingonly. The new router test holds the publish-date PUT open, fires an SEO update, and asserts the publish-date trigger stays disabled — a direct regression test for the prior bug. - Conventions: Strings are Lingui-wrapped (
t\Publish date`,t`Update publish date``); the new layout uses logical/vertical Tailwind spacing; the changeset is concise and user-facing; no new SQL, no new logged-out query path, no justification/reviewer comments added. - Edge cases: The input is disabled during the update; the button is disabled when the value is empty, unchanged, or a request is in flight;
storedPublishedDateis synced back into local state when the item or itspublishedAtchanges; empty/cleared values are not submitted.
There are no blocking issues or convention violations. The implementation is consistent with how scheduling and other auxiliary metadata writes are handled, and the regression test makes the fix durable.
There was a problem hiding this comment.
Thanks for addressing this @masonjames. Just one small timezone issue. datetime-local uses local time, but these helpers treat it as UTC, so users outside UTC will save a shifted publish time.
Could we convert it like the scheduler does with new Date(publishedDate).toISOString()?
There was a problem hiding this comment.
This is the right change in the right place: the backend already accepts publishedAt on the content-update body and gates it behind content:publish_any (EDITOR+), and the frontend correctly restricts the control to published entries for editor+ users. The dedicated publishedAtMutation also fixes the prior concurrency issue where isUpdatingPublishedAt was inferred from a shared mutation's latest variables.
However, on a fresh read I caught a timezone-bug the prior review missed. ContentSettingsPanel displays publishedAt through toDatetimeLocalInputValue, which keeps the value in UTC (2025-01-15T10:30:00.000Z → 2025-01-15T10:30). But the submit handler converts with new Date(publishedDate).toISOString(), which parses the bare datetime-local value as local time. On any non-UTC client the persisted timestamp shifts by the local offset every edit, directly contradicting the datetime-local.ts helper documentation that was added specifically to avoid this mistake. This is a data-integrity regression for a field whose purpose is precise backdating.
The fix is small: use fromDatetimeLocalInputValue instead of new Date(...).toISOString(). The existing test needs to stop stubbing Date and stop asserting the buggy shifted value.
What I checked:
- Diff coverage:
ContentSettingsPanel,ContentEditor,router.tsx, API client type, changeset, and tests. - Backend authorization:
packages/core/src/astro/routes/api/content/[collection]/[id].tsrequirescontent:publish_anyforpublishedAtwrites;content:publish_anymaps toEDITOR(40), matching the frontendROLE_EDITORcheck. - Schema:
contentUpdateBodyacceptspublishedAtas an ISO datetime/null. - Conventions: strings are Lingui-wrapped, layout uses logical Tailwind classes, no new SQL/logged-out query paths, changeset is concise and user-facing.
- The router regression test for concurrent publish-date/SEO updates is a durable test of the prior bug.
|
Your earlier code was right, @masonjames, my suggestion introduced the timezone shift. Could we switch back to |
|
@khoinguyenpham04 no worries! |
There was a problem hiding this comment.
This is the right follow-up: the PR wires the admin publish-date control through the existing backend capability (publishedAt on contentUpdateBody, gated by content:publish_any → Role.EDITOR), uses a dedicated mutation so isUpdatingPublishedAt no longer collides with other auxiliary writes, and restricts the UI to published entries for editor+ users.
The previously flagged timezone regression is fixed:
ContentSettingsPanelnow displayspublishedAtviatoDatetimeLocalInputValueand submits viafromDatetimeLocalInputValue, keeping the value as UTC (2025-01-15T10:30:00.000Z→2025-01-15T10:30→2020-06-01T08:45:00.000Z) instead of re-parsing thedatetime-localstring as local time.- The component test no longer stubs
Dateand asserts the stable UTC output. - The router regression test verifies that publish-date updates fly independently of concurrent SEO updates and that the pending state only disables the publish-date control.
What I checked:
- Authorization parity: frontend uses
ROLE_EDITOR = 40, backendcontent:publish_anymaps toRole.EDITOR(40), and the route rejectspublishedAtwrites without that permission. - Schema:
contentUpdateBody.publishedAtaccepts an ISO datetime/null withoffset: true. - Conventions: the new strings (
Publish date,Update publish date) are Lingui-wrapped, the new layout uses non-directional Tailwind utilities (space-y-2,pt-2), and the changeset is user-facing and concise. - No new SQL, no logged-out route queries, no new indexes, no stale comments introduced.
- Tests cover RTL rendering, role gating, the exact update payload, and concurrent-update isolation.
Everything in the diff is consistent with EmDash’s patterns, and the data-integrity issue from the prior review is resolved. LGTM.
6e95d38 to
9c13c9c
Compare
There was a problem hiding this comment.
This re-review confirms the approved follow-up state still holds. The PR wires the admin publish-date control through the existing backend capability (publishedAt on contentUpdateBody, gated server-side by content:publish_any → Role.EDITOR), uses a separate mutation so the UI can isolate the publish-date pending state, and restricts the field to entries that already have a publishedAt value for editor+ users.
What I re-checked:
- Authorization parity — the route at
packages/core/src/astro/routes/api/content/[collection]/[id].tsrejectspublishedAtwrites unless the actor hascontent:publish_any, which maps toRole.EDITOR(40). The frontend gating uses the sameROLE_EDITOR = 40threshold. - Timezone/data integrity —
toDatetimeLocalInputValueslices the stored UTC ISO value toYYYY-MM-DDTHH:mm, andfromDatetimeLocalInputValueappends:00.000Z, so the persisted timestamp is UTC-stable rather than reinterpreted as local time. - Schema —
contentUpdateBody.publishedAtaccepts an ISO datetime/null withoffset: true. - Conventions — new UI strings (
Publish date,Update publish date) are Lingui-wrapped; layout uses non-directional Tailwind utilities (space-y-2,pt-2); the changeset is concise and user-facing; no newmessages.pochurn. - Cross-cutting concerns — no new SQL, no logged-out-route queries, no new indexes, no stale comments. Tests cover RTL rendering, role gating, the exact
publishedAtpayload, and concurrent-update isolation.
The diff is consistent with EmDash’s existing patterns and the previously-flagged timezone/data-integrity issue is resolved. No blocking or suggestion-level findings remain.
What does this PR do?
Adds a publish-date field to the content settings panel for published entries. Editors and administrators can update the date, while authors retain the existing read-only permissions. The value is normalized to an ISO timestamp and sent through the existing content update endpoint.
Closes #2178
Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runmessages.pochanges except in translation PRs — a workflow extracts catalogs on merge tomain.AI-generated code disclosure
Screenshots / test output
pnpm --filter @emdash-cms/admin exec vitest run tests/components/ContentSettingsPanel.test.tsx tests/router.test.tsx— 32 tests passedpnpm --filter @emdash-cms/admin test— 1,240 tests passedpnpm typecheckpnpm lintpnpm formatThe coverage includes Arabic/RTL rendering, editor authorization, the exact update payload, and concurrent auxiliary updates while a publish-date request remains pending.