Implement Git repo config

This commit is contained in:
Philipp Czora
2018-12-14 16:01:57 +01:00
parent c2d872bd59
commit 8a6a235e77
10 changed files with 203 additions and 78 deletions

View File

@@ -0,0 +1,120 @@
// @flow
import React from "react";
import {apiClient, BranchSelector, ErrorPage, Loading, SubmitButton} from "@scm-manager/ui-components";
import type {Branch, Repository} from "@scm-manager/ui-types";
import {translate} from "react-i18next";
type Props = {
repository: Repository,
t: string => string
};
type State = {
loadingBranches: boolean,
loadingDefaultBranch: boolean,
submitPending: boolean,
error: Error,
branches: Branch[],
selectedBranchName: string
};
const GIT_CONFIG_CONTENT_TYPE = "application/vnd.scmm-gitConfig+json";
class RepositoryConfig extends React.Component<Props, State> {
state = {
branches: []
};
componentDidMount() {
const { repository } = this.props;
this.setState({ ...this.state, loadingBranches: true });
apiClient
.get(repository._links.branches.href)
.then(response => response.json())
.then(payload => payload._embedded.branches)
.then(branches =>
this.setState({ ...this.state, branches, loadingBranches: false })
)
.catch(error => this.setState({ ...this.state, error }));
this.setState({ ...this.state, loadingDefaultBranch: true });
apiClient
.get(repository._links.configuration.href)
.then(response => response.json())
.then(payload => payload.defaultBranch)
.then(selectedBranchName =>
this.setState({
...this.state,
selectedBranchName,
loadingDefaultBranch: false
})
)
.catch(error => this.setState({ ...this.state, error }));
}
branchSelected = (branch: Branch) => {
if (!branch) {
this.setState({ ...this.state, selectedBranchName: null });
}
this.setState({ ...this.state, selectedBranchName: branch.name });
};
submit = (event: Event) => {
event.preventDefault();
const { repository } = this.props;
const newConfig = {
defaultBranch: this.state.selectedBranchName
};
this.setState({ ...this.state, submitPending: true });
apiClient
.put(
repository._links.configuration.href,
newConfig,
GIT_CONFIG_CONTENT_TYPE
)
.then(() => this.setState({ ...this.state, submitPending: false }))
.catch(error => this.setState({ ...this.state, error }));
};
render() {
const { t, error } = this.props;
const { loadingBranches, loadingDefaultBranch, submitPending } = this.state;
if (error) {
return (
<ErrorPage
title={t("scm-git-plugin.repo-config.error.title")}
subtitle={t("scm-git-plugin.repo-config.error.subtitle")}
error={error}
/>
);
}
if (!(loadingBranches || loadingDefaultBranch)) {
return (
<form onSubmit={this.submit}>
<BranchSelector
label={t("scm-git-plugin.repo-config.default-branch")}
branches={this.state.branches}
selected={this.branchSelected}
selectedBranch={this.state.selectedBranchName}
/>
<SubmitButton
label={t("scm-git-plugin.repo-config.submit")}
loading={submitPending}
disabled={
!this.state.selectedBranchName
}
/>
</form>
);
} else {
return <Loading />;
}
}
}
export default translate("plugins")(RepositoryConfig);

View File

@@ -1,11 +1,13 @@
//@flow
import { binder } from "@scm-manager/ui-extensions";
import React from "react";
import {binder} from "@scm-manager/ui-extensions";
import ProtocolInformation from "./ProtocolInformation";
import GitAvatar from "./GitAvatar";
import { ConfigurationBinder as cfgBinder } from "@scm-manager/ui-components";
import {ConfigurationBinder as cfgBinder} from "@scm-manager/ui-components";
import GitGlobalConfiguration from "./GitGlobalConfiguration";
import GitMergeInformation from "./GitMergeInformation";
import RepositoryConfig from "./RepositoryConfig";
// repository
@@ -13,10 +15,29 @@ const gitPredicate = (props: Object) => {
return props.repository && props.repository.type === "git";
};
binder.bind("repos.repository-details.information", ProtocolInformation, gitPredicate);
binder.bind("repos.repository-merge.information", GitMergeInformation, gitPredicate);
binder.bind(
"repos.repository-details.information",
ProtocolInformation,
gitPredicate
);
binder.bind(
"repos.repository-merge.information",
GitMergeInformation,
gitPredicate
);
binder.bind("repos.repository-avatar", GitAvatar, gitPredicate);
cfgBinder.bindRepository(
"/configuration",
"scm-git-plugin.repo-config.link",
"configuration",
RepositoryConfig
);
// global config
cfgBinder.bindGlobal("/git", "scm-git-plugin.config.link", "gitConfig", GitGlobalConfiguration);
cfgBinder.bindGlobal(
"/git",
"scm-git-plugin.config.link",
"gitConfig",
GitGlobalConfiguration
);

