import {Component} from 'react'; import styled from '@emotion/styled'; import FileChange from 'sentry/components/fileChange'; import {ListGroup, ListGroupItem} from 'sentry/components/listGroup'; import {t, tn} from 'sentry/locale'; import space from 'sentry/styles/space'; import {FilesByRepository} from 'sentry/types'; type CollapsedProps = { count: number; onClick: React.MouseEventHandler; }; function Collapsed(props: CollapsedProps) { return ( {tn('Show %s collapsed file', 'Show %s collapsed files', props.count)} ); } type Props = { collapsible: boolean; fileChangeSummary: FilesByRepository[string]; maxWhenCollapsed: number; repository: string; }; type State = { collapsed: boolean; loading: boolean; }; class RepositoryFileSummary extends Component { static defaultProps = { collapsible: true, maxWhenCollapsed: 5, }; state: State = { loading: true, collapsed: true, }; onCollapseToggle = () => { this.setState({ collapsed: !this.state.collapsed, }); }; render() { const {repository, fileChangeSummary, collapsible, maxWhenCollapsed} = this.props; let files = Object.keys(fileChangeSummary); const fileCount = files.length; files.sort(); if (this.state.collapsed && collapsible && fileCount > maxWhenCollapsed) { files = files.slice(0, maxWhenCollapsed); } const numCollapsed = fileCount - files.length; const canCollapse = collapsible && fileCount > maxWhenCollapsed; return (
{tn('%s file changed in %s', '%s files changed in %s', fileCount, repository)}
{files.map(filename => { const {authors} = fileChangeSummary[filename]; return ( ); })} {numCollapsed > 0 && ( )} {numCollapsed === 0 && canCollapse && ( {t('Collapse')} )}
); } } const Container = styled('div')` margin-bottom: ${space(2)}; `; export default RepositoryFileSummary;