mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-06 13:35:44 +01:00
Load tree in FileTree
This commit is contained in:
@@ -1,35 +1,28 @@
|
||||
// @flow
|
||||
import React from "react";
|
||||
import { connect } from "react-redux";
|
||||
import { Route, withRouter } from "react-router-dom";
|
||||
import type { Repository, Branch, File } from "@scm-manager/ui-types";
|
||||
import FileTree from "../components/FileTree";
|
||||
import { ErrorNotification, Loading } from "@scm-manager/ui-components";
|
||||
import {
|
||||
fetchSources,
|
||||
getFetchSourcesFailure,
|
||||
getSources,
|
||||
isFetchSourcesPending
|
||||
} from "../modules/sources";
|
||||
import BranchSelector from "../../containers/BranchSelector";
|
||||
import { fetchBranches, getBranches } from "../../modules/branches";
|
||||
import {
|
||||
fetchBranches,
|
||||
getBranches,
|
||||
getFetchBranchesFailure,
|
||||
isFetchBranchesPending
|
||||
} from "../../modules/branches";
|
||||
import { compose } from "redux";
|
||||
|
||||
type Props = {
|
||||
repository: Repository,
|
||||
sources: File,
|
||||
loading: boolean,
|
||||
error: Error,
|
||||
revision: string,
|
||||
path: string,
|
||||
baseUrl: string,
|
||||
branches: Branch[],
|
||||
|
||||
// dispatch props
|
||||
fetchBranches: Repository => void,
|
||||
fetchSources: (
|
||||
repository: Repository,
|
||||
revision: string,
|
||||
path: string
|
||||
) => void,
|
||||
|
||||
// Context props
|
||||
history: any,
|
||||
@@ -38,57 +31,41 @@ type Props = {
|
||||
|
||||
class Sources extends React.Component<Props> {
|
||||
componentDidMount() {
|
||||
const {
|
||||
fetchSources,
|
||||
fetchBranches,
|
||||
repository,
|
||||
revision,
|
||||
path
|
||||
} = this.props;
|
||||
const { fetchBranches, repository } = this.props;
|
||||
|
||||
fetchBranches(repository);
|
||||
fetchSources(repository, revision, path);
|
||||
}
|
||||
|
||||
branchSelected = (branch?: Branch) => {
|
||||
const { path, baseUrl, history } = this.props;
|
||||
const { baseUrl, history } = this.props;
|
||||
let url;
|
||||
if (branch) {
|
||||
if (path) {
|
||||
url = `${baseUrl}/${branch.name}/${path}`;
|
||||
} else {
|
||||
url = `${baseUrl}/${branch.name}`;
|
||||
}
|
||||
url = `${baseUrl}/${branch.name}`;
|
||||
} else {
|
||||
url = `${baseUrl}/`;
|
||||
}
|
||||
history.push(url);
|
||||
};
|
||||
|
||||
findSelectedBranch = () => {
|
||||
const { revision, branches } = this.props;
|
||||
return branches.find((branch: Branch) => branch.name === revision);
|
||||
};
|
||||
|
||||
render() {
|
||||
const { sources, revision, path, baseUrl, loading, error } = this.props;
|
||||
const { repository, baseUrl, loading, error } = this.props;
|
||||
|
||||
if (error) {
|
||||
return <ErrorNotification error={error} />;
|
||||
}
|
||||
|
||||
if (!sources || loading) {
|
||||
if (loading) {
|
||||
return <Loading />;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{this.renderBranchSelector()}
|
||||
<FileTree
|
||||
tree={sources}
|
||||
revision={revision}
|
||||
path={path}
|
||||
baseUrl={baseUrl}
|
||||
<Route
|
||||
path={`${baseUrl}/:revision/:path*`}
|
||||
component={() => (
|
||||
<FileTree repository={repository} baseUrl={baseUrl} />
|
||||
)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
@@ -111,36 +88,32 @@ class Sources extends React.Component<Props> {
|
||||
}
|
||||
|
||||
const mapStateToProps = (state, ownProps) => {
|
||||
const { repository, match } = ownProps;
|
||||
const { revision, path } = match.params;
|
||||
const { repository } = ownProps;
|
||||
|
||||
const loading = isFetchSourcesPending(state, repository, revision, path);
|
||||
const error = getFetchSourcesFailure(state, repository, revision, path);
|
||||
const loading = isFetchBranchesPending(state, repository);
|
||||
const error = getFetchBranchesFailure(state, repository);
|
||||
const branches = getBranches(state, repository);
|
||||
const sources = getSources(state, repository, revision, path);
|
||||
|
||||
return {
|
||||
repository,
|
||||
loading,
|
||||
error,
|
||||
sources,
|
||||
revision,
|
||||
path,
|
||||
branches
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
fetchSources: (repository: Repository, revision: string, path: string) => {
|
||||
dispatch(fetchSources(repository, revision, path));
|
||||
},
|
||||
fetchBranches: (repository: Repository) => {
|
||||
dispatch(fetchBranches(repository));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
export default compose(
|
||||
withRouter,
|
||||
connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)
|
||||
)(Sources);
|
||||
|
||||
Reference in New Issue
Block a user