import { formatDate, parseDate } from '@openmrs/esm-framework'; import { dashboardMeta } from './dashboard.meta'; export const makeThrottled = any>( func: T, time = 1000, ): ((...funcArgs: Parameters) => void) => { let waiting = false; let toBeExecuted = false; let lastArgs: Parameters = null; const throttledFunc = (...args: Parameters) => { if (!waiting) { waiting = true; setTimeout(() => { waiting = false; if (toBeExecuted) { toBeExecuted = false; throttledFunc(...lastArgs); } }, time); func(...args); } else { toBeExecuted = true; lastArgs = args; } }; return throttledFunc; }; export const testResultsBasePath = (basePath: string) => `${window.spaBase}${basePath}/${dashboardMeta.path}`; export function formatResultDate(obsDatetime?: string) { return obsDatetime ? formatDate(parseDate(obsDatetime), { mode: 'standard', time: true }) : '--'; }