From 51663407793b9d7ff0c770130d92f7d40ea30eb4 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 16 Aug 2021 17:26:54 +0200 Subject: [PATCH] Extracted some QR code modal components to external components --- src/short-urls/helpers/QrCodeModal.tsx | 25 ++++------------- .../qr-codes/QrErrorCorrectionDropdown.tsx | 28 +++++++++++++++++++ .../helpers/qr-codes/QrFormatDropdown.tsx | 16 +++++++++++ test/short-urls/helpers/QrCodeModal.test.tsx | 7 +++-- 4 files changed, 53 insertions(+), 23 deletions(-) create mode 100644 src/short-urls/helpers/qr-codes/QrErrorCorrectionDropdown.tsx create mode 100644 src/short-urls/helpers/qr-codes/QrFormatDropdown.tsx diff --git a/src/short-urls/helpers/QrCodeModal.tsx b/src/short-urls/helpers/QrCodeModal.tsx index fd20672a..ad4fc209 100644 --- a/src/short-urls/helpers/QrCodeModal.tsx +++ b/src/short-urls/helpers/QrCodeModal.tsx @@ -1,12 +1,11 @@ import { FC, useMemo, useState } from 'react'; -import { Modal, DropdownItem, FormGroup, ModalBody, ModalHeader, Row, Button } from 'reactstrap'; +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'; import { ExternalLink } from 'react-external-link'; import classNames from 'classnames'; import { ShortUrlModalProps } from '../data'; import { SelectedServer } from '../../servers/data'; -import { DropdownBtn } from '../../utils/DropdownBtn'; import { CopyToClipboardIcon } from '../../utils/CopyToClipboardIcon'; import { buildQrCodeUrl, QrCodeCapabilities, QrCodeFormat, QrErrorCorrection } from '../../utils/helpers/qrCodes'; import { @@ -17,7 +16,9 @@ import { } from '../../utils/helpers/features'; import { ImageDownloader } from '../../common/services/ImageDownloader'; import { Versions } from '../../utils/helpers/version'; +import { QrFormatDropdown } from './qr-codes/QrFormatDropdown'; import './QrCodeModal.scss'; +import { QrErrorCorrectionDropdown } from './qr-codes/QrErrorCorrectionDropdown'; interface QrCodeModalConnectProps extends ShortUrlModalProps { selectedServer: SelectedServer; @@ -90,28 +91,12 @@ const QrCodeModal = (imageDownloader: ImageDownloader, ForServerVersion: FC - - setFormat('png')}>PNG - setFormat('svg')}>SVG - + )} {capabilities.errorCorrectionIsSupported && ( - - setErrorCorrection('L')}> - Low - - setErrorCorrection('M')}> - Medium - - setErrorCorrection('Q')}> - Quartile - - setErrorCorrection('H')}> - High - - + )} diff --git a/src/short-urls/helpers/qr-codes/QrErrorCorrectionDropdown.tsx b/src/short-urls/helpers/qr-codes/QrErrorCorrectionDropdown.tsx new file mode 100644 index 00000000..b6fd68b7 --- /dev/null +++ b/src/short-urls/helpers/qr-codes/QrErrorCorrectionDropdown.tsx @@ -0,0 +1,28 @@ +import { FC } from 'react'; +import { DropdownItem } from 'reactstrap'; +import { DropdownBtn } from '../../../utils/DropdownBtn'; +import { QrErrorCorrection } from '../../../utils/helpers/qrCodes'; + +interface QrErrorCorrectionDropdownProps { + errorCorrection: QrErrorCorrection; + setErrorCorrection: (errorCorrection: QrErrorCorrection) => void; +} + +export const QrErrorCorrectionDropdown: FC = ( + { errorCorrection, setErrorCorrection }, +) => ( + + setErrorCorrection('L')}> + Low + + setErrorCorrection('M')}> + Medium + + setErrorCorrection('Q')}> + Quartile + + setErrorCorrection('H')}> + High + + +); diff --git a/src/short-urls/helpers/qr-codes/QrFormatDropdown.tsx b/src/short-urls/helpers/qr-codes/QrFormatDropdown.tsx new file mode 100644 index 00000000..3c9ca705 --- /dev/null +++ b/src/short-urls/helpers/qr-codes/QrFormatDropdown.tsx @@ -0,0 +1,16 @@ +import { FC } from 'react'; +import { DropdownItem } from 'reactstrap'; +import { DropdownBtn } from '../../../utils/DropdownBtn'; +import { QrCodeFormat } from '../../../utils/helpers/qrCodes'; + +interface QrFormatDropdownProps { + format: QrCodeFormat; + setFormat: (format: QrCodeFormat) => void; +} + +export const QrFormatDropdown: FC = ({ format, setFormat }) => ( + + setFormat('png')}>PNG + setFormat('svg')}>SVG + +); diff --git a/test/short-urls/helpers/QrCodeModal.test.tsx b/test/short-urls/helpers/QrCodeModal.test.tsx index 2daeafce..aa8b5160 100644 --- a/test/short-urls/helpers/QrCodeModal.test.tsx +++ b/test/short-urls/helpers/QrCodeModal.test.tsx @@ -6,9 +6,10 @@ import createQrCodeModal from '../../../src/short-urls/helpers/QrCodeModal'; import { ShortUrl } from '../../../src/short-urls/data'; import { ReachableServer } from '../../../src/servers/data'; import { CopyToClipboardIcon } from '../../../src/utils/CopyToClipboardIcon'; -import { DropdownBtn } from '../../../src/utils/DropdownBtn'; import { SemVer } from '../../../src/utils/helpers/version'; import { ImageDownloader } from '../../../src/common/services/ImageDownloader'; +import { QrFormatDropdown } from '../../../src/short-urls/helpers/qr-codes/QrFormatDropdown'; +import { QrErrorCorrectionDropdown } from '../../../src/short-urls/helpers/qr-codes/QrErrorCorrectionDropdown'; describe('', () => { let wrapper: ShallowWrapper; @@ -95,10 +96,10 @@ describe('', () => { [ '2.8.0' as SemVer, 2, 'col-md-6' ], ])('shows expected components based on server version', (version, expectedAmountOfDropdowns, expectedRangeClass) => { const wrapper = createWrapper(version); - const dropdown = wrapper.find(DropdownBtn); + const dropdownsLength = wrapper.find(QrFormatDropdown).length + wrapper.find(QrErrorCorrectionDropdown).length; const firstCol = wrapper.find(Row).find(FormGroup).first(); - expect(dropdown).toHaveLength(expectedAmountOfDropdowns); + expect(dropdownsLength).toEqual(expectedAmountOfDropdowns); expect(firstCol.prop('className')).toEqual(expectedRangeClass); });