mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-08 02:52:39 -05:00
🐛 Fixed links being shown in incorrect order
ref https://linear.app/ghost/issue/ONC-845 Our API returns links ordered by click count descending. However we merge together links with matching titles to aggregate the counts. We didn't reorder based on the aggregated count, which resulted in a broken looking UI, by adding a sort after the aggregation we display the links in the correct order.
This commit is contained in:
parent
7a2707e9e1
commit
3b874f9ba1
2 changed files with 60 additions and 1 deletions
|
@ -249,7 +249,11 @@ export default class Analytics extends Component {
|
|||
return acc;
|
||||
}, {});
|
||||
|
||||
this.links = Object.values(linksByTitle);
|
||||
this.links = Object.values(linksByTitle).sort((a, b) => {
|
||||
const aClicks = a.count?.clicks || 0;
|
||||
const bClicks = b.count?.clicks || 0;
|
||||
return bClicks - aClicks;
|
||||
});
|
||||
}
|
||||
|
||||
async fetchReferrersStats() {
|
||||
|
|
55
ghost/admin/tests/unit/components/posts/analytics-test.js
Normal file
55
ghost/admin/tests/unit/components/posts/analytics-test.js
Normal file
|
@ -0,0 +1,55 @@
|
|||
import Analytics from 'ghost-admin/components/posts/analytics';
|
||||
import {describe, it} from 'mocha';
|
||||
import {expect} from 'chai';
|
||||
|
||||
describe('Unit: Component: posts/analytics', function () {
|
||||
describe('updateLinkData', function () {
|
||||
it('Correctly orders `this.links`', function () {
|
||||
const instance = Object.create(Analytics.prototype);
|
||||
instance.utils = {
|
||||
cleanTrackedUrl(url, title) {
|
||||
if (title) {
|
||||
return url.split('//')[1];
|
||||
}
|
||||
return url;
|
||||
}
|
||||
};
|
||||
|
||||
const links = [{
|
||||
id: 1,
|
||||
link: {
|
||||
to: 'https://lone.com'
|
||||
},
|
||||
count: {
|
||||
clicks: 3
|
||||
}
|
||||
}, {
|
||||
id: 2,
|
||||
link: {
|
||||
to: 'https://duplicate.com'
|
||||
},
|
||||
count: {
|
||||
clicks: 2
|
||||
}
|
||||
}, {
|
||||
id: 3,
|
||||
link: {
|
||||
to: 'https://duplicate.com'
|
||||
},
|
||||
count: {
|
||||
clicks: 2
|
||||
}
|
||||
}];
|
||||
|
||||
instance.updateLinkData(links);
|
||||
|
||||
expect(instance.links.length).to.equal(2);
|
||||
|
||||
expect(instance.links[0].count.clicks).to.equal(4);
|
||||
expect(instance.links[0].id).to.equal(2);
|
||||
|
||||
expect(instance.links[1].count.clicks).to.equal(3);
|
||||
expect(instance.links[1].id).to.equal(1);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue