Repository: hashicorp/vault
File: ui/lib/core/addon/utils/client-count-utils.ts (TypeScript)

Code before:
    // if there are noteworthy upgrades, only return those during queried date range
    if (upgrades.length) {
      const startDate = parseAPITimestamp(start) as Date;
      const endDate = parseAPITimestamp(end) as Date;
      return upgrades.filter(({ timestampInstalled }) => {
        const upgradeDate = parseAPITimestamp(timestampInstalled) as Date;
        return isWithinInterval(upgradeDate, { start: startDate, end: endDate });
      });
    }
  }
  return [];
};

// This method is used to return totals relevant only to the specified
// mount path within the specified namespace.
export const filteredTotalForMount = (
  byMonth: ByMonthClients[],
  nsPath: string,
  mountPath: string
): TotalClients => {
  if (!nsPath || !mountPath || isEmpty(byMonth)) return emptyCounts();

  return newClientTotal(byMonth, nsPath, mountPath);
};

export const newClientTotal = (
  byMonth: ByMonthClients[],
  nsPath?: string,
  mountPath?: string
): TotalClients => {
  if (isEmpty(byMonth)) return emptyCounts();

  if (!nsPath || !mountPath) {
    const total = byMonth.reduce((acc, curr) => {
      for (const key of CLIENT_TYPES) {
        acc[key] += curr.new_clients[key] || 0;
      }
      return acc;
    }, emptyCounts());

    return total;
  }

  const filteredTotals = byMonth?.reduce((acc, month) => {
    month.new_clients.namespaces
      .filter((ns) => sanitizePath(ns.label) === sanitizePath(nsPath))
      .forEach((ns) => {
        ns.mounts
          .filter((mount) => sanitizePath(mount.label) === sanitizePath(mountPath))
          .forEach((mount) => {
            for (const key of CLIENT_TYPES) {

Review comment (suggestion):
The UI should avoid doing any calculations. The `total.clients` in the `/activity` response is the  "total new clients" for a billing period, so this number is already provided for us - unless I'm missing context 🤔 

Code after:
    // if there are noteworthy upgrades, only return those during queried date range
    if (upgrades.length) {
      const startDate = parseAPITimestamp(start) as Date;
      const endDate = parseAPITimestamp(end) as Date;
      return upgrades.filter(({ timestampInstalled }) => {
        const upgradeDate = parseAPITimestamp(timestampInstalled) as Date;
        return isWithinInterval(upgradeDate, { start: startDate, end: endDate });
      });
    }
  }
  return [];
};

// This method is used to return totals relevant only to the specified
// mount path within the specified namespace.
export const filteredTotalForMount = (
  byNamespace: ByNamespaceClients[],
  nsPath: string,
  mountPath: string
): TotalClients => {
  if (!nsPath || !mountPath || isEmpty(byNamespace)) return emptyCounts();
  return (
    byNamespace
      .find((namespace) => sanitizePath(namespace.label) === sanitizePath(nsPath))
      ?.mounts.find((mount: MountClients) => sanitizePath(mount.label) === sanitizePath(mountPath)) ||
    emptyCounts()
  );
};

// This method is used to filter byMonth data and return data for only
// the specified mount within the specified namespace. If data exists
// for the month but not the mount, it should return zero'd data. If
// no data exists for the month is returns the month as-is.
export const filterByMonthDataForMount = (
  byMonth: ByMonthClients[],
  namespacePath: string,
  mountPath: string
): ByMonthClients[] => {
  if (byMonth && namespacePath && mountPath) {
    const months: ByMonthClients[] = JSON.parse(JSON.stringify(byMonth));
    return [...months].map((m) => {
      if (m?.clients === undefined) {
        // if the month doesn't have data we can just return the block
        return m;
      }

      const nsData = m.namespaces?.find((ns) => sanitizePath(ns.label) === sanitizePath(namespacePath));
      const mountData = nsData?.mounts.find((mount) => sanitizePath(mount.label) === sanitizePath(mountPath));
      if (mountData) {
        // if we do have mount data, we need to add in new_client namespace information
        const nsNew = m.new_clients?.namespaces?.find(