mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 23:45:44 +01:00
added protocol switcher to git protocol information
This commit is contained in:
57
scm-plugins/scm-git-plugin/src/main/js/CloneInformation.js
Normal file
57
scm-plugins/scm-git-plugin/src/main/js/CloneInformation.js
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
//@flow
|
||||||
|
import React from "react";
|
||||||
|
import { translate } from "react-i18next";
|
||||||
|
import type { Repository } from "@scm-manager/ui-types";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
url: string,
|
||||||
|
repository: Repository,
|
||||||
|
|
||||||
|
// context props
|
||||||
|
t: (string) => string
|
||||||
|
};
|
||||||
|
|
||||||
|
class CloneInformation extends React.Component<Props> {
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { url, repository, t } = this.props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h4>{t("scm-git-plugin.information.clone")}</h4>
|
||||||
|
<pre>
|
||||||
|
<code>git clone {url}</code>
|
||||||
|
</pre>
|
||||||
|
<h4>{t("scm-git-plugin.information.create")}</h4>
|
||||||
|
<pre>
|
||||||
|
<code>
|
||||||
|
git init {repository.name}
|
||||||
|
<br />
|
||||||
|
echo "# {repository.name}" > README.md
|
||||||
|
<br />
|
||||||
|
git add README.md
|
||||||
|
<br />
|
||||||
|
git commit -m "added readme"
|
||||||
|
<br />
|
||||||
|
git remote add origin {url}
|
||||||
|
<br />
|
||||||
|
git push -u origin master
|
||||||
|
<br />
|
||||||
|
</code>
|
||||||
|
</pre>
|
||||||
|
<h4>{t("scm-git-plugin.information.replace")}</h4>
|
||||||
|
<pre>
|
||||||
|
<code>
|
||||||
|
git remote add origin {url}
|
||||||
|
<br />
|
||||||
|
git push -u origin master
|
||||||
|
<br />
|
||||||
|
</code>
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default translate("plugins")(CloneInformation);
|
||||||
@@ -1,59 +1,108 @@
|
|||||||
//@flow
|
//@flow
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { repositories } from "@scm-manager/ui-components";
|
import { ButtonGroup, Button } from "@scm-manager/ui-components";
|
||||||
import type { Repository } from "@scm-manager/ui-types";
|
import type { Repository } from "@scm-manager/ui-types";
|
||||||
import { translate } from "react-i18next";
|
import CloneInformation from "./CloneInformation";
|
||||||
|
import type { Link } from "@scm-manager/ui-types";
|
||||||
|
import injectSheets from "react-jss";
|
||||||
|
|
||||||
|
const styles = {
|
||||||
|
protocols: {
|
||||||
|
position: "relative"
|
||||||
|
},
|
||||||
|
switcher: {
|
||||||
|
position: "absolute",
|
||||||
|
top: 0,
|
||||||
|
right: 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
repository: Repository,
|
repository: Repository,
|
||||||
t: string => string
|
|
||||||
|
// context props
|
||||||
|
classes: Object
|
||||||
}
|
}
|
||||||
|
|
||||||
class ProtocolInformation extends React.Component<Props> {
|
type State = {
|
||||||
|
selected?: Link
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
function selectHttpOrFirst(repository: Repository) {
|
||||||
const { repository, t } = this.props;
|
const protocols = repository._links["protocol"] || [];
|
||||||
const href = repositories.getProtocolLinkByType(repository, "http");
|
|
||||||
if (!href) {
|
for (let protocol of protocols) {
|
||||||
return null;
|
if (protocol.name === "http") {
|
||||||
|
return protocol;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocols.length > 0) {
|
||||||
|
return protocols[0];
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ProtocolInformation extends React.Component<Props, State> {
|
||||||
|
|
||||||
|
constructor(props: Props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
selected: selectHttpOrFirst(props.repository)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
selectProtocol = (protocol: Link) => {
|
||||||
|
this.setState({
|
||||||
|
selected: protocol
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
renderProtocolButton = (protocol: Link) => {
|
||||||
|
const name = protocol.name || "unknown";
|
||||||
|
|
||||||
|
let color = null;
|
||||||
|
|
||||||
|
const { selected } = this.state;
|
||||||
|
if ( selected && protocol.name === selected.name ) {
|
||||||
|
color = "link is-selected";
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<Button color={ color } action={() => this.selectProtocol(protocol)}>
|
||||||
<h4>{t("scm-git-plugin.information.clone")}</h4>
|
{name.toUpperCase()}
|
||||||
<pre>
|
</Button>
|
||||||
<code>git clone {href}</code>
|
);
|
||||||
</pre>
|
};
|
||||||
<h4>{t("scm-git-plugin.information.create")}</h4>
|
|
||||||
<pre>
|
render() {
|
||||||
<code>
|
const { repository, classes } = this.props;
|
||||||
git init {repository.name}
|
|
||||||
<br />
|
const protocols = repository._links["protocol"];
|
||||||
echo "# {repository.name}" > README.md
|
if (!protocols || protocols.length === 0) {
|
||||||
<br />
|
return null;
|
||||||
git add README.md
|
}
|
||||||
<br />
|
|
||||||
git commit -m "added readme"
|
if (protocols.length === 1) {
|
||||||
<br />
|
return <CloneInformation url={protocols[0].href} repository={repository} />;
|
||||||
git remote add origin {href}
|
}
|
||||||
<br />
|
|
||||||
git push -u origin master
|
const { selected } = this.state;
|
||||||
<br />
|
let cloneInformation = null;
|
||||||
</code>
|
if (selected) {
|
||||||
</pre>
|
cloneInformation = <CloneInformation repository={repository} url={selected.href} />;
|
||||||
<h4>{t("scm-git-plugin.information.replace")}</h4>
|
}
|
||||||
<pre>
|
|
||||||
<code>
|
return (
|
||||||
git remote add origin {href}
|
<div className={classes.protocols}>
|
||||||
<br />
|
<ButtonGroup className={classes.switcher}>
|
||||||
git push -u origin master
|
{protocols.map(this.renderProtocolButton)}
|
||||||
<br />
|
</ButtonGroup>
|
||||||
</code>
|
{ cloneInformation }
|
||||||
</pre>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default translate("plugins")(ProtocolInformation);
|
export default injectSheets(styles)(ProtocolInformation);
|
||||||
|
|||||||
Reference in New Issue
Block a user