diff options
Diffstat (limited to 'app/assets/javascripts/projects/storage_counter/utils.js')
-rw-r--r-- | app/assets/javascripts/projects/storage_counter/utils.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/app/assets/javascripts/projects/storage_counter/utils.js b/app/assets/javascripts/projects/storage_counter/utils.js new file mode 100644 index 00000000000..cb26603fff5 --- /dev/null +++ b/app/assets/javascripts/projects/storage_counter/utils.js @@ -0,0 +1,40 @@ +import { numberToHumanSize } from '~/lib/utils/number_utils'; +import { PROJECT_STORAGE_TYPES } from './constants'; + +/** + * This method parses the results from `getProjectStorageCount` call. + * + * @param {Object} data graphql result + * @returns {Object} + */ +export const parseGetProjectStorageResults = (data, helpLinks) => { + const projectStatistics = data?.project?.statistics; + if (!projectStatistics) { + return {}; + } + const { storageSize, ...storageStatistics } = projectStatistics; + const storageTypes = PROJECT_STORAGE_TYPES.reduce((types, currentType) => { + if (!storageStatistics[currentType.id]) { + return types; + } + + const helpPathKey = currentType.id.replace(`Size`, `HelpPagePath`); + const helpPath = helpLinks[helpPathKey]; + + return types.concat({ + storageType: { + ...currentType, + helpPath, + }, + value: storageStatistics[currentType.id], + }); + }, []); + + return { + storage: { + totalUsage: numberToHumanSize(storageSize, 1), + storageTypes, + }, + statistics: projectStatistics, + }; +}; |