From 012857c146b6e2cd068c16d65855407b9ffbded9 Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal Date: Thu, 21 Sep 2023 12:43:30 +0530 Subject: [PATCH] fix: handle no issues in custom analytics --- web/components/analytics/custom-analytics/graph/index.tsx | 1 - web/helpers/array.helper.ts | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/web/components/analytics/custom-analytics/graph/index.tsx b/web/components/analytics/custom-analytics/graph/index.tsx index 349f9884db0..733d1743729 100644 --- a/web/components/analytics/custom-analytics/graph/index.tsx +++ b/web/components/analytics/custom-analytics/graph/index.tsx @@ -9,7 +9,6 @@ import { findStringWithMostCharacters } from "helpers/array.helper"; import { generateBarColor } from "helpers/analytics.helper"; // types import { IAnalyticsParams, IAnalyticsResponse } from "types"; -// constants type Props = { analytics: IAnalyticsResponse; diff --git a/web/helpers/array.helper.ts b/web/helpers/array.helper.ts index bcadbe3c8cc..a682b0a1c12 100644 --- a/web/helpers/array.helper.ts +++ b/web/helpers/array.helper.ts @@ -38,10 +38,13 @@ export const orderArrayBy = ( export const checkDuplicates = (array: any[]) => new Set(array).size !== array.length; -export const findStringWithMostCharacters = (strings: string[]) => - strings.reduce((longestString, currentString) => +export const findStringWithMostCharacters = (strings: string[]): string => { + if (!strings || strings.length === 0) return ""; + + return strings.reduce((longestString, currentString) => currentString.length > longestString.length ? currentString : longestString ); +}; export const checkIfArraysHaveSameElements = (arr1: any[] | null, arr2: any[] | null): boolean => { if (!arr1 || !arr2) return false;