Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle users normalization #1460

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Fix tests 2
jjpaulino committed Jul 8, 2019
commit de9379c285ce509607d5a0af6ace733f53f64f2c
2 changes: 1 addition & 1 deletion lib/drawers/layout-history.vue
Original file line number Diff line number Diff line change
@@ -124,7 +124,7 @@
formattedHistory = formatHistoryToDisplay(pageHistory, cacheUsers);

return formattedHistory;
},
}
},
mounted: function () {
const usersIds = _.uniq(_.flatMap(_.map(_.get(this.$store, 'state.page.state.history'), (history) => _.map(history.users, (user) => user.id))));
2 changes: 1 addition & 1 deletion lib/drawers/page-history.vue
Original file line number Diff line number Diff line change
@@ -125,7 +125,7 @@
formattedHistory = formatHistoryToDisplay(pageHistory, cacheUsers);

return formattedHistory;
},
}
},
mounted: function () {
const usersIds = _.uniq(_.flatMap(_.get(this.$store, 'state.page.state.history'), (history) => _.map(history.users, (user) => user.id)));
7 changes: 6 additions & 1 deletion lib/nav/mutations.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import _ from 'lodash';
import { CHANGE_FAVORITE_PAGE_CATEGORY, SHOW_NAV_BACKGROUND, HIDE_NAV_BACKGROUND, SAVE_USERS } from './mutationTypes';
import {
CHANGE_FAVORITE_PAGE_CATEGORY,
SHOW_NAV_BACKGROUND,
HIDE_NAV_BACKGROUND,
SAVE_USERS
} from './mutationTypes';

export default {
[CHANGE_FAVORITE_PAGE_CATEGORY]: (state, id) => {
14 changes: 8 additions & 6 deletions lib/nav/page-list.vue
Original file line number Diff line number Diff line change
@@ -340,12 +340,14 @@

// set the url hash
if (_.get(this.$store, 'state.ui.currentDrawer')) {
this.$store.dispatch('setHash', { menu: {
tab: isMyPages ? 'my-pages' : 'all-pages',
sites: siteFilter.join(','),
status: statusFilter,
query: this.query
}});
this.$store.dispatch('setHash', {
menu: {
tab: isMyPages ? 'my-pages' : 'all-pages',
sites: siteFilter.join(','),
status: statusFilter,
query: this.query
}
});
}
});
});
4 changes: 2 additions & 2 deletions lib/utils/history.js
Original file line number Diff line number Diff line change
@@ -112,8 +112,8 @@ export function formatHistoryToDisplay(history, cacheUsers) {
if (event.users.length > 0) {
event.avatar = {
name: event.users.slice(-1)[0].name || event.users.slice(-1)[0].username,
imageUrl: event.users.slice(-1)[0].imageUrl,
stacked: event.users.length > 1,
imageUrl: event.users.slice(-1)[0].imageUrl,
stacked: event.users.length > 1
};
} else {
event.avatar = {};
4 changes: 2 additions & 2 deletions lib/utils/history.test.js
Original file line number Diff line number Diff line change
@@ -29,14 +29,14 @@ describe('history', () => {
const state = { history: [{ action: 'edit', users: [{ username: 'c@d', id: 'Y0BkQHVuZGVmaW5lZA==' }] }] },
result = fn(state, currentUser);

expect(result.history[result.history.length - 1].users).toEqual([{ username: 'c@d', id: 'Y0BkQHVuZGVmaW5lZA==' }, {username: 'a@b', id: 'YUBiQHVuZGVmaW5lZA=='}]);
expect(result.history[result.history.length - 1].users).toEqual([{ username: 'c@d', id: 'Y0BkQHVuZGVmaW5lZA==' }, { username: 'a@b', id: 'YUBiQHVuZGVmaW5lZA==' }]);
}
);

test(
'will move the user to be the latest the user is already included',
() => {
const state = { history: [{action: 'edit', users: [{ username: 'a@b', id: 'YUBiQHVuZGVmaW5lZA==' }, { username: 'c@d', id: 'Y0BkQHVuZGVmaW5lZA==' }]}]},
const state = { history: [{ action: 'edit', users: [{ username: 'a@b', id: 'YUBiQHVuZGVmaW5lZA==' }, { username: 'c@d', id: 'Y0BkQHVuZGVmaW5lZA==' }] }]},
result = fn(state, currentUser);

expect(result.history[result.history.length - 1].users).toEqual([{ username: 'c@d', id: 'Y0BkQHVuZGVmaW5lZA==' }, { username: 'a@b', id: 'YUBiQHVuZGVmaW5lZA==' }]);