2021-01-28 11:40:35 +01:00
|
|
|
/*
|
|
|
|
|
* MIT License
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
|
|
|
|
*/
|
2021-06-28 13:19:03 +02:00
|
|
|
import React, { FC, FormEvent, useEffect, useState } from "react";
|
|
|
|
|
import { Repository, RepositoryCreation, RepositoryType } from "@scm-manager/ui-types";
|
|
|
|
|
import { ErrorNotification, Level, SubmitButton } from "@scm-manager/ui-components";
|
2021-01-28 11:40:35 +01:00
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
|
import ImportFullRepositoryForm from "./ImportFullRepositoryForm";
|
2021-06-28 13:19:03 +02:00
|
|
|
import { extensionPoints } from "@scm-manager/ui-extensions";
|
|
|
|
|
import { useImportFullRepository } from "@scm-manager/ui-api";
|
2021-01-28 11:40:35 +01:00
|
|
|
|
|
|
|
|
type Props = {
|
2021-06-28 13:19:03 +02:00
|
|
|
repositoryType: RepositoryType;
|
2021-01-28 11:40:35 +01:00
|
|
|
setImportPending: (pending: boolean) => void;
|
2021-06-28 13:19:03 +02:00
|
|
|
setImportedRepository: (repository: Repository) => void;
|
|
|
|
|
nameForm: extensionPoints.RepositoryCreatorComponentProps["nameForm"];
|
|
|
|
|
informationForm: extensionPoints.RepositoryCreatorComponentProps["informationForm"];
|
2021-01-28 11:40:35 +01:00
|
|
|
};
|
|
|
|
|
|
2021-05-14 09:15:35 +02:00
|
|
|
const ImportFullRepository: FC<Props> = ({
|
|
|
|
|
repositoryType,
|
|
|
|
|
setImportPending,
|
2021-06-28 13:19:03 +02:00
|
|
|
setImportedRepository,
|
2021-05-14 09:15:35 +02:00
|
|
|
nameForm: NameForm,
|
2021-06-28 13:19:03 +02:00
|
|
|
informationForm: InformationForm,
|
2021-05-14 09:15:35 +02:00
|
|
|
}) => {
|
|
|
|
|
const [repo, setRepo] = useState<RepositoryCreation>({
|
2021-01-28 11:40:35 +01:00
|
|
|
name: "",
|
|
|
|
|
namespace: "",
|
2021-06-28 13:19:03 +02:00
|
|
|
type: repositoryType.name,
|
2021-01-28 11:40:35 +01:00
|
|
|
contact: "",
|
|
|
|
|
description: "",
|
2021-06-28 13:19:03 +02:00
|
|
|
contextEntries: [],
|
2021-01-28 11:40:35 +01:00
|
|
|
});
|
2021-02-25 13:01:03 +01:00
|
|
|
const [password, setPassword] = useState("");
|
2021-01-28 11:40:35 +01:00
|
|
|
const [valid, setValid] = useState({ namespaceAndName: false, contact: true, file: false });
|
|
|
|
|
const [file, setFile] = useState<File | null>(null);
|
|
|
|
|
const [t] = useTranslation("repos");
|
2021-06-28 13:19:03 +02:00
|
|
|
const { importFullRepository, importedRepository, isLoading, error } = useImportFullRepository(repositoryType);
|
2021-01-28 11:40:35 +01:00
|
|
|
|
2021-06-28 13:19:03 +02:00
|
|
|
useEffect(() => setRepo({...repo, type: repositoryType.name}), [repositoryType]);
|
|
|
|
|
useEffect(() => setImportPending(isLoading), [isLoading]);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (importedRepository) {
|
|
|
|
|
setImportedRepository(importedRepository);
|
|
|
|
|
}
|
|
|
|
|
}, [importedRepository]);
|
2021-01-28 11:40:35 +01:00
|
|
|
|
2021-06-28 13:19:03 +02:00
|
|
|
const isValid = () => Object.values(valid).every((v) => v);
|
2021-01-28 11:40:35 +01:00
|
|
|
|
|
|
|
|
const submit = (event: FormEvent<HTMLFormElement>) => {
|
|
|
|
|
event.preventDefault();
|
2021-06-28 13:19:03 +02:00
|
|
|
importFullRepository(repo, file!, password);
|
2021-01-28 11:40:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<form onSubmit={submit}>
|
|
|
|
|
<ErrorNotification error={error} />
|
2021-02-25 13:01:03 +01:00
|
|
|
<ImportFullRepositoryForm
|
|
|
|
|
setFile={setFile}
|
|
|
|
|
password={password}
|
|
|
|
|
setPassword={setPassword}
|
|
|
|
|
setValid={(file: boolean) => setValid({ ...valid, file })}
|
|
|
|
|
/>
|
2021-01-28 11:40:35 +01:00
|
|
|
<hr />
|
2021-05-14 09:15:35 +02:00
|
|
|
<NameForm
|
2021-01-28 11:40:35 +01:00
|
|
|
repository={repo}
|
2021-05-14 09:15:35 +02:00
|
|
|
onChange={setRepo as React.Dispatch<React.SetStateAction<RepositoryCreation>>}
|
2021-01-28 11:40:35 +01:00
|
|
|
setValid={(namespaceAndName: boolean) => setValid({ ...valid, namespaceAndName })}
|
2021-06-28 13:19:03 +02:00
|
|
|
disabled={isLoading}
|
2021-01-28 11:40:35 +01:00
|
|
|
/>
|
2021-05-14 09:15:35 +02:00
|
|
|
<InformationForm
|
2021-01-28 11:40:35 +01:00
|
|
|
repository={repo}
|
2021-05-14 09:15:35 +02:00
|
|
|
onChange={setRepo as React.Dispatch<React.SetStateAction<RepositoryCreation>>}
|
2021-06-28 13:19:03 +02:00
|
|
|
disabled={isLoading}
|
2021-01-28 11:40:35 +01:00
|
|
|
setValid={(contact: boolean) => setValid({ ...valid, contact })}
|
|
|
|
|
/>
|
|
|
|
|
<Level
|
2021-06-28 13:19:03 +02:00
|
|
|
right={<SubmitButton disabled={!isValid()} loading={isLoading} label={t("repositoryForm.submitImport")} />}
|
2021-01-28 11:40:35 +01:00
|
|
|
/>
|
|
|
|
|
</form>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ImportFullRepository;
|