Skip to content

Commit

Permalink
feat:(UA-9616): Support purchases per country daily metric
Browse files Browse the repository at this point in the history
  • Loading branch information
rphilippen committed Dec 13, 2024
1 parent e7995e7 commit 56502f6
Show file tree
Hide file tree
Showing 5 changed files with 310 additions and 246 deletions.
8 changes: 6 additions & 2 deletions src/AnimatedGlobe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
envRegionMapping,
LiveEvent,
CoveoEnvironment,
RealTimeMetricsResponse,
} from "./Events";
import { uniqBy } from "lodash";
import * as THREE from "three";
Expand Down Expand Up @@ -55,6 +56,9 @@ interface AnimatedGlobeProps {
env: CoveoEnvironment;
}

// Normalize the response until the lambda is updated everywhere.
const normalizeResponse = (response: RealTimeMetricsResponse | LiveEvent[]) => Array.isArray(response) ? response : response.items;

export const AnimatedGlobe: FunctionComponent<AnimatedGlobeProps> = ({
renderRings,
renderArcs,
Expand Down Expand Up @@ -83,9 +87,9 @@ export const AnimatedGlobe: FunctionComponent<AnimatedGlobeProps> = ({
const emitArc = async () => {
const resTotal = new Map<ValidRegions, LiveEvent[]>();
for (const regionConfig of envRegionMapping[env]) {
const liveEventFetcher: LiveEvent[] = (await (
const liveEventFetcher: LiveEvent[] = normalizeResponse(await (
await fetch(`${regionConfig.lambdaEndpoint}&last=${tickSpeed}`)
).json()) as LiveEvent[];
).json());
resTotal.set(regionConfig.region, liveEventFetcher);
}

Expand Down
Loading

0 comments on commit 56502f6

Please sign in to comment.