Merge pull request #777 from acelaya-forks/feature/fix-visits-filters

Fixed bots filter getting reset when changing date
This commit is contained in:
Alejandro Celaya 2022-12-25 09:49:57 +01:00 committed by GitHub
commit 51283cc130
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 9 deletions

View file

@ -87,13 +87,11 @@ export const VisitsStats: FC<VisitsStatsProps> = ({
() => processStatsFromVisits(normalizedVisits), () => processStatsFromVisits(normalizedVisits),
[normalizedVisits], [normalizedVisits],
); );
const mapLocations = values(citiesForMap); const resolvedFilter = useMemo(() => ({
const resolvedFilter = useMemo(() => (
!isFirstLoad.current ? visitsFilter : {
...visitsFilter, ...visitsFilter,
excludeBots: visitsFilter.excludeBots ?? settings.visits?.excludeBots, excludeBots: visitsFilter.excludeBots ?? settings.visits?.excludeBots,
} }), [visitsFilter]);
), [visitsFilter]); const mapLocations = values(citiesForMap);
const setSelectedVisits = (selectedVisits: NormalizedVisit[]) => { const setSelectedVisits = (selectedVisits: NormalizedVisit[]) => {
selectedBar = undefined; selectedBar = undefined;

View file

@ -6,7 +6,7 @@ import { DateRange, datesToDateRange } from '../../utils/helpers/dateIntervals';
import { OrphanVisitType, VisitsFilter } from '../types'; import { OrphanVisitType, VisitsFilter } from '../types';
import { parseQuery, stringifyQuery } from '../../utils/helpers/query'; import { parseQuery, stringifyQuery } from '../../utils/helpers/query';
import { formatIsoDate } from '../../utils/helpers/date'; import { formatIsoDate } from '../../utils/helpers/date';
import { BooleanString } from '../../utils/utils'; import { BooleanString, parseBooleanToString } from '../../utils/utils';
interface VisitsQuery { interface VisitsQuery {
startDate?: string; startDate?: string;
@ -47,11 +47,12 @@ export const useVisitsQuery = (): [VisitsFiltering, UpdateFiltering] => {
); );
const updateFiltering = (extra: DeepPartial<VisitsFiltering>) => { const updateFiltering = (extra: DeepPartial<VisitsFiltering>) => {
const { dateRange, visitsFilter } = mergeDeepRight(filtering, extra); const { dateRange, visitsFilter } = mergeDeepRight(filtering, extra);
const { excludeBots, orphanVisitsType } = visitsFilter;
const query: VisitsQuery = { const query: VisitsQuery = {
startDate: (dateRange?.startDate && formatIsoDate(dateRange.startDate)) || '', startDate: (dateRange?.startDate && formatIsoDate(dateRange.startDate)) || '',
endDate: (dateRange?.endDate && formatIsoDate(dateRange.endDate)) || '', endDate: (dateRange?.endDate && formatIsoDate(dateRange.endDate)) || '',
excludeBots: visitsFilter.excludeBots ? 'true' : 'false', excludeBots: excludeBots === undefined ? undefined : parseBooleanToString(excludeBots),
orphanVisitsType: visitsFilter.orphanVisitsType, orphanVisitsType,
domain: theDomain, domain: theDomain,
}; };
const stringifiedQuery = stringifyQuery(query); const stringifiedQuery = stringifyQuery(query);