fix too long diff file title

This commit is contained in:
Florian Scholdei
2019-05-26 14:10:59 +02:00
parent ecbc7b67e6
commit 2174db20cd

View File

@@ -17,13 +17,27 @@ const styles = {
panel: { panel: {
fontSize: "1rem" fontSize: "1rem"
}, },
/* breaks into a second row
* when buttons and title become too long
*/
level: {
flexWrap: "wrap"
},
titleHeader: { titleHeader: {
display: "flex",
maxWidth: "100%",
cursor: "pointer" cursor: "pointer"
}, },
title: { title: {
marginLeft: ".25rem", marginLeft: ".25rem",
fontSize: "1rem" fontSize: "1rem"
}, },
/* align child to right
*/
buttonHeader: {
display: "flex",
marginLeft: "auto"
},
hunkDivider: { hunkDivider: {
margin: ".5rem 0" margin: ".5rem 0"
}, },
@@ -143,14 +157,41 @@ class DiffFile extends React.Component<Props, State> {
return file.newPath; return file.newPath;
}; };
hoverFileTitle = (file: any) => {
if (
file.oldPath !== file.newPath &&
(file.type === "copy" || file.type === "rename")
) {
return (
<>
{file.oldPath} > {file.newPath}
</>
);
} else if (file.type === "delete") {
return file.oldPath;
}
return file.newPath;
};
renderChangeTag = (file: any) => { renderChangeTag = (file: any) => {
const { t } = this.props; const { t, classes } = this.props;
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) {
value = file.type; value = file.type;
} }
return <span className="tag is-info has-text-weight-normal">{value}</span>; return (
<span
className={classNames(
"tag",
"is-info",
"has-text-weight-normal",
classes.changeType
)}
>
{value}
</span>
);
}; };
render() { render() {
@@ -187,20 +228,21 @@ class DiffFile extends React.Component<Props, State> {
return ( return (
<div className={classNames("panel", classes.panel)}> <div className={classNames("panel", classes.panel)}>
<div className="panel-heading"> <div className="panel-heading">
<div className="level"> <div className={classNames("level", classes.level)}>
<div <div
className={classNames("level-left", classes.titleHeader)} className={classNames("level-left", classes.titleHeader)}
onClick={this.toggleCollapse} onClick={this.toggleCollapse}
title={this.hoverFileTitle(file)}
> >
<i className={icon} /> <i className={icon} />
<span className={classes.title}> <span
className={classNames("is-ellipsis-overflow", classes.title)}
>
{this.renderFileTitle(file)} {this.renderFileTitle(file)}
</span> </span>
<span className={classes.changeType}> {this.renderChangeTag(file)}
{this.renderChangeTag(file)}
</span>
</div> </div>
<div className="level-right"> <div className={classNames("level-right", classes.buttonHeader)}>
<Button action={this.toggleSideBySide} className="reduced-mobile"> <Button action={this.toggleSideBySide} className="reduced-mobile">
<span className="icon is-small"> <span className="icon is-small">
<i <i