From 35c78b7ad93c24604e9649eb4b20192c09d73567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Pfeuffer?= Date: Wed, 10 Jun 2020 10:34:55 +0200 Subject: [PATCH] Handle errors and show loading state --- scm-ui/ui-components/src/repos/DiffFile.tsx | 73 +++++++++++++------ .../src/repos/HunkExpandLink.tsx | 44 +++++++++++ scm-ui/ui-webapp/public/locales/en/repos.json | 4 +- 3 files changed, 96 insertions(+), 25 deletions(-) create mode 100644 scm-ui/ui-components/src/repos/HunkExpandLink.tsx diff --git a/scm-ui/ui-components/src/repos/DiffFile.tsx b/scm-ui/ui-components/src/repos/DiffFile.tsx index 4f6fceef93..96af23d51a 100644 --- a/scm-ui/ui-components/src/repos/DiffFile.tsx +++ b/scm-ui/ui-components/src/repos/DiffFile.tsx @@ -36,6 +36,8 @@ import DiffButton from "./DiffButton"; import { MenuContext } from "@scm-manager/ui-components"; import DiffExpander, { ExpandableHunk } from "./DiffExpander"; import HunkExpandLink from "./HunkExpandLink"; +import { Modal } from "../modals"; +import ErrorNotification from "../ErrorNotification"; const EMPTY_ANNOTATION_FACTORY = {}; @@ -153,9 +155,10 @@ class DiffFile extends React.Component { return ( - - {this.props.t("diff.expandHeadComplete", { count: expandableHunk.maxExpandHeadRange })} - + ); @@ -163,12 +166,14 @@ class DiffFile extends React.Component { return ( - - {this.props.t("diff.expandHeadByLines", { count: 10 })} - {" "} - - {this.props.t("diff.expandHeadComplete", { count: expandableHunk.maxExpandHeadRange })} - + {" "} + ); @@ -184,9 +189,10 @@ class DiffFile extends React.Component { return ( - expandableHunk.expandBottom(expandableHunk.maxExpandBottomRange).then(this.diffExpanded)}> - {this.props.t("diff.expandBottomComplete", { count: expandableHunk.maxExpandBottomRange })} - + ); @@ -194,12 +200,14 @@ class DiffFile extends React.Component { return ( - - {this.props.t("diff.expandBottomByLines", { count: 10 })} - {" "} - - {this.props.t("diff.expandBottomComplete", { count: expandableHunk.maxExpandBottomRange })} - + {" "} + ); @@ -214,10 +222,14 @@ class DiffFile extends React.Component { return ( - {this.props.t("diff.expandLastBottomByLines")}{" "} - - {this.props.t("diff.expandLastBottomComplete")} - + {" "} + ); @@ -228,7 +240,7 @@ class DiffFile extends React.Component { expandHead = (expandableHunk: ExpandableHunk, count: number) => { return () => { - expandableHunk + return expandableHunk .expandHead(count) .then(this.diffExpanded) .catch(this.diffExpansionFailed); @@ -237,7 +249,7 @@ class DiffFile extends React.Component { expandBottom = (expandableHunk: ExpandableHunk, count: number) => { return () => { - expandableHunk + return expandableHunk .expandBottom(count) .then(this.diffExpanded) .catch(this.diffExpansionFailed); @@ -424,8 +436,21 @@ class DiffFile extends React.Component { ) : null; + let errorModal; + if (expansionError) { + errorModal = ( + this.setState({ expansionError: undefined })} + body={} + active={true} + /> + ); + } + return ( + {errorModal}
Promise; +}; + +const HunkExpandLink: FC = ({ text, onClick }) => { + const [t] = useTranslation("repos"); + const [loading, setLoading] = useState(false); + + const onClickWithLoadingMarker = () => { + setLoading(true); + onClick().then(() => setLoading(false)); + }; + + return {loading? t("diff.expanding"): text}; +}; + +export default HunkExpandLink; diff --git a/scm-ui/ui-webapp/public/locales/en/repos.json b/scm-ui/ui-webapp/public/locales/en/repos.json index fa97c7d6cf..aaddfb4f12 100644 --- a/scm-ui/ui-webapp/public/locales/en/repos.json +++ b/scm-ui/ui-webapp/public/locales/en/repos.json @@ -208,7 +208,9 @@ "expandBottomComplete": ">> load {{count}} line", "expandBottomComplete_plural": ">> load all {{count}} lines", "expandLastBottomByLines": "> load up to 10 more lines", - "expandLastBottomComplete": ">> load all remaining lines" + "expandLastBottomComplete": ">> load all remaining lines", + "expanding": "loading lines ...", + "expansionFailed": "Error loading additional content" }, "fileUpload": { "clickHere": "Click here to select your file",