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(
...
@@ -163,10 +163,12 @@ function groups(
*
*
* @return {Promise<Group[]>}
* @return {Promise<Group[]>}
*/
*/
function
load
()
{
async
function
load
()
{
let
uri
=
Promise
.
resolve
(
null
);
// Step 1: Get the URI of the active document, so we can fetch groups
// associated with that document.
let
uri
=
null
;
if
(
isSidebar
)
{
if
(
isSidebar
)
{
uri
=
getDocumentUriForGroupSearch
();
uri
=
await
getDocumentUriForGroupSearch
();
}
}
const
directLinkedGroupId
=
store
.
getState
().
directLinkedGroupId
;
const
directLinkedGroupId
=
store
.
getState
().
directLinkedGroupId
;
const
directLinkedAnnId
=
store
.
getState
().
directLinkedAnnotationId
;
const
directLinkedAnnId
=
store
.
getState
().
directLinkedAnnotationId
;
...
@@ -176,67 +178,62 @@ function groups(
...
@@ -176,67 +178,62 @@ function groups(
let
directLinkedAnnotationGroupId
=
null
;
let
directLinkedAnnotationGroupId
=
null
;
// Step 1: Get the URI of the active document, so we can fetch groups
// Step 2: Concurrently fetch the groups the user is a member of,
// associated with that document.
// the groups associated with the current document and the annotation
return
uri
// or group that was direct-linked (if any).
.
then
(
uri
=>
{
if
(
authority
)
{
// Step 2: Concurrently fetch the groups the user is a member of,
params
.
authority
=
authority
;
// the groups associated with the current document and the annotation
}
// or group that was direct-linked (if any).
if
(
uri
)
{
if
(
authority
)
{
params
.
document_uri
=
uri
;
params
.
authority
=
authority
;
}
}
documentUri
=
uri
;
if
(
uri
)
{
params
.
document_uri
=
uri
;
}
documentUri
=
uri
;
const
profileGroupsApi
=
api
.
profile
.
groups
.
read
({
const
profileGroupsApi
=
api
.
profile
.
groups
.
read
({
expand
:
params
.
expand
,
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
=
[
groupApiRequests
=
groupApiRequests
.
concat
(
directLinkedAnnApi
);
profileGroupsApi
,
listGroupsApi
,
// If there is a direct-linked group, add an API request to get that
auth
.
tokenGetter
(),
// particular group since it may not be in the results returned by
];
// group.list or profile.groups.
let
directLinkedGroupApi
=
Promise
.
resolve
(
null
);
// If there is a direct-linked annotation, fetch the annotation to see
if
(
directLinkedGroupId
)
{
// if there needs to be a second API request to fetch its group since
directLinkedGroupApi
=
fetchGroup
({
// the group may not be in the results returned by group.list,
id
:
directLinkedGroupId
,
// profile.groups, or the direct-linked group.
expand
:
params
.
expand
,
let
directLinkedAnnApi
=
Promise
.
resolve
(
null
);
}).
then
(
group
=>
{
if
(
directLinkedAnnId
)
{
// If the group does not exist or the user doesn't have permission.
directLinkedAnnApi
=
api
.
annotation
if
(
group
===
null
)
{
.
get
({
id
:
directLinkedAnnId
})
store
.
setDirectLinkedGroupFetchFailed
();
.
catch
(()
=>
{
}
else
{
// If the annotation does not exist or the user doesn't have permission.
store
.
clearDirectLinkedGroupFetchFailed
();
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
(
directLinkedGroupApi
);
return
group
;
return
Promise
.
all
(
groupApiRequests
);
});
})
}
groupApiRequests
=
groupApiRequests
.
concat
(
directLinkedGroupApi
);
return
Promise
.
all
(
groupApiRequests
)
.
then
(
.
then
(
([
([
myGroups
,
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