Skip to content

Commit 87b8af0

Browse files
committed
Fix up navigation
1 parent c158fcb commit 87b8af0

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

site/pages/projects/index.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ import { Column, Table } from "../../components/Table"
1212
import { useUser } from "../../contexts/UserContext"
1313
import { FullScreenLoader } from "../../components/Loader/FullScreenLoader"
1414

15-
import { Project } from "./../../api"
15+
import { Organization, Project } from "./../../api"
1616
import useSWR from "swr"
1717

1818
const ProjectsPage: React.FC = () => {
1919
const styles = useStyles()
2020
const router = useRouter()
2121
const { me, signOut } = useUser(true)
2222
const { data, error } = useSWR<Project[] | null, Error>("/api/v2/projects")
23+
const { data: orgs, error: orgsError } = useSWR<Organization[], Error>("/api/v2/users/me/organizations")
2324

2425
// TODO: The API call is currently returning `null`, which isn't ideal
2526
// - it breaks checking for data presence with SWR.
@@ -29,7 +30,11 @@ const ProjectsPage: React.FC = () => {
2930
return <ErrorSummary error={error} />
3031
}
3132

32-
if (!me || !projects) {
33+
if (orgsError) {
34+
return <ErrorSummary error={error} />
35+
}
36+
37+
if (!me || !projects || !orgs) {
3338
return <FullScreenLoader />
3439
}
3540

@@ -42,12 +47,21 @@ const ProjectsPage: React.FC = () => {
4247
onClick: createProject,
4348
}
4449

50+
// Create a dictionary of organization ID -> organization Name
51+
// Needed to properly construct links to dive into a project
52+
const orgDictionary = orgs.reduce((acc: Record<string, string>, curr: Organization) => {
53+
return {
54+
...acc,
55+
[curr.id]: curr.name,
56+
}
57+
}, {})
58+
4559
const columns: Column<Project>[] = [
4660
{
4761
key: "name",
4862
name: "Name",
4963
renderer: (nameField: string, data: Project) => {
50-
return <Link href={`/projects/${data.organization_id}/${data.id}`}>{nameField}</Link>
64+
return <Link href={`/projects/${orgDictionary[data.organization_id]}/${nameField}`}>{nameField}</Link>
5165
},
5266
},
5367
]

0 commit comments

Comments
 (0)