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
b470e9f2
Unverified
Commit
b470e9f2
authored
Aug 10, 2018
by
Robert Knight
Committed by
GitHub
Aug 10, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #756 from hypothesis/fix-group-refetch-triggers
Remove unnecessary extra `/api/groups` call on startup
parents
2a618966
43ddf16d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
23 deletions
+40
-23
events.js
src/sidebar/events.js
+0
-2
groups.js
src/sidebar/services/groups.js
+7
-10
groups-test.js
src/sidebar/services/test/groups-test.js
+33
-11
No files found.
src/sidebar/events.js
View file @
b470e9f2
...
@@ -11,8 +11,6 @@ module.exports = {
...
@@ -11,8 +11,6 @@ module.exports = {
// Session state changes
// Session state changes
/** The list of groups changed */
GROUPS_CHANGED
:
'groupsChanged'
,
/** The logged-in user changed */
/** The logged-in user changed */
USER_CHANGED
:
'userChanged'
,
USER_CHANGED
:
'userChanged'
,
/**
/**
...
...
src/sidebar/services/groups.js
View file @
b470e9f2
...
@@ -20,8 +20,6 @@ var serviceConfig = require('../service-config');
...
@@ -20,8 +20,6 @@ var serviceConfig = require('../service-config');
// @ngInject
// @ngInject
function
groups
(
$rootScope
,
store
,
api
,
isSidebar
,
localStorage
,
serviceUrl
,
session
,
function
groups
(
$rootScope
,
store
,
api
,
isSidebar
,
localStorage
,
serviceUrl
,
session
,
settings
)
{
settings
)
{
var
documentUri
;
var
svc
=
serviceConfig
(
settings
);
var
svc
=
serviceConfig
(
settings
);
var
authority
=
svc
?
svc
.
authority
:
null
;
var
authority
=
svc
?
svc
.
authority
:
null
;
...
@@ -40,6 +38,12 @@ function groups($rootScope, store, api, isSidebar, localStorage, serviceUrl, ses
...
@@ -40,6 +38,12 @@ function groups($rootScope, store, api, isSidebar, localStorage, serviceUrl, ses
return
awaitStateChange
(
store
,
mainUri
);
return
awaitStateChange
(
store
,
mainUri
);
}
}
// The document URI passed to the most recent `GET /api/groups` call in order
// to include groups associated with this page. This is retained to determine
// whether we need to re-fetch groups if the URLs of frames connected to the
// sidebar app changes.
var
documentUri
;
/**
/**
* Fetch the list of applicable groups from the API.
* Fetch the list of applicable groups from the API.
*
*
...
@@ -61,6 +65,7 @@ function groups($rootScope, store, api, isSidebar, localStorage, serviceUrl, ses
...
@@ -61,6 +65,7 @@ function groups($rootScope, store, api, isSidebar, localStorage, serviceUrl, ses
if
(
uri
)
{
if
(
uri
)
{
params
.
document_uri
=
uri
;
params
.
document_uri
=
uri
;
}
}
documentUri
=
uri
;
return
api
.
groups
.
list
(
params
);
return
api
.
groups
.
list
(
params
);
}).
then
(
groups
=>
{
}).
then
(
groups
=>
{
var
isFirstLoad
=
store
.
allGroups
().
length
===
0
;
var
isFirstLoad
=
store
.
allGroups
().
length
===
0
;
...
@@ -126,12 +131,6 @@ function groups($rootScope, store, api, isSidebar, localStorage, serviceUrl, ses
...
@@ -126,12 +131,6 @@ function groups($rootScope, store, api, isSidebar, localStorage, serviceUrl, ses
}
}
});
});
// reset the focused group if the user leaves it
$rootScope
.
$on
(
events
.
GROUPS_CHANGED
,
function
()
{
// return for use in test
return
load
();
});
// refetch the list of groups when user changes
// refetch the list of groups when user changes
$rootScope
.
$on
(
events
.
USER_CHANGED
,
()
=>
{
$rootScope
.
$on
(
events
.
USER_CHANGED
,
()
=>
{
// FIXME Makes a second api call on page load. better way?
// FIXME Makes a second api call on page load. better way?
...
@@ -141,8 +140,6 @@ function groups($rootScope, store, api, isSidebar, localStorage, serviceUrl, ses
...
@@ -141,8 +140,6 @@ function groups($rootScope, store, api, isSidebar, localStorage, serviceUrl, ses
// refetch the list of groups when document url changes
// refetch the list of groups when document url changes
$rootScope
.
$on
(
events
.
FRAME_CONNECTED
,
()
=>
{
$rootScope
.
$on
(
events
.
FRAME_CONNECTED
,
()
=>
{
// FIXME Makes a third api call on page load. better way?
// return for use in test
return
getDocumentUriForGroupSearch
().
then
(
uri
=>
{
return
getDocumentUriForGroupSearch
().
then
(
uri
=>
{
if
(
documentUri
!==
uri
)
{
if
(
documentUri
!==
uri
)
{
documentUri
=
uri
;
documentUri
=
uri
;
...
...
src/sidebar/services/test/groups-test.js
View file @
b470e9f2
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
var
events
=
require
(
'../../events'
);
var
events
=
require
(
'../../events'
);
var
fakeReduxStore
=
require
(
'../../test/fake-redux-store'
);
var
fakeReduxStore
=
require
(
'../../test/fake-redux-store'
);
var
groups
=
require
(
'../groups'
);
var
groups
=
require
(
'../groups'
);
var
unroll
=
require
(
'../../../shared/test/util'
).
unroll
;
// Return a mock session service containing three groups.
// Return a mock session service containing three groups.
var
sessionWithThreeGroups
=
function
()
{
var
sessionWithThreeGroups
=
function
()
{
...
@@ -68,7 +67,7 @@ describe('groups', function() {
...
@@ -68,7 +67,7 @@ describe('groups', function() {
},
},
$on
:
function
(
event
,
callback
)
{
$on
:
function
(
event
,
callback
)
{
if
(
event
===
events
.
GROUPS_CHANGED
||
event
===
events
.
USER_CHANGED
||
event
===
events
.
FRAME_CONNECTED
)
{
if
(
event
===
events
.
USER_CHANGED
||
event
===
events
.
FRAME_CONNECTED
)
{
this
.
eventCallbacks
[
event
]
=
callback
;
this
.
eventCallbacks
[
event
]
=
callback
;
}
}
},
},
...
@@ -250,18 +249,41 @@ describe('groups', function() {
...
@@ -250,18 +249,41 @@ describe('groups', function() {
});
});
describe
(
'calls load on various events'
,
function
()
{
describe
(
'calls load on various events'
,
function
()
{
var
changeEvents
=
[
it
(
'refetches groups when the logged-in user changes'
,
()
=>
{
{
event
:
events
.
GROUPS_CHANGED
},
{
event
:
events
.
USER_CHANGED
},
{
event
:
events
.
FRAME_CONNECTED
},
];
unroll
(
'should fetch the list of groups from the server when #event occurs'
,
function
(
testCase
)
{
service
();
service
();
return
fakeRootScope
.
eventCallbacks
[
testCase
.
event
]().
then
(()
=>
{
return
fakeRootScope
.
eventCallbacks
[
events
.
USER_CHANGED
]().
then
(()
=>
{
assert
.
calledOnce
(
fakeApi
.
groups
.
list
);
});
});
context
(
'when a new frame connects'
,
()
=>
{
it
(
'should refetch groups if main frame URL has changed'
,
()
=>
{
var
svc
=
service
();
fakeStore
.
setState
({
searchUris
:
[
'https://domain.com/page-a'
]
});
return
svc
.
load
().
then
(()
=>
{
// Simulate main frame URL change, eg. due to client-side navigation in
// a single page application.
fakeApi
.
groups
.
list
.
resetHistory
();
fakeStore
.
setState
({
searchUris
:
[
'https://domain.com/page-b'
]});
return
fakeRootScope
.
eventCallbacks
[
events
.
FRAME_CONNECTED
]();
}).
then
(()
=>
{
assert
.
calledOnce
(
fakeApi
.
groups
.
list
);
assert
.
calledOnce
(
fakeApi
.
groups
.
list
);
});
});
},
changeEvents
);
});
it
(
'should not refetch groups if main frame URL has not changed'
,
()
=>
{
var
svc
=
service
();
fakeStore
.
setState
({
searchUris
:
[
'https://domain.com/page-a'
]
});
return
svc
.
load
().
then
(()
=>
{
return
fakeRootScope
.
eventCallbacks
[
events
.
FRAME_CONNECTED
]();
}).
then
(()
=>
{
assert
.
calledOnce
(
fakeApi
.
groups
.
list
);
});
});
});
});
});
});
});
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