diff --git a/src/App.tsx b/src/App.tsx
index 3596401..013b79e 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -14,7 +14,7 @@ function App() {
element={
<>
-
+
>
}
/>
diff --git a/src/Charts.tsx b/src/Charts.tsx
index e17319a..ebae2d6 100644
--- a/src/Charts.tsx
+++ b/src/Charts.tsx
@@ -1,6 +1,6 @@
/* eslint-disable */
-import { FunctionComponent, useEffect, useState } from "react";
+import { FunctionComponent, useEffect, useState, useRef } from "react";
import "chart.js/auto"; // ADD THIS
import { Grid, Text } from "@mantine/core";
import {
@@ -19,15 +19,12 @@ export interface ChartsProps {
tickSpeed?: number;
}
-
const euClient: AxiosInstance = axios.create();
const usClient: AxiosInstance = axios.create();
const auClient: AxiosInstance = axios.create();
const client: AxiosInstance = axios.create();
-export const Charts: FunctionComponent = ({
- tickSpeed = 1000,
-}) => {
+export const Charts: FunctionComponent = (props) => {
const [latencyUs, setLatencyUs] = useState(0);
const [latencyEu, setLatencyEu] = useState(0);
const [latencyAu, setLatencyAu] = useState(0);
@@ -36,17 +33,13 @@ export const Charts: FunctionComponent = ({
const [revenuePerMinute, setRevenuePerMinute] = useState(0);
const [addToCartsPerMinute, setAddToCartsPerMinute] = useState(0);
+ const prevPurchaseStateRef = useRef(0);
+ const prevRevenueStateRef = useRef(0);
+ const prevAddToCartStateRef = useRef(0);
const [purchasesPerDay, setPurchasesPerDay] = useState(0);
const [revenuePerDay, setRevenuePerDay] = useState(0);
const [addToCartsPerDay, setAddToCartsPerDay] = useState(0);
- const [prevPurchasesPerDay, setPrevPurchasesPerDay] = useState(0);
- const [prevRevenuePerDay, setPrevRevenuePerDay] = useState(0);
- const [prevAddToCartsPerDay, setPrevAddToCartsPerDay] = useState(0);
-
- const [latency, setLatency] = useState>({});
-
-
const [animationTick, setAnimationTick] = useState(0);
const [query] = useQueryParams({
@@ -64,6 +57,18 @@ export const Charts: FunctionComponent = ({
}
}, [query.env, env])
+ useEffect(() => {
+ prevPurchaseStateRef.current = purchasesPerDay;
+ }, [purchasesPerDay]);
+
+ useEffect(() => {
+ prevRevenueStateRef.current = revenuePerDay;
+ }, [revenuePerDay]);
+
+ useEffect(() => {
+ prevAddToCartStateRef.current = addToCartsPerDay;
+ }, [addToCartsPerDay]);
+
function force(v: T | null | undefined, fallback: T): T {
return v !== null && v !== undefined ? v : fallback;
}
@@ -78,7 +83,7 @@ export const Charts: FunctionComponent = ({
var revenuePerDayAcrossRegions = 0;
var addToCartsPerDayAcrossRegions = 0;
- var arrayPromises = [];
+ var arrayPromises:any = [];
for (const regionConfig of envRegionMapping[query.env]) {
var currentdate = new Date();
var currentMinute = currentdate.getMinutes();
@@ -87,7 +92,10 @@ export const Charts: FunctionComponent = ({
currentdate.setMinutes(currentMinute - 1);
var currentDay = currentdate.toISOString().split('T')[0];
arrayPromises.push(await client
- .get(`${regionConfig.lambdaEndpoint}&timeBucket=${currentdate.toISOString()}&timeBucketType=minutely`));
+ .get(`${regionConfig.lambdaEndpoint}&timeBucket=${currentdate.toISOString()}&timeBucketType=minutely`).catch((e) => {
+ console.log("Caught an error calling the lambda", e);
+ return new Promise(() => { return {"data":[]}});
+ }));
arrayPromises.push(await client
.get(`${regionConfig.lambdaEndpoint}&timeBucket=${currentDay}&timeBucketType=daily`));
}
@@ -122,10 +130,6 @@ export const Charts: FunctionComponent = ({
setPurchasesPerMinute(purchasesPerMinuteAcrossRegions);
setRevenuePerMinute(revenuePerMinuteAcrossRegions);
setAddToCartsPerMinute(addToCartsPerMinuteAcrossRegions);
-
- setPrevPurchasesPerDay(purchasesPerDay);
- setPrevRevenuePerDay(revenuePerDay);
- setPrevAddToCartsPerDay(addToCartsPerDay);
setPurchasesPerDay(purchasesPerDayAcrossRegions);
setRevenuePerDay(revenuePerDayAcrossRegions);
@@ -135,7 +139,7 @@ export const Charts: FunctionComponent = ({
};
const getUsEvents = async () => {
const events = await usClient
- .get(`${LambdaURLUsEast}&last=${tickSpeed}`)
+ .get(`${LambdaURLUsEast}&last=${props.tickSpeed}`)
.then((res) => res.data)
.catch((e) => {
console.log(e);
@@ -163,7 +167,7 @@ export const Charts: FunctionComponent = ({
const getEuEvents = async () => {
const events = await euClient
- .get(`${LambdaURLEU}&last=${tickSpeed}`)
+ .get(`${LambdaURLEU}&last=${props.tickSpeed}`)
.then((res) => res.data)
.catch((e) => {
console.log(e);
@@ -191,7 +195,7 @@ export const Charts: FunctionComponent = ({
const getAuEvents = async () => {
const events = await auClient
- .get(`${LambdaURLAu}&last=${tickSpeed}`)
+ .get(`${LambdaURLAu}&last=${props.tickSpeed}`)
.then((res) => res.data)
.catch((e) => {
console.log(e);
@@ -231,7 +235,7 @@ export const Charts: FunctionComponent = ({
useEffect(() => {
const timeout = setInterval(async () => {
await emitData();
- }, tickSpeed);
+ }, props.tickSpeed);
return () => {
clearInterval(timeout);
};
@@ -272,7 +276,7 @@ export const Charts: FunctionComponent = ({
Total sales today (USD)
= ({
Total add to cart today
= ({
Total transactions today
= ({
left: 0
}}>
Latency
- <>
- {Object.entries(latency).map(([key, value]) => {
- return {value.toString()} seconds
- })}
- >
-