// @flow import React from "react"; import { translate } from "react-i18next"; import type { File, Repository } from "@scm-manager/ui-types"; import { DateFromNow } from "@scm-manager/ui-components"; import FileSize from "../components/FileSize"; import injectSheet from "react-jss"; import classNames from "classnames"; import FileButtonGroup from "../components/content/FileButtonGroup"; import SourcesView from "./SourcesView"; import HistoryView from "./HistoryView"; import { getSources } from "../modules/sources"; import { connect } from "react-redux"; import {ExtensionPoint} from "@scm-manager/ui-extensions"; type Props = { loading: boolean, error: Error, file: File, repository: Repository, revision: string, path: string, classes: any, t: string => string }; type State = { collapsed: boolean, showHistory: boolean }; const styles = { pointer: { cursor: "pointer" }, marginInHeader: { marginRight: "0.5em" }, isVerticalCenter: { display: "flex", alignItems: "center" }, hasBackground: { backgroundColor: "#FBFBFB" } }; class Content extends React.Component { constructor(props: Props) { super(props); this.state = { collapsed: true, showHistory: false }; } toggleCollapse = () => { this.setState(prevState => ({ collapsed: !prevState.collapsed })); }; setShowHistoryState(showHistory: boolean) { this.setState({ ...this.state, showHistory }); } showHeader() { const { file, classes } = this.props; const { showHistory, collapsed } = this.state; const icon = collapsed ? "fa-angle-right" : "fa-angle-down"; const selector = file._links.history ? ( this.setShowHistoryState(changeShowHistory) } /> ) : null; return (
{file.name}
{selector}
); } showMoreInformation() { const collapsed = this.state.collapsed; const { classes, file, revision, t, repository } = this.props; const date = ; const description = file.description ? (

{file.description.split("\n").map((item, key) => { return ( {item}
); })}

) : null; const fileSize = file.directory ? "" : ; if (!collapsed) { return (
{t("sources.content.path")} {file.path}
{t("sources.content.branch")} {revision}
{t("sources.content.size")} {fileSize}
{t("sources.content.lastModified")} {date}
{t("sources.content.description")} {description}
); } return null; } render() { const { file, revision, repository, path } = this.props; const { showHistory } = this.state; const header = this.showHeader(); const content = showHistory && file._links.history ? ( ) : ( ); const moreInformation = this.showMoreInformation(); return (
{header}
{moreInformation} {content}
); } } const mapStateToProps = (state: any, ownProps: Props) => { const { repository, revision, path } = ownProps; const file = getSources(state, repository, revision, path); return { file }; }; export default injectSheet(styles)( connect(mapStateToProps)(translate("repos")(Content)) );