All files / src/app/core/store/content/page-tree page-tree.selectors.ts

77.27% Statements 17/22
0% Branches 0/1
62.5% Functions 5/8
70.58% Lines 12/17

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 41 42 43 44 45 4626x 26x   26x         26x   26x 26x   26x   26x               26x 4x     4x                 26x                  
import { createSelector, createSelectorFactory, defaultMemoize, resultMemoize } from '@ngrx/store';
import { isEqual } from 'lodash-es';
 
import {
  ContentPageTreeView,
  createCompleteContentPageTreeView,
  createContentPageTreeView,
} from 'ish-core/models/content-page-tree-view/content-page-tree-view.model';
import { ContentPageTreeHelper } from 'ish-core/models/content-page-tree/content-page-tree.helper';
import { ContentPageTree } from 'ish-core/models/content-page-tree/content-page-tree.model';
import { getContentState } from 'ish-core/store/content/content-store';
import { selectRouteParam } from 'ish-core/store/core/router';
 
const getPageTreeState = createSelector(getContentState, state => state.pagetree);
 
export const getPageTree = createSelector(getPageTreeState, state => state.pagetree);
 
/**
 * Get the content page tree for the given root and the currently selected content page.
 *
 * @param rootId  The Id of the root content page of the tree
 * @returns       The fitting content page tree
 */
export const getContentPageTree = (rootId: string) =>
  createSelectorFactory<object, ContentPageTreeView>(projector => resultMemoize(projector, isEqual))(
    getPageTree,
    selectRouteParam('contentPageId'),
    (pagetree: ContentPageTree, contentPageId: string) => createContentPageTreeView(pagetree, rootId, contentPageId)
  );
 
/**
 * Get the complete content page tree (all branches) for the given root to the given depth.
 *
 * @param rootId  The Id of the root content page of the tree
 * @returns       The complete content page tree
 */
export const getCompleteContentPageTree = (rootId: string, depth: number) =>
  createSelectorFactory<object, ContentPageTreeView>(projector =>
    defaultMemoize(projector, ContentPageTreeHelper.equals, isEqual)
  )(getPageTree, (tree: ContentPageTree): ContentPageTreeView => {
    Iif (!rootId) {
      return;
    }
    return createCompleteContentPageTreeView(ContentPageTreeHelper.subTree(tree, rootId), rootId, depth);
  });