// @flow import React from "react"; import { connect } from "react-redux"; import { translate } from "react-i18next"; import classNames from "classnames"; import styled from "styled-components"; import { ExtensionPoint } from "@scm-manager/ui-extensions"; import type { File, Repository } from "@scm-manager/ui-types"; import { DateFromNow, FileSize, ErrorNotification, Icon } from "@scm-manager/ui-components"; import { getSources } from "../modules/sources"; import FileButtonAddons from "../components/content/FileButtonAddons"; import SourcesView from "./SourcesView"; import HistoryView from "./HistoryView"; type Props = { loading: boolean, file: File, repository: Repository, revision: string, path: string, // context props t: string => string }; type State = { collapsed: boolean, showHistory: boolean, errorFromExtension?: Error }; const VCenteredChild = styled.article` align-items: center; `; const RightMarginIcon = styled(Icon)` margin-right: 0.5em; `; const RightMarginFileButtonAddons = styled(FileButtonAddons)` margin-right: 0.5em; `; const LighterGreyBackgroundPanelBlock = styled.div` background-color: #fbfbfb; `; const LighterGreyBackgroundTable = styled.table` background-color: #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 }); } handleExtensionError = (error: Error) => { this.setState({ errorFromExtension: error }); }; showHeader() { const { file, revision } = this.props; const { showHistory, collapsed } = this.state; const icon = collapsed ? "angle-right" : "angle-down"; const selector = file._links.history ? ( this.setShowHistoryState(changeShowHistory) } /> ) : null; return (
{file.name}
{selector}
); } showMoreInformation() { const collapsed = this.state.collapsed; const { 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, errorFromExtension } = this.state; const header = this.showHeader(); const content = showHistory && file._links.history ? ( ) : ( ); const moreInformation = this.showMoreInformation(); return (
{header}
{moreInformation} {content}
{errorFromExtension && }
); } } const mapStateToProps = (state: any, ownProps: Props) => { const { repository, revision, path } = ownProps; const file = getSources(state, repository, revision, path); return { file }; }; export default connect(mapStateToProps)(translate("repos")(Content));