Commit 66629ab6 authored by Robert Knight's avatar Robert Knight

Rename `focusedGroup` state key to `focusedGroupId`

As noted in CR feedback, having a selector named `focusedGroup` which
returns a `Group` and a state property named `focusedGroup` is
`string|null` is confusing.

Also change a `g` variable to `group` for clarity.
parent 6585c54e
......@@ -14,31 +14,31 @@ function init() {
* ID of currently selected group.
* @type {string|null}
*/
focusedGroup: null,
focusedGroupId: null,
};
}
const update = {
FOCUS_GROUP(state, action) {
const g = state.groups.find(g => g.id === action.id);
return { focusedGroup: g ? action.id : null };
const group = state.groups.find(g => g.id === action.id);
return { focusedGroupId: group ? action.id : null };
},
LOAD_GROUPS(state, action) {
const groups = action.groups;
let focusedGroup = state.focusedGroup;
let focusedGroupId = state.focusedGroupId;
// Reset focused group if not in the new set of groups.
if (state.focusedGroup === null || !groups.find(g => g.id === state.focusedGroup)) {
if (state.focusedGroupId === null || !groups.find(g => g.id === state.focusedGroupId)) {
if (groups.length > 0) {
focusedGroup = groups[0].id;
focusedGroupId = groups[0].id;
} else {
focusedGroup = null;
focusedGroupId = null;
}
}
return {
focusedGroup,
focusedGroupId,
groups: action.groups,
};
},
......@@ -76,10 +76,10 @@ function loadGroups(groups) {
* @return {Group|null}
*/
function focusedGroup(state) {
if (!state.focusedGroup) {
if (!state.focusedGroupId) {
return null;
}
return getGroup(state, state.focusedGroup);
return getGroup(state, state.focusedGroupId);
}
/**
......
......@@ -24,13 +24,13 @@ describe('sidebar.store.modules.groups', () => {
it('updates the focused group if valid', () => {
store.loadGroups([publicGroup]);
store.focusGroup(publicGroup.id);
assert.equal(store.getState().focusedGroup, publicGroup.id);
assert.equal(store.getState().focusedGroupId, publicGroup.id);
});
it('does not set the focused group if invalid', () => {
store.loadGroups([publicGroup]);
store.focusGroup(privateGroup.id);
assert.equal(store.getState().focusedGroup, null);
assert.equal(store.getState().focusedGroupId, null);
});
});
......@@ -45,7 +45,7 @@ describe('sidebar.store.modules.groups', () => {
store.focusGroup(publicGroup.id);
store.loadGroups([]);
assert.equal(store.getState().focusedGroup, null);
assert.equal(store.getState().focusedGroupId, null);
});
it('leaves focused group unchanged if in new set of groups', () => {
......@@ -53,7 +53,7 @@ describe('sidebar.store.modules.groups', () => {
store.focusGroup(publicGroup.id);
store.loadGroups([publicGroup, privateGroup]);
assert.equal(store.getState().focusedGroup, publicGroup.id);
assert.equal(store.getState().focusedGroupId, publicGroup.id);
});
});
......
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