Merge pull request #3306 from harryo/bugfix/other-domain-groups

Fix counting _other domain groups
This commit is contained in:
Mike Cao 2025-03-24 20:20:55 -07:00 committed by GitHub
commit bc2518a369
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -60,19 +60,24 @@ export function ReferrersTable({ allowFilter, ...props }: ReferrersTableProps) {
);
};
const getDomain = (x: string) => {
for (const { domain, match } of GROUPED_DOMAINS) {
if (Array.isArray(match) ? match.some(str => x.includes(str)) : x.includes(match)) {
return domain;
}
}
return '_other';
};
const groupedFilter = (data: any[]) => {
const groups = { _other: 0 };
for (const { x, y } of data) {
for (const { domain, match } of GROUPED_DOMAINS) {
if (Array.isArray(match) ? match.some(str => x.includes(str)) : x.includes(match)) {
if (!groups[domain]) {
groups[domain] = 0;
}
groups[domain] += +y;
}
const domain = getDomain(x);
if (!groups[domain]) {
groups[domain] = 0;
}
groups._other += +y;
groups[domain] += +y;
}
return Object.keys(groups)