Skip to content

feat(ui): add document link to drawer #12036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 5, 2025

Conversation

tak-amboss
Copy link
Contributor

What?

Adds an option to open the current document in a new tab when opened in a drawer.

Why?

There is currently no direct way to open a document when opened in a drawer. However, sometimes editors want to edit one or multiple documents from relationships independently of the current edit view and need an easy option to open these separately.

How?

Converts the document id to a link if in drawer context.

image

@JarrodMFlesch
Copy link
Contributor

Hey thanks for this! My only concern is that this only works for ID's and not useAsTitle titles. For that you would need to adjust the RenderTitle component. But I am wondering if just having an external link icon (which I think we already have) that users can click would be easier. @tylandavis what do you think?

@tylandavis
Copy link
Member

My only concern is that this only works for ID's and not useAsTitle titles.

I believe inside a drawer, we always render the ID: 96776asd9876asdf9asdf component regardless of useAsTitle (the example above does) as well as custom IDs, so I think turning this into a clickable link is a good move as it doesn't add extra components to the view.

A couple UX things that come to my mind:

  • If I made edits and then click the link to open in a new tab, what happens to my edits?
    • Could probably show the unsaved changes modal.
  • When opening a new tab, should the drawer close? I don't know that it would be good to have the related document's form open in two places.

@tak-amboss
Copy link
Contributor Author

If I made edits and then click the link to open in a new tab, what happens to my edits?

  • Could probably show the unsaved changes modal.

The leave page modal in general doesn't show if a link is opened in a new tab, because you're technically not leaving the page. So if you open it in a new tab, you will then still have the option to either continue editing / saving or closing the drawer which would then trigger the leave page modal as currently.

When opening a new tab, should the drawer close? I don't know that it would be good to have the related document's form open in two places.

I personally don't think a link which opens in a new tab should have additional side effects. A "close drawer and open in new tab"-action would IMO be a different thing.

@tak-amboss tak-amboss force-pushed the feat-open-in-new-tab-link branch from 6fabec2 to 2de5f8c Compare April 15, 2025 08:06
@tak-amboss tak-amboss force-pushed the feat-open-in-new-tab-link branch 2 times, most recently from bbf97e6 to bd98758 Compare April 15, 2025 08:29
Copy link
Member

@jacobsfletch jacobsfletch left a comment

Choose a reason for hiding this comment

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

One general point of discussion here is that the link should probably not open in a new tab by default, and instead behave as any other anchor. This way the user could cmd+click, etc. in order to open in a new tab as expected. Some users might actually want to directly navigate to the document anyway.

This also means that we need to ensure that the LeaveWithoutSaving modal is activated even when the drawer's form is modified and the user attempts to navigate away.

Besides that, a couple of small changes needed here. I think overall this is a good change.

@tak-amboss
Copy link
Contributor Author

Thanks @jacobsfletch . I addressed your comments and added e2e tests to ensure that the link can actually be opened in both the same and in a new tab and that the leave page modal shows when necessary.

@tak-amboss tak-amboss requested a review from jacobsfletch May 2, 2025 19:48
@jacobsfletch jacobsfletch changed the title feat(ui): add option to open document in a new tab from drawer feat(ui): add document link to drawer May 5, 2025
@jacobsfletch jacobsfletch merged commit 292b462 into payloadcms:main May 5, 2025
78 checks passed
Copy link
Contributor

github-actions bot commented May 5, 2025

🚀 This is included in version v3.37.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants