All files / app/codeCharta/ui/ribbonBar/searchPanel/matchingFilesCounter/selectors matchingFilesCounter.selector.ts

100% Statements 14/14
100% Branches 2/2
100% Functions 4/4
100% Lines 11/11

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  5x 5x 5x 5x 5x   5x 22x               5x 2x 2x                             5x            
import { BlacklistItem, BlacklistType, CodeMapNode } from "../../../../../codeCharta.model"
import { searchedNodesSelector } from "../../../../../state/selectors/searchedNodes/searchedNodes.selector"
import { blacklistSelector } from "../../../../../state/store/fileSettings/blacklist/blacklist.selector"
import { isLeaf, isPathBlacklisted } from "../../../../../util/codeMapHelper"
import { codeMapNodesSelector } from "../../../../../state/selectors/accumulatedData/codeMapNodes.selector"
import { createSelector } from "@ngrx/store"
 
const getBlacklistedFileCount = (blacklistType: BlacklistType, nodes: CodeMapNode[], blacklist: BlacklistItem[]) =>
    nodes.reduce((count, node) => (isPathBlacklisted(node.path, blacklist, blacklistType) ? count + 1 : count), 0)
 
export type MatchingFilesCounter = {
    fileCount: string
    flattenCount: string
    excludeCount: string
}
 
export const _calculateMatchingFilesCounter = (searchedNodes: CodeMapNode[], blacklist: BlacklistItem[], allNodes: CodeMapNode[]) => {
    const searchedNodeLeaves = searchedNodes.filter(node => isLeaf(node))
    return {
        fileCount: `${searchedNodeLeaves.length}/${allNodes.length}`,
        flattenCount: `${getBlacklistedFileCount("flatten", searchedNodeLeaves, blacklist)}/${getBlacklistedFileCount(
            "flatten",
            allNodes,
            blacklist
        )}`,
        excludeCount: `${getBlacklistedFileCount("exclude", searchedNodeLeaves, blacklist)}/${getBlacklistedFileCount(
            "exclude",
            allNodes,
            blacklist
        )}`
    }
}
 
export const matchingFilesCounterSelector = createSelector(
    searchedNodesSelector,
    blacklistSelector,
    codeMapNodesSelector,
    _calculateMatchingFilesCounter
)