/* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ import { EuiAccordion, EuiFlexGroup, EuiFlexItem, EuiIcon, EuiText, EuiTitle } from '@elastic/eui'; import theme from '@elastic/eui/dist/eui_theme_light.json'; import React, { MouseEvent } from 'react'; import { connect } from 'react-redux'; import { Link, RouteComponentProps, withRouter } from 'react-router-dom'; import styled from 'styled-components'; import { CommitDiff, FileDiff } from '../../../common/git_diff'; import { SearchScope } from '../../../model'; import { changeSearchScope } from '../../actions'; import { RootState } from '../../reducers'; // import { SearchBar } from '../search_bar'; import { DiffEditor } from './diff_editor'; const COMMIT_ID_LENGTH = 16; const B = styled.b` font-weight: bold; `; const PrimaryB = styled(B)` color: ${theme.euiColorPrimary}; `; const CommitId = styled.span` display: inline-block; padding: 0 ${theme.paddingSizes.xs}; border: ${theme.euiBorderThin}; `; const Addition = styled.div` padding: ${theme.paddingSizes.xs} ${theme.paddingSizes.s}; border-radius: ${theme.euiSizeXS}; color: white; margin-right: ${theme.euiSizeS}; background-color: ${theme.euiColorDanger}; `; const Deletion = styled(Addition)` background-color: ${theme.euiColorVis0}; `; const Container = styled.div` padding: ${theme.paddingSizes.xs} ${theme.paddingSizes.m}; `; const TopBarContainer = styled.div` height: calc(48rem / 14); border-bottom: ${theme.euiBorderThin}; padding: 0 ${theme.paddingSizes.m}; display: flex; flex-direction: row; justify-content: space-between; `; const Accordion = styled(EuiAccordion)` border: ${theme.euiBorderThick}; border-radius: ${theme.euiSizeS}; margin-bottom: ${theme.euiSize}; `; const Icon = styled(EuiIcon)` margin-right: ${theme.euiSizeS}; `; const Parents = styled.div` border-left: ${theme.euiBorderThin}; height: calc(32rem / 14); line-height: calc(32rem / 14); padding-left: ${theme.paddingSizes.s}; margin: ${theme.euiSizeS} 0; `; const H4 = styled.h4` height: 100%; line-height: calc(48rem / 14); `; const ButtonContainer = styled.div` cursor: default; `; interface Props extends RouteComponentProps<{ resource: string; org: string; repo: string }> { commit: CommitDiff | null; query: string; onSearchScopeChanged: (s: SearchScope) => void; repoScope: string[]; } export enum DiffLayout { Unified, Split, } const onClick = (e: MouseEvent) => { e.preventDefault(); e.stopPropagation(); }; const Difference = (props: { fileDiff: FileDiff; repoUri: string; revision: string }) => ( {props.fileDiff.additions} {props.fileDiff.deletions} {props.fileDiff.path}
View File
} >
); export class DiffPage extends React.Component { public state = { diffLayout: DiffLayout.Split, }; public setLayoutUnified = () => { this.setState({ diffLayout: DiffLayout.Unified }); }; public setLayoutSplit = () => { this.setState({ diffLayout: DiffLayout.Split }); }; public render() { const { commit, match } = this.props; const { repo, org, resource } = match.params; const repoUri = `${resource}/${org}/${repo}`; if (!commit) { return null; } const { additions, deletions, files } = commit; const { parents } = commit.commit; const title = commit.commit.message.split('\n')[0]; let parentsLinks = null; if (parents.length > 1) { const [p1, p2] = parents; parentsLinks = ( {p1}+ {p2} ); } else if (parents.length === 1) { parentsLinks = {parents[0]}; } const topBar = (

{title}

Parents: {parentsLinks}
); const fileCount = files.length; const diffs = commit.files.map(file => ( )); return (
{/* */} {topBar} {commit.commit.message} Showing {fileCount} Changed files with {additions} additions and {deletions} deletions Committed by {commit.commit.committer} {commit.commit.id.substr(0, COMMIT_ID_LENGTH)} {diffs}
); } } const mapStateToProps = (state: RootState) => ({ commit: state.commit.commit, query: state.search.query, repoScope: state.search.searchOptions.repoScope.map(r => r.uri), }); const mapDispatchToProps = { onSearchScopeChanged: changeSearchScope, }; export const Diff = withRouter( connect( mapStateToProps, mapDispatchToProps )(DiffPage) );