All files / app/assets/javascripts/packages_and_registries/package_registry utils.js

96.42% Statements 27/28
94.44% Branches 17/18
100% Functions 7/7
95.83% Lines 23/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73                                    14x 406x   3x   3x   385x   6x   2x   1x   3x       1x   1x   1x       55x   14x 50x   14x         14x           14x 24x 1x     23x 1x     22x    
import { capitalize } from 'lodash';
import { s__ } from '~/locale';
import {
  GRAPHQL_PAGE_SIZE,
  PACKAGE_TYPE_CONAN,
  PACKAGE_TYPE_MAVEN,
  PACKAGE_TYPE_NPM,
  PACKAGE_TYPE_NUGET,
  PACKAGE_TYPE_PYPI,
  PACKAGE_TYPE_COMPOSER,
  PACKAGE_TYPE_RUBYGEMS,
  PACKAGE_TYPE_GENERIC,
  PACKAGE_TYPE_DEBIAN,
  PACKAGE_TYPE_HELM,
  LIST_KEY_PROJECT,
  SORT_FIELDS,
} from './constants';
 
export const getPackageTypeLabel = (packageType) => {
  switch (packageType) {
    case PACKAGE_TYPE_CONAN:
      return s__('PackageRegistry|Conan');
    case PACKAGE_TYPE_MAVEN:
      return s__('PackageRegistry|Maven');
    case PACKAGE_TYPE_NPM:
      return s__('PackageRegistry|npm');
    case PACKAGE_TYPE_NUGET:
      return s__('PackageRegistry|NuGet');
    case PACKAGE_TYPE_PYPI:
      return s__('PackageRegistry|PyPI');
    case PACKAGE_TYPE_RUBYGEMS:
      return s__('PackageRegistry|RubyGems');
    case PACKAGE_TYPE_COMPOSER:
      return s__('PackageRegistry|Composer');
    case PACKAGE_TYPE_GENERIC:
      return s__('PackageRegistry|Generic');
    case PACKAGE_TYPE_DEBIAN:
      return s__('PackageRegistry|Debian');
    case PACKAGE_TYPE_HELM:
      return s__('PackageRegistry|Helm');
    default:
      return null;
  }
};
 
export const packageTypeToTrackCategory = (type) => `UI::${capitalize(type)}Packages`;
 
export const sortableFields = (isGroupPage) =>
  SORT_FIELDS.filter((f) => f.orderBy !== LIST_KEY_PROJECT || isGroupPage);
 
export const getNextPageParams = (cursor) => ({
  after: cursor,
  first: GRAPHQL_PAGE_SIZE,
});
 
export const getPreviousPageParams = (cursor) => ({
  first: null,
  before: cursor,
  last: GRAPHQL_PAGE_SIZE,
});
 
export const getPageParams = (pageInfo = {}) => {
  if (pageInfo.before) {
    return getPreviousPageParams(pageInfo.before);
  }
 
  if (pageInfo.after) {
    return getNextPageParams(pageInfo.after);
  }
 
  return {};
};