View File

@@ -1,9 +1,9 @@
{
"scm-git-plugin": {
"information": {
"clone" : "Clone the repository",
"create" : "Create a new repository",
"replace" : "Push an existing repository",
"clone": "Clone the repository",
"create": "Create a new repository",
"replace": "Push an existing repository",
"merge": {
"heading": "How to merge source branch into target branch",
"checkout": "1. Make sure your workspace is clean and checkout target branch",
@@ -22,6 +22,15 @@
"disabled": "Disabled",
"disabledHelpText": "Enable or disable the Git plugin",
"submit": "Submit"
},
"repo-config": {
"link": "Configuration",
"default-branch": "Default branch",
"submit": "Submit",
"error": {
"title": "Error",
"subtitle": "Something went wrong"
}
}
}
}

View File

@@ -1,12 +1,10 @@
// @flow
import React from "react";
import type { Branch } from "@scm-manager/ui-types";
import DropDown from "../components/DropDown";
import { translate } from "react-i18next";
import type {Branch} from "packages/ui-types/src/index";
import injectSheet from "react-jss";
import { compose } from "redux";
import classNames from "classnames";
import DropDown from "./forms/DropDown";
const styles = {
zeroflex: {
@@ -20,11 +18,11 @@ const styles = {
type Props = {
branches: Branch[], // TODO: Use generics?
selected: (branch?: Branch) => void,
selectedBranch: string,
selectedBranch?: string,
label: string,
// context props
classes: Object,
t: string => string
classes: Object
};
type State = { selectedBranch?: Branch };
@@ -36,13 +34,12 @@ class BranchSelector extends React.Component<Props, State> {
}
componentDidMount() {
this.props.branches
.filter(branch => branch.name === this.props.selectedBranch)
.forEach(branch => this.setState({ selectedBranch: branch }));
const selectedBranch = this.props.branches.find(branch => branch.name === this.props.selectedBranch);
this.setState({ selectedBranch })
}
render() {
const { branches, classes, t } = this.props;
const { branches, classes, label } = this.props;
if (branches) {
return (
@@ -55,7 +52,7 @@ class BranchSelector extends React.Component<Props, State> {
classes.minWidthOfLabel
)}
>
<label className="label">{t("branch-selector.label")}</label>
<label className="label">{label}</label>
</div>
<div className="field-body">
<div className="field is-narrow">
@@ -89,7 +86,4 @@ class BranchSelector extends React.Component<Props, State> {
};
}
export default compose(
injectSheet(styles),
translate("repos")
)(BranchSelector);
export default injectSheet(styles)(BranchSelector);

View File

@@ -7,5 +7,6 @@ export { default as InputField } from "./InputField.js";
export { default as Select } from "./Select.js";
export { default as Textarea } from "./Textarea.js";
export { default as PasswordConfirmation } from "./PasswordConfirmation.js";
export { default as LabelWithHelpIcon } from "./LabelWithHelpIcon";
export { default as LabelWithHelpIcon } from "./LabelWithHelpIcon.js";
export { default as DropDown } from "./DropDown.js";

View File

@@ -24,6 +24,7 @@ export { default as HelpIcon } from "./HelpIcon";
export { default as Tooltip } from "./Tooltip";
export { getPageFromMatch } from "./urls";
export { default as Autocomplete} from "./Autocomplete";
export { default as BranchSelector } from "./BranchSelector";
export { apiClient, NOT_FOUND_ERROR, UNAUTHORIZED_ERROR, CONFLICT_ERROR } from "./apiclient.js";

View File

@@ -1,19 +1,14 @@
// @flow
import React from "react";
import type { Branch, Repository } from "@scm-manager/ui-types";
import { Route, withRouter } from "react-router-dom";
import type {Branch, Repository} from "@scm-manager/ui-types";
import {translate} from "react-i18next";
import {Route, withRouter} from "react-router-dom";
import Changesets from "./Changesets";
import BranchSelector from "./BranchSelector";
import { connect } from "react-redux";
import { ErrorNotification, Loading } from "@scm-manager/ui-components";
import {
fetchBranches,
getBranches,
getFetchBranchesFailure,
isFetchBranchesPending
} from "../modules/branches";
import { compose } from "redux";
import {connect} from "react-redux";
import {BranchSelector, ErrorNotification, Loading} from "@scm-manager/ui-components";
import {fetchBranches, getBranches, getFetchBranchesFailure, isFetchBranchesPending} from "../modules/branches";
import {compose} from "redux";
type Props = {
repository: Repository,
@@ -92,10 +87,11 @@ class BranchRoot extends React.Component<Props> {
}
renderBranchSelector = () => {
const { repository, branches, selected } = this.props;
const { repository, branches, selected, t } = this.props;
if (repository._links.branches) {
return (
<BranchSelector
label={t("branch-selector.label")}
branches={branches}
selectedBranch={selected}
selected={(b: Branch) => {
@@ -133,6 +129,7 @@ const mapStateToProps = (state: any, ownProps: Props) => {
export default compose(
withRouter,
translate("repos"),
connect(
mapStateToProps,
mapDispatchToProps

View File

@@ -1,32 +1,19 @@
//@flow
import React from "react";
import {
deleteRepo,
fetchRepoByName,
getFetchRepoFailure,
getRepository,
isFetchRepoPending
} from "../modules/repos";
import {deleteRepo, fetchRepoByName, getFetchRepoFailure, getRepository, isFetchRepoPending} from "../modules/repos";
import { connect } from "react-redux";
import { Route, Switch } from "react-router-dom";
import type { Repository } from "@scm-manager/ui-types";
import {connect} from "react-redux";
import {Route, Switch} from "react-router-dom";
import type {Repository} from "@scm-manager/ui-types";
import {
ErrorPage,
Loading,
Navigation,
NavLink,
Page,
Section
} from "@scm-manager/ui-components";
import { translate } from "react-i18next";
import {ErrorPage, Loading, Navigation, NavLink, Page, Section} from "@scm-manager/ui-components";
import {translate} from "react-i18next";
import RepositoryDetails from "../components/RepositoryDetails";
import DeleteNavAction from "../components/DeleteNavAction";
import Edit from "../containers/Edit";
import Permissions from "../permissions/containers/Permissions";
import type { History } from "history";
import type {History} from "history";
import EditNavLink from "../components/EditNavLink";
import BranchRoot from "./ChangesetsRoot";
@@ -34,8 +21,8 @@ import ChangesetView from "./ChangesetView";
import PermissionsNavLink from "../components/PermissionsNavLink";
import Sources from "../sources/containers/Sources";
import RepositoryNavLink from "../components/RepositoryNavLink";
import { getRepositoriesLink } from "../../modules/indexResource";
import { ExtensionPoint } from "@scm-manager/ui-extensions";
import {getRepositoriesLink} from "../../modules/indexResource";
import {ExtensionPoint} from "@scm-manager/ui-extensions";
type Props = {
namespace: string,
@@ -198,16 +185,16 @@ class RepositoryRoot extends React.Component<Props> {
label={t("repository-root.sources")}
activeOnlyWhenExact={false}
/>
<ExtensionPoint
name="repository.navigation"
props={extensionProps}
renderAll={true}
/>
<PermissionsNavLink
permissionUrl={`${url}/permissions`}
repository={repository}
/>
<EditNavLink repository={repository} editUrl={`${url}/edit`} />
<ExtensionPoint
name="repository.navigation"
props={extensionProps}
renderAll={true}
/>
</Section>
<Section label={t("repository-root.actions-label")}>
<DeleteNavAction repository={repository} delete={this.delete} />

View File

@@ -1,20 +1,15 @@
// @flow
import React from "react";
import { connect } from "react-redux";
import { withRouter } from "react-router-dom";
import type { Branch, Repository } from "@scm-manager/ui-types";
import {connect} from "react-redux";
import {withRouter} from "react-router-dom";
import type {Branch, Repository} from "@scm-manager/ui-types";
import FileTree from "../components/FileTree";
import { ErrorNotification, Loading } from "@scm-manager/ui-components";
import BranchSelector from "../../containers/BranchSelector";
import {
fetchBranches,
getBranches,
getFetchBranchesFailure,
isFetchBranchesPending
} from "../../modules/branches";
import { compose } from "redux";
import {ErrorNotification, Loading} from "@scm-manager/ui-components";
import BranchSelector from "../../../../../scm-ui-components/packages/ui-components/src/BranchSelector";
import {fetchBranches, getBranches, getFetchBranchesFailure, isFetchBranchesPending} from "../../modules/branches";
import {compose} from "redux";
import Content from "./Content";
import { fetchSources, isDirectory } from "../modules/sources";
import {fetchSources, isDirectory} from "../modules/sources";
type Props = {
repository: Repository,