Ensured bots exclusion is selected by default in visits filter dropdown, if it was selected in settings

This commit is contained in:
Alejandro Celaya 2022-12-23 10:07:23 +01:00
parent 5942cd6fcf
commit 80cea91339
2 changed files with 12 additions and 6 deletions

View file

@ -93,6 +93,12 @@ export const VisitsStats: FC<VisitsStatsProps> = ({
[normalizedVisits],
);
const mapLocations = values(citiesForMap);
const resolvedFilter = useMemo(() => (
!isFirstLoad.current ? visitsFilter : {
...visitsFilter,
excludeBots: visitsFilter.excludeBots ?? settings.visits?.excludeBots,
}
), [visitsFilter]);
const setSelectedVisits = (selectedVisits: NormalizedVisit[]) => {
selectedBar = undefined;
@ -115,7 +121,7 @@ export const VisitsStats: FC<VisitsStatsProps> = ({
useEffect(() => cancelGetVisits, []);
useEffect(() => {
const resolvedDateRange = !isFirstLoad.current ? dateRange : (dateRange ?? toDateRange(initialInterval.current));
getVisits({ dateRange: resolvedDateRange, filter: visitsFilter }, isFirstLoad.current);
getVisits({ dateRange: resolvedDateRange, filter: resolvedFilter }, isFirstLoad.current);
isFirstLoad.current = false;
}, [dateRange, visitsFilter]);
useEffect(() => {
@ -301,7 +307,7 @@ export const VisitsStats: FC<VisitsStatsProps> = ({
className="ms-0 ms-md-2 mt-3 mt-md-0"
isOrphanVisits={isOrphanVisits}
botsSupported={botsSupported}
selected={visitsFilter}
selected={resolvedFilter}
onChange={(newVisitsFilter) => updateFiltering({ visitsFilter: newVisitsFilter })}
/>
</div>

View file

@ -1,7 +1,7 @@
import { DeepPartial } from '@reduxjs/toolkit';
import { useLocation, useNavigate } from 'react-router-dom';
import { useMemo } from 'react';
import { isEmpty, mergeDeepRight, pipe } from 'ramda';
import { isEmpty, isNil, mergeDeepRight, pipe } from 'ramda';
import { DateRange, datesToDateRange } from '../../utils/helpers/dateIntervals';
import { OrphanVisitType, VisitsFilter } from '../types';
import { parseQuery, stringifyQuery } from '../../utils/helpers/query';
@ -11,7 +11,7 @@ interface VisitsQuery {
startDate?: string;
endDate?: string;
orphanVisitsType?: OrphanVisitType;
excludeBots?: 'true';
excludeBots?: 'true' | 'false';
domain?: string;
}
@ -38,7 +38,7 @@ export const useVisitsQuery = (): [VisitsFiltering, UpdateFiltering] => {
domain,
filtering: {
dateRange: startDate != null || endDate != null ? datesToDateRange(startDate, endDate) : undefined,
visitsFilter: { orphanVisitsType, excludeBots: excludeBots === 'true' },
visitsFilter: { orphanVisitsType, excludeBots: !isNil(excludeBots) ? excludeBots === 'true' : undefined },
},
}),
),
@ -49,7 +49,7 @@ export const useVisitsQuery = (): [VisitsFiltering, UpdateFiltering] => {
const query: VisitsQuery = {
startDate: (dateRange?.startDate && formatIsoDate(dateRange.startDate)) || '',
endDate: (dateRange?.endDate && formatIsoDate(dateRange.endDate)) || '',
excludeBots: visitsFilter.excludeBots ? 'true' : undefined,
excludeBots: visitsFilter.excludeBots ? 'true' : 'false',
orphanVisitsType: visitsFilter.orphanVisitsType,
domain: theDomain,
};