mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-18 11:11:07 +01:00
Disable create view when create link is missing
This commit is contained in:
@@ -15,7 +15,8 @@ type Props = {
|
|||||||
value?: string,
|
value?: string,
|
||||||
onChange: (value: string, name?: string) => void,
|
onChange: (value: string, name?: string) => void,
|
||||||
loading?: boolean,
|
loading?: boolean,
|
||||||
helpText?: string
|
helpText?: string,
|
||||||
|
disabled?: boolean
|
||||||
};
|
};
|
||||||
|
|
||||||
class Select extends React.Component<Props> {
|
class Select extends React.Component<Props> {
|
||||||
@@ -34,7 +35,7 @@ class Select extends React.Component<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { options, value, label, helpText, loading } = this.props;
|
const { options, value, label, helpText, loading, disabled } = this.props;
|
||||||
const loadingClass = loading ? "is-loading" : "";
|
const loadingClass = loading ? "is-loading" : "";
|
||||||
|
|
||||||
|
|
||||||
@@ -51,6 +52,7 @@ class Select extends React.Component<Props> {
|
|||||||
}}
|
}}
|
||||||
value={value}
|
value={value}
|
||||||
onChange={this.handleInput}
|
onChange={this.handleInput}
|
||||||
|
disabled={disabled}
|
||||||
>
|
>
|
||||||
{options.map(opt => {
|
{options.map(opt => {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ type Props = {
|
|||||||
branches: Branch[],
|
branches: Branch[],
|
||||||
loading?: boolean,
|
loading?: boolean,
|
||||||
transmittedName?: string,
|
transmittedName?: string,
|
||||||
|
disabled?: boolean,
|
||||||
t: string => string
|
t: string => string
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -59,7 +60,7 @@ class BranchForm extends React.Component<Props, State> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { t, branches, loading, transmittedName } = this.props;
|
const { t, branches, loading, transmittedName, disabled } = this.props;
|
||||||
const { name } = this.state;
|
const { name } = this.state;
|
||||||
orderBranches(branches);
|
orderBranches(branches);
|
||||||
const options = branches.map(branch => ({
|
const options = branches.map(branch => ({
|
||||||
@@ -78,6 +79,7 @@ class BranchForm extends React.Component<Props, State> {
|
|||||||
options={options}
|
options={options}
|
||||||
onChange={this.handleSourceChange}
|
onChange={this.handleSourceChange}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
|
disabled={disabled}
|
||||||
/>
|
/>
|
||||||
<InputField
|
<InputField
|
||||||
name="name"
|
name="name"
|
||||||
@@ -86,14 +88,14 @@ class BranchForm extends React.Component<Props, State> {
|
|||||||
value={name ? name : ""}
|
value={name ? name : ""}
|
||||||
validationError={this.state.nameValidationError}
|
validationError={this.state.nameValidationError}
|
||||||
errorMessage={t("validation.branch.nameInvalid")}
|
errorMessage={t("validation.branch.nameInvalid")}
|
||||||
disabled={!!transmittedName}
|
disabled={!!transmittedName || disabled}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="columns">
|
<div className="columns">
|
||||||
<div className="column">
|
<div className="column">
|
||||||
<SubmitButton
|
<SubmitButton
|
||||||
disabled={!this.isValid()}
|
disabled={disabled || !this.isValid()}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
label={t("branches.create.submit")}
|
label={t("branches.create.submit")}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ import {
|
|||||||
fetchBranches,
|
fetchBranches,
|
||||||
getBranches,
|
getBranches,
|
||||||
getFetchBranchesFailure,
|
getFetchBranchesFailure,
|
||||||
isFetchBranchesPending
|
isFetchBranchesPending,
|
||||||
|
isPermittedToCreateBranches
|
||||||
} from "../modules/branches";
|
} from "../modules/branches";
|
||||||
import { orderBranches } from "../util/orderBranches";
|
import { orderBranches } from "../util/orderBranches";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
@@ -67,8 +68,7 @@ class BranchesOverview extends React.Component<Props> {
|
|||||||
|
|
||||||
renderCreateButton() {
|
renderCreateButton() {
|
||||||
const { showCreateButton, t } = this.props;
|
const { showCreateButton, t } = this.props;
|
||||||
if (showCreateButton || true) {
|
if (showCreateButton) {
|
||||||
// TODO
|
|
||||||
return (
|
return (
|
||||||
<CreateButton
|
<CreateButton
|
||||||
label={t("branches.overview.createButton")}
|
label={t("branches.overview.createButton")}
|
||||||
@@ -85,12 +85,14 @@ const mapStateToProps = (state, ownProps) => {
|
|||||||
const loading = isFetchBranchesPending(state, repository);
|
const loading = isFetchBranchesPending(state, repository);
|
||||||
const error = getFetchBranchesFailure(state, repository);
|
const error = getFetchBranchesFailure(state, repository);
|
||||||
const branches = getBranches(state, repository);
|
const branches = getBranches(state, repository);
|
||||||
|
const showCreateButton = isPermittedToCreateBranches(state, repository);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
repository,
|
repository,
|
||||||
loading,
|
loading,
|
||||||
error,
|
error,
|
||||||
branches
|
branches,
|
||||||
|
showCreateButton
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ type Props = {
|
|||||||
repository: Repository,
|
repository: Repository,
|
||||||
branches: Branch[],
|
branches: Branch[],
|
||||||
createBranchesLink: string,
|
createBranchesLink: string,
|
||||||
|
isPermittedToCreateBranches: boolean,
|
||||||
|
|
||||||
// dispatcher functions
|
// dispatcher functions
|
||||||
fetchBranches: Repository => void,
|
fetchBranches: Repository => void,
|
||||||
@@ -78,7 +79,7 @@ class CreateBranch extends React.Component<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { t, loading, error, repository, branches, location } = this.props;
|
const { t, loading, error, repository, branches, createBranchesLink, location } = this.props;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return <ErrorNotification error={error} />;
|
return <ErrorNotification error={error} />;
|
||||||
@@ -97,6 +98,7 @@ class CreateBranch extends React.Component<Props> {
|
|||||||
repository={repository}
|
repository={repository}
|
||||||
branches={branches}
|
branches={branches}
|
||||||
transmittedName={this.transmittedName(location.search)}
|
transmittedName={this.transmittedName(location.search)}
|
||||||
|
disabled={!createBranchesLink}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ export function getBranches(state: Object, repository: Repository) {
|
|||||||
|
|
||||||
export function getBranchCreateLink(state: Object, repository: Repository) {
|
export function getBranchCreateLink(state: Object, repository: Repository) {
|
||||||
const repoState = getRepoState(state, repository);
|
const repoState = getRepoState(state, repository);
|
||||||
if (repoState && repoState.list) {
|
if (repoState && repoState.list && repoState.list._links && repoState.list._links.create) {
|
||||||
return repoState.list._links.create.href;
|
return repoState.list._links.create.href;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user