All files / libs/payout-calculation/statements/views/list/src/lib/hooks use-highlighted-kpi-progress.hook.ts

100% Statements 24/24
100% Branches 10/10
100% Functions 1/1
100% Lines 24/24

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 251x 1x 1x 1x 1x 1x 10x 10x 10x 4x 4x 6x 6x 6x 10x 1x 1x 5x 10x 1x 1x 4x 4x 1x  
import { useMemo } from 'react';
 
import { type UserStatements } from '@amalia/core/types';
import { evaluateHighlightedKpisProgress } from '@amalia/payout-calculation/statements/shared';
 
export const useHighlightedKpiProgress = (userStatements: Pick<UserStatements, 'lines'>, isForecast = false) =>
  useMemo(() => {
    // Only compute highlighted kpis if there is exactly 1 statement for this user and period.
    if (userStatements.lines.length !== 1) {
      return undefined;
    }
 
    const [statement] = userStatements.lines;
 
    if (isForecast && statement.forecast?.resultSummary) {
      return evaluateHighlightedKpisProgress(statement.forecast.resultSummary);
    }
 
    if (statement.resultSummary) {
      return evaluateHighlightedKpisProgress(statement.resultSummary);
    }
 
    return undefined;
  }, [userStatements, isForecast]);