Skip to content

Edit page link for preview bar#306

Merged
anareyna merged 38 commits intomainfrom
feat/edit-page
Feb 3, 2026
Merged

Edit page link for preview bar#306
anareyna merged 38 commits intomainfrom
feat/edit-page

Conversation

@anareyna
Copy link
Member

@anareyna anareyna commented Jan 20, 2026

Changes

Adds an “edit page” link to the preview bar that links to the current page record editor (when we have id + __typename), so editors can jump from a preview page straight into the CMS record.

Documentation link

See: https://github.com/voorhoede/head-start/blob/feat/edit-page/docs/preview-mode.md#edit-in-datocms-link

How to test

SCR-20260120-nsbz

Checklist

  • I have performed a self-review of my own code
  • I have made sure that my PR is easy to review (not too big, includes comments)
  • I have made updated relevant documentation files (in project README, docs/, etc)
  • I have added a decision log entry if the change affects the architecture or changes a significant technology
  • I have notified a reviewer

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 20, 2026

Deploying head-start with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3f958a8
Status: ✅  Deploy successful!
Preview URL: https://3685c179.head-start.pages.dev
Branch Preview URL: https://feat-edit-page.head-start.pages.dev

View logs

@anareyna anareyna changed the title Feat/edit page Edit page in DatoCMS link for preview bar Jan 20, 2026
@anareyna anareyna marked this pull request as ready for review January 20, 2026 14:28
Copy link
Contributor

@jurgenbelien jurgenbelien left a comment

Choose a reason for hiding this comment

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

If it weren't for how the PreviewMode works now I think this is a great way to do it. However, since there is already a lot of plumbing in the PreviewMode I'd rather leverage that, meaning showing links to records that are being watched

@anareyna anareyna changed the title Edit page in DatoCMS link for preview bar Edit page link for preview bar Jan 28, 2026
@anareyna anareyna requested a review from jurgenbelien January 29, 2026 08:33
Copy link
Contributor

@jurgenbelien jurgenbelien left a comment

Choose a reason for hiding this comment

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

edit: sorry I wanted to comment instead of approve

}
} else {
entry = await getAstroCollectionEntry(collection, combine({ id, locale }));
entry = await getAstroCollectionEntry(collection, combine({ id, locale })) as BareCollectionEntry<K> | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this necessary? I'm a bit worried about the type assignment

Copy link
Member Author

Choose a reason for hiding this comment

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

updated types ✅

@jurgenbelien jurgenbelien self-requested a review January 29, 2026 09:58
Copy link
Contributor

@jurgenbelien jurgenbelien left a comment

Choose a reason for hiding this comment

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

Looks good but the type reassignments could hint at an underlying issue. Could you explain why this is necessary? I'd rather have no type reassignments at all honestly.

@jurgenbelien jurgenbelien self-requested a review January 29, 2026 11:03

To enable preview mode for a git branch, you must add it to [`config/preview.ts`](../config/preview.ts). Preview branches will deploy as `output: 'server'` rather than `output: 'hybrid'`, ignoring all `getStaticPaths()` and always rendering the page during run-time. The `preview` branch is configured as one of the preview branches and is automatically kept in sync with the `main` branch, so it can be used as preview equivalent, for example from the CMS.

### Local development
Copy link
Member

Choose a reason for hiding this comment

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

Good suggestion. I would format this as a tip to make it clear. And also because otherwise it cuts the current text section on enabling preview mode in two:

> [!TIP]
> To enable preview mode during local development:
> - Make sure your current git branch is included in [`config/preview.ts`](../config/preview.ts).
> - Set `HEAD_START_PREVIEW_SECRET` and `DATOCMS_READONLY_API_TOKEN` in your local `.env`.
> - Enter preview mode via `/api/preview/enter/?secret=...` (or the preview login form).

<a href={ `/api/preview/exit/?location=${Astro.url}` }>exit preview</a>
<div class="preview-mode-actions">
{/* eslint-disable-next-line astro/jsx-a11y/anchor-is-valid */}
<a data-edit-record target="_blank">edit page</a>
Copy link
Member

Choose a reason for hiding this comment

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

We don't know what type of record this will link to. Could be an event or a person or ... . So I would change the text to "edit in CMS".

Copy link
Member

Choose a reason for hiding this comment

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

And since it's a [target="_blank"] I would always add rel="noreferrer noopener".

}

connectedCallback() {
if (!this.editableRecord?.id || !this.editableRecord?.type || !this.#datocmsProject) {
Copy link
Member

Choose a reason for hiding this comment

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

maybe add a const isLinkableRecord = !this.editableRecord?.id || !this.editableRecord?.type || !this.#datocmsProject to make it easier to read?

@anareyna anareyna requested a review from jbmoelker February 3, 2026 09:53
@anareyna anareyna merged commit aa18c42 into main Feb 3, 2026
5 checks passed
@anareyna anareyna deleted the feat/edit-page branch February 3, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments