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( ...@@ -204,23 +204,23 @@ function groups(
// If there is a directLinkedAnnId, fetch the annotation to see if there needs // 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 // 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. // 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) { if (directLinkedAnnId) {
selectedAnnApi = api.annotation directLinkedAnnApi = api.annotation
.get({ id: directLinkedAnnId }) .get({ id: directLinkedAnnId })
.catch(() => { .catch(() => {
// If the annotation does not exist or the user doesn't have permission. // If the annotation does not exist or the user doesn't have permission.
return null; return null;
}); });
} }
groupApiRequests = groupApiRequests.concat(selectedAnnApi); groupApiRequests = groupApiRequests.concat(directLinkedAnnApi);
// If there is a directLinkedGroupId, add an api request to get that // If there is a directLinkedGroupId, add an api request to get that
// particular group since it may not be in the results returned by // particular group since it may not be in the results returned by
// group.list or profile.groups. // group.list or profile.groups.
let selectedGroupApi = Promise.resolve(null); let directLinkedGroupApi = Promise.resolve(null);
if (directLinkedGroupId) { if (directLinkedGroupId) {
selectedGroupApi = fetchGroup({ directLinkedGroupApi = fetchGroup({
id: directLinkedGroupId, id: directLinkedGroupId,
expand: params.expand, expand: params.expand,
}).then(group => { }).then(group => {
...@@ -233,54 +233,62 @@ function groups( ...@@ -233,54 +233,62 @@ function groups(
return group; return group;
}); });
} }
groupApiRequests = groupApiRequests.concat(selectedGroupApi); groupApiRequests = groupApiRequests.concat(directLinkedGroupApi);
return Promise.all(groupApiRequests); return Promise.all(groupApiRequests);
}) })
.then(([myGroups, featuredGroups, token, selectedAnn, selectedGroup]) => { .then(
// 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 myGroups,
// don't already have it. featuredGroups,
token,
// If there is a direct-linked group, add it to the featured groups list. directLinkedAnn,
let allFeaturedGroups = directLinkedGroup,
selectedGroup !== null && ]) => {
!featuredGroups.some(g => g.id === selectedGroup.id) // Step 3. Add the direct-linked group to the list of featured groups,
? featuredGroups.concat([selectedGroup]) // and if there was a direct-linked annotation, fetch its group if we
: featuredGroups; // don't already have it.
// If there's a selected annotation it may require an extra api call // If there is a direct-linked group, add it to the featured groups list.
// to fetch its group. let allFeaturedGroups =
if (selectedAnn) { directLinkedGroup !== null &&
// Set the directLinkedAnnotationGroupId to be used later in !featuredGroups.some(g => g.id === directLinkedGroup.id)
// the filterGroups method. ? featuredGroups.concat([directLinkedGroup])
directLinkedAnnotationGroupId = selectedAnn.group; : featuredGroups;
const selectedAnnGroup = myGroups // If there's a selected annotation it may require an extra api call
.concat(allFeaturedGroups) // to fetch its group.
.some(g => g.id === selectedAnn.group); if (directLinkedAnn) {
// Set the directLinkedAnnotationGroupId to be used later in
// If the direct-linked annotation's group has not already been fetched, // the filterGroups method.
// fetch it. directLinkedAnnotationGroupId = directLinkedAnn.group;
if (!selectedAnnGroup) {
const initialFeaturedGroups = allFeaturedGroups; const directLinkedAnnGroup = myGroups
allFeaturedGroups = fetchGroup({ .concat(allFeaturedGroups)
id: selectedAnn.group, .some(g => g.id === directLinkedAnn.group);
expand: params.expand,
}).then(directLinkedAnnGroup => { // If the direct-linked annotation's group has not already been fetched,
// If the directLinkedAnnotation's group fetch failed, return // fetch it.
// the list of groups without it. if (!directLinkedAnnGroup) {
if (!directLinkedAnnGroup) { const initialFeaturedGroups = allFeaturedGroups;
return initialFeaturedGroups; allFeaturedGroups = fetchGroup({
} id: directLinkedAnn.group,
expand: params.expand,
// If the directLinkedAnnotation's group fetch was successful, }).then(directLinkedAnnGroup => {
// combine it with the other groups. // If the directLinkedAnnotation's group fetch failed, return
return initialFeaturedGroups.concat(directLinkedAnnGroup); // 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]) => { .then(([myGroups, featuredGroups, documentUri, token]) => {
// Step 4. Combine all the groups into a single list and set additional // Step 4. Combine all the groups into a single list and set additional
// metadata on them that will be used elsewhere in the app. // 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