Commit e5824a34 authored by Robert Knight's avatar Robert Knight

Re-render `GroupListItem` when focused group changes

Fix an issue where `GroupListItem` components did not re-render when the
focused group changed. This component is due to be replaced shortly, so
this is really just a test case to show that `useStore` works as
expected.
parent 7107d402
...@@ -4,18 +4,26 @@ const classnames = require('classnames'); ...@@ -4,18 +4,26 @@ const classnames = require('classnames');
const propTypes = require('prop-types'); const propTypes = require('prop-types');
const { createElement } = require('preact'); const { createElement } = require('preact');
const useStore = require('../store/use-store');
const { orgName } = require('../util/group-list-item-common'); const { orgName } = require('../util/group-list-item-common');
const { withServices } = require('../util/service-context'); const { withServices } = require('../util/service-context');
function GroupListItem({ analytics, group, store }) { function GroupListItem({ analytics, group }) {
const actions = useStore(store => ({
clearDirectLinkedGroupFetchFailed: store.clearDirectLinkedGroupFetchFailed,
clearDirectLinkedIds: store.clearDirectLinkedIds,
focusGroup: store.focusGroup,
}));
const focusGroup = () => { const focusGroup = () => {
analytics.track(analytics.events.GROUP_SWITCH); analytics.track(analytics.events.GROUP_SWITCH);
store.clearDirectLinkedGroupFetchFailed(); actions.clearDirectLinkedGroupFetchFailed();
store.clearDirectLinkedIds(); actions.clearDirectLinkedIds();
store.focusGroup(group.id); actions.focusGroup(group.id);
}; };
const isSelected = group.id === store.focusedGroupId(); const focusedGroupId = useStore(store => store.focusedGroupId());
const isSelected = group.id === focusedGroupId;
const groupOrgName = orgName(group); const groupOrgName = orgName(group);
return ( return (
...@@ -59,9 +67,8 @@ GroupListItem.propTypes = { ...@@ -59,9 +67,8 @@ GroupListItem.propTypes = {
group: propTypes.object.isRequired, group: propTypes.object.isRequired,
analytics: propTypes.object.isRequired, analytics: propTypes.object.isRequired,
store: propTypes.object.isRequired,
}; };
GroupListItem.injectedProps = ['analytics', 'store']; GroupListItem.injectedProps = ['analytics'];
module.exports = withServices(GroupListItem); module.exports = withServices(GroupListItem);
...@@ -31,6 +31,7 @@ describe('GroupListItem', () => { ...@@ -31,6 +31,7 @@ describe('GroupListItem', () => {
GroupListItem.$imports.$mock({ GroupListItem.$imports.$mock({
'../util/group-list-item-common': fakeGroupListItemCommon, '../util/group-list-item-common': fakeGroupListItemCommon,
'../store/use-store': callback => callback(fakeStore),
}); });
}); });
......
...@@ -26,10 +26,7 @@ ...@@ -26,10 +26,7 @@
} }
&.is-selected { &.is-selected {
.name-link { background: $gray-lightest;
font-size: $body2-font-size;
font-weight: 600;
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment