import { DEPRECATED_JOB_TYPES } from '../../common/constants' ; import { ExportTypesHandler } from './get_export_type_handler' ; import { AvailableTotal , FeatureAvailabilityMap , RangeStats } from './types' ; const jobTypeIsDeprecated = ( jobType ) => DEPRECATED_JOB_TYPES . includes ( jobType ) ; const defaultTotalsForFeature = { total : 0 , deprecated : 0 , app : { 'canvas workpad' : 0 , search : 0 , visualization : 0 , dashboard : 0 } , layout : { canvas : 0 , print : 0 , preserve_layout : 0 } , } ; const isAvailable = ( featureAvailability , feature ) => ! ! featureAvailability [ feature ] ; function getAvailableTotalForFeature ( jobType , typeKey , featureAvailability ) { const deprecated = jobTypeIsDeprecated ( typeKey ) ? jobType . total : jobType . deprecated || 0 ; const availableTotal = { available : isAvailable ( featureAvailability , typeKey ) , total : jobType . total , deprecated , output_size : jobType . sizes , app : { ... defaultTotalsForFeature . app , ... jobType . app } , layout : { ... defaultTotalsForFeature . layout , ... jobType . layout } , } ; return availableTotal as AvailableTotal ; } export const getExportStats = ( rangeStatsInput = { } , featureAvailability , exportTypesHandler ) => { const { _all : rangeAll , status : rangeStatus , statuses : rangeStatusByApp , output_size : outputSize , ... rangeStats } = rangeStatsInput ; const statsForExportType = exportTypesHandler . getJobTypes ( ) . reduce ( ( accum , exportType ) => { const availableTotal = rangeStats [ exportType as keyof typeof rangeStats ] ; if ( ! availableTotal ) { return { ... accum , [ exportType ] : { available : isAvailable ( featureAvailability , exportType ) , ... defaultTotalsForFeature , } , } ; } return { ... accum , [ exportType ] : getAvailableTotalForFeature ( availableTotal , exportType , featureAvailability ) , } ; } , { } ) ; const resultStats = { ... statsForExportType , _all : rangeAll || 0 , status : { completed : 0 , failed : 0 , ... rangeStatus } , statuses : rangeStatusByApp , output_size : outputSize , } as RangeStats ; return resultStats ; } ;