-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adding import repo modal * fix copy * remove name requirement as it's defaulted * upadte query cache after create
- Loading branch information
1 parent
47fccf3
commit 32aa1bb
Showing
4 changed files
with
137 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
components/dashboard/src/repositories/create/ImportRepositoryModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** | ||
* Copyright (c) 2023 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { FC, useCallback, useState } from "react"; | ||
import Modal, { ModalBody, ModalFooter, ModalFooterAlert, ModalHeader } from "../../components/Modal"; | ||
import { SuggestedRepository } from "@gitpod/gitpod-protocol"; | ||
import RepositoryFinder from "../../components/RepositoryFinder"; | ||
import { InputField } from "../../components/forms/InputField"; | ||
import { AuthorizeGit, useNeedsGitAuthorization } from "../../components/AuthorizeGit"; | ||
import { useTemporaryState } from "../../hooks/use-temporary-value"; | ||
import { CreateConfigurationArgs, useCreateConfiguration } from "../../data/configurations/configuration-queries"; | ||
import type { Configuration } from "@gitpod/public-api/lib/gitpod/v1/configuration_pb"; | ||
import { LoadingButton } from "@podkit/buttons/LoadingButton"; | ||
import { Button } from "@podkit/buttons/Button"; | ||
|
||
type Props = { | ||
onCreated: (configuration: Configuration) => void; | ||
onClose: () => void; | ||
}; | ||
|
||
export const ImportRepositoryModal: FC<Props> = ({ onClose, onCreated }) => { | ||
const needsGitAuth = useNeedsGitAuthorization(); | ||
const [selectedRepo, setSelectedRepo] = useState<SuggestedRepository>(); | ||
const createConfiguration = useCreateConfiguration(); | ||
const [createErrorMsg, setCreateErrorMsg] = useTemporaryState("", 3000); | ||
|
||
const handleSubmit = useCallback(() => { | ||
if (!selectedRepo) { | ||
setCreateErrorMsg("Please select a repository"); | ||
return; | ||
} | ||
|
||
const newProjectArgs: CreateConfigurationArgs = { | ||
// leave the name empty to let the backend generate the name | ||
name: "", | ||
cloneUrl: selectedRepo.url, | ||
}; | ||
|
||
createConfiguration.mutate(newProjectArgs, { | ||
onSuccess: onCreated, | ||
}); | ||
}, [createConfiguration, onCreated, selectedRepo, setCreateErrorMsg]); | ||
|
||
const errorMessage = | ||
createErrorMsg || | ||
(createConfiguration.isError && | ||
(createConfiguration.error?.message ?? "There was a problem importing your repository")); | ||
|
||
return ( | ||
<Modal visible onClose={onClose} onSubmit={handleSubmit}> | ||
<ModalHeader>Import repository</ModalHeader> | ||
<ModalBody> | ||
<div className="w-112 max-w-full"> | ||
{needsGitAuth ? ( | ||
<AuthorizeGit /> | ||
) : ( | ||
<> | ||
<InputField className="mb-8 w-full"> | ||
<RepositoryFinder | ||
selectedContextURL={selectedRepo?.url} | ||
selectedProjectID={selectedRepo?.projectId} | ||
onChange={setSelectedRepo} | ||
excludeProjects | ||
/> | ||
</InputField> | ||
</> | ||
)} | ||
</div> | ||
</ModalBody> | ||
<ModalFooter | ||
alert={ | ||
errorMessage && ( | ||
<ModalFooterAlert type="danger" onClose={() => setCreateErrorMsg("")}> | ||
{errorMessage} | ||
</ModalFooterAlert> | ||
) | ||
} | ||
> | ||
<Button variant="secondary" onClick={onClose}> | ||
Cancel | ||
</Button> | ||
<LoadingButton type="submit" loading={createConfiguration.isLoading}> | ||
Import | ||
</LoadingButton> | ||
</ModalFooter> | ||
</Modal> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters