Files
SCM-Manager/scm-ui/src/repos/sources/containers/Sources.js

90 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-09-27 16:32:37 +02:00
// @flow
import React from "react";
import { connect } from "react-redux";
import type { Repository, File } from "@scm-manager/ui-types";
2018-09-27 16:32:37 +02:00
import FileTree from "../components/FileTree";
import { ErrorNotification, Loading } from "@scm-manager/ui-components";
import {
fetchSources,
getFetchSourcesFailure,
getSources,
isFetchSourcesPending
} from "../modules/sources";
type Props = {
repository: Repository,
sources: File,
2018-09-27 16:32:37 +02:00
loading: boolean,
error: Error,
revision: string,
path: string,
baseUrl: string,
2018-09-27 16:32:37 +02:00
// dispatch props
fetchSources: (
repository: Repository,
revision: string,
path: string
) => void,
match: any
2018-09-27 16:32:37 +02:00
};
class Sources extends React.Component<Props> {
componentDidMount() {
const { fetchSources, repository, revision, path } = this.props;
2018-09-27 16:32:37 +02:00
fetchSources(repository, revision, path);
2018-09-27 16:32:37 +02:00
}
render() {
const { sources, revision, path, baseUrl, loading, error } = this.props;
2018-09-27 16:32:37 +02:00
if (error) {
return <ErrorNotification error={error} />;
}
if (!sources || loading) {
return <Loading />;
}
return (
<FileTree
tree={sources}
revision={revision}
path={path}
baseUrl={baseUrl}
/>
);
2018-09-27 16:32:37 +02:00
}
}
const mapStateToProps = (state, ownProps) => {
const { repository } = ownProps;
const { revision, path } = ownProps.match.params;
2018-09-27 16:32:37 +02:00
const loading = isFetchSourcesPending(state, repository, revision, path);
const error = getFetchSourcesFailure(state, repository, revision, path);
const sources = getSources(state, repository, revision, path);
2018-09-27 16:32:37 +02:00
return {
loading,
error,
sources,
revision,
path
2018-09-27 16:32:37 +02:00
};
};
const mapDispatchToProps = dispatch => {
return {
fetchSources: (repository: Repository, revision: string, path: string) => {
dispatch(fetchSources(repository, revision, path));
2018-09-27 16:32:37 +02:00
}
};
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(Sources);