diff --git a/CHANGELOG.md b/CHANGELOG.md index 024f6ace..41116880 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Fixed * [#413](https://github.com/shlinkio/shlink-web-client/issues/413) Fixed edit short URL form reflecting outdated info after navigating back from other section. +* [#412](https://github.com/shlinkio/shlink-web-client/issues/412) Ensured new visits coming from mercure hub are prepended and not appended, to keep proper sorting. ## [3.1.0] - 2021-03-29 diff --git a/package-lock.json b/package-lock.json index a66eb638..3efeca4b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13118,7 +13118,7 @@ }, "load-json-file": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz", + "resolved": "https://registry.yarnpkg.com/load-json-file/-/load-json-file-2.0.0.tgz", "integrity": "sha1-eUfkIUmvgNaWy/eXvKq8/h/inKg=", "dev": true, "requires": { @@ -13164,7 +13164,7 @@ }, "parse-json": { "version": "2.2.0", - "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-2.2.0.tgz", + "resolved": "https://registry.yarnpkg.com/parse-json/-/parse-json-2.2.0.tgz", "integrity": "sha1-9ID0BDTvgHQfhGkJn43qGPVaTck=", "dev": true, "requires": { @@ -13173,7 +13173,7 @@ }, "path-type": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/path-type/-/path-type-2.0.0.tgz", + "resolved": "https://registry.yarnpkg.com/path-type/-/path-type-2.0.0.tgz", "integrity": "sha1-8BLMuEFbcJb8LaoQVMPXI4lZTHM=", "dev": true, "requires": { @@ -13182,13 +13182,13 @@ }, "pify": { "version": "2.3.0", - "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "resolved": "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz", "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", "dev": true }, "read-pkg": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-2.0.0.tgz", + "resolved": "https://registry.yarnpkg.com/read-pkg/-/read-pkg-2.0.0.tgz", "integrity": "sha1-jvHAYjxqbbDcZxPEv6xGMysjaPg=", "dev": true, "requires": { @@ -13199,7 +13199,7 @@ }, "read-pkg-up": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-2.0.0.tgz", + "resolved": "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-2.0.0.tgz", "integrity": "sha1-a3KoBImE4MQeeVEP1en6mbO1Sb4=", "dev": true, "requires": { diff --git a/src/visits/reducers/orphanVisits.ts b/src/visits/reducers/orphanVisits.ts index d6d30828..11b90836 100644 --- a/src/visits/reducers/orphanVisits.ts +++ b/src/visits/reducers/orphanVisits.ts @@ -44,7 +44,7 @@ export default buildReducer({ const { visits } = state; const newVisits = createdVisits.map(({ visit }) => visit); - return { ...state, visits: [ ...visits, ...newVisits ] }; + return { ...state, visits: [ ...newVisits, ...visits ] }; }, }, initialState); diff --git a/src/visits/reducers/shortUrlVisits.ts b/src/visits/reducers/shortUrlVisits.ts index 1b66a033..6641c1e8 100644 --- a/src/visits/reducers/shortUrlVisits.ts +++ b/src/visits/reducers/shortUrlVisits.ts @@ -58,7 +58,7 @@ export default buildReducer({ .filter(({ shortUrl }) => shortUrl && shortUrlMatches(shortUrl, shortCode, domain)) .map(({ visit }) => visit); - return { ...state, visits: [ ...visits, ...newVisits ] }; + return { ...state, visits: [ ...newVisits, ...visits ] }; }, }, initialState); diff --git a/src/visits/reducers/tagVisits.ts b/src/visits/reducers/tagVisits.ts index c78295af..6bbff367 100644 --- a/src/visits/reducers/tagVisits.ts +++ b/src/visits/reducers/tagVisits.ts @@ -52,7 +52,7 @@ export default buildReducer({ .filter(({ shortUrl }) => shortUrl?.tags.includes(tag)) .map(({ visit }) => visit); - return { ...state, visits: [ ...visits, ...newVisits ] }; + return { ...state, visits: [ ...newVisits, ...visits ] }; }, }, initialState); diff --git a/test/visits/reducers/orphanVisits.test.ts b/test/visits/reducers/orphanVisits.test.ts index 9c4b0d80..2dddf73c 100644 --- a/test/visits/reducers/orphanVisits.test.ts +++ b/test/visits/reducers/orphanVisits.test.ts @@ -64,7 +64,7 @@ describe('orphanVisitsReducer', () => { expect(visits).toEqual(actionVisits); }); - it('appends a new visits on CREATE_VISIT', () => { + it('prepends new visits on CREATE_VISIT', () => { const prevState = buildState({ visits: visitsMocks }); const { visits } = reducer( @@ -72,7 +72,7 @@ describe('orphanVisitsReducer', () => { { type: CREATE_VISITS, createdVisits: [{ visit: {} }, { visit: {} }] } as any, ); - expect(visits).toEqual([ ...visitsMocks, {}, {}]); + expect(visits).toEqual([{}, {}, ...visitsMocks ]); }); it('returns new progress on GET_ORPHAN_VISITS_PROGRESS_CHANGED', () => { diff --git a/test/visits/reducers/shortUrlVisits.test.ts b/test/visits/reducers/shortUrlVisits.test.ts index ba6fe837..947faabd 100644 --- a/test/visits/reducers/shortUrlVisits.test.ts +++ b/test/visits/reducers/shortUrlVisits.test.ts @@ -66,9 +66,9 @@ describe('shortUrlVisitsReducer', () => { }); it.each([ - [{ shortCode: 'abc123' }, [ ...visitsMocks, {}]], + [{ shortCode: 'abc123' }, [{}, ...visitsMocks ]], [{ shortCode: 'def456' }, visitsMocks ], - ])('appends a new visit on CREATE_VISIT', (state, expectedVisits) => { + ])('prepends new visits on CREATE_VISIT', (state, expectedVisits) => { const shortUrl = { shortCode: 'abc123', }; diff --git a/test/visits/reducers/tagVisits.test.ts b/test/visits/reducers/tagVisits.test.ts index cd687b55..dd595899 100644 --- a/test/visits/reducers/tagVisits.test.ts +++ b/test/visits/reducers/tagVisits.test.ts @@ -66,9 +66,9 @@ describe('tagVisitsReducer', () => { }); it.each([ - [{ tag: 'foo' }, [ ...visitsMocks, {}]], + [{ tag: 'foo' }, [{}, ...visitsMocks ]], [{ tag: 'bar' }, visitsMocks ], - ])('appends a new visit on CREATE_VISIT', (state, expectedVisits) => { + ])('prepends new visits on CREATE_VISIT', (state, expectedVisits) => { const shortUrl = { tags: [ 'foo', 'baz' ], };