mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
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
This commit is contained in:
@ -19,13 +19,9 @@ 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: projects, 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.
|
||||
const projects = data || []
|
||||
|
||||
if (error) {
|
||||
return <ErrorSummary error={error} />
|
||||
}
|
||||
|
Reference in New Issue
Block a user