Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,37 @@ import { useParams, useRouter } from '@tanstack/react-router'
import { useMemo } from 'react'
import { ClusterAvatar, useClusters } from '@qovery/domains/clusters/feature'
import { useOrganization, useOrganizations } from '@qovery/domains/organizations/feature'
import { useProjects } from '@qovery/domains/projects/feature'
import { Avatar } from '@qovery/shared/ui'
import { Separator } from '../header'
import { BreadcrumbItem, type BreadcrumbItemData } from './breadcrumb-item'

export function Breadcrumbs() {
const { buildLocation } = useRouter()
const { organizationId, clusterId } = useParams({ strict: false })
const { organizationId, clusterId, projectId } = useParams({ strict: false })

const { data: organizations = [] } = useOrganizations({
enabled: true,
suspense: true,
})
const { data: organization } = useOrganization({ organizationId, enabled: !!organizationId })
const { data: clusters = [] } = useClusters({ organizationId })
const { data: organization } = useOrganization({ organizationId, enabled: !!organizationId, suspense: true })
const { data: clusters = [] } = useClusters({ organizationId, suspense: true })
const { data: projects = [] } = useProjects({ organizationId, suspense: true })

// Necessary to keep the organization from client by Qovery team
const allOrganizations =
organizations.find((org) => org.id !== organizationId) && organization
? [...organizations, organization]
? [...organizations.filter((org) => org.id !== organizationId), organization]
: organizations

const orgItems: BreadcrumbItemData[] = allOrganizations.map((organization) => ({
id: organization.id,
label: organization.name,
path: buildLocation({ to: '/organization/$organizationId', params: { organizationId: organization.id } }).href,
logo_url: organization.logo_url ?? undefined,
}))
const orgItems: BreadcrumbItemData[] = allOrganizations
.sort((a, b) => a.name.trim().localeCompare(b.name.trim()))
.map((organization) => ({
id: organization.id,
label: organization.name,
path: buildLocation({ to: '/organization/$organizationId', params: { organizationId: organization.id } }).href,
logo_url: organization.logo_url ?? undefined,
}))

const currentOrg = useMemo(
() => orgItems.find((organization) => organization.id === organizationId),
Expand All @@ -43,11 +48,27 @@ export function Breadcrumbs() {
}).href,
}))

const projectItems: BreadcrumbItemData[] = projects
.sort((a, b) => a.name.trim().localeCompare(b.name.trim()))
.map((project) => ({
id: project.id,
label: project.name,
path: buildLocation({
to: '/organization/$organizationId/project/$projectId/overview',
params: { organizationId, projectId: project.id },
}).href,
}))

const currentCluster = useMemo(
() => clusterItems.find((cluster) => cluster.id === clusterId),
[clusterId, clusterItems]
)

const currentProject = useMemo(
() => projectItems.find((project) => project.id === projectId),
[projectId, projectItems]
)

const breadcrumbData: Array<{ item: BreadcrumbItemData; items: BreadcrumbItemData[] }> = []

if (currentOrg) {
Expand Down Expand Up @@ -78,6 +99,16 @@ export function Breadcrumbs() {
})
}

if (currentProject) {
breadcrumbData.push({
item: {
...currentProject,
// prefix: <ProjectAvatar project={projects.find((project) => project.id === projectId)} size="sm" />,
},
items: projectItems,
})
}

return (
<div className="flex items-center gap-2">
{breadcrumbData.map((data, index) => (
Expand Down
3 changes: 3 additions & 0 deletions apps/console-v5/src/app/components/header/header.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Suspense } from 'react'
import { LogoIcon } from '@qovery/shared/ui'
import { Breadcrumbs } from './breadcrumbs/breadcrumbs'
import { UserMenu } from './user-menu/user-menu'
Expand All @@ -21,7 +22,9 @@ export function Header() {
<div className="flex items-center gap-4">
<LogoIcon />
<Separator />
{/* <Suspense fallback={<div>Loading...</div>}> */}
<Breadcrumbs />
{/* </Suspense> */}
<div className="ml-auto">
<UserMenu />
</div>
Expand Down
100 changes: 100 additions & 0 deletions apps/console-v5/src/routeTree.gen.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Navigate, createFileRoute, useParams } from '@tanstack/react-router'

export const Route = createFileRoute(
'/_authenticated/organization/$organizationId/project/$projectId/environment/$environmentId/'
)({
component: RouteComponent,
})

function RouteComponent() {
const { organizationId, projectId, environmentId } = useParams({ strict: false })

return (
<Navigate
to="/organization/$organizationId/project/$projectId/environment/$environmentId/overview"
params={{ organizationId, projectId, environmentId }}
replace
/>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { createFileRoute, useParams } from '@tanstack/react-router'
import { Suspense } from 'react'
import { useEnvironment } from '@qovery/domains/environments/feature'
import { LoaderSpinner } from '@qovery/shared/ui'

export const Route = createFileRoute(
'/_authenticated/organization/$organizationId/project/$projectId/environment/$environmentId/overview'
)({
component: RouteComponent,
})

function EnvironmentOverview() {
const { environmentId } = useParams({ strict: false })
const { data: environment } = useEnvironment({ environmentId, suspense: true })

return <div>Environment: {environment?.name}</div>
}

function RouteComponent() {
return (
<Suspense
fallback={
<div className="flex min-h-screen items-center justify-center">
<LoaderSpinner className="w-6" />
</div>
}
>
<EnvironmentOverview />
</Suspense>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Navigate, createFileRoute, useParams } from '@tanstack/react-router'

export const Route = createFileRoute('/_authenticated/organization/$organizationId/project/$projectId/')({
component: RouteComponent,
})

function RouteComponent() {
const { organizationId, projectId } = useParams({ strict: false })

return (
<Navigate to="/organization/$organizationId/project/$projectId/overview" params={{ organizationId, projectId }} />
)
}
Loading