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
f05b1b05
Commit
f05b1b05
authored
May 14, 2019
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use async/await to simplify the first part of the load() method
parent
06209ef5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
61 deletions
+58
-61
groups.js
src/sidebar/services/groups.js
+58
-61
No files found.
src/sidebar/services/groups.js
View file @
f05b1b05
...
...
@@ -163,10 +163,12 @@ function groups(
*
* @return {Promise<Group[]>}
*/
function
load
()
{
let
uri
=
Promise
.
resolve
(
null
);
async
function
load
()
{
// Step 1: Get the URI of the active document, so we can fetch groups
// associated with that document.
let
uri
=
null
;
if
(
isSidebar
)
{
uri
=
getDocumentUriForGroupSearch
();
uri
=
await
getDocumentUriForGroupSearch
();
}
const
directLinkedGroupId
=
store
.
getState
().
directLinkedGroupId
;
const
directLinkedAnnId
=
store
.
getState
().
directLinkedAnnotationId
;
...
...
@@ -176,67 +178,62 @@ function groups(
let
directLinkedAnnotationGroupId
=
null
;
// Step 1: Get the URI of the active document, so we can fetch groups
// associated with that document.
return
uri
.
then
(
uri
=>
{
// Step 2: Concurrently fetch the groups the user is a member of,
// the groups associated with the current document and the annotation
// or group that was direct-linked (if any).
if
(
authority
)
{
params
.
authority
=
authority
;
}
if
(
uri
)
{
params
.
document_uri
=
uri
;
}
documentUri
=
uri
;
// Step 2: Concurrently fetch the groups the user is a member of,
// the groups associated with the current document and the annotation
// or group that was direct-linked (if any).
if
(
authority
)
{
params
.
authority
=
authority
;
}
if
(
uri
)
{
params
.
document_uri
=
uri
;
}
documentUri
=
uri
;
const
profileGroupsApi
=
api
.
profile
.
groups
.
read
({
expand
:
params
.
expand
,
const
profileGroupsApi
=
api
.
profile
.
groups
.
read
({
expand
:
params
.
expand
,
});
const
listGroupsApi
=
api
.
groups
.
list
(
params
);
let
groupApiRequests
=
[
profileGroupsApi
,
listGroupsApi
,
auth
.
tokenGetter
(),
];
// If there is a direct-linked annotation, fetch the annotation to see
// if there needs to be a second API request to fetch its group since
// the group may not be in the results returned by group.list,
// profile.groups, or the direct-linked group.
let
directLinkedAnnApi
=
Promise
.
resolve
(
null
);
if
(
directLinkedAnnId
)
{
directLinkedAnnApi
=
api
.
annotation
.
get
({
id
:
directLinkedAnnId
})
.
catch
(()
=>
{
// If the annotation does not exist or the user doesn't have permission.
return
null
;
});
const
listGroupsApi
=
api
.
groups
.
list
(
params
);
let
groupApiRequests
=
[
profileGroupsApi
,
listGroupsApi
,
auth
.
tokenGetter
(),
];
// If there is a direct-linked annotation, fetch the annotation to see
// if there needs to be a second API request to fetch its group since
// the group may not be in the results returned by group.list,
// profile.groups, or the direct-linked group.
let
directLinkedAnnApi
=
Promise
.
resolve
(
null
);
if
(
directLinkedAnnId
)
{
directLinkedAnnApi
=
api
.
annotation
.
get
({
id
:
directLinkedAnnId
})
.
catch
(()
=>
{
// If the annotation does not exist or the user doesn't have permission.
return
null
;
});
}
groupApiRequests
=
groupApiRequests
.
concat
(
directLinkedAnnApi
);
// If there is a direct-linked group, add an API request to get that
// particular group since it may not be in the results returned by
// group.list or profile.groups.
let
directLinkedGroupApi
=
Promise
.
resolve
(
null
);
if
(
directLinkedGroupId
)
{
directLinkedGroupApi
=
fetchGroup
({
id
:
directLinkedGroupId
,
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
(
directLinkedAnnApi
);
// If there is a direct-linked group, add an API request to get that
// particular group since it may not be in the results returned by
// group.list or profile.groups.
let
directLinkedGroupApi
=
Promise
.
resolve
(
null
);
if
(
directLinkedGroupId
)
{
directLinkedGroupApi
=
fetchGroup
({
id
:
directLinkedGroupId
,
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
();
}
groupApiRequests
=
groupApiRequests
.
concat
(
directLinkedGroupApi
);
return
Promise
.
all
(
groupApiRequests
);
})
return
group
;
});
}
groupApiRequests
=
groupApiRequests
.
concat
(
directLinkedGroupApi
);
return
Promise
.
all
(
groupApiRequests
)
.
then
(
([
myGroups
,
...
...
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