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

[DASH-638] Improve page load speed for <project>/connect tab by skipping a redirect #5758

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions apps/dashboard/src/@/components/ui/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export function TabPathLinks(props: {
path: string;
exactMatch?: boolean;
isDisabled?: boolean;
isActive?: (pathname: string) => boolean;
}[];
className?: string;
tabContainerClassName?: string;
Expand All @@ -212,9 +213,11 @@ export function TabPathLinks(props: {
links={links.map((l) => ({
name: l.name,
href: l.path,
isActive: l.exactMatch
? pathname === l.path
: pathname.startsWith(l.path),
isActive: l.isActive
? l.isActive(pathname)
: l.exactMatch
? pathname === l.path
: pathname.startsWith(l.path),
isDisabled: l.isDisabled,
}))}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getProject } from "@/api/projects";
import { notFound, redirect } from "next/navigation";
import { redirect } from "next/navigation";

export default async function Page(props: {
params: Promise<{
Expand All @@ -8,11 +7,6 @@ export default async function Page(props: {
}>;
}) {
const params = await props.params;
const project = await getProject(params.team_slug, params.project_slug);

if (!project) {
notFound();
}

redirect(
`/team/${params.team_slug}/${params.project_slug}/connect/in-app-wallets`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getProjects } from "@/api/projects";
import { getTeamNebulaWaitList, getTeams } from "@/api/team";
import { TabPathLinks } from "@/components/ui/tabs";
import { notFound, redirect } from "next/navigation";
import { getValidAccount } from "../../../account/settings/getAccount";
import { TeamHeaderLoggedIn } from "../../components/TeamHeader/team-header-logged-in.client";
import { ProjectTabs } from "./tabs";

export default async function TeamLayout(props: {
children: React.ReactNode;
Expand Down Expand Up @@ -55,39 +55,9 @@ export default async function TeamLayout(props: {
teamsAndProjects={teamsAndProjects}
account={account}
/>
<TabPathLinks
tabContainerClassName="px-4 lg:px-6"
links={[
{
path: `/team/${params.team_slug}/${params.project_slug}`,
exactMatch: true,
name: "Overview",
},
{
path: `/team/${params.team_slug}/${params.project_slug}/connect`,
name: "Connect",
},
{
path: `/team/${params.team_slug}/${params.project_slug}/contracts`,
name: "Contracts",
},
...(isOnNebulaWaitList
? [
{
path: `/team/${params.team_slug}/${params.project_slug}/nebula`,
name: "Nebula",
},
]
: []),
{
path: `/team/${params.team_slug}/${params.project_slug}/insight`,
name: "Insight",
},
{
path: `/team/${params.team_slug}/${params.project_slug}/settings`,
name: "Settings",
},
]}
<ProjectTabs
layoutPath={`/team/${params.team_slug}/${params.project_slug}`}
isOnNebulaWaitList={!!isOnNebulaWaitList}
/>
</div>
<div className="flex grow flex-col">{props.children}</div>
Expand Down
49 changes: 49 additions & 0 deletions apps/dashboard/src/app/team/[team_slug]/[project_slug]/tabs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"use client";

import { TabPathLinks } from "@/components/ui/tabs";

export function ProjectTabs(props: {
layoutPath: string;
isOnNebulaWaitList: boolean;
}) {
const { layoutPath, isOnNebulaWaitList } = props;

return (
<TabPathLinks
tabContainerClassName="px-4 lg:px-6"
links={[
{
path: layoutPath,
exactMatch: true,
name: "Overview",
},
{
// directly link to /in-app-wallets to skip 1 redirect and use `isActive` for checking if the tab is active or not
path: `${layoutPath}/connect/in-app-wallets`,
name: "Connect",
isActive: (path) => path.startsWith(`${layoutPath}/connect`),
Comment on lines +22 to +24
Copy link
Member

Choose a reason for hiding this comment

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

means we have to keep this in mind if we ever want to prioritize another sub-tab

},
{
path: `${layoutPath}/contracts`,
name: "Contracts",
},
...(isOnNebulaWaitList
? [
{
path: `${layoutPath}/nebula`,
name: "Nebula",
},
]
: []),
{
path: `${layoutPath}/insight`,
name: "Insight",
},
{
path: `${layoutPath}/settings`,
name: "Settings",
},
]}
/>
);
}
Loading