Fix reduce error with empty diff

This commit is contained in:
Rene Pfeuffer
2020-01-08 16:42:07 +01:00
parent 658a2bd3cd
commit 67777ff52d

View File

@@ -222,6 +222,14 @@ class DiffFile extends React.Component<Props, State> {
return <ChangeTypeTag className={classNames("is-rounded", "has-text-weight-normal")} color={color} label={value} />;
};
concat = (array: object[][]) => {
if (array.length > 0) {
return array.reduce((a, b) => a.concat(b));
} else {
return [];
}
};
render() {
const { file, fileControlFactory, fileAnnotationFactory, t } = this.props;
const { collapsed, sideBySide } = this.state;
@@ -236,7 +244,7 @@ class DiffFile extends React.Component<Props, State> {
<div className="panel-block is-paddingless">
{fileAnnotations}
<ModifiedDiffComponent className={viewType} viewType={viewType} hunks={file.hunks} diffType={file.type}>
{(hunks: HunkType[]) => hunks.map(this.renderHunk).reduce((a, b) => a.concat(b))}
{(hunks: HunkType[]) => this.concat(hunks.map(this.renderHunk))}
</ModifiedDiffComponent>
</div>
);