From 677f1da8df6f765d3bb667e159806c733fa23e22 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 2 May 2022 19:24:57 +0200 Subject: [PATCH] Removed last occurrence of ForServerVersion component, replaced by feature check --- src/short-urls/helpers/QrCodeModal.tsx | 12 ++++++------ src/short-urls/services/provideServices.ts | 2 +- src/utils/helpers/features.ts | 1 + test/short-urls/helpers/QrCodeModal.test.tsx | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/short-urls/helpers/QrCodeModal.tsx b/src/short-urls/helpers/QrCodeModal.tsx index a16d6654..8e07279c 100644 --- a/src/short-urls/helpers/QrCodeModal.tsx +++ b/src/short-urls/helpers/QrCodeModal.tsx @@ -1,4 +1,4 @@ -import { FC, useMemo, useState } from 'react'; +import { useMemo, useState } from 'react'; import { Modal, FormGroup, ModalBody, ModalHeader, Row, Button } from 'reactstrap'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faFileDownload as downloadIcon } from '@fortawesome/free-solid-svg-icons'; @@ -7,9 +7,8 @@ import { ShortUrlModalProps } from '../data'; import { SelectedServer } from '../../servers/data'; import { CopyToClipboardIcon } from '../../utils/CopyToClipboardIcon'; import { buildQrCodeUrl, QrCodeCapabilities, QrCodeFormat, QrErrorCorrection } from '../../utils/helpers/qrCodes'; -import { supportsQrErrorCorrection } from '../../utils/helpers/features'; +import { supportsNonRestCors, supportsQrErrorCorrection } from '../../utils/helpers/features'; import { ImageDownloader } from '../../common/services/ImageDownloader'; -import { ForServerVersionProps } from '../../servers/helpers/ForServerVersion'; import { QrFormatDropdown } from './qr-codes/QrFormatDropdown'; import { QrErrorCorrectionDropdown } from './qr-codes/QrErrorCorrectionDropdown'; import './QrCodeModal.scss'; @@ -18,7 +17,7 @@ interface QrCodeModalConnectProps extends ShortUrlModalProps { selectedServer: SelectedServer; } -const QrCodeModal = (imageDownloader: ImageDownloader, ForServerVersion: FC) => ( +const QrCodeModal = (imageDownloader: ImageDownloader) => ( { shortUrl: { shortUrl, shortCode }, toggle, isOpen, selectedServer }: QrCodeModalConnectProps, ) => { const [size, setSize] = useState(300); @@ -28,6 +27,7 @@ const QrCodeModal = (imageDownloader: ImageDownloader, ForServerVersion: FC ({ errorCorrectionIsSupported: supportsQrErrorCorrection(selectedServer), }), [selectedServer]); + const displayDownloadBtn = supportsNonRestCors(selectedServer); const willRenderThreeControls = !capabilities.errorCorrectionIsSupported; const qrCodeUrl = useMemo( () => buildQrCodeUrl(shortUrl, { size, format, margin, errorCorrection }, capabilities), @@ -89,7 +89,7 @@ const QrCodeModal = (imageDownloader: ImageDownloader, ForServerVersion: FC QR code - + {displayDownloadBtn && (
-
+ )} diff --git a/src/short-urls/services/provideServices.ts b/src/short-urls/services/provideServices.ts index 052cb165..f895bb72 100644 --- a/src/short-urls/services/provideServices.ts +++ b/src/short-urls/services/provideServices.ts @@ -47,7 +47,7 @@ const provideServices = (bottle: Bottle, connect: ConnectDecorator) => { bottle.serviceFactory('DeleteShortUrlModal', () => DeleteShortUrlModal); bottle.decorator('DeleteShortUrlModal', connect(['shortUrlDeletion'], ['deleteShortUrl', 'resetDeleteShortUrl'])); - bottle.serviceFactory('QrCodeModal', QrCodeModal, 'ImageDownloader', 'ForServerVersion'); + bottle.serviceFactory('QrCodeModal', QrCodeModal, 'ImageDownloader'); bottle.decorator('QrCodeModal', connect(['selectedServer'])); bottle.serviceFactory('ShortUrlsFilteringBar', ShortUrlsFilteringBar, 'ColorGenerator', 'ExportShortUrlsBtn'); diff --git a/src/utils/helpers/features.ts b/src/utils/helpers/features.ts index 20b3d589..e3fbbd12 100644 --- a/src/utils/helpers/features.ts +++ b/src/utils/helpers/features.ts @@ -9,6 +9,7 @@ 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'); export const supportsNonOrphanVisits = serverMatchesMinVersion('3.0.0'); export const supportsAllTagsFiltering = supportsNonOrphanVisits; diff --git a/test/short-urls/helpers/QrCodeModal.test.tsx b/test/short-urls/helpers/QrCodeModal.test.tsx index 44c7cd57..fad659dc 100644 --- a/test/short-urls/helpers/QrCodeModal.test.tsx +++ b/test/short-urls/helpers/QrCodeModal.test.tsx @@ -14,7 +14,7 @@ import { QrErrorCorrectionDropdown } from '../../../src/short-urls/helpers/qr-co describe('', () => { let wrapper: ShallowWrapper; const saveImage = jest.fn().mockReturnValue(Promise.resolve()); - const QrCodeModal = createQrCodeModal(Mock.of({ saveImage }), () => null); + const QrCodeModal = createQrCodeModal(Mock.of({ saveImage })); const shortUrl = 'https://doma.in/abc123'; const createWrapper = (version: SemVer = '2.6.0') => { const selectedServer = Mock.of({ version }); @@ -99,7 +99,7 @@ describe('', () => { }); it('saves the QR code image when clicking the Download button', () => { - const wrapper = createWrapper(); + const wrapper = createWrapper('2.9.0'); const downloadBtn = wrapper.find(Button); expect(saveImage).not.toHaveBeenCalled();