diff --git a/webui/src/lib/components/repository/ChangeSummary.jsx b/webui/src/lib/components/repository/ChangeSummary.jsx index 1fad68a34e6..05629ef6862 100644 --- a/webui/src/lib/components/repository/ChangeSummary.jsx +++ b/webui/src/lib/components/repository/ChangeSummary.jsx @@ -1,11 +1,10 @@ -import React, {useEffect, useState} from "react"; +import React, {useCallback, useEffect, useState} from "react"; import { ClockIcon, DiffAddedIcon, DiffIgnoredIcon, DiffModifiedIcon, DiffRemovedIcon, - XCircleIcon } from "@primer/octicons-react"; import {OverlayTrigger, Tooltip} from "react-bootstrap"; import {humanSize} from "./tree"; @@ -41,13 +40,13 @@ class SummaryData { * @param {(after : string, path : string, useDelimiter :? boolean, amount :? number) => Promise } getMore - function to use to get the change entries. */ export default ({prefix, getMore}) => { - const [resultsState, setResultsState] = useState({results: [], pagination: {}, tooManyPages: false}); + const [pullMore, setPullMore] = useState(false); + const [resultsState, setResultsState] = useState({results: [], pagination: {}}); const [loading, setLoading] = useState(true); useEffect(() => { const calculateChanges = async () => { // get pages until reaching the max change size - if (resultsState.results && resultsState.results.length >= MAX_NUM_OBJECTS) { - setResultsState({results: null, pagination: {}, tooManyPages: true}) + if (resultsState.results && resultsState.results.length >= MAX_NUM_OBJECTS && !pullMore) { setLoading(false) return } @@ -58,19 +57,25 @@ export default ({prefix, getMore}) => { if (!pagination.has_more) { setLoading(false) } - setResultsState({results: resultsState.results.concat(results), pagination: pagination, tooManyPages: false}) + setResultsState({results: resultsState.results.concat(results), pagination: pagination}) } calculateChanges() .catch(e => { alert(e.toString()); - setResultsState({results: [], pagination: {}, tooManyPages: false}) + setResultsState({results: [], pagination: {}}) setLoading(false) }) - }, [resultsState.results, loading]) + }, [resultsState.results, loading, pullMore]) - if (loading) return - if (resultsState.tooManyPages) { + const onLoadAll = useCallback((e) => { + e.preventDefault() + setLoading(true) + setPullMore(true) + }, [setLoading, setPullMore]) + + if (loading || !resultsState || !resultsState.results) return + if (resultsState.results && resultsState.results.length >= MAX_NUM_OBJECTS && !pullMore) { return ( { }> - + + >= {MAX_NUM_OBJECTS.toLocaleString()} results, load more? + ) } @@ -91,26 +98,26 @@ export default ({prefix, getMore}) => { const detailsTooltip =
{summaryData.added.count > 0 && - <>{summaryData.added.count} objects added (total {humanSize(summaryData.added.sizeBytes)})
} + <>{summaryData.added.count.toLocaleString()} objects added (total {humanSize(summaryData.added.sizeBytes)})
} {summaryData.removed.count > 0 && - <>{summaryData.removed.count} objects removed (total {humanSize(summaryData.removed.sizeBytes)})
} + <>{summaryData.removed.count.toLocaleString()} objects removed (total {humanSize(summaryData.removed.sizeBytes)})
} {summaryData.changed.count > 0 && - <>{summaryData.changed.count} objects changed
} + <>{summaryData.changed.count.toLocaleString()} objects changed
} {summaryData.conflict.count > 0 && - <>{summaryData.conflict.count} conflicts
} + <>{summaryData.conflict.count.toLocaleString()} conflicts
}
return (
{summaryData.added.count > 0 && - {summaryData.added.count}} + {summaryData.added.count.toLocaleString()}} {summaryData.removed.count > 0 && - {summaryData.removed.count}} + {summaryData.removed.count.toLocaleString()}} {summaryData.changed.count > 0 && - {summaryData.changed.count}} + {summaryData.changed.count.toLocaleString()}} {summaryData.conflict.count > 0 && - {summaryData.conflict.count}} + {summaryData.conflict.count.toLocaleString()}}
)