Commit 960b4c19 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Change `Focused` to `Active` in user-focus items in `selection`

- Use `Active` instead of `Focused` as it's easier to understand
- Use `toggleFocusMode` instead of `setFocusModeFocused`
parent cd7dbf51
...@@ -8,11 +8,9 @@ import useStore from '../store/use-store'; ...@@ -8,11 +8,9 @@ import useStore from '../store/use-store';
* and abstracted if needed. Allow user to toggle in and out of the focus "mode." * and abstracted if needed. Allow user to toggle in and out of the focus "mode."
*/ */
export default function FocusedModeHeader() { export default function FocusedModeHeader() {
const actions = useStore(store => ({ const toggleFocusMode = useStore(store => store.toggleFocusMode);
setFocusModeFocused: store.setFocusModeFocused,
}));
const selectors = useStore(store => ({ const selectors = useStore(store => ({
focusModeFocused: store.focusModeFocused(), focusModeActive: store.focusModeActive(),
focusModeHasUser: store.focusModeHasUser(), focusModeHasUser: store.focusModeHasUser(),
focusModeUserPrettyName: store.focusModeUserPrettyName(), focusModeUserPrettyName: store.focusModeUserPrettyName(),
})); }));
...@@ -22,13 +20,9 @@ export default function FocusedModeHeader() { ...@@ -22,13 +20,9 @@ export default function FocusedModeHeader() {
return null; return null;
} }
const toggleFocusedMode = () => {
actions.setFocusModeFocused(!selectors.focusModeFocused);
};
const filterStatus = ( const filterStatus = (
<div className="focused-mode-header__filter-status"> <div className="focused-mode-header__filter-status">
{selectors.focusModeFocused ? ( {selectors.focusModeActive ? (
<span> <span>
Showing <strong>{selectors.focusModeUserPrettyName}</strong> only Showing <strong>{selectors.focusModeUserPrettyName}</strong> only
</span> </span>
...@@ -41,7 +35,7 @@ export default function FocusedModeHeader() { ...@@ -41,7 +35,7 @@ export default function FocusedModeHeader() {
); );
const buttonText = (() => { const buttonText = (() => {
if (selectors.focusModeFocused) { if (selectors.focusModeActive) {
return 'Show all'; return 'Show all';
} else { } else {
return `Show only ${selectors.focusModeUserPrettyName}`; return `Show only ${selectors.focusModeUserPrettyName}`;
...@@ -51,7 +45,10 @@ export default function FocusedModeHeader() { ...@@ -51,7 +45,10 @@ export default function FocusedModeHeader() {
return ( return (
<div className="focused-mode-header"> <div className="focused-mode-header">
{filterStatus} {filterStatus}
<button onClick={toggleFocusedMode} className="focused-mode-header__btn"> <button
onClick={() => toggleFocusMode()}
className="focused-mode-header__btn"
>
{buttonText} {buttonText}
</button> </button>
</div> </div>
......
...@@ -39,13 +39,13 @@ function SearchStatusBar({ rootThread }) { ...@@ -39,13 +39,13 @@ function SearchStatusBar({ rootThread }) {
const { const {
filterQuery, filterQuery,
focusModeFocused, focusModeActive,
focusModeUserPrettyName, focusModeUserPrettyName,
hasSelectedAnnotations, hasSelectedAnnotations,
selectedTab, selectedTab,
} = useStore(store => ({ } = useStore(store => ({
filterQuery: store.getState().selection.filterQuery, filterQuery: store.getState().selection.filterQuery,
focusModeFocused: store.focusModeFocused(), focusModeActive: store.focusModeActive(),
focusModeUserPrettyName: store.focusModeUserPrettyName(), focusModeUserPrettyName: store.focusModeUserPrettyName(),
hasSelectedAnnotations: store.hasSelectedAnnotations(), hasSelectedAnnotations: store.hasSelectedAnnotations(),
selectedTab: store.getState().selection.selectedTab, selectedTab: store.getState().selection.selectedTab,
...@@ -64,7 +64,7 @@ function SearchStatusBar({ rootThread }) { ...@@ -64,7 +64,7 @@ function SearchStatusBar({ rootThread }) {
* The client has a currently-applied focus on a single user. Superseded by * The client has a currently-applied focus on a single user. Superseded by
* `filtered` mode. * `filtered` mode.
*/ */
focused: focusModeFocused && !filterQuery, focused: focusModeActive && !filterQuery,
/** /**
* @type {Boolean} * @type {Boolean}
* 0 - n annotations are currently "selected", by, e.g. clicking on highlighted * 0 - n annotations are currently "selected", by, e.g. clicking on highlighted
......
...@@ -21,10 +21,10 @@ describe('FocusedModeHeader', function () { ...@@ -21,10 +21,10 @@ describe('FocusedModeHeader', function () {
focused: true, focused: true,
}, },
}, },
focusModeFocused: sinon.stub().returns(true), focusModeActive: sinon.stub().returns(true),
focusModeUserPrettyName: sinon.stub().returns('Fake User'), focusModeUserPrettyName: sinon.stub().returns('Fake User'),
focusModeHasUser: sinon.stub().returns(true), focusModeHasUser: sinon.stub().returns(true),
setFocusModeFocused: sinon.stub(), toggleFocusMode: sinon.stub(),
}; };
$imports.$mock(mockImportedComponents()); $imports.$mock(mockImportedComponents());
...@@ -66,7 +66,7 @@ describe('FocusedModeHeader', function () { ...@@ -66,7 +66,7 @@ describe('FocusedModeHeader', function () {
context('focus is not applied (unfocused/off)', () => { context('focus is not applied (unfocused/off)', () => {
beforeEach(() => { beforeEach(() => {
fakeStore.focusModeFocused = sinon.stub().returns(false); fakeStore.focusModeActive = sinon.stub().returns(false);
}); });
it("should render status text indicating that all user's annotations are visible", () => { it("should render status text indicating that all user's annotations are visible", () => {
...@@ -86,21 +86,12 @@ describe('FocusedModeHeader', function () { ...@@ -86,21 +86,12 @@ describe('FocusedModeHeader', function () {
describe('toggle button', () => { describe('toggle button', () => {
it('should toggle focus mode to false if clicked when focused', () => { it('should toggle focus mode to false if clicked when focused', () => {
fakeStore.focusModeFocused = sinon.stub().returns(true); fakeStore.focusModeActive = sinon.stub().returns(true);
const wrapper = createComponent(); const wrapper = createComponent();
wrapper.find('button').simulate('click'); wrapper.find('button').simulate('click');
assert.calledWith(fakeStore.setFocusModeFocused, false); assert.calledOnce(fakeStore.toggleFocusMode);
});
it('should toggle focus mode to true if clicked when not focused', () => {
fakeStore.focusModeFocused = sinon.stub().returns(false);
const wrapper = createComponent();
wrapper.find('button').simulate('click');
assert.calledWith(fakeStore.setFocusModeFocused, true);
}); });
}); });
}); });
......
...@@ -24,7 +24,7 @@ describe('SearchStatusBar', () => { ...@@ -24,7 +24,7 @@ describe('SearchStatusBar', () => {
selection: {}, selection: {},
}), }),
annotationCount: sinon.stub().returns(1), annotationCount: sinon.stub().returns(1),
focusModeFocused: sinon.stub().returns(false), focusModeActive: sinon.stub().returns(false),
focusModeUserPrettyName: sinon.stub().returns('Fake User'), focusModeUserPrettyName: sinon.stub().returns('Fake User'),
hasSelectedAnnotations: sinon.stub(), hasSelectedAnnotations: sinon.stub(),
noteCount: sinon.stub().returns(0), noteCount: sinon.stub().returns(0),
...@@ -122,7 +122,7 @@ describe('SearchStatusBar', () => { ...@@ -122,7 +122,7 @@ describe('SearchStatusBar', () => {
context('user-focused mode applied', () => { context('user-focused mode applied', () => {
beforeEach(() => { beforeEach(() => {
fakeStore.focusModeFocused = sinon.stub().returns(true); fakeStore.focusModeActive = sinon.stub().returns(true);
}); });
it('should not display a clear/show-all-annotations button when user-focused', () => { it('should not display a clear/show-all-annotations button when user-focused', () => {
...@@ -262,7 +262,7 @@ describe('SearchStatusBar', () => { ...@@ -262,7 +262,7 @@ describe('SearchStatusBar', () => {
{ tab: 'note', buttonText: 'Show all notes by Fake User' }, { tab: 'note', buttonText: 'Show all notes by Fake User' },
].forEach(test => { ].forEach(test => {
it(`displays correct text for tab '${test.tab}', without count`, () => { it(`displays correct text for tab '${test.tab}', without count`, () => {
fakeStore.focusModeFocused = sinon.stub().returns(true); fakeStore.focusModeActive = sinon.stub().returns(true);
fakeStore.getState.returns({ fakeStore.getState.returns({
selection: { selection: {
filterQuery: null, filterQuery: null,
...@@ -286,7 +286,7 @@ describe('SearchStatusBar', () => { ...@@ -286,7 +286,7 @@ describe('SearchStatusBar', () => {
context('combined with applied query filter', () => { context('combined with applied query filter', () => {
// Applied-query mode wins out here; no selection UI rendered // Applied-query mode wins out here; no selection UI rendered
it('does not show selected-mode elements', () => { it('does not show selected-mode elements', () => {
fakeStore.focusModeFocused = sinon.stub().returns(true); fakeStore.focusModeActive = sinon.stub().returns(true);
fakeStore.getState.returns({ fakeStore.getState.returns({
selection: { selection: {
filterQuery: 'tag:foo', filterQuery: 'tag:foo',
......
...@@ -46,7 +46,7 @@ export default function RootThread( ...@@ -46,7 +46,7 @@ export default function RootThread(
const sortFn = sortFns[state.selection.sortKey]; const sortFn = sortFns[state.selection.sortKey];
const shouldFilterThread = () => { const shouldFilterThread = () => {
// Is there a search query, or are we in an active (focused) focus mode? // Is there a search query, or are we in an active (focused) focus mode?
return state.selection.filterQuery || store.focusModeFocused(); return state.selection.filterQuery || store.focusModeActive();
}; };
const options = { const options = {
...@@ -62,7 +62,7 @@ export default function RootThread( ...@@ -62,7 +62,7 @@ export default function RootThread(
state.selection.filterQuery, state.selection.filterQuery,
{ {
// if a focus mode is applied (focused) and we're focusing on a user // if a focus mode is applied (focused) and we're focusing on a user
user: store.focusModeFocused() && store.focusModeUserId(), user: store.focusModeActive() && store.focusModeUserId(),
} }
); );
......
...@@ -64,7 +64,7 @@ describe('rootThread', function () { ...@@ -64,7 +64,7 @@ describe('rootThread', function () {
getDraftIfNotEmpty: sinon.stub().returns(null), getDraftIfNotEmpty: sinon.stub().returns(null),
removeDraft: sinon.stub(), removeDraft: sinon.stub(),
createAnnotation: sinon.stub(), createAnnotation: sinon.stub(),
focusModeFocused: sinon.stub().returns(false), focusModeActive: sinon.stub().returns(false),
focusModeUserId: sinon.stub().returns({}), focusModeUserId: sinon.stub().returns({}),
}; };
...@@ -323,7 +323,7 @@ describe('rootThread', function () { ...@@ -323,7 +323,7 @@ describe('rootThread', function () {
const filters = [{ user: { terms: ['acct:bill@localhost'] } }]; const filters = [{ user: { terms: ['acct:bill@localhost'] } }];
const annotation = annotationFixtures.defaultAnnotation(); const annotation = annotationFixtures.defaultAnnotation();
fakeSearchFilter.generateFacetedFilter.returns(filters); fakeSearchFilter.generateFacetedFilter.returns(filters);
fakeStore.focusModeFocused = sinon.stub().returns(true); fakeStore.focusModeActive = sinon.stub().returns(true);
rootThread.thread(fakeStore.state); rootThread.thread(fakeStore.state);
const filterFn = fakeBuildThread.args[0][1].filterFn; const filterFn = fakeBuildThread.args[0][1].filterFn;
......
...@@ -60,23 +60,6 @@ function initialSelection(settings) { ...@@ -60,23 +60,6 @@ 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 {
/** /**
...@@ -114,7 +97,7 @@ function init(settings) { ...@@ -114,7 +97,7 @@ function init(settings) {
filterQuery: settings.query || null, filterQuery: settings.query || null,
focusMode: { focusMode: {
configured: settings.hasOwnProperty('focus'), configured: settings.hasOwnProperty('focus'),
focused: true, active: 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 : {}) },
}, },
...@@ -166,11 +149,15 @@ const update = { ...@@ -166,11 +149,15 @@ const update = {
return { focused: toTrueMap(action.focusedTags) }; return { focused: toTrueMap(action.focusedTags) };
}, },
SET_FOCUS_MODE_FOCUSED: function (state, action) { SET_FOCUS_MODE: function (state, action) {
const active =
typeof action.active !== 'undefined'
? action.active
: !state.focusMode.active;
return { return {
focusMode: { focusMode: {
...state.focusMode, ...state.focusMode,
focused: action.focused, active,
}, },
}; };
}, },
...@@ -181,7 +168,7 @@ const update = { ...@@ -181,7 +168,7 @@ const update = {
focusMode: { focusMode: {
...state.focusMode, ...state.focusMode,
configured: false, configured: false,
focused: false, active: false,
}, },
}; };
} else { } else {
...@@ -189,7 +176,7 @@ const update = { ...@@ -189,7 +176,7 @@ const update = {
focusMode: { focusMode: {
...state.focusMode, ...state.focusMode,
configured: true, configured: true,
focused: true, active: true,
config: { config: {
user: { ...action.user }, user: { ...action.user },
}, },
...@@ -380,12 +367,15 @@ function setFilterQuery(query) { ...@@ -380,12 +367,15 @@ function setFilterQuery(query) {
} }
/** /**
* Set the focused to only show annotations matching the current focus mode. * Toggle whether or not a (user-)focus mode is applied, either inverting the
* current active state or setting it to a target `active` state, if provided.
*
* @param {boolean} [active] - Optional `active` state for focus mode
*/ */
function setFocusModeFocused(focused) { function toggleFocusMode(active) {
return { return {
type: actions.SET_FOCUS_MODE_FOCUSED, type: actions.SET_FOCUS_MODE,
focused, active,
}; };
} }
...@@ -494,8 +484,8 @@ function focusModeConfigured(state) { ...@@ -494,8 +484,8 @@ function focusModeConfigured(state) {
* *
* @return {boolean} * @return {boolean}
*/ */
function focusModeFocused(state) { function focusModeActive(state) {
return focusModeConfigured(state) && state.selection.focusMode.focused; return focusModeConfigured(state) && state.selection.focusMode.active;
} }
/** /**
...@@ -559,10 +549,10 @@ function focusModeUserPrettyName(state) { ...@@ -559,10 +549,10 @@ function focusModeUserPrettyName(state) {
*/ */
const hasAppliedFilter = createSelector( const hasAppliedFilter = createSelector(
filterQuery, filterQuery,
focusModeFocused, focusModeActive,
hasSelectedAnnotations, hasSelectedAnnotations,
(filterQuery, focusModeFocused, hasSelectedAnnotations) => (filterQuery, focusModeActive, hasSelectedAnnotations) =>
!!filterQuery || focusModeFocused || hasSelectedAnnotations !!filterQuery || focusModeActive || hasSelectedAnnotations
); );
const selectedAnnotations = createSelector( const selectedAnnotations = createSelector(
...@@ -598,17 +588,17 @@ export default { ...@@ -598,17 +588,17 @@ export default {
selectTab, selectTab,
setExpanded, setExpanded,
setFilterQuery, setFilterQuery,
setFocusModeFocused,
changeFocusModeUser, changeFocusModeUser,
setForcedVisible, setForcedVisible,
setSortKey, setSortKey,
toggleFocusMode,
toggleSelectedAnnotations, toggleSelectedAnnotations,
}, },
selectors: { selectors: {
expandedMap, expandedMap,
filterQuery, filterQuery,
focusModeFocused, focusModeActive,
focusModeConfigured, focusModeConfigured,
focusModeHasUser, focusModeHasUser,
focusModeUserId, focusModeUserId,
......
...@@ -83,9 +83,9 @@ describe('sidebar/store/modules/selection', () => { ...@@ -83,9 +83,9 @@ describe('sidebar/store/modules/selection', () => {
assert.isTrue(store.hasAppliedFilter()); assert.isTrue(store.hasAppliedFilter());
}); });
it('returns true if in user-focused mode', () => { it('returns true if user-focused mode applied', () => {
store = createStore([selection], [{ focus: { user: {} } }]); store = createStore([selection], [{ focus: { user: {} } }]);
store.setFocusModeFocused(true); store.toggleFocusMode(true);
assert.isTrue(store.hasAppliedFilter()); assert.isTrue(store.hasAppliedFilter());
}); });
...@@ -218,14 +218,14 @@ describe('sidebar/store/modules/selection', () => { ...@@ -218,14 +218,14 @@ describe('sidebar/store/modules/selection', () => {
describe('changeFocusModeUser()', function () { describe('changeFocusModeUser()', function () {
it('sets the focused user and enables focus mode', function () { it('sets the focused user and enables focus mode', function () {
store.setFocusModeFocused(false); store.toggleFocusMode(false);
store.changeFocusModeUser({ store.changeFocusModeUser({
username: 'testuser', username: 'testuser',
displayName: 'Test User', displayName: 'Test User',
}); });
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.focusModeActive(), true);
assert.equal(store.focusModeConfigured(), true); assert.equal(store.focusModeConfigured(), true);
}); });
...@@ -237,17 +237,17 @@ describe('sidebar/store/modules/selection', () => { ...@@ -237,17 +237,17 @@ describe('sidebar/store/modules/selection', () => {
// //
// This is the LMS app's way of asking the client to disable focus mode. // This is the LMS app's way of asking the client to disable focus mode.
it('disables focus mode if username is undefined', function () { it('disables focus mode if username is undefined', function () {
store.setFocusModeFocused(true); store.toggleFocusMode(true);
store.changeFocusModeUser({ store.changeFocusModeUser({
username: undefined, username: undefined,
displayName: undefined, displayName: undefined,
}); });
assert.equal(store.focusModeFocused(), false); assert.equal(store.focusModeActive(), false);
assert.equal(store.focusModeConfigured(), false); assert.equal(store.focusModeConfigured(), false);
}); });
it('clears other applied selections', () => { it('clears other applied selections', () => {
store.setFocusModeFocused(true); store.toggleFocusMode(true);
store.setForcedVisible('someAnnotationId'); store.setForcedVisible('someAnnotationId');
store.setFilterQuery('somequery'); store.setFilterQuery('somequery');
store.changeFocusModeUser({ store.changeFocusModeUser({
...@@ -260,16 +260,17 @@ describe('sidebar/store/modules/selection', () => { ...@@ -260,16 +260,17 @@ describe('sidebar/store/modules/selection', () => {
}); });
}); });
describe('setFocusModeFocused()', function () { describe('toggleFocusMode', function () {
it('sets the focus mode to focused', function () { it('toggles the current active state if called without arguments', function () {
store.setFocusModeFocused(true); store.toggleFocusMode(false);
assert.equal(getSelectionState().focusMode.focused, true); store.toggleFocusMode();
assert.equal(getSelectionState().focusMode.active, true);
}); });
it('sets the focus mode to not focused', function () { it('toggles the current active state to designated state', function () {
store = createStore([selection], [{ focus: { user: {} } }]); store.toggleFocusMode(true);
store.setFocusModeFocused(false); store.toggleFocusMode(false);
assert.equal(getSelectionState().focusMode.focused, false); assert.equal(getSelectionState().focusMode.active, false);
}); });
}); });
...@@ -283,17 +284,17 @@ describe('sidebar/store/modules/selection', () => { ...@@ -283,17 +284,17 @@ describe('sidebar/store/modules/selection', () => {
}); });
}); });
describe('focusModeFocused', function () { describe('focusModeActive', function () {
it('should return true by default when focus mode is focused', function () { it('should return true by default when focus mode is active', function () {
store = createStore([selection], [{ focus: { user: {} } }]); store = createStore([selection], [{ focus: { user: {} } }]);
assert.equal(getSelectionState().focusMode.configured, true); assert.equal(getSelectionState().focusMode.configured, true);
assert.equal(getSelectionState().focusMode.focused, true); assert.equal(getSelectionState().focusMode.active, true);
assert.equal(store.focusModeFocused(), true); assert.equal(store.focusModeActive(), true);
}); });
it('should return false by default when focus mode is not focused', function () { it('should return false by default when focus mode is not active', function () {
assert.equal(getSelectionState().focusMode.configured, false); assert.equal(getSelectionState().focusMode.configured, false);
assert.equal(getSelectionState().focusMode.focused, true); assert.equal(getSelectionState().focusMode.active, true);
assert.equal(store.focusModeFocused(), false); assert.equal(store.focusModeActive(), false);
}); });
}); });
......
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