Commit cd7dbf51 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Clarify `focusMode` in `selection` module

- Rename `enabled` to `configured`
parent 1bcc0b06
...@@ -32,7 +32,7 @@ function SidebarContent({ ...@@ -32,7 +32,7 @@ function SidebarContent({
// Store state values // Store state values
const focusedGroupId = useStore(store => store.focusedGroupId()); const focusedGroupId = useStore(store => store.focusedGroupId());
const hasAppliedFilter = useStore(store => store.hasAppliedFilter()); const hasAppliedFilter = useStore(store => store.hasAppliedFilter());
const isFocusedMode = useStore(store => store.focusModeEnabled()); const isFocusedMode = useStore(store => store.focusModeConfigured());
const isLoading = useStore(store => store.isLoading()); const isLoading = useStore(store => store.isLoading());
const isLoggedIn = useStore(store => store.isLoggedIn()); const isLoggedIn = useStore(store => store.isLoggedIn());
const linkedAnnotationId = useStore(store => const linkedAnnotationId = useStore(store =>
......
...@@ -52,7 +52,7 @@ describe('SidebarContent', () => { ...@@ -52,7 +52,7 @@ describe('SidebarContent', () => {
directLinkedGroupFetchFailed: sinon.stub(), directLinkedGroupFetchFailed: sinon.stub(),
findAnnotationByID: sinon.stub(), findAnnotationByID: sinon.stub(),
focusedGroupId: sinon.stub(), focusedGroupId: sinon.stub(),
focusModeEnabled: sinon.stub(), focusModeConfigured: sinon.stub(),
hasAppliedFilter: sinon.stub(), hasAppliedFilter: sinon.stub(),
hasFetchedAnnotations: sinon.stub(), hasFetchedAnnotations: sinon.stub(),
hasSidebarOpened: sinon.stub(), hasSidebarOpened: sinon.stub(),
...@@ -226,7 +226,7 @@ describe('SidebarContent', () => { ...@@ -226,7 +226,7 @@ describe('SidebarContent', () => {
}); });
it('renders a focused header if in focused mode', () => { it('renders a focused header if in focused mode', () => {
fakeStore.focusModeEnabled.returns(true); fakeStore.focusModeConfigured.returns(true);
const wrapper = createComponent(); const wrapper = createComponent();
assert.isTrue(wrapper.find('FocusedModeHeader').exists()); assert.isTrue(wrapper.find('FocusedModeHeader').exists());
......
...@@ -60,6 +60,23 @@ function initialSelection(settings) { ...@@ -60,6 +60,23 @@ function initialSelection(settings) {
return selection; return selection;
} }
// function initialFocus(settings) {
// const focusConfig = {
// configured: false,
// active: false,
// user: undefined,
// };
//
// if (settings.hasOwnProperty('user')) {
// const focusedUser = {...settings.user};
// if (focusedUser.username && focusedUser.authority) {
// focusConfig.configured = true;
// focusConfig.user = focusedUser;
// }
// }
// return focusConfig;
// }
function init(settings) { function init(settings) {
return { return {
/** /**
...@@ -96,7 +113,7 @@ function init(settings) { ...@@ -96,7 +113,7 @@ function init(settings) {
filterQuery: settings.query || null, filterQuery: settings.query || null,
focusMode: { focusMode: {
enabled: settings.hasOwnProperty('focus'), configured: settings.hasOwnProperty('focus'),
focused: true, focused: true,
// Copy over the focus confg from settings object // Copy over the focus confg from settings object
config: { ...(settings.focus ? settings.focus : {}) }, config: { ...(settings.focus ? settings.focus : {}) },
...@@ -163,7 +180,7 @@ const update = { ...@@ -163,7 +180,7 @@ const update = {
return { return {
focusMode: { focusMode: {
...state.focusMode, ...state.focusMode,
enabled: false, configured: false,
focused: false, focused: false,
}, },
}; };
...@@ -171,7 +188,7 @@ const update = { ...@@ -171,7 +188,7 @@ const update = {
return { return {
focusMode: { focusMode: {
...state.focusMode, ...state.focusMode,
enabled: true, configured: true,
focused: true, focused: true,
config: { config: {
user: { ...action.user }, user: { ...action.user },
...@@ -464,21 +481,21 @@ function filterQuery(state) { ...@@ -464,21 +481,21 @@ function filterQuery(state) {
} }
/** /**
* Do the config settings indicate that the client should be in a focused mode? * Does the configuration used by the app contain valid focus-mode configuration?
* *
* @return {boolean} * @return {boolean}
*/ */
function focusModeEnabled(state) { function focusModeConfigured(state) {
return state.selection.focusMode.enabled; return state.selection.focusMode.configured;
} }
/** /**
* Is a focus mode enabled, and is it presently applied? * Is a focus mode configured, and is it presently applied?
* *
* @return {boolean} * @return {boolean}
*/ */
function focusModeFocused(state) { function focusModeFocused(state) {
return focusModeEnabled(state) && state.selection.focusMode.focused; return focusModeConfigured(state) && state.selection.focusMode.focused;
} }
/** /**
...@@ -507,7 +524,7 @@ function focusModeUserId(state) { ...@@ -507,7 +524,7 @@ function focusModeUserId(state) {
* @return {boolean} * @return {boolean}
*/ */
function focusModeHasUser(state) { function focusModeHasUser(state) {
return focusModeEnabled(state) && !!focusModeUserId(state); return focusModeConfigured(state) && !!focusModeUserId(state);
} }
/** /**
...@@ -592,7 +609,7 @@ export default { ...@@ -592,7 +609,7 @@ export default {
expandedMap, expandedMap,
filterQuery, filterQuery,
focusModeFocused, focusModeFocused,
focusModeEnabled, focusModeConfigured,
focusModeHasUser, focusModeHasUser,
focusModeUserId, focusModeUserId,
focusModeUserPrettyName, focusModeUserPrettyName,
......
...@@ -226,7 +226,7 @@ describe('sidebar/store/modules/selection', () => { ...@@ -226,7 +226,7 @@ describe('sidebar/store/modules/selection', () => {
assert.equal(store.focusModeUserId(), 'testuser'); assert.equal(store.focusModeUserId(), 'testuser');
assert.equal(store.focusModeUserPrettyName(), 'Test User'); assert.equal(store.focusModeUserPrettyName(), 'Test User');
assert.equal(store.focusModeFocused(), true); assert.equal(store.focusModeFocused(), true);
assert.equal(store.focusModeEnabled(), true); assert.equal(store.focusModeConfigured(), true);
}); });
// When the LMS app wants the client to disable focus mode it sends a // When the LMS app wants the client to disable focus mode it sends a
...@@ -243,7 +243,7 @@ describe('sidebar/store/modules/selection', () => { ...@@ -243,7 +243,7 @@ describe('sidebar/store/modules/selection', () => {
displayName: undefined, displayName: undefined,
}); });
assert.equal(store.focusModeFocused(), false); assert.equal(store.focusModeFocused(), false);
assert.equal(store.focusModeEnabled(), false); assert.equal(store.focusModeConfigured(), false);
}); });
it('clears other applied selections', () => { it('clears other applied selections', () => {
...@@ -261,51 +261,51 @@ describe('sidebar/store/modules/selection', () => { ...@@ -261,51 +261,51 @@ describe('sidebar/store/modules/selection', () => {
}); });
describe('setFocusModeFocused()', function () { describe('setFocusModeFocused()', function () {
it('sets the focus mode to enabled', function () { it('sets the focus mode to focused', function () {
store.setFocusModeFocused(true); store.setFocusModeFocused(true);
assert.equal(getSelectionState().focusMode.focused, true); assert.equal(getSelectionState().focusMode.focused, true);
}); });
it('sets the focus mode to not enabled', function () { it('sets the focus mode to not focused', function () {
store = createStore([selection], [{ focus: { user: {} } }]); store = createStore([selection], [{ focus: { user: {} } }]);
store.setFocusModeFocused(false); store.setFocusModeFocused(false);
assert.equal(getSelectionState().focusMode.focused, false); assert.equal(getSelectionState().focusMode.focused, false);
}); });
}); });
describe('focusModeEnabled()', function () { describe('focusModeConfigured', function () {
it('should be true when the focus setting is present', function () { it('should be true when the focus setting is present', function () {
store = createStore([selection], [{ focus: { user: {} } }]); store = createStore([selection], [{ focus: { user: {} } }]);
assert.equal(store.focusModeEnabled(), true); assert.equal(store.focusModeConfigured(), true);
}); });
it('should be false when the focus setting is not present', function () { it('should be false when the focus setting is not present', function () {
assert.equal(store.focusModeEnabled(), false); assert.equal(store.focusModeConfigured(), false);
}); });
}); });
describe('focusModeFocused()', function () { describe('focusModeFocused', function () {
it('should return true by default when focus mode is enabled', function () { it('should return true by default when focus mode is focused', function () {
store = createStore([selection], [{ focus: { user: {} } }]); store = createStore([selection], [{ focus: { user: {} } }]);
assert.equal(getSelectionState().focusMode.enabled, true); assert.equal(getSelectionState().focusMode.configured, true);
assert.equal(getSelectionState().focusMode.focused, true); assert.equal(getSelectionState().focusMode.focused, true);
assert.equal(store.focusModeFocused(), true); assert.equal(store.focusModeFocused(), true);
}); });
it('should return false by default when focus mode is not enabled', function () { it('should return false by default when focus mode is not focused', function () {
assert.equal(getSelectionState().focusMode.enabled, false); assert.equal(getSelectionState().focusMode.configured, false);
assert.equal(getSelectionState().focusMode.focused, true); assert.equal(getSelectionState().focusMode.focused, true);
assert.equal(store.focusModeFocused(), false); assert.equal(store.focusModeFocused(), false);
}); });
}); });
describe('focusModeHasUser()', () => { describe('focusModeHasUser()', () => {
it('should return `true` if focus enabled and valid `user` object present', () => { it('should return `true` if focus configured and valid `user` object present', () => {
store = createStore( store = createStore(
[selection], [selection],
[{ focus: { user: { userid: 'acct:userid@authority' } } }] [{ focus: { user: { userid: 'acct:userid@authority' } } }]
); );
assert.isTrue(store.focusModeHasUser()); assert.isTrue(store.focusModeHasUser());
}); });
it('should return `false` if focus enabled but `user` object invalid', () => { it('should return `false` if focus configured but `user` object invalid', () => {
store = createStore( store = createStore(
[selection], [selection],
[{ focus: { user: { displayName: 'FakeDisplayName' } } }] // `userid` is required [{ focus: { user: { displayName: 'FakeDisplayName' } } }] // `userid` is required
...@@ -319,7 +319,7 @@ describe('sidebar/store/modules/selection', () => { ...@@ -319,7 +319,7 @@ describe('sidebar/store/modules/selection', () => {
}); });
describe('focusModeUserPrettyName()', function () { describe('focusModeUserPrettyName()', function () {
it('returns false by default when focus mode is not enabled', function () { it('returns false by default when focus mode is not configured', function () {
store = createStore( store = createStore(
[selection], [selection],
[{ focus: { user: { displayName: 'FakeDisplayName' } } }] [{ focus: { user: { displayName: 'FakeDisplayName' } } }]
......
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