1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151import { useQuery } from "@tanstack/react-query";
import { useState } from "react";
import style from "./BlockersTableSummary.module.scss";
import * as API from "aws-amplify/api";
import { DataRow } from "./DataRow";
import { Card } from "./Card";
import { Page } from "#src/routes/Audit.tsx";
import { Pie, PieChart, ResponsiveContainer } from "recharts";
import themeVariables from "../global-styles/variables.module.scss";
import { SkeletonAuditHeader } from "./Skeleton";
//const apiClient = API.generateClient();
interface BlockersTableSummaryProps {
auditId: string;
isShared: boolean;
chartData: any;
pages: Page[]
}
interface SummaryRespCountItem {
"count": number,
"key": string
}
interface SummaryResp {
"mostCommonErrors": SummaryRespCountItem[],
"urlsWithBlockersCount": number,
"urlsWithMostErrors": SummaryRespCountItem[],
"mostCommonCategory": SummaryRespCountItem[],
"mostCommonTags": SummaryRespCountItem[]
}
export const BlockersTableSummary = ({ auditId, isShared, chartData, pages }: BlockersTableSummaryProps) => {
const [mostCommonUrlsLimit, setMostCommonUrlsLimit] = useState(5);
const [mostCommonBlockersLimit, setMostCommonBlockersLimit] = useState(5);
const [mostCommonCategoriesLimit, setMostCommonCategoriesLimit] = useState(3);
const [mostCommonTagsLimit, setMostCommonTagsLimit] = useState(3);
const { data, isLoading, error } = useQuery({
queryKey: [
"auditSummary"
],
queryFn: async () => {
const params: Record<string, string> = {
id: auditId,
mostCommonUrlsLimit: mostCommonUrlsLimit.toString(),
mostCommonBlockersLimit: mostCommonBlockersLimit.toString(),
mostCommonCategoriesLimit: mostCommonCategoriesLimit.toString(),
mostCommonTagsLimit: mostCommonTagsLimit.toString()
};
const response = await API.get({
apiName: isShared ? "public" : "auth",
path: "/getAuditSummary",
options: { queryParams: params },
}).response;
const resp = (await response.body.json()) as any as SummaryResp;
console.log(resp);
return resp;
}
});
return (
<div className={style.BlockersTableSummary}>
<h2>Audit Summary</h2>
{data ? (
<>
<div className="cards-50">
<Card>
<h2>{pages.length} of {data.urlsWithBlockersCount} URLs Have Blockers</h2>
<ResponsiveContainer width="100%" height={120}>
<PieChart>
<Pie
data={[
{
name: "URLs with Blockers",
value: data.urlsWithBlockersCount,
fill: themeVariables.white
},
{
name: "URLs without Blockers",
value: pages.length - data.urlsWithBlockersCount,
fill: themeVariables.black
},
]}
cx={60}
cy={60}
innerRadius={30}
outerRadius={40}
paddingAngle={0}
stroke="0"
dataKey="value"
>
</Pie>
</PieChart>
</ResponsiveContainer>
</Card>
<Card>
<h2>{chartData.data[chartData.data.length - 1].blockers.toLocaleString()}</h2> Blockers Found
</Card>
</div>
<div className="cards-50">
<Card variant="light">
<h2>URLs with Most Blockers</h2>
{data.urlsWithMostErrors.map((item, index) => {
return <DataRow
key={index}
the_value={item.key}
the_key={item.count.toString()} />
})}
</Card>
<Card variant="light">
<h2>Most Common Blockers</h2>
{data.mostCommonErrors.map((item, index) => {
return <DataRow
key={index}
the_value={item.key}
the_key={item.count.toString()} />
})}
</Card>
</div>
<div className="cards-50">
<Card variant="light">
<h2>Most Common Blocker Category</h2>
{data.mostCommonCategory.map((item, index) => {
return <DataRow
key={index}
the_value={item.key}
the_key={item.count.toString()} />
})}
</Card>
<Card variant="light">
<h2>Most Common Blocker Tag</h2>
{data.mostCommonTags.map((item, index) => {
return <DataRow
key={index}
the_value={item.key}
the_key={item.count.toString()} />
})}
</Card>
</div>
</>
) : (<><SkeletonAuditHeader/></>)}
</div >
);
};