Ghost/ghost/admin/app/helpers/most-recently-updated.js
Kevin Ansfield 17710c3e8e Switched members table to show info from most-recently-updated subscription instead of first in array
no issue

- members having multiple subscriptions is not really expected but if it does happen then the most recently updated subscription is most likely to be the one that we're interested in showing the details of in the members table
- added `{{most-recently-updated arr}}` helper+function that will return the item in the array argument with the most recent "updated at" value
  - uses `updatedAtUTC` or `updatedAt` or `updated_at` values so it will work against any of our models or un-transformed API response objects
- updated `<GhMembersListItemColumn>` to use a `mostRecentSubscription` getter when showing subscription data rather than assuming the first object in the subscriptions array should be displayed
2022-03-04 16:32:41 +00:00

20 lines
540 B
JavaScript

import moment from 'moment';
import {helper} from '@ember/component/helper';
export function mostRecentlyUpdated(objs) {
const items = [...(objs || [])];
(items || []).sort((a, b) => {
const momentA = moment(a.updatedAtUTC || a.updatedAt || a.updated_at);
const momentB = moment(b.updatedAtUTC || b.updatedAt || b.updated_at);
return momentB.valueOf() - momentA.valueOf();
});
return items[0] || null;
}
export default helper(function ([items = []]) {
return mostRecentlyUpdated(items);
});