All files / app/codeCharta/ui/customConfigs/downloadCustomConfigsButton getDownloadableCustomConfigs.ts

100% Statements 12/12
100% Branches 1/1
100% Functions 3/3
100% Lines 10/10

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  8x         8x 2x 2x   2x   3x 2x     2x             3x 3x    
import { ExportCustomConfig, MapNamesByChecksum } from "../../../model/customConfig/customConfig.api.model"
import { CustomConfigHelper } from "../../../util/customConfigHelper"
import { VisibleFilesBySelectionMode } from "../visibleFilesBySelectionMode.selector"
 
export type DownloadableConfigs = Map<string, ExportCustomConfig>
 
export const getDownloadableCustomConfigs = ({ assignedMaps }: VisibleFilesBySelectionMode): DownloadableConfigs => {
    const downloadableConfigs: DownloadableConfigs = new Map()
    const customConfigs = CustomConfigHelper.getCustomConfigs()
 
    for (const [checksum, customConfig] of customConfigs.entries()) {
        // Only Configs which are applicable for at least one of the uploaded maps should be downloaded.
        if (isConfigApplicableForUploadedMaps(customConfig.assignedMaps, assignedMaps)) {
            downloadableConfigs.set(checksum, CustomConfigHelper.createExportCustomConfigFromConfig(customConfig))
        }
    }
    return downloadableConfigs
}
 
function isConfigApplicableForUploadedMaps(
    assignedMapsOfConfig: MapNamesByChecksum,
    assignedMapsOfVisibleFiles: MapNamesByChecksum
): boolean {
    const mapChecksumsOfConfig = [...assignedMapsOfConfig.keys()]
    return mapChecksumsOfConfig.some(mapChecksumConfig => assignedMapsOfVisibleFiles.has(mapChecksumConfig))
}