mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-02 03:25:56 +01:00
Determine branch for which to show changesets via URL
This commit is contained in:
@@ -4,15 +4,17 @@ import React from "react";
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
options: string[],
|
options: string[],
|
||||||
optionSelected: string => void
|
optionSelected: string => void,
|
||||||
|
preselectedOption: string
|
||||||
}
|
}
|
||||||
|
|
||||||
class DropDown extends React.Component<Props> {
|
class DropDown extends React.Component<Props> {
|
||||||
render() {
|
render() {
|
||||||
const {options} = this.props;
|
const {options, preselectedOption} = this.props;
|
||||||
return <select onChange={this.change}>
|
return <select value={preselectedOption} onChange={this.change}>
|
||||||
{options.map(option => {
|
{options.map(option => {
|
||||||
return <option key={option} value={option}>{option}</option>
|
return <option key={option}
|
||||||
|
value={option}>{option}</option>
|
||||||
})}
|
})}
|
||||||
</select>
|
</select>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ import {
|
|||||||
fetchChangesetsByNamespaceAndName, fetchChangesetsByNamespaceNameAndBranch,
|
fetchChangesetsByNamespaceAndName, fetchChangesetsByNamespaceNameAndBranch,
|
||||||
getChangesets,
|
getChangesets,
|
||||||
} from "../modules/changesets";
|
} from "../modules/changesets";
|
||||||
import {translate} from "react-i18next";
|
import type { History } from "history";
|
||||||
import {fetchBranchesByNamespaceAndName, getBranchNames} from "../../repos/modules/branches";
|
import {fetchBranchesByNamespaceAndName, getBranchNames} from "../../repos/modules/branches";
|
||||||
import type {Repository} from "@scm-manager/ui-types";
|
import type {Repository} from "@scm-manager/ui-types";
|
||||||
import ChangesetTable from "../components/ChangesetTable";
|
import ChangesetTable from "../components/ChangesetTable";
|
||||||
import DropDown from "../components/DropDown";
|
import DropDown from "../components/DropDown";
|
||||||
|
import {withRouter} from "react-router-dom";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
repository: Repository,
|
repository: Repository,
|
||||||
@@ -18,30 +19,34 @@ type Props = {
|
|||||||
fetchChangesetsByNamespaceNameAndBranch: (namespace: string, name: string, branch: string) => void
|
fetchChangesetsByNamespaceNameAndBranch: (namespace: string, name: string, branch: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
type State = {
|
|
||||||
branchName: string
|
|
||||||
}
|
|
||||||
|
|
||||||
class Changesets extends React.Component<State, Props> {
|
class Changesets extends React.Component<State, Props> {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {};
|
this.state = {
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const {namespace, name} = this.props.repository;
|
const {namespace, name} = this.props.repository;
|
||||||
this.props.fetchChangesetsByNamespaceNameAndBranch(namespace, name, this.props.branchName);
|
const branchName = this.props.match.params.branch;
|
||||||
|
if (branchName) {
|
||||||
|
this.props.fetchChangesetsByNamespaceNameAndBranch(namespace, name, branchName);
|
||||||
|
} else {
|
||||||
|
this.props.fetchChangesetsByNamespaceAndName(namespace, name);
|
||||||
|
}
|
||||||
this.props.fetchBranchesByNamespaceAndName(namespace, name);
|
this.props.fetchBranchesByNamespaceAndName(namespace, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {changesets, branchNames} = this.props;
|
const {changesets, branchNames} = this.props;
|
||||||
|
const branch = this.props.match.params.branch;
|
||||||
if (changesets === null) {
|
if (changesets === null) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
if (branchNames) {
|
if (branchNames) {
|
||||||
return <div>
|
return <div>
|
||||||
<DropDown options={branchNames} optionSelected={this.branchChanged}/>
|
<DropDown options={branchNames} preselectedOption={branch} optionSelected={branch => this.branchChanged(branch)}/>
|
||||||
<ChangesetTable changesets={changesets}/>
|
<ChangesetTable changesets={changesets}/>
|
||||||
</div>;
|
</div>;
|
||||||
} else {
|
} else {
|
||||||
@@ -51,16 +56,16 @@ class Changesets extends React.Component<State, Props> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
branchChanged = (branchName: string) => {
|
branchChanged = (branchName: string) => {
|
||||||
this.props.history.push(branchName)
|
const { history, repository } = this.props;
|
||||||
|
history.push(`/repo/${repository.namespace}/${repository.name}/history/${branchName}`);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const mapStateToProps = (state, ownProps: Props) => {
|
const mapStateToProps = (state, ownProps: Props) => {
|
||||||
console.log("mapStateToProps ownProps: ", ownProps);
|
|
||||||
const {namespace, name} = ownProps.repository;
|
const {namespace, name} = ownProps.repository;
|
||||||
return {
|
return {
|
||||||
changesets: getChangesets(namespace, name, ownProps.branchName, state),
|
changesets: getChangesets(namespace, name, ownProps.match.params.branch, state),
|
||||||
branchNames: getBranchNames(namespace, name, state)
|
branchNames: getBranchNames(namespace, name, state)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -79,7 +84,7 @@ const mapDispatchToProps = dispatch => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default connect(
|
export default withRouter(connect(
|
||||||
mapStateToProps,
|
mapStateToProps,
|
||||||
mapDispatchToProps
|
mapDispatchToProps
|
||||||
)(Changesets);
|
)(Changesets));
|
||||||
|
|||||||
@@ -103,13 +103,9 @@ class RepositoryRoot extends React.Component<Props> {
|
|||||||
component={() => <Edit repository={repository}/>}
|
component={() => <Edit repository={repository}/>}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path={`${url}/history`}
|
path={`${url}/history/:branch`}
|
||||||
component={() => <Changesets repository={repository} branchName={"master"} history={this.props.history}/>}
|
component={() => <Changesets repository={repository}/>}
|
||||||
/>
|
/>
|
||||||
{/*<Route*/}
|
|
||||||
{/*path={`${url}/history/:branchName`}*/}
|
|
||||||
{/*component={() => <Changesets repository={repository} branchName={} history={this.props.history}/>}*/}
|
|
||||||
{/*/>*/}
|
|
||||||
</div>
|
</div>
|
||||||
<div className="column">
|
<div className="column">
|
||||||
<Navigation>
|
<Navigation>
|
||||||
|
|||||||
Reference in New Issue
Block a user