Skip to content

Commit c44d036

Browse files
authored
fix: /projects endpoint returning null instead of empty array (#140)
While working on the projects page, I noticed the `/projects` endpoint would return 'null' instead of an empty array. An empty array would simplify the behavior on the client page. There were already tests in place for this, but they only validated that the item's length is 0... and it turns out `len(nil)` is also `0`. So this does a couple things: - Updates the empty-project tests to check for `NotNil` as well - Update the project endpoints to return an empty array if no rows are returned - Remove the hack in `/projects` page for populating data, as it is no longer needed
1 parent d379767 commit c44d036

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

site/pages/projects/index.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,9 @@ const ProjectsPage: React.FC = () => {
1919
const styles = useStyles()
2020
const router = useRouter()
2121
const { me, signOut } = useUser(true)
22-
const { data, error } = useSWR<Project[] | null, Error>("/api/v2/projects")
22+
const { data: projects, error } = useSWR<Project[] | null, Error>("/api/v2/projects")
2323
const { data: orgs, error: orgsError } = useSWR<Organization[], Error>("/api/v2/users/me/organizations")
2424

25-
// TODO: The API call is currently returning `null`, which isn't ideal
26-
// - it breaks checking for data presence with SWR.
27-
const projects = data || []
28-
2925
if (error) {
3026
return <ErrorSummary error={error} />
3127
}

0 commit comments

Comments
 (0)