From affe2309b067f1baaf12f4f9f0287fedec8dd647 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 22 Jun 2021 21:01:20 +0200 Subject: [PATCH] Ensured filter for bots does not show for Shlink older than 2.7.0 --- src/visits/VisitsStats.tsx | 3 +++ src/visits/helpers/VisitsFilterDropdown.tsx | 22 +++++++++++++------ test/short-urls/EditShortUrl.test.tsx | 2 +- test/short-urls/ShortUrlForm.test.tsx | 2 +- .../helpers/VisitsFilterDropdown.test.tsx | 20 ++++++++++++++++- 5 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/visits/VisitsStats.tsx b/src/visits/VisitsStats.tsx index f0cad255..feb354f1 100644 --- a/src/visits/VisitsStats.tsx +++ b/src/visits/VisitsStats.tsx @@ -16,6 +16,7 @@ import { Result } from '../utils/Result'; import { ShlinkApiError } from '../api/ShlinkApiError'; import { Settings } from '../settings/reducers/settings'; import { SelectedServer } from '../servers/data'; +import { supportsBotVisits } from '../utils/helpers/features'; import SortableBarGraph from './helpers/SortableBarGraph'; import GraphCard from './helpers/GraphCard'; import LineChartCard from './helpers/LineChartCard'; @@ -86,6 +87,7 @@ const VisitsStats: FC = ({ const [ highlightedVisits, setHighlightedVisits ] = useState([]); const [ highlightedLabel, setHighlightedLabel ] = useState(); const [ visitsFilter, setVisitsFilter ] = useState({}); + const botsSupported = supportsBotVisits(selectedServer); const buildSectionUrl = (subPath?: string) => { const query = domain ? `?domain=${domain}` : ''; @@ -282,6 +284,7 @@ const VisitsStats: FC = ({ diff --git a/src/visits/helpers/VisitsFilterDropdown.tsx b/src/visits/helpers/VisitsFilterDropdown.tsx index 85e46869..6cbdcdc9 100644 --- a/src/visits/helpers/VisitsFilterDropdown.tsx +++ b/src/visits/helpers/VisitsFilterDropdown.tsx @@ -13,28 +13,36 @@ interface VisitsFilterDropdownProps { selected?: VisitsFilter; className?: string; isOrphanVisits: boolean; + botsSupported: boolean; } export const VisitsFilterDropdown = ( - { onChange, selected = {}, className, isOrphanVisits }: VisitsFilterDropdownProps, + { onChange, selected = {}, className, isOrphanVisits, botsSupported }: VisitsFilterDropdownProps, ) => { + if (!botsSupported && !isOrphanVisits) { + return null; + } + const { orphanVisitsType, excludeBots = false } = selected; const propsForOrphanVisitsTypeItem = (type: OrphanVisitType): DropdownItemProps => ({ active: orphanVisitsType === type, onClick: () => onChange({ ...selected, orphanVisitsType: type }), }); + const onBotsClick = () => onChange({ ...selected, excludeBots: !selected?.excludeBots }); return ( - Bots: - onChange({ ...selected, excludeBots: !selected?.excludeBots })}> - Exclude potential bots - + {botsSupported && ( + <> + Bots: + Exclude potential bots + + )} + + {botsSupported && isOrphanVisits && } {isOrphanVisits && ( <> - - Orphan visits type: Base URL Invalid short URL diff --git a/test/short-urls/EditShortUrl.test.tsx b/test/short-urls/EditShortUrl.test.tsx index 2522cfee..51243bf7 100644 --- a/test/short-urls/EditShortUrl.test.tsx +++ b/test/short-urls/EditShortUrl.test.tsx @@ -14,7 +14,7 @@ describe('', () => { const ShortUrlForm = () => null; const goBack = jest.fn(); const getShortUrlDetail = jest.fn(); - const editShortUrl = jest.fn(); + const editShortUrl = jest.fn(async () => Promise.resolve()); const shortUrlCreation = { validateUrls: true }; const createWrapper = (detail: Partial = {}, edition: Partial = {}) => { const EditSHortUrl = createEditShortUrl(ShortUrlForm); diff --git a/test/short-urls/ShortUrlForm.test.tsx b/test/short-urls/ShortUrlForm.test.tsx index b5b9dc6d..7fca5360 100644 --- a/test/short-urls/ShortUrlForm.test.tsx +++ b/test/short-urls/ShortUrlForm.test.tsx @@ -12,7 +12,7 @@ import { SimpleCard } from '../../src/utils/SimpleCard'; describe('', () => { let wrapper: ShallowWrapper; const TagsSelector = () => null; - const createShortUrl = jest.fn(); + const createShortUrl = jest.fn(async () => Promise.resolve()); const createWrapper = (selectedServer: SelectedServer = null, mode: Mode = 'create') => { const ShortUrlForm = createShortUrlForm(TagsSelector, () => null); diff --git a/test/visits/helpers/VisitsFilterDropdown.test.tsx b/test/visits/helpers/VisitsFilterDropdown.test.tsx index a947eb31..9476ac9c 100644 --- a/test/visits/helpers/VisitsFilterDropdown.test.tsx +++ b/test/visits/helpers/VisitsFilterDropdown.test.tsx @@ -8,7 +8,12 @@ describe('', () => { const onChange = jest.fn(); const createWrapper = (selected: VisitsFilter = {}, isOrphanVisits = true) => { wrapper = shallow( - , + , ); return wrapper; @@ -68,4 +73,17 @@ describe('', () => { expect(onChange).toHaveBeenCalledWith(expectedSelection); }); + + it('does not render the component when neither orphan visits or bots filtering will be displayed', () => { + const wrapper = shallow( + , + ); + + expect(wrapper.text()).toEqual(''); + }); });