Welcome to mirror list, hosted at ThFree Co, Russian Federation.

utils.js « storage « usage_quotas « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 445c3efc9e64a24e1d38d499b45695808bc454df (plain)
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
/**
 * Populates an array of storage types with usage value and other details
 *
 * @param {Array} selectedStorageTypes selected storage types that will be populated
 * @param {Object} projectStatistics object of storage values, with storage type as keys
 * @param {Object} statisticsDetailsPaths object of storage detail paths, with storage type as keys
 * @param {Object} helpLinks object of help paths, with storage type as keys
 * @returns {Array}
 */
export const getStorageTypesFromProjectStatistics = (
  selectedStorageTypes,
  projectStatistics,
  statisticsDetailsPaths = {},
  helpLinks = {},
) =>
  selectedStorageTypes.reduce((types, currentType) => {
    const helpPath = helpLinks[currentType.id];
    const value = projectStatistics[`${currentType.id}Size`];
    const detailsPath = statisticsDetailsPaths[currentType.id];

    return types.concat({
      ...currentType,
      helpPath,
      detailsPath,
      value,
    });
  }, []);

/**
 * Creates a sorting function to sort storage types by usage in the graph and in the table
 *
 * @param {string} storageUsageKey key storing value of storage usage
 * @returns {Function} sorting function
 */
export function descendingStorageUsageSort(storageUsageKey) {
  return (a, b) => b[storageUsageKey] - a[storageUsageKey];
}