-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[dashboard] lint warnings: NewProject.tsx #8995
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* See License-AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { useContext, useEffect, useState } from "react"; | ||
import { useCallback, useContext, useEffect, useState } from "react"; | ||
import { getGitpodService, gitpodHostUrl } from "../service/service"; | ||
import { iconForAuthProvider, openAuthorizeWindow, simplifyProviderName } from "../provider-utils"; | ||
import { AuthProviderInfo, Project, ProviderRepository, Team, TeamMemberInfo, User } from "@gitpod/gitpod-protocol"; | ||
|
@@ -42,6 +42,29 @@ export default function NewProject() { | |
|
||
const [authProviders, setAuthProviders] = useState<AuthProviderInfo[]>([]); | ||
|
||
const updateReposInAccounts = useCallback( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it really necessary to use I think I'd prefer not using this feature here, to limit the "magic" in our code. What do you think? 🙂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh it was actually a cascading effect 🙂
The only alternative seems to be silencing the ESLint rule for this line, but as long as the code still works as intended I'd rather follow the lead of the linting rules and move on. Let me know what you want me to do! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I'm not mistaken, you've already added the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or, actually I really don't like this pattern of implementing functions that are only called once (EDIT: to clarify, this is a pre-existing problem from before your Pull Request, not something you did here). What about moving all the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Oh that's also my usual first move 🤝 but in this case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, but we have another warning :D look at the first of my bullet points above:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's because without |
||
async (installationId?: string) => { | ||
setLoaded(false); | ||
setReposInAccounts([]); | ||
if (!selectedProviderHost) { | ||
return []; | ||
} | ||
try { | ||
const repos = await getGitpodService().server.getProviderRepositoriesForUser({ | ||
provider: selectedProviderHost, | ||
hints: { installationId }, | ||
}); | ||
setReposInAccounts(repos); | ||
setLoaded(true); | ||
return repos; | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
return []; | ||
}, | ||
[selectedProviderHost], | ||
); | ||
|
||
useEffect(() => { | ||
if (user && selectedProviderHost === undefined) { | ||
if (user.identities.find((i) => i.authProviderId === "Public-GitLab")) { | ||
|
@@ -55,7 +78,7 @@ export default function NewProject() { | |
setAuthProviders(await getGitpodService().server.getAuthProviders()); | ||
})(); | ||
} | ||
}, [user]); | ||
}, [selectedProviderHost, user]); | ||
|
||
useEffect(() => { | ||
const params = new URLSearchParams(location.search); | ||
|
@@ -69,7 +92,7 @@ export default function NewProject() { | |
window.history.replaceState({}, "", window.location.pathname); | ||
setSelectedTeamOrUser(user); | ||
} | ||
}, []); | ||
}, [location.search, teams, user]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not 100% sure whether this change makes sense:
All in all, since this code currently seems to work in all cases, I'm a bit hesitant to change the effect logic here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I totally get it: this is a classic situation and it happens frequently when you start paying attention to ESLint rules. My current stance about it, as you can infer from the proposed changes, is to just let ESLint do its thing and use its auto-fix feature: since the resulting code is basically always equivalent to what it was before the auto-fix, the auto-fixed dependency array quickly becomes like an implementation detail of sorts, I'm positive that ESLint has my back, and I can focus on the real features I need to work on. Again, let me know what you want me to do :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! I generally agree with you, but I believe I had one bad experience where I just followed ESLint and it broke my component 😬 (or, maybe the bug was my fault and I now wrongly blame ESLint for it). I guess this calls for more testing. 👀 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it happened to me once! |
||
|
||
const [teamMembers, setTeamMembers] = useState<Record<string, TeamMemberInfo[]>>({}); | ||
useEffect(() => { | ||
|
@@ -123,10 +146,34 @@ export default function NewProject() { | |
}, [selectedRepo]); | ||
|
||
useEffect(() => { | ||
const createProject = async (teamOrUser: Team | User, repo: ProviderRepository) => { | ||
if (!selectedProviderHost) { | ||
return; | ||
} | ||
const repoSlug = repo.path || repo.name; | ||
|
||
try { | ||
const project = await getGitpodService().server.createProject({ | ||
name: repo.name, | ||
slug: repoSlug, | ||
cloneUrl: repo.cloneUrl, | ||
account: repo.account, | ||
provider: selectedProviderHost, | ||
...(User.is(teamOrUser) ? { userId: teamOrUser.id } : { teamId: teamOrUser.id }), | ||
appInstallationId: String(repo.installationId), | ||
}); | ||
|
||
setProject(project); | ||
} catch (error) { | ||
const message = (error && error?.message) || "Failed to create new project."; | ||
window.alert(message); | ||
} | ||
}; | ||
|
||
if (selectedTeamOrUser && selectedRepo) { | ||
createProject(selectedTeamOrUser, selectedRepo); | ||
} | ||
}, [selectedTeamOrUser, selectedRepo]); | ||
}, [selectedTeamOrUser, selectedRepo, selectedProviderHost]); | ||
|
||
useEffect(() => { | ||
if (reposInAccounts.length === 0) { | ||
|
@@ -155,7 +202,7 @@ export default function NewProject() { | |
(async () => { | ||
await updateReposInAccounts(); | ||
})(); | ||
}, [selectedProviderHost]); | ||
}, [selectedProviderHost, updateReposInAccounts]); | ||
|
||
useEffect(() => { | ||
if (project && sourceOfConfig) { | ||
|
@@ -166,30 +213,10 @@ export default function NewProject() { | |
await getGitpodService().server.triggerPrebuild(project.id, null); | ||
})(); | ||
} | ||
}, [project, sourceOfConfig]); | ||
}, [guessedConfigString, project, sourceOfConfig]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reading the code, I think depending on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, same reasoning as in https://github.com/gitpod-io/gitpod/pull/8995/files#r839619341 |
||
|
||
const isGitHub = () => selectedProviderHost === "github.com"; | ||
|
||
const updateReposInAccounts = async (installationId?: string) => { | ||
setLoaded(false); | ||
setReposInAccounts([]); | ||
if (!selectedProviderHost) { | ||
return []; | ||
} | ||
try { | ||
const repos = await getGitpodService().server.getProviderRepositoriesForUser({ | ||
provider: selectedProviderHost, | ||
hints: { installationId }, | ||
}); | ||
setReposInAccounts(repos); | ||
setLoaded(true); | ||
return repos; | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
return []; | ||
}; | ||
|
||
const reconfigure = () => { | ||
openReconfigureWindow({ | ||
account: selectedAccount, | ||
|
@@ -203,30 +230,6 @@ export default function NewProject() { | |
}); | ||
}; | ||
|
||
const createProject = async (teamOrUser: Team | User, repo: ProviderRepository) => { | ||
if (!selectedProviderHost) { | ||
return; | ||
} | ||
const repoSlug = repo.path || repo.name; | ||
|
||
try { | ||
const project = await getGitpodService().server.createProject({ | ||
name: repo.name, | ||
slug: repoSlug, | ||
cloneUrl: repo.cloneUrl, | ||
account: repo.account, | ||
provider: selectedProviderHost, | ||
...(User.is(teamOrUser) ? { userId: teamOrUser.id } : { teamId: teamOrUser.id }), | ||
appInstallationId: String(repo.installationId), | ||
}); | ||
|
||
setProject(project); | ||
} catch (error) { | ||
const message = (error && error?.message) || "Failed to create new project."; | ||
window.alert(message); | ||
} | ||
}; | ||
|
||
const toSimpleName = (fullName: string) => { | ||
const splitted = fullName.split("/"); | ||
if (splitted.length < 2) { | ||
|
@@ -243,7 +246,7 @@ export default function NewProject() { | |
const getDropDownEntries = (accounts: Map<string, { avatarUrl: string }>) => { | ||
const renderItemContent = (label: string, icon: string, addClasses?: string) => ( | ||
<div className="w-full flex"> | ||
<img src={icon} className="rounded-full w-6 h-6 my-auto" /> | ||
<img src={icon} className="rounded-full w-6 h-6 my-auto" alt="" /> | ||
<span className={"pl-2 text-gray-600 dark:text-gray-100 text-base " + (addClasses || "")}>{label}</span> | ||
</div> | ||
); | ||
|
@@ -311,9 +314,9 @@ export default function NewProject() { | |
<p className="text-gray-500 text-center text-base mt-12"> | ||
{loaded && noReposAvailable ? "Select account on " : "Select a Git repository on "} | ||
<b>{selectedProviderHost}</b> ( | ||
<a className="gp-link cursor-pointer" onClick={() => setShowGitProviders(true)}> | ||
<button className="gp-link cursor-pointer" onClick={() => setShowGitProviders(true)}> | ||
change | ||
</a> | ||
</button> | ||
) | ||
</p> | ||
<div className={`mt-2 flex-col ${noReposAvailable && isGitHub() ? "w-96" : ""}`}> | ||
|
@@ -325,6 +328,7 @@ export default function NewProject() { | |
<img | ||
src={user?.avatarUrl} | ||
className="rounded-full w-6 h-6 absolute my-2.5 left-3" | ||
alt="" | ||
/> | ||
<input | ||
className="w-full px-12 cursor-pointer font-semibold" | ||
|
@@ -339,6 +343,7 @@ export default function NewProject() { | |
<img | ||
src={icon ? icon : ""} | ||
className="rounded-full w-6 h-6 absolute my-2.5 left-3" | ||
alt="" | ||
/> | ||
<input | ||
className="w-full px-12 cursor-pointer font-semibold" | ||
|
@@ -352,12 +357,18 @@ export default function NewProject() { | |
src={CaretDown} | ||
title="Select Account" | ||
className="filter-grayscale absolute top-1/2 right-3" | ||
alt="" | ||
/> | ||
</div> | ||
</ContextMenu> | ||
{showSearchInput && ( | ||
<div className="w-full relative "> | ||
<img src={search} title="Search" className="filter-grayscale absolute top-1/3 left-3" /> | ||
<img | ||
src={search} | ||
title="Search" | ||
alt="Search" | ||
className="filter-grayscale absolute top-1/3 left-3" | ||
/> | ||
<input | ||
className="w-96 pl-10 border-0" | ||
type="text" | ||
|
@@ -430,13 +441,12 @@ export default function NewProject() { | |
<div> | ||
<div className="text-gray-500 text-center w-96 mx-8"> | ||
Repository not found?{" "} | ||
<a | ||
href="javascript:void(0)" | ||
<button | ||
onClick={(e) => reconfigure()} | ||
className="text-gray-400 underline underline-thickness-thin underline-offset-small hover:text-gray-600" | ||
className="gp-link text-gray-400 underline underline-thickness-thin underline-offset-small hover:text-gray-600" | ||
> | ||
Reconfigure | ||
</a> | ||
</button> | ||
</div> | ||
</div> | ||
)} | ||
|
@@ -682,7 +692,7 @@ function GitProviders(props: { | |
{errorMessage && ( | ||
<div className="mt-16 flex space-x-2 py-6 px-6 w-96 justify-between bg-gitpod-kumquat-light rounded-xl"> | ||
<div className="pr-3 self-center w-6"> | ||
<img src={exclamation} /> | ||
<img src={exclamation} alt="Heads up!" /> | ||
</div> | ||
<div className="flex-1 flex flex-col"> | ||
<p className="text-gitpod-red text-sm">{errorMessage}</p> | ||
|
Uh oh!
There was an error while loading. Please reload this page.