Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
35d32057
Unverified
Commit
35d32057
authored
Aug 08, 2019
by
Lyza Gardner
Committed by
GitHub
Aug 08, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1292 from hypothesis/tweak-user-focus
Update user-focus store, rootThread intergration for clarity
parents
b104d018
48718916
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
22 deletions
+52
-22
focused-mode-header.js
src/sidebar/components/focused-mode-header.js
+5
-0
root-thread.js
src/sidebar/services/root-thread.js
+4
-12
selection.js
src/sidebar/store/modules/selection.js
+22
-10
selection-test.js
src/sidebar/store/modules/test/selection-test.js
+21
-0
No files found.
src/sidebar/components/focused-mode-header.js
View file @
35d32057
...
@@ -4,6 +4,11 @@ const { createElement } = require('preact');
...
@@ -4,6 +4,11 @@ const { createElement } = require('preact');
const
useStore
=
require
(
'../store/use-store'
);
const
useStore
=
require
(
'../store/use-store'
);
/**
* Render a control to interact with any focused "mode" in the sidebar.
* Currently only a user-focus mode is supported but this could be broadened
* and abstracted if needed. Allow user to toggle in and out of the focus "mode."
*/
function
FocusedModeHeader
()
{
function
FocusedModeHeader
()
{
const
store
=
useStore
(
store
=>
({
const
store
=
useStore
(
store
=>
({
actions
:
{
actions
:
{
...
...
src/sidebar/services/root-thread.js
View file @
35d32057
...
@@ -49,22 +49,14 @@ function RootThread($rootScope, store, searchFilter, viewFilter) {
...
@@ -49,22 +49,14 @@ function RootThread($rootScope, store, searchFilter, viewFilter) {
function
buildRootThread
(
state
)
{
function
buildRootThread
(
state
)
{
const
sortFn
=
sortFns
[
state
.
sortKey
];
const
sortFn
=
sortFns
[
state
.
sortKey
];
const
shouldFilterThread
=
()
=>
{
const
shouldFilterThread
=
()
=>
{
//
is there a query or focused truthy value from the config
?
//
Is there a search query, or are we in an active (focused) focus mode
?
return
state
.
filterQuery
||
store
.
focusModeFocused
();
return
state
.
filterQuery
||
store
.
focusModeFocused
();
};
};
let
filterFn
;
let
filterFn
;
if
(
shouldFilterThread
())
{
if
(
shouldFilterThread
())
{
const
userFilter
=
{};
// optional user filter object for focused mode
const
filters
=
searchFilter
.
generateFacetedFilter
(
state
.
filterQuery
,
{
// look for a unique username, if present, add it to the user filter
user
:
store
.
focusModeUsername
(),
// `null` if no focused user
const
focusedUsername
=
store
.
focusModeUsername
();
// may be null if no focused user
});
if
(
focusedUsername
)
{
// focused user found, add it to the filter object
userFilter
.
user
=
focusedUsername
;
}
const
filters
=
searchFilter
.
generateFacetedFilter
(
state
.
filterQuery
,
userFilter
);
filterFn
=
function
(
annot
)
{
filterFn
=
function
(
annot
)
{
return
viewFilter
.
filter
([
annot
],
filters
).
length
>
0
;
return
viewFilter
.
filter
([
annot
],
filters
).
length
>
0
;
...
...
src/sidebar/store/modules/selection.js
View file @
35d32057
...
@@ -324,7 +324,7 @@ function setFilterQuery(query) {
...
@@ -324,7 +324,7 @@ function setFilterQuery(query) {
}
}
/**
/**
* Set the focused to only show annotations
by the focused user
.
* Set the focused to only show annotations
matching the current focus mode
.
*/
*/
function
setFocusModeFocused
(
focused
)
{
function
setFocusModeFocused
(
focused
)
{
return
{
return
{
...
@@ -379,28 +379,29 @@ const getFirstSelectedAnnotationId = createSelector(
...
@@ -379,28 +379,29 @@ const getFirstSelectedAnnotationId = createSelector(
function
filterQuery
(
state
)
{
function
filterQuery
(
state
)
{
return
state
.
filterQuery
;
return
state
.
filterQuery
;
}
}
/**
/**
* Returns the on/off state of the focus mode. This can be toggled on or off to
* Do the config settings indicate that the client should be in a focused mode?
* filter to the focused user.
*
*
* @return {boolean}
* @return {boolean}
*/
*/
function
focusMode
Focus
ed
(
state
)
{
function
focusMode
Enabl
ed
(
state
)
{
return
state
.
focusMode
.
enabled
&&
state
.
focusMode
.
focused
;
return
state
.
focusMode
.
enabled
;
}
}
/**
/**
*
Returns the value of the focus mode from the config.
*
Is a focus mode enabled, and is it presently applied?
*
*
* @return {boolean}
* @return {boolean}
*/
*/
function
focusMode
Enabl
ed
(
state
)
{
function
focusMode
Focus
ed
(
state
)
{
return
state
.
focusMode
.
enabl
ed
;
return
focusModeEnabled
(
state
)
&&
state
.
focusMode
.
focus
ed
;
}
}
/**
/**
* Returns the username
of the focused mode or null if none is found
.
* Returns the username
for a focused user or `null` if no focused user
.
*
*
* @return {object}
* @return {object
|null
}
*/
*/
function
focusModeUsername
(
state
)
{
function
focusModeUsername
(
state
)
{
if
(
state
.
focusMode
.
config
.
user
&&
state
.
focusMode
.
config
.
user
.
username
)
{
if
(
state
.
focusMode
.
config
.
user
&&
state
.
focusMode
.
config
.
user
.
username
)
{
...
@@ -409,6 +410,16 @@ function focusModeUsername(state) {
...
@@ -409,6 +410,16 @@ function focusModeUsername(state) {
return
null
;
return
null
;
}
}
/**
* Does the configured focus mode include user info, i.e. are we focusing on a
* user?
*
* @return {boolean}
*/
function
focusModeHasUser
(
state
)
{
return
focusModeEnabled
(
state
)
&&
!!
focusModeUsername
(
state
);
}
/**
/**
* Returns the display name for a user or the username
* Returns the display name for a user or the username
* if display name is not present. If both are missing
* if display name is not present. If both are missing
...
@@ -453,6 +464,7 @@ module.exports = {
...
@@ -453,6 +464,7 @@ module.exports = {
filterQuery
,
filterQuery
,
focusModeFocused
,
focusModeFocused
,
focusModeEnabled
,
focusModeEnabled
,
focusModeHasUser
,
focusModeUsername
,
focusModeUsername
,
focusModeUserPrettyName
,
focusModeUserPrettyName
,
isAnnotationSelected
,
isAnnotationSelected
,
...
...
src/sidebar/store/modules/test/selection-test.js
View file @
35d32057
...
@@ -223,6 +223,27 @@ describe('store/modules/selection', () => {
...
@@ -223,6 +223,27 @@ describe('store/modules/selection', () => {
});
});
});
});
describe
(
'focusModeHasUser()'
,
()
=>
{
it
(
'should return `true` if focus enabled and valid `user` object present'
,
()
=>
{
store
=
createStore
(
[
selection
],
[{
focus
:
{
user
:
{
username
:
'whatever'
}
}
}]
);
assert
.
isTrue
(
store
.
focusModeHasUser
());
});
it
(
'should return `false` if focus enabled but `user` object invalid'
,
()
=>
{
store
=
createStore
(
[
selection
],
[{
focus
:
{
user
:
{
displayName
:
'whatever'
}
}
}]
// `username` is required
);
assert
.
isFalse
(
store
.
focusModeHasUser
());
});
it
(
'should return `false` if `user` object missing'
,
()
=>
{
store
=
createStore
([
selection
],
[{
focus
:
{}
}]);
assert
.
isFalse
(
store
.
focusModeHasUser
());
});
});
describe
(
'focusModeUserPrettyName()'
,
function
()
{
describe
(
'focusModeUserPrettyName()'
,
function
()
{
it
(
'should return false by default when focus mode is not enabled'
,
function
()
{
it
(
'should return false by default when focus mode is not enabled'
,
function
()
{
store
=
createStore
(
store
=
createStore
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment