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