diff --git a/plugins/cost-insights/src/components/ProductInsightsCard/ProductInsightsCard.tsx b/plugins/cost-insights/src/components/ProductInsightsCard/ProductInsightsCard.tsx index e4cb475ab5..534ef490c3 100644 --- a/plugins/cost-insights/src/components/ProductInsightsCard/ProductInsightsCard.tsx +++ b/plugins/cost-insights/src/components/ProductInsightsCard/ProductInsightsCard.tsx @@ -36,7 +36,7 @@ import { useLoading, useScroll, } from '../../hooks'; -import { findFirstKey } from '../../utils/assert'; +import { findAnyKey } from '../../utils/assert'; type LoadingProps = (isLoading: boolean) => void; @@ -93,7 +93,7 @@ export const ProductInsightsCard = ({ }, [product, duration, onSelectAsync, dispatchLoadingProduct]); // Only a single entities Record for the root product entity is supported - const entityKey = findFirstKey(entity?.entities); + const entityKey = findAnyKey(entity?.entities); const entities = entityKey ? entity!.entities[entityKey] : []; const subheader = entityKey diff --git a/plugins/cost-insights/src/components/ProductInsightsCard/ProductInsightsChart.tsx b/plugins/cost-insights/src/components/ProductInsightsCard/ProductInsightsChart.tsx index d7c796adf3..08a4c5efa2 100644 --- a/plugins/cost-insights/src/components/ProductInsightsCard/ProductInsightsChart.tsx +++ b/plugins/cost-insights/src/components/ProductInsightsCard/ProductInsightsChart.tsx @@ -37,7 +37,7 @@ import { findAlways, notEmpty, isUndefined, - findFirstKey, + findAnyKey, assertAlways, } from '../../utils/assert'; import { formatPeriod, formatPercent } from '../../utils/formatters'; @@ -70,7 +70,7 @@ export const ProductInsightsChart = ({ const layoutClasses = useLayoutStyles(); // Only a single entities Record for the root product entity is supported - const entityLabel = assertAlways(findFirstKey(entity.entities)); + const entityLabel = assertAlways(findAnyKey(entity.entities)); const entities = entity.entities[entityLabel] ?? []; const [activeLabel, setActive] = useState>(); diff --git a/plugins/cost-insights/src/utils/assert.ts b/plugins/cost-insights/src/utils/assert.ts index 39b710ac3d..05ce65197b 100644 --- a/plugins/cost-insights/src/utils/assert.ts +++ b/plugins/cost-insights/src/utils/assert.ts @@ -51,7 +51,7 @@ export function findAlways( return assertAlways(collection.find(callback)); } -export function findFirstKey( +export function findAnyKey( record: Record | undefined, ): string | undefined { return Object.keys(record ?? {}).find(_ => true);