-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Allow renaming project #18630
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
Allow renaming project #18630
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 |
---|---|---|
|
@@ -16,6 +16,10 @@ import { getProjectSettingsMenu, getProjectTabs } from "./projects.routes"; | |
import { Heading2, Subheading } from "../components/typography/headings"; | ||
import { RemoveProjectModal } from "./RemoveProjectModal"; | ||
import SelectWorkspaceClassComponent from "../components/SelectWorkspaceClassComponent"; | ||
import { TextInputField } from "../components/forms/TextInputField"; | ||
import { Button } from "../components/Button"; | ||
import { useRefreshProjects } from "../data/projects/list-projects-query"; | ||
import { useToast } from "../components/toasts/Toasts"; | ||
|
||
export function ProjectSettingsPage(props: { project?: Project; children?: React.ReactNode }) { | ||
return ( | ||
|
@@ -34,10 +38,30 @@ export default function ProjectSettingsView() { | |
const { setProject } = useContext(ProjectContext); | ||
const { project } = useCurrentProject(); | ||
const [showRemoveModal, setShowRemoveModal] = useState(false); | ||
const [projectName, setProjectName] = useState(project?.name || ""); | ||
let badProjectName = projectName.length > 0 ? undefined : "Project name can not be blank."; | ||
if (projectName.length > 32) { | ||
badProjectName = "Project name can not be longer than 32 characters."; | ||
} | ||
const history = useHistory(); | ||
const refreshProjects = useRefreshProjects(); | ||
const toast = useToast(); | ||
|
||
const updateProjectName = useCallback( | ||
async (e: React.FormEvent) => { | ||
e.preventDefault(); | ||
if (!project || badProjectName) return; | ||
|
||
await getGitpodService().server.updateProjectPartial({ id: project.id, name: projectName }); | ||
setProject({ ...project, name: projectName }); | ||
refreshProjects(project.teamId); | ||
toast.toast(`Project ${projectName} updated.`); | ||
}, | ||
[project, badProjectName, projectName, setProject, refreshProjects, toast], | ||
); | ||
|
||
const updateProjectSettings = useCallback( | ||
(settings: ProjectSettings) => { | ||
async (settings: ProjectSettings) => { | ||
if (!project) return; | ||
|
||
const newSettings = { ...project.settings, ...settings }; | ||
|
@@ -80,7 +104,20 @@ export default function ProjectSettingsView() { | |
|
||
return ( | ||
<ProjectSettingsPage project={project}> | ||
<Heading2>Prebuilds</Heading2> | ||
<Heading2>Project Name</Heading2> | ||
<form onSubmit={updateProjectName}> | ||
<TextInputField | ||
hint="The name can be up to 32 characters long." | ||
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. nitpick: Help text look useful, but is needed here all the time? Since we catch this with the validation anyway, thoughts on dropping the help text all together? |
||
value={projectName} | ||
error={badProjectName} | ||
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. praise: Thanks for adding the validation here! 🐈 |
||
onChange={setProjectName} | ||
/> | ||
|
||
<Button className="mt-4" htmlType="submit" disabled={project?.name === projectName || !!badProjectName}> | ||
Update Name | ||
</Button> | ||
gtsiolis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</form> | ||
<Heading2 className="mt-12">Prebuilds</Heading2> | ||
<Subheading>Choose the workspace machine type for your prebuilds.</Subheading> | ||
<div className="max-w-md"> | ||
<SelectWorkspaceClassComponent | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not we have it rather on server that it is aligned among all clients? Is it enforced by DB?