visits.redu
);
export const normalizeVisits = map((visit: Visit): NormalizedVisit => {
- const { userAgent, date, referer, visitLocation } = visit;
+ const { userAgent, date, referer, visitLocation, potentialBot = false } = visit;
const common = {
date,
+ potentialBot,
...parseUserAgent(userAgent),
referer: extractDomain(referer),
country: visitLocation?.countryName || 'Unknown', // eslint-disable-line @typescript-eslint/prefer-nullish-coalescing
diff --git a/src/visits/services/provideServices.ts b/src/visits/services/provideServices.ts
index 733cac95..9eb3f5eb 100644
--- a/src/visits/services/provideServices.ts
+++ b/src/visits/services/provideServices.ts
@@ -18,19 +18,19 @@ const provideServices = (bottle: Bottle, connect: ConnectDecorator) => {
bottle.serviceFactory('ShortUrlVisits', ShortUrlVisits, 'VisitsExporter');
bottle.decorator('ShortUrlVisits', connect(
- [ 'shortUrlVisits', 'shortUrlDetail', 'mercureInfo', 'settings' ],
+ [ 'shortUrlVisits', 'shortUrlDetail', 'mercureInfo', 'settings', 'selectedServer' ],
[ 'getShortUrlVisits', 'getShortUrlDetail', 'cancelGetShortUrlVisits', 'createNewVisits', 'loadMercureInfo' ],
));
bottle.serviceFactory('TagVisits', TagVisits, 'ColorGenerator', 'VisitsExporter');
bottle.decorator('TagVisits', connect(
- [ 'tagVisits', 'mercureInfo', 'settings' ],
+ [ 'tagVisits', 'mercureInfo', 'settings', 'selectedServer' ],
[ 'getTagVisits', 'cancelGetTagVisits', 'createNewVisits', 'loadMercureInfo' ],
));
bottle.serviceFactory('OrphanVisits', OrphanVisits, 'VisitsExporter');
bottle.decorator('OrphanVisits', connect(
- [ 'orphanVisits', 'mercureInfo', 'settings' ],
+ [ 'orphanVisits', 'mercureInfo', 'settings', 'selectedServer' ],
[ 'getOrphanVisits', 'cancelGetOrphanVisits', 'createNewVisits', 'loadMercureInfo' ],
));
diff --git a/src/visits/types/CommonVisitsProps.ts b/src/visits/types/CommonVisitsProps.ts
new file mode 100644
index 00000000..7e5a21b4
--- /dev/null
+++ b/src/visits/types/CommonVisitsProps.ts
@@ -0,0 +1,7 @@
+import { SelectedServer } from '../../servers/data';
+import { Settings } from '../../settings/reducers/settings';
+
+export interface CommonVisitsProps {
+ selectedServer: SelectedServer;
+ settings: Settings;
+}
diff --git a/src/visits/types/index.ts b/src/visits/types/index.ts
index 0e2879d5..ffaccb47 100644
--- a/src/visits/types/index.ts
+++ b/src/visits/types/index.ts
@@ -38,6 +38,7 @@ export interface RegularVisit {
date: string;
userAgent: string;
visitLocation: VisitLocation | null;
+ potentialBot?: boolean; // Optional only when using Shlink older than v2.7
}
export interface OrphanVisit extends RegularVisit {
@@ -59,6 +60,7 @@ export interface NormalizedRegularVisit extends UserAgent {
city: string;
latitude?: number | null;
longitude?: number | null;
+ potentialBot: boolean;
}
export interface NormalizedOrphanVisit extends NormalizedRegularVisit {
diff --git a/test/visits/VisitsTable.test.tsx b/test/visits/VisitsTable.test.tsx
index 393ab64d..65c71992 100644
--- a/test/visits/VisitsTable.test.tsx
+++ b/test/visits/VisitsTable.test.tsx
@@ -5,6 +5,7 @@ import { rangeOf } from '../../src/utils/utils';
import SimplePaginator from '../../src/common/SimplePaginator';
import SearchField from '../../src/utils/SearchField';
import { NormalizedVisit } from '../../src/visits/types';
+import { SelectedServer } from '../../src/servers/data';
describe('', () => {
const matchMedia = () => Mock.of({ matches: false });
@@ -18,6 +19,7 @@ describe('', () => {
setSelectedVisits={setSelectedVisits}
matchMedia={matchMedia}
isOrphanVisits={isOrphanVisits}
+ selectedServer={Mock.all()}
/>,
);
diff --git a/test/visits/services/VisitsParser.test.ts b/test/visits/services/VisitsParser.test.ts
index 7edafab8..d629985e 100644
--- a/test/visits/services/VisitsParser.test.ts
+++ b/test/visits/services/VisitsParser.test.ts
@@ -43,6 +43,7 @@ describe('VisitsParser', () => {
}),
Mock.of({
userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36 OPR/38.0.2220.41',
+ potentialBot: true,
}),
];
const orphanVisits: OrphanVisit[] = [
@@ -61,6 +62,7 @@ describe('VisitsParser', () => {
Mock.of({
type: 'regular_404',
visitedUrl: 'bar',
+ potentialBot: true,
}),
Mock.of({
type: 'invalid_short_url',
@@ -73,6 +75,7 @@ describe('VisitsParser', () => {
latitude: 123.45,
longitude: -543.21,
},
+ potentialBot: false,
}),
];
@@ -176,6 +179,7 @@ describe('VisitsParser', () => {
date: undefined,
latitude: 123.45,
longitude: -543.21,
+ potentialBot: false,
},
{
browser: 'Firefox',
@@ -186,6 +190,7 @@ describe('VisitsParser', () => {
date: undefined,
latitude: 1029,
longitude: 6758,
+ potentialBot: false,
},
{
browser: 'Chrome',
@@ -196,6 +201,7 @@ describe('VisitsParser', () => {
date: undefined,
latitude: undefined,
longitude: undefined,
+ potentialBot: false,
},
{
browser: 'Chrome',
@@ -206,6 +212,7 @@ describe('VisitsParser', () => {
date: undefined,
latitude: 123.45,
longitude: -543.21,
+ potentialBot: false,
},
{
browser: 'Opera',
@@ -216,6 +223,7 @@ describe('VisitsParser', () => {
date: undefined,
latitude: undefined,
longitude: undefined,
+ potentialBot: true,
},
]);
});
@@ -233,6 +241,7 @@ describe('VisitsParser', () => {
longitude: 6758,
type: 'base_url',
visitedUrl: 'foo',
+ potentialBot: false,
},
{
type: 'regular_404',
@@ -245,6 +254,7 @@ describe('VisitsParser', () => {
longitude: undefined,
os: 'Others',
referer: 'Direct',
+ potentialBot: true,
},
{
browser: 'Chrome',
@@ -257,6 +267,7 @@ describe('VisitsParser', () => {
longitude: -543.21,
type: 'invalid_short_url',
visitedUrl: 'bar',
+ potentialBot: false,
},
]);
});