All files / utils dashboardUtils.js

100% Statements 32/32
100% Branches 35/35
100% Functions 8/8
100% Lines 32/32

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 46 47 48 49 50 51 52 531x   1x   1x 275x 275x   1x 140x 140x   1x 141x 141x   1x 140x 140x   1x 139x 139x 139x 139x   1x 139x 139x 139x 139x   1x 692x 690x 692x 692x   1x 684x 684x                        
// dashboardUtil.js
 
import { timestampToDate, daysSinceTimestamp } from "main/utils/dateUtils";
 
const fieldOrBlank = (commonsPlus, field) => {
  return commonsPlus?.[field] ?? "--";
};
 
const getCommonsName = (commonsPlus) => {
  return commonsPlus?.commons?.name ?? "--";
};
 
const getIsHidden = (commonsPlus) => {
  return commonsPlus?.commons?.hidden === true;
};
 
const getCommonsId = (commonsPlus, id) => {
  return commonsPlus?.commons?.id ?? id ?? "--";
};
 
const getStartingDate = (commonsPlus) => {
  return commonsPlus?.commons?.startingDate
    ? timestampToDate(commonsPlus.commons.startingDate)
    : "--";
};
 
const getDaysActive = (commonsPlus) => {
  return commonsPlus?.commons?.startingDate
    ? daysSinceTimestamp(commonsPlus.commons.startingDate)
    : "--";
};
 
const formatOneDecimal = (value) => {
  if (value === null) return "--";
  const numericValue = Number(value);
  return Number.isNaN(numericValue) ? "--" : numericValue.toFixed(1);
};
 
const numericFieldOrBlank = (commonsPlus, field) => {
  return formatOneDecimal(commonsPlus?.[field]);
};
 
export {
  fieldOrBlank,
  getCommonsName,
  getIsHidden,
  getCommonsId,
  getStartingDate,
  getDaysActive,
  formatOneDecimal,
  numericFieldOrBlank,
};