Improve repository information page (#1636)

Only show relevant information for repository on repository information page. The initialization code example is only shown if the repository is still empty.
This commit is contained in:
Eduard Heimbuch
2021-04-29 18:13:32 +02:00
committed by GitHub
parent 32b268e6f5
commit af8980de19
13 changed files with 442 additions and 116 deletions

View File

@@ -21,67 +21,84 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import React from "react";
import { WithTranslation, withTranslation } from "react-i18next";
import { Repository } from "@scm-manager/ui-types";
import { repositories } from "@scm-manager/ui-components";
import React, { FC, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { Link, Repository } from "@scm-manager/ui-types";
import { apiClient, repositories } from "@scm-manager/ui-components";
type Props = WithTranslation & {
type Props = {
repository: Repository;
};
class ProtocolInformation extends React.Component<Props> {
render() {
const { repository, t } = this.props;
const href = repositories.getProtocolLinkByType(repository, "http");
if (!href) {
return null;
}
return (
<div>
<h4>{t("scm-hg-plugin.information.clone")}</h4>
<pre>
<code>hg clone {href}</code>
</pre>
<h4>{t("scm-hg-plugin.information.create")}</h4>
<pre>
<code>
hg init {repository.name}
<br />
cd {repository.name}
<br />
echo "[paths]" &gt; .hg/hgrc
<br />
echo "default = {href}
" &gt;&gt; .hg/hgrc
<br />
echo "# {repository.name}
" &gt; README.md
<br />
hg add README.md
<br />
hg commit -m "added readme"
<br />
<br />
hg push
<br />
</code>
</pre>
<h4>{t("scm-hg-plugin.information.replace")}</h4>
<pre>
<code>
# add the repository url as default to your .hg/hgrc e.g:
<br />
default = {href}
<br />
# push to remote repository
<br />
hg push
</code>
</pre>
</div>
);
}
}
const ProtocolInformation: FC<Props> = ({ repository }) => {
const [t] = useTranslation("plugins");
const [emptyRepository, setEmptyRepository] = useState<boolean>();
export default withTranslation("plugins")(ProtocolInformation);
const href = repositories.getProtocolLinkByType(repository, "http");
useEffect(() => {
if (repository) {
apiClient
.get((repository._links.changesets as Link).href)
.then(r => r.json())
.then(result => {
const empty = result._embedded.changesets.length === 0;
setEmptyRepository(empty);
});
}
}, [repository]);
if (!href) {
return null;
}
return (
<div>
<h4>{t("scm-hg-plugin.information.clone")}</h4>
<pre>
<code>hg clone {href}</code>
</pre>
{emptyRepository && (
<>
<h4>{t("scm-hg-plugin.information.create")}</h4>
<pre>
<code>
hg init {repository.name}
<br />
cd {repository.name}
<br />
echo "[paths]" &gt; .hg/hgrc
<br />
echo "default = {href}
" &gt;&gt; .hg/hgrc
<br />
echo "# {repository.name}
" &gt; README.md
<br />
hg add README.md
<br />
hg commit -m "added readme"
<br />
<br />
hg push
<br />
</code>
</pre>
</>
)}
<h4>{t("scm-hg-plugin.information.replace")}</h4>
<pre>
<code>
# add the repository url as default to your .hg/hgrc e.g:
<br />
default = {href}
<br />
# push to remote repository
<br />
hg push
</code>
</pre>
</div>
);
};
export default ProtocolInformation;

View File

@@ -3,7 +3,7 @@
"information": {
"clone" : "Repository klonen",
"create" : "Neues Repository erstellen",
"replace" : "Ein bestehendes Repository aktualisieren",
"replace" : "Quelle zum bestehenden Repository hinzufügen",
"fetch": "Remote-Änderungen herunterladen",
"checkout": "Branch wechseln",
"checkoutTag": "Tag auschecken"

View File

@@ -3,7 +3,7 @@
"information": {
"clone" : "Clone the repository",
"create" : "Create a New Repository",
"replace" : "Push an Existing Repository",
"replace" : "Add Remote Origin to an Existing Repository",
"fetch": "Get Remote Changes",
"checkout": "Switch Branch",
"checkoutTag": "Checkout Tag"