notes: selectLocalizedContent()

in src/amo/reducers/collections.js [796:889]


      notes: selectLocalizedContent(notes, lang),
    };
  });
};

type GetCollectionByIdParams = {|
  state: CollectionsState,
  id: CollectionId,
|};

export const getCollectionById = ({
  id,
  state,
}: GetCollectionByIdParams): CollectionType | null => {
  if (!id) {
    throw new Error('The id parameter is required');
  }
  if (!state) {
    throw new Error('The state parameter is required');
  }

  return state.byId[id] || null;
};

export const getCurrentCollection = (
  collectionsState: CollectionsState,
): CollectionType | null => {
  if (!collectionsState) {
    throw new Error('The collectionsState parameter is required');
  }
  if (!collectionsState.current.id) {
    return null;
  }

  return getCollectionById({
    id: collectionsState.current.id,
    state: collectionsState,
  });
};

type CreateInternalCollectionParams = {|
  addonsResponse?: CollectionAddonsListResponse,
  detail: ExternalCollectionDetail,
  lang: string,
|};

export const createInternalCollection = ({
  addonsResponse,
  detail,
  lang,
}: CreateInternalCollectionParams): CollectionType => ({
  addons: addonsResponse
    ? createInternalAddons(addonsResponse.results, lang)
    : null,
  authorId: detail.author.id,
  authorName: detail.author.name,
  authorUsername: detail.author.username,
  defaultLocale: detail.default_locale,
  description: selectLocalizedContent(detail.description, lang),
  id: detail.id,
  lastUpdatedDate: detail.modified,
  name: selectLocalizedContent(detail.name, lang) || '',
  numberOfAddons: addonsResponse ? addonsResponse.count : detail.addon_count,
  pageSize: addonsResponse ? addonsResponse.page_size : null,
  slug: detail.slug,
});

type LoadCollectionIntoStateParams = {|
  addonsResponse?: CollectionAddonsListResponse,
  collection: ExternalCollectionDetail,
  state: CollectionsState,
|};

export const loadCollectionIntoState = ({
  addonsResponse,
  collection,
  state,
}: LoadCollectionIntoStateParams): CollectionsState => {
  const existingCollection = state.byId[collection.id];
  const internalCollection = createInternalCollection({
    detail: collection,
    addonsResponse,
    lang: state.lang,
  });
  // In case the new collection isn't loaded with add-ons,
  // make sure we don't overwrite any existing addons.
  if (!internalCollection.addons && existingCollection) {
    internalCollection.addons = existingCollection.addons;
    internalCollection.pageSize = existingCollection.pageSize;
  }

  return {
    ...state,
    byId: {