findFirst -> findAny

This commit is contained in:
Tim Hansen
2020-12-04 15:24:40 -07:00
parent b14cbe28d3
commit cadb4b5311
3 changed files with 5 additions and 5 deletions
@@ -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>>();
+1 -1
View File
@@ -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);