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
346a8b22
Unverified
Commit
346a8b22
authored
Nov 21, 2019
by
Kyle Keating
Committed by
GitHub
Nov 21, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1496 from hypothesis/rename-username-to-userid
Rename the username to userid in selection module
parents
bde588a9
366cdc04
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
69 additions
and
46 deletions
+69
-46
config.rst
docs/publishers/config.rst
+0
-2
root-thread.js
src/sidebar/services/root-thread.js
+1
-1
root-thread-test.js
src/sidebar/services/test/root-thread-test.js
+1
-1
selection.js
src/sidebar/store/modules/selection.js
+32
-25
selection-test.js
src/sidebar/store/modules/test/selection-test.js
+35
-17
No files found.
docs/publishers/config.rst
View file @
346a8b22
...
...
@@ -408,10 +408,8 @@ loads.
user: {
// required
username: "foobar1234",
// optional
displayName: "Foo Bar",
authority: "example.com",
}
}
};
...
...
src/sidebar/services/root-thread.js
View file @
346a8b22
...
...
@@ -58,7 +58,7 @@ function RootThread($rootScope, store, searchFilter, viewFilter) {
state
.
selection
.
filterQuery
,
{
// if a focus mode is applied (focused) and we're focusing on a user
user
:
store
.
focusModeFocused
()
&&
store
.
focusModeUser
name
(),
user
:
store
.
focusModeFocused
()
&&
store
.
focusModeUser
Id
(),
}
);
...
...
src/sidebar/services/test/root-thread-test.js
View file @
346a8b22
...
...
@@ -67,7 +67,7 @@ describe('rootThread', function() {
removeDraft
:
sinon
.
stub
(),
createAnnotation
:
sinon
.
stub
(),
focusModeFocused
:
sinon
.
stub
().
returns
(
false
),
focusModeUser
name
:
sinon
.
stub
().
returns
({}),
focusModeUser
Id
:
sinon
.
stub
().
returns
({}),
};
fakeBuildThread
=
sinon
.
stub
().
returns
(
fixtures
.
emptyThread
);
...
...
src/sidebar/store/modules/selection.js
View file @
346a8b22
...
...
@@ -10,7 +10,7 @@
/**
* @typedef User
* @property {string} user
name - Unique user's username
* @property {string} user
id - Unique user's id
* @property {string} displayName - User's display name
*/
...
...
@@ -441,16 +441,20 @@ function focusModeFocused(state) {
}
/**
* Returns the
username
for a focused user or `null` if no focused user.
* Returns the
`userid`
for a focused user or `null` if no focused user.
*
* @return {
object
|null}
* @return {
string
|null}
*/
function
focusModeUsername
(
state
)
{
if
(
state
.
selection
.
focusMode
.
config
.
user
&&
state
.
selection
.
focusMode
.
config
.
user
.
username
)
{
return
state
.
selection
.
focusMode
.
config
.
user
.
username
;
function
focusModeUserId
(
state
)
{
if
(
state
.
selection
.
focusMode
.
config
.
user
)
{
if
(
state
.
selection
.
focusMode
.
config
.
user
.
userid
)
{
return
state
.
selection
.
focusMode
.
config
.
user
.
userid
;
}
if
(
state
.
selection
.
focusMode
.
config
.
user
.
username
)
{
// remove once LMS no longer sends username in RPC or config
// https://github.com/hypothesis/client/issues/1516
return
state
.
selection
.
focusMode
.
config
.
user
.
username
;
}
}
return
null
;
}
...
...
@@ -462,11 +466,11 @@ function focusModeUsername(state) {
* @return {boolean}
*/
function
focusModeHasUser
(
state
)
{
return
focusModeEnabled
(
state
)
&&
!!
focusModeUser
name
(
state
);
return
focusModeEnabled
(
state
)
&&
!!
focusModeUser
Id
(
state
);
}
/**
* Returns the display name for a user or the user
name
* Returns the display name for a user or the user
id
* if display name is not present. If both are missing
* then this returns an empty string.
*
...
...
@@ -478,7 +482,10 @@ function focusModeUserPrettyName(state) {
return
''
;
}
else
if
(
user
.
displayName
)
{
return
user
.
displayName
;
}
else
if
(
user
.
userid
)
{
return
user
.
userid
;
}
else
if
(
user
.
username
)
{
// remove once LMS no longer sends `username` in RPC
return
user
.
username
;
}
else
{
return
''
;
...
...
@@ -491,19 +498,19 @@ module.exports = {
update
:
update
,
actions
:
{
clearSelectedAnnotations
:
clearSelectedAnnotations
,
clearSelection
:
clearSelection
,
focusAnnotations
:
focusAnnotations
,
highlightAnnotations
:
highlightAnnotations
,
selectAnnotations
:
selectAnnotations
,
selectTab
:
selectTab
,
setCollapsed
:
setCollapsed
,
setFilterQuery
:
setFilterQuery
,
setFocusModeFocused
:
setFocusModeFocused
,
changeFocusModeUser
:
changeFocusModeUser
,
setForceVisible
:
setForceVisible
,
setSortKey
:
setSortKey
,
toggleSelectedAnnotations
:
toggleSelectedAnnotations
,
clearSelectedAnnotations
,
clearSelection
,
focusAnnotations
,
highlightAnnotations
,
selectAnnotations
,
selectTab
,
setCollapsed
,
setFilterQuery
,
setFocusModeFocused
,
changeFocusModeUser
,
setForceVisible
,
setSortKey
,
toggleSelectedAnnotations
,
},
selectors
:
{
...
...
@@ -512,7 +519,7 @@ module.exports = {
focusModeFocused
,
focusModeEnabled
,
focusModeHasUser
,
focusModeUser
name
,
focusModeUser
Id
,
focusModeUserPrettyName
,
isAnnotationSelected
,
getFirstSelectedAnnotationId
,
...
...
src/sidebar/store/modules/test/selection-test.js
View file @
346a8b22
...
...
@@ -205,10 +205,10 @@ describe('sidebar/store/modules/selection', () => {
it
(
'sets the focused user and enables focus mode'
,
function
()
{
store
.
setFocusModeFocused
(
false
);
store
.
changeFocusModeUser
({
user
name
:
'testuser'
,
user
id
:
'testuser'
,
displayName
:
'Test User'
,
});
assert
.
equal
(
store
.
focusModeUser
name
(),
'testuser'
);
assert
.
equal
(
store
.
focusModeUser
Id
(),
'testuser'
);
assert
.
equal
(
store
.
focusModeUserPrettyName
(),
'Test User'
);
assert
.
equal
(
store
.
focusModeFocused
(),
true
);
assert
.
equal
(
store
.
focusModeEnabled
(),
true
);
...
...
@@ -256,14 +256,14 @@ describe('sidebar/store/modules/selection', () => {
it
(
'should return `true` if focus enabled and valid `user` object present'
,
()
=>
{
store
=
createStore
(
[
selection
],
[{
focus
:
{
user
:
{
user
name
:
'whatever
'
}
}
}]
[{
focus
:
{
user
:
{
user
id
:
'acct:userid@authority
'
}
}
}]
);
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
[{
focus
:
{
user
:
{
displayName
:
'
FakeDisplayName'
}
}
}]
// `userid
` is required
);
assert
.
isFalse
(
store
.
focusModeHasUser
());
});
...
...
@@ -274,43 +274,61 @@ describe('sidebar/store/modules/selection', () => {
});
describe
(
'focusModeUserPrettyName()'
,
function
()
{
it
(
'
should return
false by default when focus mode is not enabled'
,
function
()
{
it
(
'
returns
false by default when focus mode is not enabled'
,
function
()
{
store
=
createStore
(
[
selection
],
[{
focus
:
{
user
:
{
displayName
:
'FakeDisplayName'
}
}
}]
);
assert
.
equal
(
store
.
focusModeUserPrettyName
(),
'FakeDisplayName'
);
});
it
(
'
should the username
when displayName is missing'
,
function
()
{
it
(
'
returns the userid
when displayName is missing'
,
function
()
{
store
=
createStore
(
[
selection
],
[{
focus
:
{
user
:
{
user
name
:
'FakeUserName
'
}
}
}]
[{
focus
:
{
user
:
{
user
id
:
'acct:userid@authority
'
}
}
}]
);
assert
.
equal
(
store
.
focusModeUserPrettyName
(),
'
FakeUserName
'
);
assert
.
equal
(
store
.
focusModeUserPrettyName
(),
'
acct:userid@authority
'
);
});
it
(
'
should an return empty string when user object has no names
'
,
function
()
{
it
(
'
returns an empty string when user object has is empty
'
,
function
()
{
store
=
createStore
([
selection
],
[{
focus
:
{
user
:
{}
}
}]);
assert
.
equal
(
store
.
focusModeUserPrettyName
(),
''
);
});
it
(
'
should an retur
n empty string when there is no focus object'
,
function
()
{
it
(
'
return a
n empty string when there is no focus object'
,
function
()
{
assert
.
equal
(
store
.
focusModeUserPrettyName
(),
''
);
});
it
(
'returns the username when displayName and userid is missing'
,
function
()
{
// remove once LMS no longer sends username in RPC or config
// https://github.com/hypothesis/client/issues/1516
store
=
createStore
(
[
selection
],
[{
focus
:
{
user
:
{
username
:
'fake_user_name'
}
}
}]
);
assert
.
equal
(
store
.
focusModeUserPrettyName
(),
'fake_user_name'
);
});
});
describe
(
'focusModeUser
name
()'
,
function
()
{
it
(
'should return the user
name
when present'
,
function
()
{
describe
(
'focusModeUser
Id
()'
,
function
()
{
it
(
'should return the user
id
when present'
,
function
()
{
store
=
createStore
(
[
selection
],
[{
focus
:
{
user
:
{
user
name
:
'FakeUserName
'
}
}
}]
[{
focus
:
{
user
:
{
user
id
:
'acct:userid@authority
'
}
}
}]
);
assert
.
equal
(
store
.
focusModeUser
name
(),
'FakeUserName
'
);
assert
.
equal
(
store
.
focusModeUser
Id
(),
'acct:userid@authority
'
);
});
it
(
'should return null when the user
name
is not present'
,
function
()
{
it
(
'should return null when the user
id
is not present'
,
function
()
{
store
=
createStore
([
selection
],
[{
focus
:
{
user
:
{}
}
}]);
assert
.
isNull
(
store
.
focusModeUser
name
());
assert
.
isNull
(
store
.
focusModeUser
Id
());
});
it
(
'should return null when the user object is not present'
,
function
()
{
assert
.
isNull
(
store
.
focusModeUsername
());
assert
.
isNull
(
store
.
focusModeUserId
());
});
it
(
'should return the username when present but no userid'
,
function
()
{
// remove once LMS no longer sends username in RPC or config
// https://github.com/hypothesis/client/issues/1516
store
=
createStore
(
[
selection
],
[{
focus
:
{
user
:
{
username
:
'fake_user_name'
}
}
}]
);
assert
.
equal
(
store
.
focusModeUserId
(),
'fake_user_name'
);
});
});
...
...
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