Make Diff collapsible optional and render type only if present

This commit is contained in:
Rene Pfeuffer
2019-08-19 10:01:05 +02:00
parent bd5a8ba508
commit e9f56f201b

View File

@@ -46,6 +46,7 @@ const styles = {
type Props = DiffObjectProps & { type Props = DiffObjectProps & {
file: File, file: File,
collapsible: true,
// context props // context props
classes: any, classes: any,
t: string => string t: string => string
@@ -66,9 +67,11 @@ class DiffFile extends React.Component<Props, State> {
} }
toggleCollapse = () => { toggleCollapse = () => {
if (this.props.collapsable) {
this.setState(state => ({ this.setState(state => ({
collapsed: !state.collapsed collapsed: !state.collapsed
})); }));
}
}; };
toggleSideBySide = () => { toggleSideBySide = () => {
@@ -173,6 +176,9 @@ class DiffFile extends React.Component<Props, State> {
renderChangeTag = (file: any) => { renderChangeTag = (file: any) => {
const { t, classes } = this.props; const { t, classes } = this.props;
if (!file.type) {
return;
}
const key = "diff.changes." + file.type; const key = "diff.changes." + file.type;
let value = t(key); let value = t(key);
if (key === value) { if (key === value) {
@@ -205,6 +211,7 @@ class DiffFile extends React.Component<Props, State> {
file, file,
fileControlFactory, fileControlFactory,
fileAnnotationFactory, fileAnnotationFactory,
collapsible,
classes, classes,
t t
} = this.props; } = this.props;
@@ -227,6 +234,7 @@ class DiffFile extends React.Component<Props, State> {
</div> </div>
); );
} }
const collapseIcon = collapsible? <i className={icon} />: null;
const fileControls = fileControlFactory const fileControls = fileControlFactory
? fileControlFactory(file, this.setCollapse) ? fileControlFactory(file, this.setCollapse)
@@ -240,7 +248,7 @@ class DiffFile extends React.Component<Props, State> {
onClick={this.toggleCollapse} onClick={this.toggleCollapse}
title={this.hoverFileTitle(file)} title={this.hoverFileTitle(file)}
> >
<i className={icon} /> {collapseIcon}
<span <span
className={classNames("is-ellipsis-overflow", classes.title)} className={classNames("is-ellipsis-overflow", classes.title)}
> >