From c44d0369f633e8979f2f28d4c25457afdca075b6 Mon Sep 17 00:00:00 2001 From: Bryan Date: Wed, 9 Feb 2022 09:13:47 -0800 Subject: [PATCH] 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 --- site/pages/projects/index.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/site/pages/projects/index.tsx b/site/pages/projects/index.tsx index 42df98f666..bf67deb525 100644 --- a/site/pages/projects/index.tsx +++ b/site/pages/projects/index.tsx @@ -19,13 +19,9 @@ const ProjectsPage: React.FC = () => { const styles = useStyles() const router = useRouter() const { me, signOut } = useUser(true) - const { data, error } = useSWR("/api/v2/projects") + const { data: projects, error } = useSWR("/api/v2/projects") const { data: orgs, error: orgsError } = useSWR("/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. - const projects = data || [] - if (error) { return }