diff --git a/src/app/records/MetricBanner.tsx b/src/app/records/MetricBanner.tsx index 5f8f39848..ddfe56bec 100644 --- a/src/app/records/MetricBanner.tsx +++ b/src/app/records/MetricBanner.tsx @@ -2,10 +2,10 @@ import { useD2Definitions } from 'app/manifest/selectors'; import { METRICS_ACCOUNT_NODE } from 'app/search/d2-known-values'; import { DestinyObjectiveProgress } from 'bungie-api-ts/destiny2'; import clsx from 'clsx'; -import { TraitHashes } from 'data/d2/generated-enums'; import masterworkOverlay from 'images/masterwork-metric.png'; import BungieImage from '../dim-ui/BungieImage'; import styles from './MetricBanner.m.scss'; +import { getMetricTimeScope } from './presentation-nodes'; interface Props { metricHash: number; @@ -21,9 +21,7 @@ export default function MetricBanner({ metricHash, objectiveProgress, className } const metricIcon = metricDef.displayProperties.icon; - const metricScope = metricDef.traitHashes - .filter((h) => h !== TraitHashes.All) - .map((h) => defs.Trait.get(h))[0]; + const metricScope = getMetricTimeScope(defs, metricDef); const parentNodeHash = metricDef.parentNodeHashes.length ? metricDef.parentNodeHashes[0] diff --git a/src/app/records/Metrics.tsx b/src/app/records/Metrics.tsx index d91c385c7..49915331d 100644 --- a/src/app/records/Metrics.tsx +++ b/src/app/records/Metrics.tsx @@ -1,30 +1,20 @@ import BungieImage from 'app/dim-ui/BungieImage'; import { useD2Definitions } from 'app/manifest/selectors'; -import { TraitHashes } from 'data/d2/generated-enums'; -import { keyBy } from 'es-toolkit'; import Metric from './Metric'; import styles from './Metrics.m.scss'; -import { DimMetric } from './presentation-nodes'; +import { DimMetric, getMetricTimeScope } from './presentation-nodes'; export default function Metrics({ metrics }: { metrics: DimMetric[] }) { const defs = useD2Definitions()!; - const groupedMetrics = Object.groupBy( - metrics, - (metric) => metric.metricDef.traitHashes.find((h) => h !== TraitHashes.All)!, - ); - - const traits = keyBy( - Object.keys(groupedMetrics).map((th) => defs.Trait.get(Number(th))), - (t) => t.hash, - ); + const groupedMetrics = Map.groupBy(metrics, (m) => getMetricTimeScope(defs, m.metricDef)); return (
- {Object.entries(groupedMetrics).map(([traitHash, metrics]) => ( -
+ {[...groupedMetrics.entries()].map(([trait, metrics]) => ( +
- - {traits[Number(traitHash)].displayProperties.name} + + {trait.displayProperties.name}
{metrics.map((metric) => ( diff --git a/src/app/records/presentation-nodes.ts b/src/app/records/presentation-nodes.ts index c8cbf1015..1d684d5fc 100644 --- a/src/app/records/presentation-nodes.ts +++ b/src/app/records/presentation-nodes.ts @@ -27,7 +27,9 @@ import { DestinyRecordDefinition, DestinyRecordState, DestinyScope, + DestinyTraitDefinition, } from 'bungie-api-ts/destiny2'; +import { TraitHashes } from 'data/d2/generated-enums'; import { minBy } from 'es-toolkit'; import { unlockedItemsForCharacterOrProfilePlugSet } from './plugset-helpers'; @@ -609,6 +611,14 @@ export function getCollectibleState( : profileResponse.profileCollectibles?.data?.collectibles[collectibleDef.hash]?.state; } +export function getMetricTimeScope( + defs: D2ManifestDefinitions, + metric: DestinyMetricDefinition, +): DestinyTraitDefinition { + const traitHash = metric.traitHashes.find((h) => h !== TraitHashes.All); + return defs.Trait.get(traitHash ?? TraitHashes.All); +} + function getMetricComponent( metricDef: DestinyMetricDefinition, profileResponse: DestinyProfileResponse,