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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189import { QueryClient, useQuery } from '@tanstack/react-query';
import { ColumnDef } from '@tanstack/react-table';
import { Link, LoaderFunctionArgs, useLoaderData } from 'react-router-dom';
import Timeline from '~/components/charts/timeline';
import { SEO } from '~/components/layout';
import { DataTable } from '~/components/tables';
import { reportDetailsQuery } from '~/queries';
import { getApikey } from '~/services';
import { assertNonNull } from '~/utils/safety';
interface Message {
id: string;
messageId: number;
title: string;
activeCount: number;
}
interface Page {
id: string;
pageId: number;
url: string;
occurrencesActive: number;
}
interface Tag {
id: string;
tagId: number;
name: string;
referenceCount: number;
}
/**
* Loader function to fetch reports details
* @param queryClient - The Query Client instance.
* @returns Loader function to be used with React Router.
*/
export const reportDetailsLoader =
(queryClient: QueryClient) =>
async ({ params }: LoaderFunctionArgs) => {
assertNonNull(
params.reportId,
'Report ID is missing in the route parameters',
);
const initialReportDetail = await queryClient.ensureQueryData(
reportDetailsQuery(params.reportId),
);
return { initialReportDetail, reportId: params.reportId };
};
const ReportDetails = () => {
const { initialReportDetail, reportId } = useLoaderData() as Awaited<
ReturnType<ReturnType<typeof reportDetailsLoader>>
>;
const { data: details, error } = useQuery({
...reportDetailsQuery(reportId!),
initialData: initialReportDetail,
});
if (error) return <div role="alert">Error loading report details.</div>;
const {
urls: pagesData,
messages: messagesData,
tags: tagsData,
reportName,
chart,
} = details;
const messageColumns: ColumnDef<Message>[] = [
{
accessorKey: 'message',
header: 'Message',
cell: ({ row }) => (
<Link
to={`/reports/${reportId}/messages/${row.original.id}`}
className="underline"
>
{row.getValue('message')}
</Link>
),
},
{ accessorKey: 'equalifiedCount', header: 'Equalified' },
{ accessorKey: 'activeCount', header: 'Active' },
{ accessorKey: 'totalCount', header: 'Total' },
];
const tagColumns: ColumnDef<Tag>[] = [
{
accessorKey: 'tag',
header: 'Tag',
cell: ({ row }) => (
<Link
to={`/reports/${reportId}/tags/${row.original.id}`}
className="underline"
>
{row.getValue('tag')}
</Link>
),
},
// { accessorKey: 'referenceCount', header: 'Occurrences' },
];
const pageColumns: ColumnDef<Page>[] = [
{
accessorKey: 'url',
header: 'URL',
cell: ({ row }) => (
<Link
to={`/reports/${reportId}/pages/${row.original.id}`}
className="underline"
>
{row.getValue('url')}
</Link>
),
},
// { accessorKey: 'occurrencesActive', header: 'Active' },
];
const { data: apikey } = useQuery({
queryKey: ['apikey'],
queryFn: () => getApikey(),
})
return (
<div className="space-y-4">
<SEO
title={`${reportName} - Report Details - Equalify`}
description={`View the details of the ${reportName} report, including messages, pages, and tags, on Equalify.`}
url={`https://dashboard.equalify.app/reports/${reportId}`}
/>
<div className="flex w-full flex-col-reverse justify-between sm:flex-row sm:items-center">
<h1
id="report-details-heading"
className="text-2xl font-bold md:text-3xl"
>
{reportName}
</h1>
<div className='flex flex-row items-center gap-2'>
{apikey?.isAdmin && <a target='_blank'
href={`https://api.equalify.app/admin/clear-cache?apikey=${apikey?.apikey}`}
className="inline-flex h-9 items-center justify-end place-self-end whitespace-nowrap rounded-md bg-[#005031] px-4 py-3 text-base text-white shadow transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[#1D781D] focus-visible:ring-offset-2 max-sm:w-fit max-sm:px-3 max-sm:py-2.5"
>
<span aria-hidden="true">Manually Clear Cache</span>
</a>}
<a target='_blank'
href={`https://api.equalify.app/get/results/csv?reportId=${reportId}&apikey=${apikey?.apikey}`}
className="inline-flex h-9 items-center justify-end place-self-end whitespace-nowrap rounded-md bg-[#005031] px-4 py-3 text-base text-white shadow transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[#1D781D] focus-visible:ring-offset-2 max-sm:w-fit max-sm:px-3 max-sm:py-2.5"
>
<span className="sr-only">{`Download ${reportName} Report`}</span>
<span aria-hidden="true">Download CSV</span>
</a>
<Link
to={`/reports/${reportId}/edit`}
className="inline-flex h-9 items-center justify-end place-self-end whitespace-nowrap rounded-md bg-[#005031] px-4 py-3 text-base text-white shadow transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[#1D781D] focus-visible:ring-offset-2 max-sm:w-fit max-sm:px-3 max-sm:py-2.5"
>
<span className="sr-only">{`Edit ${reportName} Report`}</span>
<span aria-hidden="true">Edit Report</span>
</Link>
</div>
</div>
<div className="rounded-lg bg-white p-4 shadow md:p-8">
<Timeline data={chart} />
</div>
<div className="overflow-x-auto rounded-lg bg-white p-4 shadow">
<DataTable
columns={messageColumns}
data={messagesData}
type="messages"
/>
</div>
<div className="flex flex-col gap-4 md:flex-row">
<div className="w-full overflow-x-auto rounded-lg bg-white p-4 shadow lg:w-1/2">
<DataTable columns={tagColumns} data={tagsData} type="tags" />
</div>
<div className="w-full overflow-x-auto rounded-lg bg-white p-4 shadow lg:w-1/2">
<DataTable columns={pageColumns} data={pagesData} type="pages" />
</div>
</div>
</div>
);
};
export default ReportDetails;