Correct merge

This commit is contained in:
Florian Scholdei
2019-10-10 11:37:14 +02:00
parent 2a3e5e4ded
commit be1781275d
2 changed files with 78 additions and 40 deletions

View File

@@ -13,10 +13,11 @@ import {
} from "react-diff-view"; } from "react-diff-view";
import { Button, ButtonGroup } from "../buttons"; import { Button, ButtonGroup } from "../buttons";
import Tag from "../Tag"; import Tag from "../Tag";
import Icon from "../Icon";
type Props = DiffObjectProps & { type Props = DiffObjectProps & {
file: File, file: File,
collapsible: true, defaultCollapse: boolean,
// context props // context props
t: string => string t: string => string
@@ -28,7 +29,8 @@ type State = {
}; };
const DiffFilePanel = styled.div` const DiffFilePanel = styled.div`
${props => (props.isBinary ? "border-bottom: none" : "")}; /* remove bottom border for collapsed panels */
${props => (props.collapsed ? "border-bottom: none;" : "")};
`; `;
const FlexWrapLevel = styled.div` const FlexWrapLevel = styled.div`
@@ -55,7 +57,7 @@ const HunkDivider = styled.hr`
`; `;
const ChangeTypeTag = styled(Tag)` const ChangeTypeTag = styled(Tag)`
margin-left: ".75rem"; marginleft: ".75rem";
`; `;
const ModifiedDiffComponent = styled(DiffComponent)` const ModifiedDiffComponent = styled(DiffComponent)`
@@ -82,16 +84,31 @@ const ModifiedDiffComponent = styled(DiffComponent)`
`; `;
class DiffFile extends React.Component<Props, State> { class DiffFile extends React.Component<Props, State> {
static defaultProps = {
defaultCollapse: false
};
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);
this.state = { this.state = {
collapsed: false, collapsed: this.props.defaultCollapse,
sideBySide: false sideBySide: false
}; };
} }
// collapse diff by clicking collapseDiffs button
componentDidUpdate(prevProps) {
const { defaultCollapse } = this.props;
if (prevProps.defaultCollapse !== defaultCollapse) {
this.setState({
collapsed: defaultCollapse
});
}
}
toggleCollapse = () => { toggleCollapse = () => {
if (this.props.collapsable) { const { file } = this.props;
if (file && !file.isBinary) {
this.setState(state => ({ this.setState(state => ({
collapsed: !state.collapsed collapsed: !state.collapsed
})); }));
@@ -172,7 +189,8 @@ class DiffFile extends React.Component<Props, State> {
) { ) {
return ( return (
<> <>
{file.oldPath} <i className="fa fa-arrow-right" /> {file.newPath} {file.oldPath} <Icon name="arrow-right" color="inherit" />{" "}
{file.newPath}
</> </>
); );
} else if (file.type === "delete") { } else if (file.type === "delete") {
@@ -224,23 +242,17 @@ class DiffFile extends React.Component<Props, State> {
}; };
render() { render() {
const { const { file, fileControlFactory, fileAnnotationFactory, t } = this.props;
file,
fileControlFactory,
fileAnnotationFactory,
collapsible,
t
} = this.props;
const { collapsed, sideBySide } = this.state; const { collapsed, sideBySide } = this.state;
const viewType = sideBySide ? "split" : "unified"; const viewType = sideBySide ? "split" : "unified";
let body = null; let body = null;
let icon = "fa fa-angle-right"; let icon = "angle-right";
if (!collapsed) { if (!collapsed) {
const fileAnnotations = fileAnnotationFactory const fileAnnotations = fileAnnotationFactory
? fileAnnotationFactory(file) ? fileAnnotationFactory(file)
: null; : null;
icon = "fa fa-angle-down"; icon = "angle-down";
body = ( body = (
<div className="panel-block is-paddingless"> <div className="panel-block is-paddingless">
{fileAnnotations} {fileAnnotations}
@@ -250,7 +262,9 @@ class DiffFile extends React.Component<Props, State> {
</div> </div>
); );
} }
const collapseIcon = collapsible ? <i className={icon} /> : null; const collapseIcon = file && !file.isBinary ? (
<Icon name={icon} color="inherit" />
) : null;
const fileControls = fileControlFactory const fileControls = fileControlFactory
? fileControlFactory(file, this.setCollapse) ? fileControlFactory(file, this.setCollapse)
@@ -258,7 +272,7 @@ class DiffFile extends React.Component<Props, State> {
return ( return (
<DiffFilePanel <DiffFilePanel
className={classNames("panel", "is-size-6")} className={classNames("panel", "is-size-6")}
isBinary={file && file.isBinary} collapsed={(file && file.isBinary) || collapsed}
> >
<div className="panel-heading"> <div className="panel-heading">
<FlexWrapLevel className="level"> <FlexWrapLevel className="level">
@@ -283,20 +297,10 @@ class DiffFile extends React.Component<Props, State> {
<ButtonGroup> <ButtonGroup>
<Button <Button
action={this.toggleSideBySide} action={this.toggleSideBySide}
className="reduced-mobile" icon={sideBySide ? "align-left" : "columns"}
> label={t(sideBySide ? "diff.combined" : "diff.sideBySide")}
<span className="icon is-small"> reducedMobile={true}
<i
className={classNames(
"fas",
sideBySide ? "fa-align-left" : "fa-columns"
)}
/> />
</span>
<span>
{t(sideBySide ? "diff.combined" : "diff.sideBySide")}
</span>
</Button>
{fileControls} {fileControls}
</ButtonGroup> </ButtonGroup>
</ButtonWrapper> </ButtonWrapper>

View File

@@ -3,8 +3,8 @@ import React from "react";
import { Interpolate, translate } from "react-i18next"; import { Interpolate, translate } from "react-i18next";
import classNames from "classnames"; import classNames from "classnames";
import styled from "styled-components"; import styled from "styled-components";
import type { Changeset, Repository, Tag } from "@scm-manager/ui-types";
import { ExtensionPoint } from "@scm-manager/ui-extensions"; import { ExtensionPoint } from "@scm-manager/ui-extensions";
import type { Changeset, Repository, Tag } from "@scm-manager/ui-types";
import { import {
DateFromNow, DateFromNow,
ChangesetId, ChangesetId,
@@ -13,7 +13,9 @@ import {
ChangesetDiff, ChangesetDiff,
AvatarWrapper, AvatarWrapper,
AvatarImage, AvatarImage,
changesets changesets,
Level,
Button
} from "@scm-manager/ui-components"; } from "@scm-manager/ui-components";
type Props = { type Props = {
@@ -24,6 +26,10 @@ type Props = {
t: string => string t: string => string
}; };
type State = {
collapsed: boolean
};
const RightMarginP = styled.p` const RightMarginP = styled.p`
margin-right: 1em; margin-right: 1em;
`; `;
@@ -34,20 +40,31 @@ const TagsWrapper = styled.div`
} }
`; `;
class ChangesetDetails extends React.Component<Props> { const BottomMarginLevel = styled(Level)`
margin-bottom: 1rem !important;
`;
class ChangesetDetails extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
collapsed: false
};
}
render() { render() {
const { changeset, repository } = this.props; const { changeset, repository, t } = this.props;
const { collapsed } = this.state;
const description = changesets.parseDescription(changeset.description); const description = changesets.parseDescription(changeset.description);
const id = ( const id = (
<ChangesetId repository={repository} changeset={changeset} link={false} /> <ChangesetId repository={repository} changeset={changeset} link={false} />
); );
const date = <DateFromNow date={changeset.date} />; const date = <DateFromNow date={changeset.date} />;
return ( return (
<div> <>
<div className="content"> <div className={classNames("content", "is-marginless")}>
<h4> <h4>
<ExtensionPoint <ExtensionPoint
name="changeset.description" name="changeset.description"
@@ -92,9 +109,20 @@ class ChangesetDetails extends React.Component<Props> {
</p> </p>
</div> </div>
<div> <div>
<ChangesetDiff changeset={changeset} /> <BottomMarginLevel
</div> right={
<Button
action={this.collapseDiffs}
color="default"
icon={collapsed ? "eye" : "eye-slash"}
label={t("changesets.collapseDiffs")}
reducedMobile={true}
/>
}
/>
<ChangesetDiff changeset={changeset} defaultCollapse={collapsed} />
</div> </div>
</>
); );
} }
@@ -115,6 +143,12 @@ class ChangesetDetails extends React.Component<Props> {
} }
return null; return null;
}; };
collapseDiffs = () => {
this.setState(state => ({
collapsed: !state.collapsed
}));
};
} }
export default translate("repos")(ChangesetDetails); export default translate("repos")(ChangesetDetails);