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
641e7953
Unverified
Commit
641e7953
authored
May 10, 2019
by
Hannah Stepanek
Committed by
GitHub
May 10, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1112 from hypothesis/add-direct-linked-group-to-store
Add direct linked group to store
parents
d86d2ba1
3ab1445d
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
118 additions
and
27 deletions
+118
-27
sidebar-content.js
src/sidebar/components/sidebar-content.js
+3
-6
sidebar-content-test.js
src/sidebar/components/test/sidebar-content-test.js
+4
-20
groups.js
src/sidebar/services/groups.js
+10
-1
groups-test.js
src/sidebar/services/test/groups-test.js
+16
-0
index.js
src/sidebar/store/index.js
+2
-0
direct-linked-group.js
src/sidebar/store/modules/direct-linked-group.js
+57
-0
direct-linked-group-test.js
src/sidebar/store/modules/test/direct-linked-group-test.js
+26
-0
No files found.
src/sidebar/components/sidebar-content.js
View file @
641e7953
...
@@ -49,8 +49,6 @@ function SidebarContentController(
...
@@ -49,8 +49,6 @@ function SidebarContentController(
streamFilter
streamFilter
)
{
)
{
const
self
=
this
;
const
self
=
this
;
this
.
directLinkedGroupFetchFailed
=
!!
settings
.
group
&&
settings
.
group
!==
store
.
focusedGroup
().
id
;
function
thread
()
{
function
thread
()
{
return
rootThread
.
thread
(
store
.
getState
());
return
rootThread
.
thread
(
store
.
getState
());
...
@@ -311,7 +309,7 @@ function SidebarContentController(
...
@@ -311,7 +309,7 @@ function SidebarContentController(
this
.
scrollTo
=
scrollToAnnotation
;
this
.
scrollTo
=
scrollToAnnotation
;
this
.
areAllAnnotationsVisible
=
function
()
{
this
.
areAllAnnotationsVisible
=
function
()
{
if
(
this
.
directLinkedGroupFetchFailed
)
{
if
(
store
.
getState
()
.
directLinkedGroupFetchFailed
)
{
return
true
;
return
true
;
}
}
const
selection
=
store
.
getState
().
selectedAnnotationMap
;
const
selection
=
store
.
getState
().
selectedAnnotationMap
;
...
@@ -322,7 +320,7 @@ function SidebarContentController(
...
@@ -322,7 +320,7 @@ function SidebarContentController(
};
};
this
.
selectedGroupUnavailable
=
function
()
{
this
.
selectedGroupUnavailable
=
function
()
{
return
!
this
.
isLoading
()
&&
this
.
directLinkedGroupFetchFailed
;
return
!
this
.
isLoading
()
&&
store
.
getState
()
.
directLinkedGroupFetchFailed
;
};
};
this
.
selectedAnnotationUnavailable
=
function
()
{
this
.
selectedAnnotationUnavailable
=
function
()
{
...
@@ -387,8 +385,7 @@ function SidebarContentController(
...
@@ -387,8 +385,7 @@ function SidebarContentController(
store
.
clearSelectedAnnotations
();
store
.
clearSelectedAnnotations
();
store
.
selectTab
(
selectedTab
);
store
.
selectTab
(
selectedTab
);
// Clear direct-linked group fetch failed state.
store
.
clearDirectLinkedGroupFetchFailed
();
this
.
directLinkedGroupFetchFailed
=
false
;
};
};
}
}
...
...
src/sidebar/components/test/sidebar-content-test.js
View file @
641e7953
...
@@ -213,11 +213,11 @@ describe('sidebar.components.sidebar-content', function() {
...
@@ -213,11 +213,11 @@ describe('sidebar.components.sidebar-content', function() {
});
});
it
(
'clears the directLinkedGroupFetchFailed state'
,
()
=>
{
it
(
'clears the directLinkedGroupFetchFailed state'
,
()
=>
{
ctrl
.
directLinkedGroupFetchFailed
=
true
;
store
.
setDirectLinkedGroupFetchFailed
()
;
ctrl
.
clearSelection
();
ctrl
.
clearSelection
();
assert
.
isFalse
(
ctrl
.
directLinkedGroupFetchFailed
);
assert
.
isFalse
(
store
.
getState
()
.
directLinkedGroupFetchFailed
);
});
});
});
});
...
@@ -234,12 +234,8 @@ describe('sidebar.components.sidebar-content', function() {
...
@@ -234,12 +234,8 @@ describe('sidebar.components.sidebar-content', function() {
it
(
'returns false if selected group is unavailable'
,
()
=>
{
it
(
'returns false if selected group is unavailable'
,
()
=>
{
fakeSettings
.
group
=
'group-id'
;
fakeSettings
.
group
=
'group-id'
;
store
.
loadGroups
([{
id
:
'default-id'
}]);
store
.
setDirectLinkedGroupFetchFailed
();
store
.
focusGroup
(
'default-id'
);
fakeGroups
.
focused
.
returns
({
id
:
'default-id'
});
$scope
.
$digest
();
$scope
.
$digest
();
// Re-construct the controller after the environment setup.
makeSidebarContentController
();
assert
.
isFalse
(
ctrl
.
showSelectedTabs
());
assert
.
isFalse
(
ctrl
.
showSelectedTabs
());
});
});
...
@@ -343,12 +339,8 @@ describe('sidebar.components.sidebar-content', function() {
...
@@ -343,12 +339,8 @@ describe('sidebar.components.sidebar-content', function() {
beforeEach
(()
=>
{
beforeEach
(()
=>
{
setFrames
([{
uri
:
'http://www.example.com'
}]);
setFrames
([{
uri
:
'http://www.example.com'
}]);
fakeSettings
.
group
=
'group-id'
;
fakeSettings
.
group
=
'group-id'
;
store
.
loadGroups
([{
id
:
'default-id'
}]);
store
.
setDirectLinkedGroupFetchFailed
();
store
.
focusGroup
(
'default-id'
);
fakeGroups
.
focused
.
returns
({
id
:
'default-id'
});
$scope
.
$digest
();
$scope
.
$digest
();
// Re-construct the controller after the environment setup.
makeSidebarContentController
();
});
});
[
null
,
'acct:person@example.com'
].
forEach
(
userid
=>
{
[
null
,
'acct:person@example.com'
].
forEach
(
userid
=>
{
...
@@ -364,10 +356,6 @@ describe('sidebar.components.sidebar-content', function() {
...
@@ -364,10 +356,6 @@ describe('sidebar.components.sidebar-content', function() {
});
});
});
});
it
(
'sets directLinkedGroupFetchFailed to true'
,
()
=>
{
assert
.
isTrue
(
ctrl
.
directLinkedGroupFetchFailed
);
});
it
(
'areAllAnnotationsVisible returns true since there is an error message'
,
()
=>
{
it
(
'areAllAnnotationsVisible returns true since there is an error message'
,
()
=>
{
assert
.
isTrue
(
ctrl
.
areAllAnnotationsVisible
());
assert
.
isTrue
(
ctrl
.
areAllAnnotationsVisible
());
});
});
...
@@ -387,10 +375,6 @@ describe('sidebar.components.sidebar-content', function() {
...
@@ -387,10 +375,6 @@ describe('sidebar.components.sidebar-content', function() {
$scope
.
$digest
();
$scope
.
$digest
();
});
});
it
(
'sets directLinkedGroupFetchFailed to false'
,
()
=>
{
assert
.
isFalse
(
ctrl
.
directLinkedGroupFetchFailed
);
});
it
(
'areAllAnnotationsVisible returns false since group has no annotations'
,
()
=>
{
it
(
'areAllAnnotationsVisible returns false since group has no annotations'
,
()
=>
{
assert
.
isFalse
(
ctrl
.
areAllAnnotationsVisible
());
assert
.
isFalse
(
ctrl
.
areAllAnnotationsVisible
());
});
});
...
...
src/sidebar/services/groups.js
View file @
641e7953
...
@@ -77,7 +77,8 @@ function groups(
...
@@ -77,7 +77,8 @@ function groups(
directLinkedGroup
.
scopes
.
enforced
directLinkedGroup
.
scopes
.
enforced
)
{
)
{
groups
=
groups
.
filter
(
g
=>
g
.
id
!==
directLinkedGroupId
);
groups
=
groups
.
filter
(
g
=>
g
.
id
!==
directLinkedGroupId
);
directLinkedGroupId
=
undefined
;
store
.
setDirectLinkedGroupFetchFailed
();
directLinkedGroupId
=
null
;
}
}
}
}
...
@@ -213,6 +214,14 @@ function groups(
...
@@ -213,6 +214,14 @@ function groups(
selectedGroupApi
=
fetchGroup
({
selectedGroupApi
=
fetchGroup
({
id
:
directLinkedGroupId
,
id
:
directLinkedGroupId
,
expand
:
params
.
expand
,
expand
:
params
.
expand
,
}).
then
(
group
=>
{
// If the group does not exist or the user doesn't have permission.
if
(
group
===
null
)
{
store
.
setDirectLinkedGroupFetchFailed
();
}
else
{
store
.
clearDirectLinkedGroupFetchFailed
();
}
return
group
;
});
});
}
}
groupApiRequests
=
groupApiRequests
.
concat
(
selectedGroupApi
);
groupApiRequests
=
groupApiRequests
.
concat
(
selectedGroupApi
);
...
...
src/sidebar/services/test/groups-test.js
View file @
641e7953
...
@@ -85,6 +85,8 @@ describe('groups', function() {
...
@@ -85,6 +85,8 @@ describe('groups', function() {
const
group
=
this
.
getState
().
focusedGroup
;
const
group
=
this
.
getState
().
focusedGroup
;
return
group
?
group
.
id
:
null
;
return
group
?
group
.
id
:
null
;
},
},
setDirectLinkedGroupFetchFailed
:
sinon
.
stub
(),
clearDirectLinkedGroupFetchFailed
:
sinon
.
stub
(),
}
}
);
);
fakeSession
=
sessionWithThreeGroups
();
fakeSession
=
sessionWithThreeGroups
();
...
@@ -191,6 +193,8 @@ describe('groups', function() {
...
@@ -191,6 +193,8 @@ describe('groups', function() {
fakeSettings
.
group
=
outOfScopeEnforcedGroup
.
id
;
fakeSettings
.
group
=
outOfScopeEnforcedGroup
.
id
;
fakeApi
.
group
.
read
.
returns
(
Promise
.
resolve
(
outOfScopeEnforcedGroup
));
fakeApi
.
group
.
read
.
returns
(
Promise
.
resolve
(
outOfScopeEnforcedGroup
));
return
svc
.
load
().
then
(
groups
=>
{
return
svc
.
load
().
then
(
groups
=>
{
// The failure state is captured in the store.
assert
.
called
(
fakeStore
.
setDirectLinkedGroupFetchFailed
);
// The focus group is not set to the direct-linked group.
// The focus group is not set to the direct-linked group.
assert
.
calledWith
(
fakeStore
.
focusGroup
,
dummyGroups
[
0
].
id
);
assert
.
calledWith
(
fakeStore
.
focusGroup
,
dummyGroups
[
0
].
id
);
// The direct-linked group is not in the list of groups.
// The direct-linked group is not in the list of groups.
...
@@ -211,6 +215,8 @@ describe('groups', function() {
...
@@ -211,6 +215,8 @@ describe('groups', function() {
)
)
);
);
return
svc
.
load
().
then
(()
=>
{
return
svc
.
load
().
then
(()
=>
{
// The failure state is captured in the store.
assert
.
called
(
fakeStore
.
setDirectLinkedGroupFetchFailed
);
// The focus group is not set to the direct-linked group.
// The focus group is not set to the direct-linked group.
assert
.
calledWith
(
fakeStore
.
focusGroup
,
dummyGroups
[
0
].
id
);
assert
.
calledWith
(
fakeStore
.
focusGroup
,
dummyGroups
[
0
].
id
);
});
});
...
@@ -381,6 +387,16 @@ describe('groups', function() {
...
@@ -381,6 +387,16 @@ describe('groups', function() {
});
});
});
});
it
(
'clears the directLinkedGroupFetchFailed state if loading a direct-linked group'
,
()
=>
{
const
svc
=
service
();
fakeSettings
.
group
=
dummyGroups
[
1
].
id
;
fakeApi
.
groups
.
list
.
returns
(
Promise
.
resolve
(
dummyGroups
));
return
svc
.
load
().
then
(()
=>
{
assert
.
called
(
fakeStore
.
clearDirectLinkedGroupFetchFailed
);
assert
.
notCalled
(
fakeStore
.
setDirectLinkedGroupFetchFailed
);
});
});
[
null
,
'some-group-id'
].
forEach
(
groupId
=>
{
[
null
,
'some-group-id'
].
forEach
(
groupId
=>
{
it
(
'does not set the focused group if not present in the groups list'
,
()
=>
{
it
(
'does not set the focused group if not present in the groups list'
,
()
=>
{
const
svc
=
service
();
const
svc
=
service
();
...
...
src/sidebar/store/index.js
View file @
641e7953
...
@@ -36,6 +36,7 @@ const debugMiddleware = require('./debug-middleware');
...
@@ -36,6 +36,7 @@ const debugMiddleware = require('./debug-middleware');
const
activity
=
require
(
'./modules/activity'
);
const
activity
=
require
(
'./modules/activity'
);
const
annotations
=
require
(
'./modules/annotations'
);
const
annotations
=
require
(
'./modules/annotations'
);
const
directLinkedGroup
=
require
(
'./modules/direct-linked-group'
);
const
frames
=
require
(
'./modules/frames'
);
const
frames
=
require
(
'./modules/frames'
);
const
links
=
require
(
'./modules/links'
);
const
links
=
require
(
'./modules/links'
);
const
groups
=
require
(
'./modules/groups'
);
const
groups
=
require
(
'./modules/groups'
);
...
@@ -86,6 +87,7 @@ function store($rootScope, settings) {
...
@@ -86,6 +87,7 @@ function store($rootScope, settings) {
const
modules
=
[
const
modules
=
[
activity
,
activity
,
annotations
,
annotations
,
directLinkedGroup
,
frames
,
frames
,
links
,
links
,
groups
,
groups
,
...
...
src/sidebar/store/modules/direct-linked-group.js
0 → 100644
View file @
641e7953
'use strict'
;
const
util
=
require
(
'../util'
);
function
init
()
{
return
{
/**
* Indicates that an error occured in retrieving/showing the direct linked group.
* This could be because:
* - the group does not exist
* - the user does not have permission
* - the group is out of scope for the given page
* @type {boolean}
*/
directLinkedGroupFetchFailed
:
false
,
};
}
const
update
=
{
UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED
(
state
,
action
)
{
return
{
directLinkedGroupFetchFailed
:
action
.
directLinkedGroupFetchFailed
,
};
},
};
const
actions
=
util
.
actionTypes
(
update
);
/**
* Set the direct linked group fetch failure to true.
*/
function
setDirectLinkedGroupFetchFailed
()
{
return
{
type
:
actions
.
UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED
,
directLinkedGroupFetchFailed
:
true
,
};
}
/**
* Clear the direct linked group fetch failure.
*/
function
clearDirectLinkedGroupFetchFailed
()
{
return
{
type
:
actions
.
UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED
,
directLinkedGroupFetchFailed
:
false
,
};
}
module
.
exports
=
{
init
,
update
,
actions
:
{
setDirectLinkedGroupFetchFailed
,
clearDirectLinkedGroupFetchFailed
,
},
selectors
:
{},
};
src/sidebar/store/modules/test/direct-linked-group-test.js
0 → 100644
View file @
641e7953
'use strict'
;
const
createStore
=
require
(
'../../create-store'
);
const
directLinkedGroup
=
require
(
'../direct-linked-group'
);
describe
(
'sidebar/store/modules/direct-linked-group'
,
()
=>
{
let
store
;
beforeEach
(()
=>
{
store
=
createStore
([
directLinkedGroup
]);
});
it
(
'sets directLinkedGroupFetchFailed to true'
,
()
=>
{
store
.
setDirectLinkedGroupFetchFailed
();
assert
.
isTrue
(
store
.
getState
().
directLinkedGroupFetchFailed
);
});
it
(
'sets directLinkedGroupFetchFailed to false'
,
()
=>
{
store
.
setDirectLinkedGroupFetchFailed
();
store
.
clearDirectLinkedGroupFetchFailed
();
assert
.
isFalse
(
store
.
getState
().
directLinkedGroupFetchFailed
);
});
});
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