diff --git a/scm-ui/ui-webapp/src/repos/sources/components/FileTree.tsx b/scm-ui/ui-webapp/src/repos/sources/components/FileTree.tsx index f3ecba8982..881a841a57 100644 --- a/scm-ui/ui-webapp/src/repos/sources/components/FileTree.tsx +++ b/scm-ui/ui-webapp/src/repos/sources/components/FileTree.tsx @@ -21,7 +21,6 @@ type Hunk = { tree: File; loading: boolean; error: Error; - updateSources: (hunk: number) => void; }; type Props = WithTranslation & { @@ -34,6 +33,7 @@ type Props = WithTranslation & { // dispatch props fetchSources: (repository: Repository, revision: string, path: string, hunk: number) => void; + updateSources: (hunk: number) => () => void; // context props match: any; @@ -67,10 +67,10 @@ class FileTree extends React.Component { componentDidUpdate(prevProps: Readonly, prevState: Readonly): void { if (prevState.stoppableUpdateHandler === this.state.stoppableUpdateHandler) { - const { hunks } = this.props; + const { hunks, updateSources } = this.props; hunks?.forEach((hunk, index) => { if (hunk.tree?._embedded?.children && hunk.tree._embedded.children.find(c => c.partialResult)) { - const stoppableUpdateHandler = setTimeout(hunk.updateSources, 3000); + const stoppableUpdateHandler = setTimeout(updateSources(index), 3000); this.setState(prevState => { return { stoppableUpdateHandler: [...prevState.stoppableUpdateHandler, stoppableUpdateHandler] @@ -177,7 +177,7 @@ const mapDispatchToProps = (dispatch: any, ownProps: Props) => { const { repository, revision, path } = ownProps; return { - updateSources: (hunk: number) => dispatch(fetchSources(repository, revision, path, false, hunk)), + updateSources: (hunk: number) => () => dispatch(fetchSources(repository, revision, path, false, hunk)), fetchSources: (repository: Repository, revision: string, path: string, hunk: number) => { dispatch(fetchSources(repository, revision, path, true, hunk)); } diff --git a/scm-ui/ui-webapp/src/repos/sources/modules/sources.ts b/scm-ui/ui-webapp/src/repos/sources/modules/sources.ts index a12bf3ba0d..d37833c1c3 100644 --- a/scm-ui/ui-webapp/src/repos/sources/modules/sources.ts +++ b/scm-ui/ui-webapp/src/repos/sources/modules/sources.ts @@ -28,8 +28,7 @@ export function fetchSources(repository: Repository, revision: string, path: str } let offset = 0; - const hunkCount = getHunkCount(state, repository, revision, path); - for (let i = 0; i < hunkCount; ++i) { + for (let i = 0; i < hunk; ++i) { const sources = getSources(state, repository, revision, path, i); if (sources?._embedded.children) { offset += sources._embedded.children.length; @@ -136,7 +135,6 @@ export default function reducer( } else if (action.itemId && action.type === FETCH_UPDATES_PENDING) { return { ...state, - [action.itemId + "hunkCount"]: action.payload.hunk + 1, [action.itemId + action.payload.hunk]: { sources: action.payload.sources, updatePending: true,