From b970b38c296534c54f09c10b0fd0dcf21512d16e Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 1 May 2022 11:00:46 +0200 Subject: [PATCH] Removed check on title support --- src/short-urls/ShortUrlForm.tsx | 66 +++++++++++-------------- src/short-urls/ShortUrlsTable.tsx | 26 ++++------ src/utils/helpers/features.ts | 1 - test/short-urls/ShortUrlForm.test.tsx | 12 ++--- test/short-urls/ShortUrlsTable.test.tsx | 10 +--- 5 files changed, 44 insertions(+), 71 deletions(-) diff --git a/src/short-urls/ShortUrlForm.tsx b/src/short-urls/ShortUrlForm.tsx index 6c36ccbb..c6b9800d 100644 --- a/src/short-urls/ShortUrlForm.tsx +++ b/src/short-urls/ShortUrlForm.tsx @@ -2,10 +2,9 @@ import { FC, useEffect, useState } from 'react'; import { InputType } from 'reactstrap/types/lib/Input'; import { Button, FormGroup, Input, Row } from 'reactstrap'; import { cond, isEmpty, pipe, replace, trim, T } from 'ramda'; -import classNames from 'classnames'; import { parseISO } from 'date-fns'; import DateInput, { DateInputProps } from '../utils/DateInput'; -import { supportsCrawlableVisits, supportsForwardQuery, supportsShortUrlTitle } from '../utils/helpers/features'; +import { supportsCrawlableVisits, supportsForwardQuery } from '../utils/helpers/features'; import { SimpleCard } from '../utils/SimpleCard'; import { handleEventPreventingDefault, hasValue, OptionalString } from '../utils/utils'; import Checkbox from '../utils/Checkbox'; @@ -33,7 +32,6 @@ export interface ShortUrlFormProps { const normalizeTag = pipe(trim, replace(/ /g, '-')); const toDate = (date?: string | Date): Date | undefined => (typeof date === 'string' ? parseISO(date) : date); -const dynamicColClasses = (flag: boolean) => ({ 'col-sm-6': flag, 'col-sm-12': !flag }); export const ShortUrlForm = ( TagsSelector: FC, @@ -115,13 +113,9 @@ export const ShortUrlForm = ( ); - const supportsTitle = supportsShortUrlTitle(selectedServer); - const showCustomizeCard = supportsTitle || !isEdit; - const limitAccessCardClasses = classNames('mb-3', dynamicColClasses(showCustomizeCard)); const showCrawlableControl = supportsCrawlableVisits(selectedServer); const showForwardQueryControl = supportsForwardQuery(selectedServer); const showBehaviorCard = showCrawlableControl || showForwardQueryControl; - const extraChecksCardClasses = classNames('mb-3', dynamicColClasses(showBehaviorCard)); return (
@@ -133,36 +127,34 @@ export const ShortUrlForm = ( - {showCustomizeCard && ( -
- - {supportsTitle && renderOptionalInput('title', 'Title')} - {!isEdit && ( - <> - -
- {renderOptionalInput('customSlug', 'Custom slug', 'text', { - disabled: hasValue(shortUrlData.shortCodeLength), - })} -
-
- {renderOptionalInput('shortCodeLength', 'Short code length', 'number', { - min: 4, - disabled: hasValue(shortUrlData.customSlug), - })} -
-
- setShortUrlData({ ...shortUrlData, domain })} - /> - - )} -
-
- )} +
+ + {renderOptionalInput('title', 'Title')} + {!isEdit && ( + <> + +
+ {renderOptionalInput('customSlug', 'Custom slug', 'text', { + disabled: hasValue(shortUrlData.shortCodeLength), + })} +
+
+ {renderOptionalInput('shortCodeLength', 'Short code length', 'number', { + min: 4, + disabled: hasValue(shortUrlData.customSlug), + })} +
+
+ setShortUrlData({ ...shortUrlData, domain })} + /> + + )} +
+
-
+
{renderOptionalInput('maxVisits', 'Maximum number of visits allowed', 'number', { min: 1 })}
@@ -174,7 +166,7 @@ export const ShortUrlForm = ( -
+
) => ({ const actionableFieldClasses = classNames({ 'short-urls-table__header-cell--with-action': !!orderByColumn }); const orderableColumnsClasses = classNames('short-urls-table__header-cell', actionableFieldClasses); const tableClasses = classNames('table table-hover responsive-table', className); - const supportsTitle = supportsShortUrlTitle(selectedServer); const renderShortUrls = () => { if (error) { @@ -70,21 +68,15 @@ export const ShortUrlsTable = (ShortUrlsRow: FC) => ({ Short URL {renderOrderIcon?.('shortCode')} - {!supportsTitle ? ( - - Long URL {renderOrderIcon?.('longUrl')} - - ) : ( - - - Title {renderOrderIcon?.('title')} - -   /   - - Long URL {renderOrderIcon?.('longUrl')} - - - )} + + + Title {renderOrderIcon?.('title')} + +   /   + + Long URL {renderOrderIcon?.('longUrl')} + + Tags Visits {renderOrderIcon?.('visits')} diff --git a/src/utils/helpers/features.ts b/src/utils/helpers/features.ts index 8746d174..20b3d589 100644 --- a/src/utils/helpers/features.ts +++ b/src/utils/helpers/features.ts @@ -4,7 +4,6 @@ import { SemVerPattern, versionMatch } from './version'; const serverMatchesMinVersion = (minVersion: SemVerPattern) => (selectedServer: SelectedServer): boolean => isReachableServer(selectedServer) && versionMatch(selectedServer.version, { minVersion }); -export const supportsShortUrlTitle = serverMatchesMinVersion('2.6.0'); export const supportsBotVisits = serverMatchesMinVersion('2.7.0'); export const supportsCrawlableVisits = supportsBotVisits; export const supportsQrErrorCorrection = serverMatchesMinVersion('2.8.0'); diff --git a/test/short-urls/ShortUrlForm.test.tsx b/test/short-urls/ShortUrlForm.test.tsx index 9469d308..13f424e4 100644 --- a/test/short-urls/ShortUrlForm.test.tsx +++ b/test/short-urls/ShortUrlForm.test.tsx @@ -66,16 +66,12 @@ describe('', () => { }); it.each([ - [null, 'create' as Mode, 4], - [null, 'create-basic' as Mode, 0], - [Mock.of({ version: '2.6.0' }), 'create' as Mode, 4], - [Mock.of({ version: '2.5.0' }), 'create' as Mode, 4], - [Mock.of({ version: '2.6.0' }), 'edit' as Mode, 4], - [Mock.of({ version: '2.5.0' }), 'edit' as Mode, 3], + ['create' as Mode, 4], + ['create-basic' as Mode, 0], ])( 'renders expected amount of cards based on server capabilities and mode', - (selectedServer, mode, expectedAmountOfCards) => { - const wrapper = createWrapper(selectedServer, mode); + (mode, expectedAmountOfCards) => { + const wrapper = createWrapper(null, mode); const cards = wrapper.find(SimpleCard); expect(cards).toHaveLength(expectedAmountOfCards); diff --git a/test/short-urls/ShortUrlsTable.test.tsx b/test/short-urls/ShortUrlsTable.test.tsx index 47651119..bf980927 100644 --- a/test/short-urls/ShortUrlsTable.test.tsx +++ b/test/short-urls/ShortUrlsTable.test.tsx @@ -4,7 +4,6 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { ShortUrlsTable as shortUrlsTableCreator } from '../../src/short-urls/ShortUrlsTable'; import { ShortUrlsList } from '../../src/short-urls/reducers/shortUrlsList'; import { ReachableServer, SelectedServer } from '../../src/servers/data'; -import { SemVer } from '../../src/utils/helpers/version'; import { ShortUrlsOrderableFields, SHORT_URLS_ORDERABLE_FIELDS } from '../../src/short-urls/data'; describe('', () => { @@ -61,13 +60,8 @@ describe('', () => { }); }); - it.each([ - ['2.6.0' as SemVer], - ['2.6.1' as SemVer], - ['2.7.0' as SemVer], - ['3.0.0' as SemVer], - ])('should render composed column when server supports title', (version) => { - const wrapper = createWrapper(Mock.of({ version })); + it('should render composed title column', () => { + const wrapper = createWrapper(Mock.of({ version: '2.0.0' })); const composedColumn = wrapper.find('table').find('th').at(2); const text = composedColumn.text();