Skip to content

refactor: Fix front-end lint issues #347

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 7 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion site/components/Form/FormCloseButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const FormCloseButton: React.FC<FormCloseButtonProps> = ({ onClose }) =>
return () => {
document.body.removeEventListener("keydown", handleKeyPress, false)
}
}, [])
}, [onClose])

return (
<IconButton className={styles.closeButton} onClick={onClose} size="medium">
Expand Down
30 changes: 13 additions & 17 deletions site/components/Navbar/UserDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ export const UserDropdown: React.FC<UserDropdownProps> = ({ user, onSignOut }: U
<div>
<MenuItem onClick={handleDropdownClick}>
<div className={styles.inner}>
{user && (
<Badge overlap="circle">
<UserAvatar user={user} />
</Badge>
)}
<Badge overlap="circle">
<UserAvatar user={user} />
</Badge>
{anchorEl ? (
<KeyboardArrowUp className={`${styles.arrowIcon} ${styles.arrowIconUp}`} />
) : (
Expand All @@ -65,20 +63,18 @@ export const UserDropdown: React.FC<UserDropdownProps> = ({ user, onSignOut }: U
variant="user-dropdown"
onClose={onPopoverClose}
>
{user && (
<div className={styles.userInfo}>
<UserProfileCard user={user} />
<div className={styles.userInfo}>
<UserProfileCard user={user} />

<Divider className={styles.divider} />
<Divider className={styles.divider} />

<MenuItem className={styles.menuItem} onClick={onSignOut}>
<ListItemIcon className={styles.icon}>
<LogoutIcon />
</ListItemIcon>
<ListItemText primary="Sign Out" />
</MenuItem>
</div>
)}
<MenuItem className={styles.menuItem} onClick={onSignOut}>
<ListItemIcon className={styles.icon}>
<LogoutIcon />
</ListItemIcon>
<ListItemText primary="Sign Out" />
</MenuItem>
</div>
</BorderedMenu>
</>
)
Expand Down
6 changes: 3 additions & 3 deletions site/components/Redirect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export interface RedirectProps {
* Helper component to perform a client-side redirect
*/
export const Redirect: React.FC<RedirectProps> = ({ to }) => {
const router = useRouter()
const { replace } = useRouter()

useEffect(() => {
void router.replace(to)
}, [])
void replace(to)
}, [replace, to])

return null
}
2 changes: 1 addition & 1 deletion site/components/SignIn/SignInForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const SignInForm: React.FC<SignInProps> = ({

const getRedirectFromRouter = (router: NextRouter) => {
const defaultRedirect = "/"
if (router.query?.redirect) {
if (router.query.redirect) {
return firstOrItem(router.query.redirect, defaultRedirect)
} else {
return defaultRedirect
Expand Down
11 changes: 7 additions & 4 deletions site/contexts/UserContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,24 @@ const UserContext = React.createContext<UserContext>({

export const useUser = (redirectOnError = false): UserContext => {
const ctx = useContext(UserContext)
const router = useRouter()
const { push, asPath } = useRouter()

const requestError = ctx.error
useEffect(() => {
if (redirectOnError && requestError) {
// 'void' means we are ignoring handling the promise returned
// from router.push (and lets the linter know we're OK with that!)
void router.push({
void push({
pathname: "/login",
query: {
redirect: router.asPath,
redirect: asPath,
},
})
}
}, [redirectOnError, requestError])
// Disabling exhaustive deps here because it can cause an
// infinite useEffect loop. Should (hopefully) go away
// when we switch to an alternate routing strategy.
}, [redirectOnError, requestError]) // eslint-disable-line react-hooks/exhaustive-deps

return ctx
}
Expand Down
File renamed without changes.
10 changes: 9 additions & 1 deletion site/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ module.exports = {
displayName: "lint",
runner: "jest-runner-eslint",
testMatch: ["<rootDir>/**/*.js", "<rootDir>/**/*.ts", "<rootDir>/**/*.tsx"],
testPathIgnorePatterns: ["/.next/", "/out/", "/_jest/", "jest.config.js", "jest-runner.*.js", "next.config.js"],
testPathIgnorePatterns: [
"/.next/",
"/out/",
"/_jest/",
"dev.ts",
"jest.config.js",
"jest-runner.*.js",
"next.config.js",
],
},
],
collectCoverageFrom: [
Expand Down
26 changes: 13 additions & 13 deletions site/pages/projects/[organization]/[project]/create.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import React, { useCallback } from "react"
import { makeStyles } from "@material-ui/core/styles"
import { useRouter } from "next/router"
import useSWR from "swr"
Expand All @@ -10,14 +10,24 @@ import { FullScreenLoader } from "../../../../components/Loader/FullScreenLoader
import { CreateWorkspaceForm } from "../../../../forms/CreateWorkspaceForm"

const CreateWorkspacePage: React.FC = () => {
const router = useRouter()
const { push, query } = useRouter()
const styles = useStyles()
const { me } = useUser(/* redirectOnError */ true)
const { organization, project: projectName } = router.query
const { organization, project: projectName } = query
const { data: project, error: projectError } = useSWR<API.Project, Error>(
`/api/v2/projects/${organization}/${projectName}`,
)

const onCancel = useCallback(async () => {
await push(`/projects/${organization}/${projectName}`)
}, [push, organization, projectName])
Comment on lines +21 to +23
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This had to be moved before the early-return because hooks always have to be called consistently and in a consistent order.


const onSubmit = async (req: API.CreateWorkspaceRequest) => {
const workspace = await API.Workspace.create(req)
await push(`/workspaces/me/${workspace.name}`)
return workspace
}

if (projectError) {
return <ErrorSummary error={projectError} />
}
Expand All @@ -26,16 +36,6 @@ const CreateWorkspacePage: React.FC = () => {
return <FullScreenLoader />
}

const onCancel = async () => {
await router.push(`/projects/${organization}/${projectName}`)
}

const onSubmit = async (req: API.CreateWorkspaceRequest) => {
const workspace = await API.Workspace.create(req)
await router.push(`/workspaces/me/${workspace.name}`)
return workspace
}

return (
<div className={styles.root}>
<CreateWorkspaceForm onCancel={onCancel} onSubmit={onSubmit} project={project} />
Expand Down
58 changes: 0 additions & 58 deletions site/pages/projects/create.tsx

This file was deleted.

9 changes: 6 additions & 3 deletions site/pages/workspaces/[user]/[workspace].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ const WorkspacesPage: React.FC = () => {
// So if the user is the same as 'me', use 'me' as the parameter
const normalizedUserParam = me && userParam === me.id ? "me" : userParam

// The SWR API expects us to 'throw' if the query isn't ready yet, so these casts to `any` are OK
// because the API expects exceptions.
return `/api/v2/workspaces/${(normalizedUserParam as any).toString()}/${(workspaceParam as any).toString()}`
// The SWR API expects us to 'throw' if the query isn't ready yet:
if (normalizedUserParam === null || workspaceParam === null) {
throw "Data not yet available to make API call"
}

return `/api/v2/workspaces/${normalizedUserParam}/${workspaceParam}`
})

if (workspaceError) {
Expand Down