From 815e06809a3a6da90e145e8bef4485dd10e20e2f Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 23 Dec 2022 20:42:47 +0100 Subject: [PATCH] Removed references to feature checks for version 2.8 --- src/common/AsideMenu.tsx | 12 +++------ src/common/MenuLayout.tsx | 5 ++-- src/short-urls/helpers/QrCodeModal.tsx | 26 ++++++++------------ src/utils/helpers/features.ts | 2 -- src/utils/helpers/qrCodes.ts | 14 ++--------- test/common/AsideMenu.test.tsx | 16 +++++------- test/common/MenuLayout.test.tsx | 1 - test/short-urls/helpers/QrCodeModal.test.tsx | 23 +++++++---------- 8 files changed, 33 insertions(+), 66 deletions(-) diff --git a/src/common/AsideMenu.tsx b/src/common/AsideMenu.tsx index f7c81965..2e36c27a 100644 --- a/src/common/AsideMenu.tsx +++ b/src/common/AsideMenu.tsx @@ -12,7 +12,6 @@ import { NavLink, NavLinkProps, useLocation } from 'react-router-dom'; import classNames from 'classnames'; import { DeleteServerButtonProps } from '../servers/DeleteServerButton'; import { isServerWithId, SelectedServer } from '../servers/data'; -import { supportsDomainRedirects } from '../utils/helpers/features'; import './AsideMenu.scss'; export interface AsideMenuProps { @@ -40,7 +39,6 @@ export const AsideMenu = (DeleteServerButton: FC) => ( const hasId = isServerWithId(selectedServer); const serverId = hasId ? selectedServer.id : ''; const { pathname } = useLocation(); - const addManageDomainsLink = supportsDomainRedirects(selectedServer); const asideClass = classNames('aside-menu', { 'aside-menu--hidden': !showOnMobile, }); @@ -68,12 +66,10 @@ export const AsideMenu = (DeleteServerButton: FC) => ( Manage tags - {addManageDomainsLink && ( - - - Manage domains - - )} + + + Manage domains + Edit this server diff --git a/src/common/MenuLayout.tsx b/src/common/MenuLayout.tsx index 03de8768..0fc05448 100644 --- a/src/common/MenuLayout.tsx +++ b/src/common/MenuLayout.tsx @@ -5,7 +5,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import classNames from 'classnames'; import { withSelectedServer } from '../servers/helpers/withSelectedServer'; import { useSwipeable, useToggle } from '../utils/helpers/hooks'; -import { supportsDomainRedirects, supportsDomainVisits, supportsNonOrphanVisits } from '../utils/helpers/features'; +import { supportsDomainVisits, supportsNonOrphanVisits } from '../utils/helpers/features'; import { isReachableServer } from '../servers/data'; import { NotFound } from './NotFound'; import { AsideMenuProps } from './AsideMenu'; @@ -47,7 +47,6 @@ export const MenuLayout = ( } const addNonOrphanVisitsRoute = supportsNonOrphanVisits(selectedServer); - const addManageDomainsRoute = supportsDomainRedirects(selectedServer); const addDomainVisitsRoute = supportsDomainVisits(selectedServer); const burgerClasses = classNames('menu-layout__burger-icon', { 'menu-layout__burger-icon--active': sidebarVisible }); const swipeableProps = useSwipeable(showSidebar, hideSidebar); @@ -73,7 +72,7 @@ export const MenuLayout = ( } /> {addNonOrphanVisitsRoute && } />} } /> - {addManageDomainsRoute && } />} + } /> List short URLs} diff --git a/src/short-urls/helpers/QrCodeModal.tsx b/src/short-urls/helpers/QrCodeModal.tsx index ac971806..f4bda9eb 100644 --- a/src/short-urls/helpers/QrCodeModal.tsx +++ b/src/short-urls/helpers/QrCodeModal.tsx @@ -6,8 +6,8 @@ import { ExternalLink } from 'react-external-link'; import { ShortUrlModalProps } from '../data'; import { SelectedServer } from '../../servers/data'; import { CopyToClipboardIcon } from '../../utils/CopyToClipboardIcon'; -import { buildQrCodeUrl, QrCodeCapabilities, QrCodeFormat, QrErrorCorrection } from '../../utils/helpers/qrCodes'; -import { supportsNonRestCors, supportsQrErrorCorrection } from '../../utils/helpers/features'; +import { buildQrCodeUrl, QrCodeFormat, QrErrorCorrection } from '../../utils/helpers/qrCodes'; +import { supportsNonRestCors } from '../../utils/helpers/features'; import { ImageDownloader } from '../../common/services/ImageDownloader'; import { QrFormatDropdown } from './qr-codes/QrFormatDropdown'; import { QrErrorCorrectionDropdown } from './qr-codes/QrErrorCorrectionDropdown'; @@ -24,14 +24,10 @@ export const QrCodeModal = (imageDownloader: ImageDownloader) => ( const [margin, setMargin] = useState(0); const [format, setFormat] = useState('png'); const [errorCorrection, setErrorCorrection] = useState('L'); - const capabilities: QrCodeCapabilities = useMemo(() => ({ - errorCorrectionIsSupported: supportsQrErrorCorrection(selectedServer), - }), [selectedServer]); const displayDownloadBtn = supportsNonRestCors(selectedServer); - const willRenderThreeControls = !capabilities.errorCorrectionIsSupported; const qrCodeUrl = useMemo( - () => buildQrCodeUrl(shortUrl, { size, format, margin, errorCorrection }, capabilities), - [shortUrl, size, format, margin, errorCorrection, capabilities], + () => buildQrCodeUrl(shortUrl, { size, format, margin, errorCorrection }), + [shortUrl, size, format, margin, errorCorrection], ); const totalSize = useMemo(() => size + margin, [size, margin]); const modalSize = useMemo(() => { @@ -49,7 +45,7 @@ export const QrCodeModal = (imageDownloader: ImageDownloader) => ( - + ( onChange={(e) => setSize(Number(e.target.value))} /> - + ( onChange={(e) => setMargin(Number(e.target.value))} /> - + - {capabilities.errorCorrectionIsSupported && ( - - - - )} + + +
diff --git a/src/utils/helpers/features.ts b/src/utils/helpers/features.ts index 90f81a51..bfc71866 100644 --- a/src/utils/helpers/features.ts +++ b/src/utils/helpers/features.ts @@ -6,8 +6,6 @@ const serverMatchesMinVersion = (minVersion: SemVerPattern) => (selectedServer: export const supportsBotVisits = serverMatchesMinVersion('2.7.0'); export const supportsCrawlableVisits = supportsBotVisits; -export const supportsQrErrorCorrection = serverMatchesMinVersion('2.8.0'); -export const supportsDomainRedirects = supportsQrErrorCorrection; export const supportsForwardQuery = serverMatchesMinVersion('2.9.0'); export const supportsNonRestCors = supportsForwardQuery; export const supportsDefaultDomainRedirectsEdition = serverMatchesMinVersion('2.10.0'); diff --git a/src/utils/helpers/qrCodes.ts b/src/utils/helpers/qrCodes.ts index 85feb888..2e66d676 100644 --- a/src/utils/helpers/qrCodes.ts +++ b/src/utils/helpers/qrCodes.ts @@ -1,10 +1,6 @@ import { isEmpty } from 'ramda'; import { stringifyQuery } from './query'; -export interface QrCodeCapabilities { - errorCorrectionIsSupported: boolean; -} - export type QrCodeFormat = 'svg' | 'png'; export type QrErrorCorrection = 'L' | 'M' | 'Q' | 'H'; @@ -16,17 +12,11 @@ export interface QrCodeOptions { errorCorrection: QrErrorCorrection; } -export const buildQrCodeUrl = ( - shortUrl: string, - { size, format, margin, errorCorrection }: QrCodeOptions, - { errorCorrectionIsSupported }: QrCodeCapabilities, -): string => { +export const buildQrCodeUrl = (shortUrl: string, { margin, ...options }: QrCodeOptions): string => { const baseUrl = `${shortUrl}/qr-code`; const query = stringifyQuery({ - size, - format, + ...options, margin: margin > 0 ? margin : undefined, - errorCorrection: errorCorrectionIsSupported ? errorCorrection : undefined, }); return `${baseUrl}${isEmpty(query) ? '' : `?${query}`}`; diff --git a/test/common/AsideMenu.test.tsx b/test/common/AsideMenu.test.tsx index df49244e..6874053d 100644 --- a/test/common/AsideMenu.test.tsx +++ b/test/common/AsideMenu.test.tsx @@ -3,26 +3,22 @@ import { Mock } from 'ts-mockery'; import { MemoryRouter } from 'react-router-dom'; import { AsideMenu as createAsideMenu } from '../../src/common/AsideMenu'; import { ReachableServer } from '../../src/servers/data'; -import { SemVer } from '../../src/utils/helpers/version'; describe('', () => { const AsideMenu = createAsideMenu(() => <>DeleteServerButton); - const setUp = (version: SemVer, id: string | false = 'abc123') => render( + const setUp = (id: string | false = 'abc123') => render( - ({ id: id || undefined, version })} /> + ({ id: id || undefined, version: '2.8.0' })} /> , ); - it.each([ - ['2.7.0' as SemVer, 5], - ['2.8.0' as SemVer, 6], - ])('contains links to different sections', (version, expectedAmountOfLinks) => { - setUp(version); + it('contains links to different sections', () => { + setUp(); const links = screen.getAllByRole('link'); expect.assertions(links.length + 1); - expect(links).toHaveLength(expectedAmountOfLinks); + expect(links).toHaveLength(6); links.forEach((link) => expect(link.getAttribute('href')).toContain('abc123')); }); @@ -30,7 +26,7 @@ describe('', () => { ['abc', true], [false, false], ])('contains a button to delete server if appropriate', (id, shouldHaveBtn) => { - setUp('2.8.0', id as string | false); + setUp(id as string | false); if (shouldHaveBtn) { expect(screen.getByText('DeleteServerButton')).toBeInTheDocument(); diff --git a/test/common/MenuLayout.test.tsx b/test/common/MenuLayout.test.tsx index 7fefe3fc..e2ebc468 100644 --- a/test/common/MenuLayout.test.tsx +++ b/test/common/MenuLayout.test.tsx @@ -77,7 +77,6 @@ describe('', () => { ['3.1.0' as SemVer, '/domain/domain.com/visits/foo', 'DomainVisits'], ['2.10.0' as SemVer, '/non-orphan-visits/foo', 'Oops! We could not find requested route.'], ['3.0.0' as SemVer, '/non-orphan-visits/foo', 'NonOrphanVisits'], - ['2.7.0' as SemVer, '/manage-domains', 'Oops! We could not find requested route.'], ['2.8.0' as SemVer, '/manage-domains', 'ManageDomains'], ])( 'renders expected component based on location and server version', diff --git a/test/short-urls/helpers/QrCodeModal.test.tsx b/test/short-urls/helpers/QrCodeModal.test.tsx index bdf120e3..b5bacdbe 100644 --- a/test/short-urls/helpers/QrCodeModal.test.tsx +++ b/test/short-urls/helpers/QrCodeModal.test.tsx @@ -11,7 +11,7 @@ describe('', () => { const saveImage = jest.fn().mockReturnValue(Promise.resolve()); const QrCodeModal = createQrCodeModal(Mock.of({ saveImage })); const shortUrl = 'https://doma.in/abc123'; - const setUp = (version: SemVer = '2.6.0') => renderWithEvents( + const setUp = (version: SemVer = '2.8.0') => renderWithEvents( ({ shortUrl })} @@ -32,12 +32,10 @@ describe('', () => { }); it.each([ - ['2.5.0' as SemVer, 0, '/qr-code?size=300&format=png'], - ['2.6.0' as SemVer, 0, '/qr-code?size=300&format=png'], - ['2.6.0' as SemVer, 10, '/qr-code?size=300&format=png&margin=10'], - ['2.8.0' as SemVer, 0, '/qr-code?size=300&format=png&errorCorrection=L'], - ])('displays an image with the QR code of the URL', async (version, margin, expectedUrl) => { - const { container } = setUp(version); + [10, '/qr-code?size=300&format=png&errorCorrection=L&margin=10'], + [0, '/qr-code?size=300&format=png&errorCorrection=L'], + ])('displays an image with the QR code of the URL', async (margin, expectedUrl) => { + const { container } = setUp(); const marginControl = container.parentNode?.querySelectorAll('.form-control-range').item(1); if (marginControl) { @@ -69,16 +67,13 @@ describe('', () => { modalSize && expect(screen.getByRole('document')).toHaveClass(`modal-${modalSize}`); }); - it.each([ - ['2.6.0' as SemVer, 1, 'col-md-4'], - ['2.8.0' as SemVer, 2, 'col-md-6'], - ])('shows expected components based on server version', (version, expectedAmountOfDropdowns, expectedRangeClass) => { - const { container } = setUp(version); + it('shows expected components based on server version', () => { + const { container } = setUp(); const dropdowns = screen.getAllByRole('button'); const firstCol = container.parentNode?.querySelectorAll('.d-grid').item(0); - expect(dropdowns).toHaveLength(expectedAmountOfDropdowns + 1); // Add one because of the close button - expect(firstCol).toHaveClass(expectedRangeClass); + expect(dropdowns).toHaveLength(2 + 1); // Add one because of the close button + expect(firstCol).toHaveClass('col-md-4'); }); it('saves the QR code image when clicking the Download button', async () => {