Added displaying of errors in changesets

This commit is contained in:
Philipp Czora
2018-09-18 09:22:08 +02:00
parent b1ffb0a562
commit a34dad585e
2 changed files with 30 additions and 19 deletions

View File

@@ -1,10 +1,10 @@
import React from "react"
import {connect} from "react-redux";
import {Loading} from "@scm-manager/ui-components";
import {ErrorNotification, Loading} from "@scm-manager/ui-components";
import {
fetchChangesetsByNamespaceAndName, fetchChangesetsByNamespaceNameAndBranch,
getChangesets, isFetchChangesetsPending,
getChangesets, getFetchChangesetsFailure, isFetchChangesetsPending,
} from "../modules/changesets";
import type {History} from "history";
import {fetchBranchesByNamespaceAndName, getBranchNames} from "../../repos/modules/branches";
@@ -24,8 +24,7 @@ type Props = {
class Changesets extends React.Component<State, Props> {
constructor(props) {
super(props);
this.state = {
};
this.state = {};
}
componentDidMount() {
@@ -40,22 +39,33 @@ class Changesets extends React.Component<State, Props> {
}
render() {
const {changesets, branchNames, loading} = this.props;
const branch = this.props.match.params.branch;
const {changesets, loading, error} = this.props;
if (loading || !changesets) {
return <Loading/>
}
if (branchNames) {
return <div>
<DropDown options={branchNames} preselectedOption={branch} optionSelected={branch => this.branchChanged(branch)}/>
<ChangesetTable changesets={changesets}/>
</div>;
} else {
return <ChangesetTable changesets={changesets}/>
}
<ErrorNotification error={error}/>
{this.renderContent()}
</div>
}
renderContent = () => {
const branch = this.props.match.params.branch;
const {changesets, branchNames} = this.props;
if (branchNames) {
return <div>
<DropDown options={branchNames} preselectedOption={branch}
optionSelected={branch => this.branchChanged(branch)}/>
<ChangesetTable changesets={changesets}/>
</div>;
}
return <ChangesetTable changesets={changesets}/>
};
branchChanged = (branchName: string) => {
const {history, repository} = this.props;
history.push(`/repo/${repository.namespace}/${repository.name}/history/${branchName}`);
@@ -68,7 +78,8 @@ const mapStateToProps = (state, ownProps: Props) => {
return {
loading: isFetchChangesetsPending(namespace, name, state),
changesets: getChangesets(state, namespace, name, ownProps.match.params.branch),
branchNames: getBranchNames(namespace, name, state)
branchNames: getBranchNames(namespace, name, state),
error: getFetchChangesetsFailure(state, namespace, name, ownProps.match.params.branch)
}
};

View File

@@ -119,7 +119,7 @@ export function getChangesetsForNamespaceAndNameFromState(namespace: string, nam
return Object.values(state.changesets[key].byId);
}
export function getChangesets(namespace: string, name: string, branch: string, state: Object) {
export function getChangesets(state: Object, namespace: string, name: string, branch: string) {
const key = createItemId(namespace, name, branch);
if (!state.changesets[key]) {
return null;