fix wrong order of svn commits and keep old changesets

This commit is contained in:
Sebastian Sdorra
2018-10-17 14:57:17 +02:00
parent dccca5ae2c
commit f95b28e15d
2 changed files with 50 additions and 9 deletions

View File

@@ -129,15 +129,20 @@ export default function reducer(
return state; return state;
} }
let oldChangesets = { [key]: {} }; let oldByIds = {};
if (state[key]) { if (state[key] && state[key].byId) {
oldChangesets[key] = state[key]; oldByIds = state[key].byId;
} }
const byIds = extractChangesetsByIds(changesets); const byIds = extractChangesetsByIds(changesets);
return { return {
...state, ...state,
[key]: { [key]: {
byId: byIds, byId: {
...oldByIds,
...byIds
},
list: { list: {
entries: changesetIds, entries: changesetIds,
entry: { entry: {
@@ -170,10 +175,14 @@ export function getChangesets(
branch?: Branch branch?: Branch
) { ) {
const key = createItemId(repository, branch); const key = createItemId(repository, branch);
if (!state.changesets[key]) {
const changesets = state.changesets[key];
if (!changesets) {
return null; return null;
} }
return Object.values(state.changesets[key].byId); return changesets.list.entries.map((id: string) => {
return changesets.byId[id];
});
} }
export function isFetchChangesetsPending( export function isFetchChangesetsPending(

View File

@@ -224,6 +224,35 @@ describe("changesets", () => {
entries: ["changeset1", "changeset2", "changeset3"] entries: ["changeset1", "changeset2", "changeset3"]
}); });
}); });
it("should not remove existing changesets", () => {
const state = {
"foo/bar": {
byId: {
id2: { id: "id2" },
id1: { id: "id1" }
},
list: {
entries: ["id1", "id2"]
}
}
};
const newState = reducer(
state,
fetchChangesetsSuccess(repository, undefined, responseBody)
);
const fooBar = newState["foo/bar"];
expect(fooBar.list.entries).toEqual([
"changeset1",
"changeset2",
"changeset3"
]);
expect(fooBar.byId["id2"]).toEqual({ id: "id2" });
expect(fooBar.byId["id1"]).toEqual({ id: "id1" });
});
}); });
describe("changeset selectors", () => { describe("changeset selectors", () => {
@@ -234,14 +263,17 @@ describe("changesets", () => {
changesets: { changesets: {
"foo/bar": { "foo/bar": {
byId: { byId: {
id1: { id: "id1" }, id2: { id: "id2" },
id2: { id: "id2" } id1: { id: "id1" }
},
list: {
entries: ["id1", "id2"]
} }
} }
} }
}; };
const result = getChangesets(state, repository); const result = getChangesets(state, repository);
expect(result).toContainEqual({ id: "id1" }); expect(result).toEqual([{ id: "id1" }, { id: "id2" }]);
}); });
it("should return true, when fetching changesets is pending", () => { it("should return true, when fetching changesets is pending", () => {