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,38 +233,45 @@ function groups( ...@@ -233,38 +233,45 @@ 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(
([
myGroups,
featuredGroups,
token,
directLinkedAnn,
directLinkedGroup,
]) => {
// Step 3. Add the direct-linked group to the list of featured groups, // 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 // and if there was a direct-linked annotation, fetch its group if we
// don't already have it. // don't already have it.
// If there is a direct-linked group, add it to the featured groups list. // If there is a direct-linked group, add it to the featured groups list.
let allFeaturedGroups = let allFeaturedGroups =
selectedGroup !== null && directLinkedGroup !== null &&
!featuredGroups.some(g => g.id === selectedGroup.id) !featuredGroups.some(g => g.id === directLinkedGroup.id)
? featuredGroups.concat([selectedGroup]) ? featuredGroups.concat([directLinkedGroup])
: featuredGroups; : featuredGroups;
// If there's a selected annotation it may require an extra api call // If there's a selected annotation it may require an extra api call
// to fetch its group. // to fetch its group.
if (selectedAnn) { if (directLinkedAnn) {
// Set the directLinkedAnnotationGroupId to be used later in // Set the directLinkedAnnotationGroupId to be used later in
// the filterGroups method. // the filterGroups method.
directLinkedAnnotationGroupId = selectedAnn.group; directLinkedAnnotationGroupId = directLinkedAnn.group;
const selectedAnnGroup = myGroups const directLinkedAnnGroup = myGroups
.concat(allFeaturedGroups) .concat(allFeaturedGroups)
.some(g => g.id === selectedAnn.group); .some(g => g.id === directLinkedAnn.group);
// If the direct-linked annotation's group has not already been fetched, // If the direct-linked annotation's group has not already been fetched,
// fetch it. // fetch it.
if (!selectedAnnGroup) { if (!directLinkedAnnGroup) {
const initialFeaturedGroups = allFeaturedGroups; const initialFeaturedGroups = allFeaturedGroups;
allFeaturedGroups = fetchGroup({ allFeaturedGroups = fetchGroup({
id: selectedAnn.group, id: directLinkedAnn.group,
expand: params.expand, expand: params.expand,
}).then(directLinkedAnnGroup => { }).then(directLinkedAnnGroup => {
// If the directLinkedAnnotation's group fetch failed, return // If the directLinkedAnnotation's group fetch failed, return
...@@ -280,7 +287,8 @@ function groups( ...@@ -280,7 +287,8 @@ function groups(
} }
} }
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