All files / app/codeCharta/state/effects/nodeContextMenu/markFolderRow/selectors markFolderItems.selector.ts

93.75% Statements 15/16
100% Branches 3/3
75% Functions 3/4
100% Lines 12/12

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 335x   5x 5x 5x 5x             5x   5x 2x 2x     1x 2x           5x            
import { createSelector } from "@ngrx/store"
import { MarkedPackage } from "../../../../../codeCharta.model"
import { mapColorsSelector } from "../../../../store/appSettings/mapColors/mapColors.selector"
import { markedPackagesSelector } from "../../../../store/fileSettings/markedPackages/markedPackages.selector"
import { findIndexOfMarkedPackageOrParent } from "../../../../store/fileSettings/markedPackages/util/findIndexOfMarkedPackageOrParent"
import { rightClickedCodeMapNodeSelector } from "../../rightClickedCodeMapNode.selector"
 
export type MarkFolderItem = {
    color: string
    isMarked: boolean
}
 
const markingColorsSelector = createSelector(mapColorsSelector, mapColors => mapColors.markingColors)
 
export const _getMarkFolderItems = (node: { path?: string } | null, markingColors: string[], markedPackages: MarkedPackage[]) => {
    if (node === null) {
        return markingColors.map(color => ({ color, isMarked: false }))
    }
 
    const nodeIndexWithinMarkedPackages = findIndexOfMarkedPackageOrParent(markedPackages, node.path)
    return markingColors.map(color => ({
        color,
        isMarked: nodeIndexWithinMarkedPackages !== -1 && color === markedPackages[nodeIndexWithinMarkedPackages].color
    }))
}
 
export const markFolderItemsSelector = createSelector(
    rightClickedCodeMapNodeSelector,
    markingColorsSelector,
    markedPackagesSelector,
    _getMarkFolderItems
)