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
a2da80d6
Commit
a2da80d6
authored
May 13, 2019
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Promise chaining to remove a layer of nesting in `groups#load`
parent
3d09d3f6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
49 deletions
+49
-49
groups.js
src/sidebar/services/groups.js
+49
-49
No files found.
src/sidebar/services/groups.js
View file @
a2da80d6
...
...
@@ -168,12 +168,13 @@ function groups(
}
const
directLinkedGroupId
=
store
.
getState
().
directLinkedGroupId
;
const
directLinkedAnnId
=
store
.
getState
().
directLinkedAnnotationId
;
const
params
=
{
expand
:
[
'organization'
,
'scopes'
],
};
let
directLinkedAnnotationGroupId
=
null
;
return
uri
.
then
(
uri
=>
{
const
params
=
{
expand
:
[
'organization'
,
'scopes'
],
};
if
(
authority
)
{
params
.
authority
=
authority
;
}
...
...
@@ -225,54 +226,53 @@ function groups(
});
}
groupApiRequests
=
groupApiRequests
.
concat
(
selectedGroupApi
);
return
Promise
.
all
(
groupApiRequests
).
then
(
([
myGroups
,
featuredGroups
,
token
,
selectedAnn
,
selectedGroup
])
=>
{
// If there is a direct-linked group, add it to the featured groups list.
const
allFeaturedGroups
=
selectedGroup
!==
null
&&
!
featuredGroups
.
some
(
g
=>
g
.
id
===
selectedGroup
.
id
)
?
featuredGroups
.
concat
([
selectedGroup
])
:
featuredGroups
;
// If there's a selected annotation it may require an extra api call
// to fetch its group.
if
(
selectedAnn
)
{
// Set the directLinkedAnnotationGroupId to be used later in
// the filterGroups method.
directLinkedAnnotationGroupId
=
selectedAnn
.
group
;
const
selectedAnnGroup
=
myGroups
.
concat
(
allFeaturedGroups
)
.
some
(
g
=>
g
.
id
===
selectedAnn
.
group
);
// If the direct-linked annotation's group has not already been fetched,
// fetch it.
if
(
!
selectedAnnGroup
)
{
return
fetchGroup
({
id
:
selectedAnn
.
group
,
expand
:
params
.
expand
,
}).
then
(
directLinkedAnnGroup
=>
{
// If the directLinkedAnnotation's group fetch failed, return
// the list of groups without it.
if
(
!
directLinkedAnnGroup
)
{
return
[
myGroups
,
allFeaturedGroups
,
documentUri
,
token
];
}
// If the directLinkedAnnotation's group fetch was successful,
// combine it with the other groups.
return
[
myGroups
,
allFeaturedGroups
.
concat
(
directLinkedAnnGroup
),
documentUri
,
token
,
];
});
return
Promise
.
all
(
groupApiRequests
);
})
.
then
(([
myGroups
,
featuredGroups
,
token
,
selectedAnn
,
selectedGroup
])
=>
{
// If there is a direct-linked group, add it to the featured groups list.
const
allFeaturedGroups
=
selectedGroup
!==
null
&&
!
featuredGroups
.
some
(
g
=>
g
.
id
===
selectedGroup
.
id
)
?
featuredGroups
.
concat
([
selectedGroup
])
:
featuredGroups
;
// If there's a selected annotation it may require an extra api call
// to fetch its group.
if
(
selectedAnn
)
{
// Set the directLinkedAnnotationGroupId to be used later in
// the filterGroups method.
directLinkedAnnotationGroupId
=
selectedAnn
.
group
;
const
selectedAnnGroup
=
myGroups
.
concat
(
allFeaturedGroups
)
.
some
(
g
=>
g
.
id
===
selectedAnn
.
group
);
// If the direct-linked annotation's group has not already been fetched,
// fetch it.
if
(
!
selectedAnnGroup
)
{
return
fetchGroup
({
id
:
selectedAnn
.
group
,
expand
:
params
.
expand
,
}).
then
(
directLinkedAnnGroup
=>
{
// If the directLinkedAnnotation's group fetch failed, return
// the list of groups without it.
if
(
!
directLinkedAnnGroup
)
{
return
[
myGroups
,
allFeaturedGroups
,
documentUri
,
token
];
}
}
// If there is no direct-linked annotation, return the list of groups without it.
return
[
myGroups
,
allFeaturedGroups
,
documentUri
,
token
];
// If the directLinkedAnnotation's group fetch was successful,
// combine it with the other groups.
return
[
myGroups
,
allFeaturedGroups
.
concat
(
directLinkedAnnGroup
),
documentUri
,
token
,
];
});
}
);
}
// If there is no direct-linked annotation, return the list of groups without it.
return
[
myGroups
,
allFeaturedGroups
,
documentUri
,
token
];
})
.
then
(([
myGroups
,
featuredGroups
,
documentUri
,
token
])
=>
{
const
groups
=
combineGroups
(
myGroups
,
featuredGroups
,
documentUri
);
...
...
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