All files / tools/src/stateManagement/segmentation getActiveSegmentIndex.ts

83.33% Statements 5/6
75% Branches 3/4
100% Functions 2/2
83.33% Lines 5/6

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                    6594x   6594x 6594x 7089x   6594x          
import { getSegmentation } from './getSegmentation';
 
/**
 * Get the active segment index for a segmentation in the global state
 * @param segmentationId - The id of the segmentation to get the active segment index from.
 * @returns The active segment index for the given segmentation.
 */
export function getActiveSegmentIndex(
  segmentationId: string
): number | undefined {
  const segmentation = getSegmentation(segmentationId);
 
  Eif (segmentation) {
    const activeSegmentIndex = Object.keys(segmentation.segments).find(
      (segmentIndex) => segmentation.segments[segmentIndex].active
    );
    return activeSegmentIndex ? Number(activeSegmentIndex) : undefined;
  }
 
  return undefined;
}