Skip to content

Commit

Permalink
set project name on backend for now
Browse files Browse the repository at this point in the history
  • Loading branch information
selfcontained committed Oct 11, 2023
1 parent 2224282 commit 205f154
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
5 changes: 2 additions & 3 deletions components/dashboard/src/components/DropDown2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export const DropDown2: FunctionComponent<DropDown2Props> = ({
onSelectionChange,
onSearchChange,
}) => {
const triggerEl = useRef<HTMLButtonElement>(null);
const inputEl = useRef<HTMLInputElement>(null);
const [showDropDown, setShowDropDown] = useState<boolean>(!disabled && !!expanded);
const [search, setSearch] = useState<string>("");
Expand Down Expand Up @@ -140,9 +139,10 @@ export const DropDown2: FunctionComponent<DropDown2Props> = ({
}
return;
}
// Capture escape ourselves instead of letting radix do it
// allows us to close the dropdown and preventDefault on event
if (e.key === "Escape") {
setShowDropDown(false);
triggerEl.current?.focus();
e.preventDefault();
}
if (e.key === "Enter") {
Expand Down Expand Up @@ -173,7 +173,6 @@ export const DropDown2: FunctionComponent<DropDown2Props> = ({
return (
<RadixPopover.Root defaultOpen={expanded} open={showDropDown} onOpenChange={handleOpenChange}>
<RadixPopover.Trigger
ref={triggerEl}
className={classNames(
"h-16 bg-gray-100 dark:bg-gray-800 flex flex-row items-center justify-start px-2 text-left",
// when open, just have border radius on top
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ export const CreateProjectModal: FC<Props> = ({ onClose, onCreated }) => {
return;
}

const projectName = selectedRepo.repositoryName || selectedRepo.projectName || selectedRepo.url;

const newProjectArgs: CreateProjectArgs = {
name: projectName,
slug: projectName,
// leave the name empty to let the backend generate the name
name: "",
// deprecated
slug: "",
cloneUrl: selectedRepo.url,
appInstallationId: "",
};
Expand Down
17 changes: 16 additions & 1 deletion components/server/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2541,6 +2541,10 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
await this.guardTeamOperation(params.teamId || "", "get");
await this.auth.checkPermissionOnOrganization(user.id, "create_project", params.teamId);

if ((params.name || "").length > 32) {
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "A project name cannot be longer than 32 characters.");
}

// Ensure we can parse the provided url ok
const { host, owner, repo } = RepoURL.parseRepoUrl(params.cloneUrl) || {};
if (!host || !owner || !repo) {
Expand All @@ -2564,7 +2568,18 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
);
}

const project = await this.projectsService.createProject(params, user);
const newProjectParams: CreateProjectParams = {
cloneUrl: params.cloneUrl,
teamId: params.teamId,
// Default to repo name (capped at 32 chars) if name is not provided
name: params.name || repo.substring(0, 32),
// TODO: we should be able to remove this - field deprecated
slug: "",
// TODO: we should be able to remove this since we don't use it anymore
appInstallationId: params.appInstallationId,
};

const project = await this.projectsService.createProject(newProjectParams, user);

// update client registration for the logged in user
if (this.client && !this.disposables.disposed) {
Expand Down

0 comments on commit 205f154

Please sign in to comment.