From 2ca15316fd257b39e7bab115e27fa706dc5c9fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Pfeuffer?= Date: Wed, 10 Jun 2020 10:09:57 +0200 Subject: [PATCH] Prepare error handling for expansion --- scm-ui/ui-components/src/repos/DiffFile.tsx | 53 +++++++++++++++------ 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/scm-ui/ui-components/src/repos/DiffFile.tsx b/scm-ui/ui-components/src/repos/DiffFile.tsx index 6b39407830..4f6fceef93 100644 --- a/scm-ui/ui-components/src/repos/DiffFile.tsx +++ b/scm-ui/ui-components/src/repos/DiffFile.tsx @@ -35,6 +35,7 @@ import TokenizedDiffView from "./TokenizedDiffView"; import DiffButton from "./DiffButton"; import { MenuContext } from "@scm-manager/ui-components"; import DiffExpander, { ExpandableHunk } from "./DiffExpander"; +import HunkExpandLink from "./HunkExpandLink"; const EMPTY_ANNOTATION_FACTORY = {}; @@ -51,6 +52,7 @@ type State = Collapsible & { file: File; sideBySide?: boolean; diffExpander: DiffExpander; + expansionError?: any; }; const DiffFilePanel = styled.div` @@ -145,17 +147,13 @@ class DiffFile extends React.Component { }); }; - diffExpanded = (newFile: File) => { - this.setState({ file: newFile, diffExpander: new DiffExpander(newFile) }); - }; - createHunkHeader = (expandableHunk: ExpandableHunk) => { if (expandableHunk.maxExpandHeadRange > 0) { if (expandableHunk.maxExpandHeadRange <= 10) { return ( - expandableHunk.expandHead(expandableHunk.maxExpandHeadRange).then(this.diffExpanded)}> + {this.props.t("diff.expandHeadComplete", { count: expandableHunk.maxExpandHeadRange })} @@ -165,10 +163,10 @@ class DiffFile extends React.Component { return ( - expandableHunk.expandHead(10).then(this.diffExpanded)}> + {this.props.t("diff.expandHeadByLines", { count: 10 })} {" "} - expandableHunk.expandHead(expandableHunk.maxExpandHeadRange).then(this.diffExpanded)}> + {this.props.t("diff.expandHeadComplete", { count: expandableHunk.maxExpandHeadRange })} @@ -196,10 +194,10 @@ class DiffFile extends React.Component { return ( - expandableHunk.expandBottom(10).then(this.diffExpanded)}> + {this.props.t("diff.expandBottomByLines", { count: 10 })} {" "} - expandableHunk.expandBottom(expandableHunk.maxExpandBottomRange).then(this.diffExpanded)}> + {this.props.t("diff.expandBottomComplete", { count: expandableHunk.maxExpandBottomRange })} @@ -207,7 +205,7 @@ class DiffFile extends React.Component { ); } } - // hunk header must be defined + // hunk footer must be defined return ; }; @@ -216,10 +214,8 @@ class DiffFile extends React.Component { return ( - expandableHunk.expandBottom(10).then(this.diffExpanded)}> - {this.props.t("diff.expandLastBottomByLines")} - {" "} - expandableHunk.expandBottom(expandableHunk.maxExpandBottomRange).then(this.diffExpanded)}> + {this.props.t("diff.expandLastBottomByLines")}{" "} + {this.props.t("diff.expandLastBottomComplete")} @@ -230,6 +226,33 @@ class DiffFile extends React.Component { return ; }; + expandHead = (expandableHunk: ExpandableHunk, count: number) => { + return () => { + expandableHunk + .expandHead(count) + .then(this.diffExpanded) + .catch(this.diffExpansionFailed); + }; + }; + + expandBottom = (expandableHunk: ExpandableHunk, count: number) => { + return () => { + expandableHunk + .expandBottom(count) + .then(this.diffExpanded) + .catch(this.diffExpansionFailed); + }; + }; + + diffExpanded = (newFile: File) => { + this.setState({ file: newFile, diffExpander: new DiffExpander(newFile) }); + }; + + diffExpansionFailed = (err: any) => { + console.log(err); + this.setState({ expansionError: err }); + }; + collectHunkAnnotations = (hunk: HunkType) => { const { annotationFactory } = this.props; const { file } = this.state; @@ -354,7 +377,7 @@ class DiffFile extends React.Component { render() { const { fileControlFactory, fileAnnotationFactory, t } = this.props; - const { file, collapsed, sideBySide, diffExpander } = this.state; + const { file, collapsed, sideBySide, diffExpander, expansionError } = this.state; const viewType = sideBySide ? "split" : "unified"; let body = null;