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

feat: make first tab active by default #19315

Merged
merged 3 commits into from
Feb 18, 2025
Merged

Conversation

retrogtx
Copy link
Contributor

What does this PR do?

Makes the first tab active by default for teams in event types

image

Copy link

vercel bot commented Feb 17, 2025

@retrogtx is attempting to deploy a commit to the cal-staging Team on Vercel.

A member of the Team first needs to authorize it.

@graphite-app graphite-app bot added the community Created by Linear-GitHub Sync label Feb 17, 2025
@graphite-app graphite-app bot requested a review from a team February 17, 2025 03:51
@keithwillcode keithwillcode added the community-interns The team responsible for reviewing, testing and shipping low/medium community PRs label Feb 17, 2025
@dosubot dosubot bot added event-types area: event types, event-types ✨ feature New feature or request labels Feb 17, 2025
Copy link

graphite-app bot commented Feb 17, 2025

Graphite Automations

"Add consumer team as reviewer" took an action on this PR • (02/17/25)

1 reviewer was added to this PR based on Keith Williams's automation.

"Add community label" took an action on this PR • (02/17/25)

1 label was added to this PR based on Keith Williams's automation.

"Add ready-for-e2e label" took an action on this PR • (02/18/25)

1 label was added to this PR based on Keith Williams's automation.

@PeerRich PeerRich added Low priority Created by Linear-GitHub Sync ui area: UI, frontend, button, form, input labels Feb 17, 2025
@retrogtx retrogtx enabled auto-merge (squash) February 17, 2025 14:45
avatar: item.profile.image,
"data-testid": item.profile.name ?? "",
}));
const tabs = eventTypeGroups.map((item, index) => {
Copy link
Contributor

@TusharBhatt1 TusharBhatt1 Feb 18, 2025

Choose a reason for hiding this comment

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

If eventTypeGroups is large (which is expected in most cases) , wrapping the mapping logic in useMemo could improve performance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added a useMemo hook, got an err with that due to early return. but will implement this soon, thanks

Comment on lines 915 to 916
let href = item.teamId ? `/event-types?teamId=${item.teamId}` : "/event-types?noTeam";
// If it's the first tab and no teamId is in the URL, set href to just /event-types
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's remove the noTeam parameter. I don't think it has any use case. Removing it will fix the issue without needing any other changes."

Copy link
Contributor Author

@retrogtx retrogtx Feb 18, 2025

Choose a reason for hiding this comment

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

its because when I pressed the first team member by default, ?noTeam was in the parameter
will implement this too!

Copy link
Contributor

Choose a reason for hiding this comment

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

Just make sure ?noTeam is not required else where

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

upon removing the parameter, it selects both of it upon clicking another team

the parameter must stay ig

Copy link
Contributor

@TusharBhatt1 TusharBhatt1 Feb 18, 2025

Choose a reason for hiding this comment

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

That's because useUrlMatchesCurrentUrl uses includes and not exact matching.
If this is required we can do something like :

const isCurrent = useUrlMatchesCurrentUrl("eventTypes",href) || props?.isActive;

type TypeAllowedValues = "eventTypes";
export const useUrlMatchesCurrentUrl = (type?: TypeAllowedValues, url: string) 
if (type === "eventTypes") {
  return pathnameWithQuery ? pathnameWithQuery === url : false;
}

return pathnameWithQuery ? pathnameWithQuery.includes(url) : false;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just make sure ?noTeam is not required else where

if you click the first tab to make it active, you will get that in url parameter by default
so to make it active I just update the url with it

try it out

image

Copy link
Contributor

@TusharBhatt1 TusharBhatt1 Feb 18, 2025

Choose a reason for hiding this comment

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

Yeah , but the approach I shared above will work without ?noTeam , without affecting other places.
But it would require some prop drilling

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's because useUrlMatchesCurrentUrl uses includes and not exact matching. If this is required we can do something like :

const isCurrent = useUrlMatchesCurrentUrl("eventTypes",href) || props?.isActive;

type TypeAllowedValues = "eventTypes";
export const useUrlMatchesCurrentUrl = (type?: TypeAllowedValues, url: string) 
if (type === "eventTypes") {
  return pathnameWithQuery ? pathnameWithQuery === url : false;
}

return pathnameWithQuery ? pathnameWithQuery.includes(url) : false;

will adding exact matching like this not going to cause issues when applying filters later on

Copy link
Contributor

@TusharBhatt1 TusharBhatt1 Feb 18, 2025

Choose a reason for hiding this comment

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

No , but it may add bit of complications , btw I was just referring to the root cause.
Also I think the current implementation is fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

useMemo has been added btw

@CLAassistant
Copy link

CLAassistant commented Feb 18, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

E2E results are ready!

@retrogtx retrogtx merged commit 0048b2d into calcom:main Feb 18, 2025
32 of 38 checks passed
nayan-bagale pushed a commit to nayan-bagale/cal.com that referenced this pull request Feb 18, 2025
* feat: make first tab active by default

* perf: optimize event types tabs rendering with useMemo

---------

Co-authored-by: Tushar Bhatt <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Created by Linear-GitHub Sync community-interns The team responsible for reviewing, testing and shipping low/medium community PRs event-types area: event types, event-types ✨ feature New feature or request Low priority Created by Linear-GitHub Sync ready-for-e2e ui area: UI, frontend, button, form, input
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants