Skip to content

feat: Implement simple Project Summary page #71

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

Merged
merged 5 commits into from
Jan 26, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix up navigation
  • Loading branch information
bryphe-coder committed Jan 26, 2022
commit 87b8af0626c46e346473cdccded861ce675df32c
20 changes: 17 additions & 3 deletions site/pages/projects/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import { Column, Table } from "../../components/Table"
import { useUser } from "../../contexts/UserContext"
import { FullScreenLoader } from "../../components/Loader/FullScreenLoader"

import { Project } from "./../../api"
import { Organization, Project } from "./../../api"
import useSWR from "swr"

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

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

if (!me || !projects) {
if (orgsError) {
return <ErrorSummary error={error} />
}

if (!me || !projects || !orgs) {
return <FullScreenLoader />
}

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

// Create a dictionary of organization ID -> organization Name
// Needed to properly construct links to dive into a project
const orgDictionary = orgs.reduce((acc: Record<string, string>, curr: Organization) => {
return {
...acc,
[curr.id]: curr.name,
}
}, {})

const columns: Column<Project>[] = [
{
key: "name",
name: "Name",
renderer: (nameField: string, data: Project) => {
return <Link href={`/projects/${data.organization_id}/${data.id}`}>{nameField}</Link>
return <Link href={`/projects/${orgDictionary[data.organization_id]}/${nameField}`}>{nameField}</Link>
},
},
]
Expand Down