Commit 43fcec9a authored by Robert Knight's avatar Robert Knight

Avoid using the term "selected" to refer to direct-linked annotations

As pointed out during code review, mixing the terms "selected" and
"direct-linked" to refer to direct-linked annotations and groups is
potentially confusing. Use the term direct-linked consistently.
parent bb4a296f
......@@ -204,23 +204,23 @@ function groups(
// If there is a directLinkedAnnId, 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 selectedAnnApi = Promise.resolve(null);
let directLinkedAnnApi = Promise.resolve(null);
if (directLinkedAnnId) {
selectedAnnApi = api.annotation
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(selectedAnnApi);
groupApiRequests = groupApiRequests.concat(directLinkedAnnApi);
// If there is a directLinkedGroupId, 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 selectedGroupApi = Promise.resolve(null);
let directLinkedGroupApi = Promise.resolve(null);
if (directLinkedGroupId) {
selectedGroupApi = fetchGroup({
directLinkedGroupApi = fetchGroup({
id: directLinkedGroupId,
expand: params.expand,
}).then(group => {
......@@ -233,54 +233,62 @@ function groups(
return group;
});
}
groupApiRequests = groupApiRequests.concat(selectedGroupApi);
groupApiRequests = groupApiRequests.concat(directLinkedGroupApi);
return Promise.all(groupApiRequests);
})
.then(([myGroups, featuredGroups, token, selectedAnn, selectedGroup]) => {
// Step 3. Add the direct-linked group to the list of featured groups,
// and if there was a direct-linked annotation, fetch its group if we
// don't already have it.
// If there is a direct-linked group, add it to the featured groups list.
let 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) {
const initialFeaturedGroups = allFeaturedGroups;
allFeaturedGroups = 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 initialFeaturedGroups;
}
// If the directLinkedAnnotation's group fetch was successful,
// combine it with the other groups.
return initialFeaturedGroups.concat(directLinkedAnnGroup);
});
.then(
([
myGroups,
featuredGroups,
token,
directLinkedAnn,
directLinkedGroup,
]) => {
// Step 3. Add the direct-linked group to the list of featured groups,
// and if there was a direct-linked annotation, fetch its group if we
// don't already have it.
// If there is a direct-linked group, add it to the featured groups list.
let allFeaturedGroups =
directLinkedGroup !== null &&
!featuredGroups.some(g => g.id === directLinkedGroup.id)
? featuredGroups.concat([directLinkedGroup])
: featuredGroups;
// If there's a selected annotation it may require an extra api call
// to fetch its group.
if (directLinkedAnn) {
// Set the directLinkedAnnotationGroupId to be used later in
// the filterGroups method.
directLinkedAnnotationGroupId = directLinkedAnn.group;
const directLinkedAnnGroup = myGroups
.concat(allFeaturedGroups)
.some(g => g.id === directLinkedAnn.group);
// If the direct-linked annotation's group has not already been fetched,
// fetch it.
if (!directLinkedAnnGroup) {
const initialFeaturedGroups = allFeaturedGroups;
allFeaturedGroups = fetchGroup({
id: directLinkedAnn.group,
expand: params.expand,
}).then(directLinkedAnnGroup => {
// If the directLinkedAnnotation's group fetch failed, return
// the list of groups without it.
if (!directLinkedAnnGroup) {
return initialFeaturedGroups;
}
// If the directLinkedAnnotation's group fetch was successful,
// combine it with the other groups.
return initialFeaturedGroups.concat(directLinkedAnnGroup);
});
}
}
return Promise.all([myGroups, allFeaturedGroups, documentUri, token]);
}
return Promise.all([myGroups, allFeaturedGroups, documentUri, token]);
})
)
.then(([myGroups, featuredGroups, documentUri, token]) => {
// Step 4. Combine all the groups into a single list and set additional
// metadata on them that will be used elsewhere in the app.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment