LatestAccountsPanel: add backwards compatibility with unsorted AdminAPI endpoint
This commit is contained in:
parent
4ca3d68bf6
commit
2ff2060354
1 changed files with 19 additions and 5 deletions
|
@ -6,15 +6,29 @@ import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
import AccountListPanel from 'soapbox/features/ui/components/account_list_panel';
|
import AccountListPanel from 'soapbox/features/ui/components/account_list_panel';
|
||||||
import { fetchUsers } from 'soapbox/actions/admin';
|
import { fetchUsers } from 'soapbox/actions/admin';
|
||||||
|
import { is } from 'immutable';
|
||||||
|
import compareId from 'soapbox/compare_id';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
title: { id: 'admin.latest_accounts_panel.title', defaultMessage: 'Latest Accounts' },
|
title: { id: 'admin.latest_accounts_panel.title', defaultMessage: 'Latest Accounts' },
|
||||||
expand: { id: 'admin.latest_accounts_panel.expand_message', defaultMessage: 'Click to see {count} more {count, plural, one {account} other {accounts}}' },
|
expand: { id: 'admin.latest_accounts_panel.expand_message', defaultMessage: 'Click to see {count} more {count, plural, one {account} other {accounts}}' },
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => {
|
||||||
accountIds: state.getIn(['admin', 'latestUsers']),
|
const accountIds = state.getIn(['admin', 'latestUsers']);
|
||||||
});
|
|
||||||
|
// HACK: AdminAPI only recently started sorting new users at the top.
|
||||||
|
// Try a dirty check to see if the users are sorted properly, or don't show the panel.
|
||||||
|
// Probably works most of the time.
|
||||||
|
const sortedIds = accountIds.sort(compareId).reverse();
|
||||||
|
const hasDates = accountIds.every(id => state.getIn(['accounts', id, 'created_at']));
|
||||||
|
const isSorted = hasDates && is(accountIds, sortedIds);
|
||||||
|
|
||||||
|
return {
|
||||||
|
isSorted,
|
||||||
|
accountIds,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export default @connect(mapStateToProps)
|
export default @connect(mapStateToProps)
|
||||||
@injectIntl
|
@injectIntl
|
||||||
|
@ -44,10 +58,10 @@ class LatestAccountsPanel extends ImmutablePureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { intl, accountIds, limit, ...props } = this.props;
|
const { intl, accountIds, limit, isSorted, ...props } = this.props;
|
||||||
const { total } = this.state;
|
const { total } = this.state;
|
||||||
|
|
||||||
if (!accountIds || accountIds.isEmpty()) {
|
if (!isSorted || !accountIds || accountIds.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue