findFirst -> findAny
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<Maybe<string>>();
|
||||
|
||||
@@ -51,7 +51,7 @@ export function findAlways<T>(
|
||||
return assertAlways(collection.find(callback));
|
||||
}
|
||||
|
||||
export function findFirstKey<T>(
|
||||
export function findAnyKey<T>(
|
||||
record: Record<string, T> | undefined,
|
||||
): string | undefined {
|
||||
return Object.keys(record ?? {}).find(_ => true);
|
||||
|
||||
Reference in New Issue
Block a user