From 5a3bb52b72ac1c99bbc7a8b02f221d4b892b6efd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Pfeuffer?= Date: Tue, 10 Mar 2020 09:28:03 +0100 Subject: [PATCH] Fix update of sources An Update of sources must not set the hunk count. --- .../src/repos/sources/modules/sources.test.ts | 10 ++++-- .../src/repos/sources/modules/sources.ts | 36 +++++++++++++++++-- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/scm-ui/ui-webapp/src/repos/sources/modules/sources.test.ts b/scm-ui/ui-webapp/src/repos/sources/modules/sources.test.ts index f49488a7df..1c819c91f1 100644 --- a/scm-ui/ui-webapp/src/repos/sources/modules/sources.test.ts +++ b/scm-ui/ui-webapp/src/repos/sources/modules/sources.test.ts @@ -295,14 +295,18 @@ describe("selector tests", () => { it("should return error when fetch sources did fail", () => { const state = { - failure: { - [FETCH_SOURCES + "/scm/core/_//"]: error + sources: { + "scm/core/_//0": { + pending: false, + sources: {}, + error: error + } } }; expect(getFetchSourcesFailure(state, repository, "", "", 0)).toEqual(error); }); it("should return undefined when fetch sources did not fail", () => { - expect(getFetchSourcesFailure({}, repository, "", "", 0)).toBe(undefined); + expect(getFetchSourcesFailure({}, repository, "", "", 0)).toBe(null); }); }); 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 cb9771a181..4c78c3525f 100644 --- a/scm-ui/ui-webapp/src/repos/sources/modules/sources.ts +++ b/scm-ui/ui-webapp/src/repos/sources/modules/sources.ts @@ -7,6 +7,7 @@ export const FETCH_SOURCES = "scm/repos/FETCH_SOURCES"; export const FETCH_SOURCES_PENDING = `${FETCH_SOURCES}_${types.PENDING_SUFFIX}`; export const FETCH_UPDATES_PENDING = `${FETCH_SOURCES}_UPDATE_PENDING`; export const FETCH_SOURCES_SUCCESS = `${FETCH_SOURCES}_${types.SUCCESS_SUFFIX}`; +export const FETCH_UPDATES_SUCCESS = `${FETCH_SOURCES}_UPDATE_SUCCESS`; export const FETCH_SOURCES_FAILURE = `${FETCH_SOURCES}_${types.FAILURE_SUFFIX}`; export function fetchSources(repository: Repository, revision: string, path: string, initialLoad = true, hunk = 0) { @@ -39,7 +40,11 @@ export function fetchSources(repository: Repository, revision: string, path: str .get(createUrl(repository, revision, path, offset)) .then(response => response.json()) .then((sources: File) => { - dispatch(fetchSourcesSuccess(repository, revision, path, hunk, sources)); + if (initialLoad) { + dispatch(fetchSourcesSuccess(repository, revision, path, hunk, sources)); + } else { + dispatch(fetchUpdatesSuccess(repository, revision, path, hunk, sources)); + } }) .catch(err => { dispatch(fetchSourcesFailure(repository, revision, path, hunk, err)); @@ -94,6 +99,20 @@ export function fetchSourcesSuccess( }; } +export function fetchUpdatesSuccess( + repository: Repository, + revision: string, + path: string, + hunk: number, + sources: File +) { + return { + type: FETCH_UPDATES_SUCCESS, + payload: { hunk, pending: false, updatePending: false, sources }, + itemId: createItemId(repository, revision, path, "") + }; +} + export function fetchSourcesFailure( repository: Repository, revision: string, @@ -133,6 +152,16 @@ export default function reducer( pending: false } }; + } else if (action.itemId && (action.type === FETCH_UPDATES_SUCCESS)) { + return { + ...state, + [action.itemId + action.payload.hunk]: { + sources: action.payload.sources, + error: action.payload.error, + updatePending: false, + pending: false + } + }; } else if (action.itemId && action.type === FETCH_UPDATES_PENDING) { return { ...state, @@ -221,5 +250,8 @@ export function getFetchSourcesFailure( path: string, hunk = 0 ): Error | null | undefined { - return state.sources[createItemId(repository, revision, path, hunk)]?.error; + if (state.sources) { + return state.sources && state.sources[createItemId(repository, revision, path, hunk)]?.error; + } + return null; }