Skip to content
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

CollectiveDetails modal Back link navigation #10551

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

kewitz
Copy link
Contributor

@kewitz kewitz commented Jul 15, 2024

Adds a "Back" button when navigating within the CollectiveDetails modal.
This is a naive prototype of navigation history.

simplescreenrecorder-2024-07-15_13.24.45.mp4

@kewitz kewitz self-assigned this Jul 15, 2024
Copy link

vercel bot commented Jul 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
opencollective-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 15, 2024 11:25am
opencollective-styleguide ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 15, 2024 11:25am

@kewitz kewitz requested a review from Betree July 15, 2024 11:25
Copy link
Member

@Betree Betree left a comment

Choose a reason for hiding this comment

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

It would be great to link to the original conversations/issues to better understand the problem we're trying to solve.

The history pattern is well implemented.

Without more context, it however looks like a complex approach to only partially solve the problem: as far as I understand it, what we want is the ability to quickly go back to the parent when clicking on a children from the collective details.
But then, why only look at the history? If I send you a link like https://opencollective-frontend-git-feat-navhistory-opencollective.vercel.app/dashboard/opensource/hosted-collectives/53kzxy4v-07wlr6m9-klepmj9n-o8agdbe5, you'll probably want to see a link at the top saying Go back to {parent}'s details.

A simpler approach would therefore be to simply replace the header with:

<div className='mb-10'>
  <h1 className="text-2xl font-bold">
    <FormattedMessage defaultMessage="Collective's overview" id="28uZ0u" />
  </h1>
  {isChild && (
    <Link href={linkToParentModal} className="text-xs text-blue-700 hover:underline">
      &larr; Back to {collective.parent.name}
    </Link>
  )}
</div>

Comment on lines +124 to +133
const history =
url === state.history.slice(-1)[0]
? // Do not repeat the same URL
state.history
: url === state.history.slice(-2)[0]
? // If returning, pop the last URL
state.history.slice(0, -1)
: // Else, keep the last 10 URLs visited
[...state.history, url].slice(-10);
return { history };
Copy link
Member

Choose a reason for hiding this comment

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

🍨 Personal preference: I tend to find if/else if blocks cleaners than nested ternaries for this kind of long condition.

@@ -462,6 +464,8 @@ const CollectiveDetails = ({
const isHostedCollective = host && collective?.host?.id === host?.id;
const isLoading = loading || loadingCollectiveInfo;
const isChild = !!collective?.parent?.id;
const lastUrl = history[history.length - 2];
const backToUrl = /\/dashboard\/[\w\d-]+\/(hosted|all)-collectives\/[\w\d-]{35}/i.test(lastUrl) ? lastUrl : null;
Copy link
Member

@Betree Betree Jul 16, 2024

Choose a reason for hiding this comment

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

Testing string URLs with a regex is always a bit risky. A safer approach is to first parse it:

const parsedUrl = new URL(url); // TODO: Handle parse exceptions
const regex = /^{regexContent}$/; // Regex with start + end
return regex.test(parsedUrl.pathname);

@kewitz
Copy link
Contributor Author

kewitz commented Jul 18, 2024

@Betree this comes from different conversations and perhaps there's no silver bullet for this issue.

In the past, we raised with @gustavlrsn the issue of drawer navigation and the requirement to have a generic way to move between multiple/different drawer contents. This is a generic issue: opening event details from a collective details drawer, opening collective details from an expense details drawer, etc...

This implementation is a prototype to solve one of these issues, but I'm not sure if this is exactly what we want TBH.

@Betree
Copy link
Member

Betree commented Jul 18, 2024

@Betree this comes from different conversations and perhaps there's no silver bullet for this issue.

In the past, we raised with @gustavlrsn the issue of drawer navigation and the requirement to have a generic way to move between multiple/different drawer contents. This is a generic issue: opening event details from a collective details drawer, opening collective details from an expense details drawer, etc...

This implementation is a prototype to solve one of these issues, but I'm not sure if this is exactly what we want TBH.

Do we have other cases today of drawers opening other drawers?

@kewitz
Copy link
Contributor Author

kewitz commented Jul 22, 2024

@Betree not right now, but ideally:

  • Transactions drawer would be able to open Expense and Order details without redirecting to the Collective page
  • Transactions drawer would be able to jump to another transaction details without requiring the user to close the drawer and open another one
  • Transactions, Order, and Expense drawers would be able to open hosted collective details

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.

2 participants