fix formatting with prettier

This commit is contained in:
Eduard Heimbuch
2020-08-12 12:53:59 +02:00
parent f3d2c3d17b
commit e9edd5ad8f
9 changed files with 177 additions and 172 deletions

View File

@@ -29,14 +29,14 @@ import parser from "gitdiff-parser";
import simpleDiff from "../__resources__/Diff.simple";
import hunksDiff from "../__resources__/Diff.hunks";
import binaryDiff from "../__resources__/Diff.binary";
import {DiffEventContext, File, FileControlFactory} from "./DiffTypes";
import { DiffEventContext, File, FileControlFactory } from "./DiffTypes";
import Toast from "../toast/Toast";
import { getPath } from "./diffs";
import DiffButton from "./DiffButton";
import styled from "styled-components";
import { MemoryRouter } from "react-router-dom";
import {one, two} from "../__resources__/changesets";
import {Changeset} from "@scm-manager/ui-types";
import { one, two } from "../__resources__/changesets";
import { Changeset } from "@scm-manager/ui-types";
import JumpToFileButton from "./JumpToFileButton";
const diffFiles = parser.parse(simpleDiff);
@@ -47,7 +47,7 @@ const Container = styled.div`
const RoutingDecorator = (story: () => ReactNode) => <MemoryRouter initialEntries={["/"]}>{story()}</MemoryRouter>;
const fileControlFactory: (changeset: Changeset) => FileControlFactory = (changeset) => (file) => {
const fileControlFactory: (changeset: Changeset) => FileControlFactory = changeset => file => {
const baseUrl = "/repo/hitchhiker/heartOfGold/code/changeset";
const sourceLink = {
url: `${baseUrl}/${changeset.id}/${file.newPath}/`,
@@ -76,10 +76,7 @@ const fileControlFactory: (changeset: Changeset) => FileControlFactory = (change
}
}
return links.map(({url, label}) => <JumpToFileButton
tooltip={label}
link={url}
/>);
return links.map(({ url, label }) => <JumpToFileButton tooltip={label} link={url} />);
};
storiesOf("Diff", module)
@@ -164,8 +161,4 @@ storiesOf("Diff", module)
});
return <Diff diff={filesWithLanguage} />;
})
.add("WithLinkToFile", () => (
<Diff
diff={diffFiles}
/>
));
.add("WithLinkToFile", () => <Diff diff={diffFiles} />);

View File

@@ -23,15 +23,15 @@
*/
import React from "react";
import DiffFile from "./DiffFile";
import {DiffObjectProps, File, FileControlFactory} from "./DiffTypes";
import { DiffObjectProps, File, FileControlFactory } from "./DiffTypes";
import Notification from "../Notification";
import {WithTranslation, withTranslation} from "react-i18next";
import { WithTranslation, withTranslation } from "react-i18next";
type Props = WithTranslation &
DiffObjectProps & {
diff: File[];
fileControlFactory?: FileControlFactory;
};
diff: File[];
fileControlFactory?: FileControlFactory;
};
class Diff extends React.Component<Props> {
static defaultProps: Partial<Props> = {
@@ -39,7 +39,7 @@ class Diff extends React.Component<Props> {
};
render() {
const {diff, t, ...fileProps} = this.props;
const { diff, t, ...fileProps } = this.props;
return (
<>
{diff.length === 0 ? (

View File

@@ -22,21 +22,21 @@
* SOFTWARE.
*/
import React from "react";
import {withTranslation, WithTranslation} from "react-i18next";
import { withTranslation, WithTranslation } from "react-i18next";
import classNames from "classnames";
import styled from "styled-components";
// @ts-ignore
import {Decoration, getChangeKey, Hunk} from "react-diff-view";
import {ButtonGroup} from "../buttons";
import { Decoration, getChangeKey, Hunk } from "react-diff-view";
import { ButtonGroup } from "../buttons";
import Tag from "../Tag";
import Icon from "../Icon";
import {Change, ChangeEvent, DiffObjectProps, File, Hunk as HunkType} from "./DiffTypes";
import { Change, ChangeEvent, DiffObjectProps, File, Hunk as HunkType } from "./DiffTypes";
import TokenizedDiffView from "./TokenizedDiffView";
import DiffButton from "./DiffButton";
import {MenuContext} from "@scm-manager/ui-components";
import DiffExpander, {ExpandableHunk} from "./DiffExpander";
import { MenuContext } from "@scm-manager/ui-components";
import DiffExpander, { ExpandableHunk } from "./DiffExpander";
import HunkExpandLink from "./HunkExpandLink";
import {Modal} from "../modals";
import { Modal } from "../modals";
import ErrorNotification from "../ErrorNotification";
import HunkExpandDivider from "./HunkExpandDivider";
@@ -44,8 +44,8 @@ const EMPTY_ANNOTATION_FACTORY = {};
type Props = DiffObjectProps &
WithTranslation & {
file: File;
};
file: File;
};
type Collapsible = {
collapsed?: boolean;
@@ -115,7 +115,7 @@ class DiffFile extends React.Component<Props, State> {
}
defaultCollapse: () => boolean = () => {
const {defaultCollapse, file} = this.props;
const { defaultCollapse, file } = this.props;
if (typeof defaultCollapse === "boolean") {
return defaultCollapse;
} else if (typeof defaultCollapse === "function") {
@@ -126,7 +126,7 @@ class DiffFile extends React.Component<Props, State> {
};
toggleCollapse = () => {
const {file} = this.state;
const { file } = this.state;
if (this.hasContent(file)) {
this.setState(state => ({
collapsed: !state.collapsed
@@ -157,7 +157,7 @@ class DiffFile extends React.Component<Props, State> {
<HunkExpandLink
icon={"fa-angle-double-up"}
onClick={this.expandHead(expandableHunk, expandableHunk.maxExpandHeadRange)}
text={this.props.t("diff.expandComplete", {count: expandableHunk.maxExpandHeadRange})}
text={this.props.t("diff.expandComplete", { count: expandableHunk.maxExpandHeadRange })}
/>
</HunkExpandDivider>
);
@@ -167,19 +167,19 @@ class DiffFile extends React.Component<Props, State> {
<HunkExpandLink
icon={"fa-angle-up"}
onClick={this.expandHead(expandableHunk, 10)}
text={this.props.t("diff.expandByLines", {count: 10})}
text={this.props.t("diff.expandByLines", { count: 10 })}
/>{" "}
<HunkExpandLink
icon={"fa-angle-double-up"}
onClick={this.expandHead(expandableHunk, expandableHunk.maxExpandHeadRange)}
text={this.props.t("diff.expandComplete", {count: expandableHunk.maxExpandHeadRange})}
text={this.props.t("diff.expandComplete", { count: expandableHunk.maxExpandHeadRange })}
/>
</HunkExpandDivider>
);
}
}
// hunk header must be defined
return <span/>;
return <span />;
};
createHunkFooter = (expandableHunk: ExpandableHunk) => {
@@ -190,7 +190,7 @@ class DiffFile extends React.Component<Props, State> {
<HunkExpandLink
icon={"fa-angle-double-down"}
onClick={this.expandBottom(expandableHunk, expandableHunk.maxExpandBottomRange)}
text={this.props.t("diff.expandComplete", {count: expandableHunk.maxExpandBottomRange})}
text={this.props.t("diff.expandComplete", { count: expandableHunk.maxExpandBottomRange })}
/>
</HunkExpandDivider>
);
@@ -200,19 +200,19 @@ class DiffFile extends React.Component<Props, State> {
<HunkExpandLink
icon={"fa-angle-down"}
onClick={this.expandBottom(expandableHunk, 10)}
text={this.props.t("diff.expandByLines", {count: 10})}
text={this.props.t("diff.expandByLines", { count: 10 })}
/>{" "}
<HunkExpandLink
icon={"fa-angle-double-down"}
onClick={this.expandBottom(expandableHunk, expandableHunk.maxExpandBottomRange)}
text={this.props.t("diff.expandComplete", {count: expandableHunk.maxExpandBottomRange})}
text={this.props.t("diff.expandComplete", { count: expandableHunk.maxExpandBottomRange })}
/>
</HunkExpandDivider>
);
}
}
// hunk footer must be defined
return <span/>;
return <span />;
};
createLastHunkFooter = (expandableHunk: ExpandableHunk) => {
@@ -222,7 +222,7 @@ class DiffFile extends React.Component<Props, State> {
<HunkExpandLink
icon={"fa-angle-down"}
onClick={this.expandBottom(expandableHunk, 10)}
text={this.props.t("diff.expandLastBottomByLines", {count: 10})}
text={this.props.t("diff.expandLastBottomByLines", { count: 10 })}
/>{" "}
<HunkExpandLink
icon={"fa-angle-double-down"}
@@ -233,7 +233,7 @@ class DiffFile extends React.Component<Props, State> {
);
}
// hunk header must be defined
return <span/>;
return <span />;
};
expandHead = (expandableHunk: ExpandableHunk, count: number) => {
@@ -255,16 +255,16 @@ class DiffFile extends React.Component<Props, State> {
};
diffExpanded = (newFile: File) => {
this.setState({file: newFile, diffExpander: new DiffExpander(newFile)});
this.setState({ file: newFile, diffExpander: new DiffExpander(newFile) });
};
diffExpansionFailed = (err: any) => {
this.setState({expansionError: err});
this.setState({ expansionError: err });
};
collectHunkAnnotations = (hunk: HunkType) => {
const {annotationFactory} = this.props;
const {file} = this.state;
const { annotationFactory } = this.props;
const { file } = this.state;
if (annotationFactory) {
return annotationFactory({
hunk,
@@ -276,8 +276,8 @@ class DiffFile extends React.Component<Props, State> {
};
handleClickEvent = (change: Change, hunk: HunkType) => {
const {onClick} = this.props;
const {file} = this.state;
const { onClick } = this.props;
const { file } = this.state;
const context = {
changeId: getChangeKey(change),
change,
@@ -290,7 +290,7 @@ class DiffFile extends React.Component<Props, State> {
};
createGutterEvents = (hunk: HunkType) => {
const {onClick} = this.props;
const { onClick } = this.props;
if (onClick) {
return {
onClick: (event: ChangeEvent) => {
@@ -311,7 +311,7 @@ class DiffFile extends React.Component<Props, State> {
} else if (i > 0) {
items.push(
<Decoration>
<HunkDivider/>
<HunkDivider />
</Decoration>
);
}
@@ -354,7 +354,7 @@ class DiffFile extends React.Component<Props, State> {
if (file.oldPath !== file.newPath && (file.type === "copy" || file.type === "rename")) {
return (
<>
{file.oldPath} <Icon name="arrow-right" color="inherit"/> {file.newPath}
{file.oldPath} <Icon name="arrow-right" color="inherit" /> {file.newPath}
</>
);
} else if (file.type === "delete") {
@@ -373,7 +373,7 @@ class DiffFile extends React.Component<Props, State> {
};
renderChangeTag = (file: File) => {
const {t} = this.props;
const { t } = this.props;
if (!file.type) {
return;
}
@@ -385,14 +385,14 @@ class DiffFile extends React.Component<Props, State> {
const color =
value === "added" ? "success is-outlined" : value === "deleted" ? "danger is-outlined" : "info is-outlined";
return <ChangeTypeTag className={classNames("is-rounded", "has-text-weight-normal")} color={color} label={value}/>;
return <ChangeTypeTag className={classNames("is-rounded", "has-text-weight-normal")} color={color} label={value} />;
};
hasContent = (file: File) => file && !file.isBinary && file.hunks && file.hunks.length > 0;
render() {
const {fileControlFactory, fileAnnotationFactory, t} = this.props;
const {file, collapsed, sideBySide, diffExpander, expansionError} = this.state;
const { fileControlFactory, fileAnnotationFactory, t } = this.props;
const { file, collapsed, sideBySide, diffExpander, expansionError } = this.state;
const viewType = sideBySide ? "split" : "unified";
let body = null;
@@ -413,39 +413,41 @@ class DiffFile extends React.Component<Props, State> {
</div>
);
}
const collapseIcon = this.hasContent(file) ? <Icon name={icon} color="inherit"/> : null;
const collapseIcon = this.hasContent(file) ? <Icon name={icon} color="inherit" /> : null;
const fileControls = fileControlFactory ? fileControlFactory(file, this.setCollapse) : null;
const sideBySideToggle = file.hunks && file.hunks.length && <MenuContext.Consumer>
{({setCollapsed}) => (
<DiffButton
icon={sideBySide ? "align-left" : "columns"}
tooltip={t(sideBySide ? "diff.combined" : "diff.sideBySide")}
onClick={() =>
this.toggleSideBySide(() => {
if (this.state.sideBySide) {
setCollapsed(true);
}
})
}
/>
)}
</MenuContext.Consumer>;
const sideBySideToggle = file.hunks && file.hunks.length && (
<MenuContext.Consumer>
{({ setCollapsed }) => (
<DiffButton
icon={sideBySide ? "align-left" : "columns"}
tooltip={t(sideBySide ? "diff.combined" : "diff.sideBySide")}
onClick={() =>
this.toggleSideBySide(() => {
if (this.state.sideBySide) {
setCollapsed(true);
}
})
}
/>
)}
</MenuContext.Consumer>
);
const headerButtons = (
<ButtonWrapper className={classNames("level-right", "is-flex")}>
<ButtonGroup>
{sideBySideToggle}
{fileControls}
</ButtonGroup>
</ButtonWrapper>
);
<ButtonWrapper className={classNames("level-right", "is-flex")}>
<ButtonGroup>
{sideBySideToggle}
{fileControls}
</ButtonGroup>
</ButtonWrapper>
);
let errorModal;
if (expansionError) {
errorModal = (
<Modal
title={t("diff.expansionFailed")}
closeFunction={() => this.setState({expansionError: undefined})}
body={<ErrorNotification error={expansionError}/>}
closeFunction={() => this.setState({ expansionError: undefined })}
body={<ErrorNotification error={expansionError} />}
active={true}
/>
);

View File

@@ -22,22 +22,22 @@
* SOFTWARE.
*/
import React from "react";
import {apiClient} from "../apiclient";
import { apiClient } from "../apiclient";
import ErrorNotification from "../ErrorNotification";
// @ts-ignore
import parser from "gitdiff-parser";
import Loading from "../Loading";
import Diff from "./Diff";
import {DiffObjectProps, File} from "./DiffTypes";
import {NotFoundError} from "../errors";
import {Notification} from "../index";
import {withTranslation, WithTranslation} from "react-i18next";
import { DiffObjectProps, File } from "./DiffTypes";
import { NotFoundError } from "../errors";
import { Notification } from "../index";
import { withTranslation, WithTranslation } from "react-i18next";
type Props = WithTranslation &
DiffObjectProps & {
url: string;
};
url: string;
};
type State = {
diff?: File[];
@@ -68,8 +68,8 @@ class LoadingDiff extends React.Component<Props, State> {
}
fetchDiff = () => {
const {url} = this.props;
this.setState({loading: true});
const { url } = this.props;
this.setState({ loading: true });
apiClient
.get(url)
.then(response => {
@@ -95,14 +95,14 @@ class LoadingDiff extends React.Component<Props, State> {
};
render() {
const {diff, loading, error} = this.state;
const { diff, loading, error } = this.state;
if (error) {
if (error instanceof NotFoundError) {
return <Notification type="info">{this.props.t("changesets.noChangesets")}</Notification>;
}
return <ErrorNotification error={error}/>;
return <ErrorNotification error={error} />;
} else if (loading) {
return <Loading/>;
return <Loading />;
} else if (!diff) {
return null;
} else {

View File

@@ -22,11 +22,11 @@
* SOFTWARE.
*/
import React from "react";
import {Changeset, Collection, Link} from "@scm-manager/ui-types";
import { Changeset, Collection, Link } from "@scm-manager/ui-types";
import LoadingDiff from "../LoadingDiff";
import Notification from "../../Notification";
import {WithTranslation, withTranslation} from "react-i18next";
import {FileControlFactory} from "../DiffTypes";
import { WithTranslation, withTranslation } from "react-i18next";
import { FileControlFactory } from "../DiffTypes";
type Props = WithTranslation & {
changeset: Changeset;
@@ -49,12 +49,19 @@ export const createUrl = (changeset: Collection) => {
class ChangesetDiff extends React.Component<Props> {
render() {
const {changeset, fileControlFactory, defaultCollapse, t} = this.props;
const { changeset, fileControlFactory, defaultCollapse, t } = this.props;
if (!isDiffSupported(changeset)) {
return <Notification type="danger">{t("changeset.diffNotSupported")}</Notification>;
} else {
const url = createUrl(changeset);
return <LoadingDiff url={url} defaultCollapse={defaultCollapse} sideBySide={false} fileControlFactory={fileControlFactory}/>;
return (
<LoadingDiff
url={url}
defaultCollapse={defaultCollapse}
sideBySide={false}
fileControlFactory={fileControlFactory}
/>
);
}
}
}

View File

@@ -35,7 +35,7 @@ import ChangesetAuthor from "./ChangesetAuthor";
import ChangesetTags from "./ChangesetTags";
import ChangesetButtonGroup from "./ChangesetButtonGroup";
import ChangesetDescription from "./ChangesetDescription";
import {FileControlFactory} from "../DiffTypes";
import { FileControlFactory } from "../DiffTypes";
type Props = WithTranslation & {
repository: Repository;
@@ -102,7 +102,7 @@ class ChangesetRow extends React.Component<Props> {
<AvatarWrapper>
<AvatarFigure className="media-left">
<FixedSizedAvatar className="image">
<AvatarImage person={changeset.author}/>
<AvatarImage person={changeset.author} />
</FixedSizedAvatar>
</AvatarFigure>
</AvatarWrapper>
@@ -120,24 +120,24 @@ class ChangesetRow extends React.Component<Props> {
</ExtensionPoint>
</h4>
<p className="is-hidden-touch">
<Trans i18nKey="repos:changeset.summary" components={[changesetId, dateFromNow]}/>
<Trans i18nKey="repos:changeset.summary" components={[changesetId, dateFromNow]} />
</p>
<p className="is-hidden-desktop">
<Trans i18nKey="repos:changeset.shortSummary" components={[changesetId, dateFromNow]}/>
<Trans i18nKey="repos:changeset.shortSummary" components={[changesetId, dateFromNow]} />
</p>
<AuthorWrapper className="is-size-7 is-ellipsis-overflow">
<ChangesetAuthor changeset={changeset}/>
<ChangesetAuthor changeset={changeset} />
</AuthorWrapper>
</Metadata>
</div>
</div>
<VCenteredColumn className="column">
<ChangesetTags changeset={changeset}/>
<ChangesetTags changeset={changeset} />
</VCenteredColumn>
</div>
</div>
<VCenteredChildColumn className={classNames("column", "is-flex")}>
<ChangesetButtonGroup repository={repository} changeset={changeset}/>
<ChangesetButtonGroup repository={repository} changeset={changeset} />
<ExtensionPoint
name="changeset.right"
props={{