Merge pull request #341 from acelaya-forks/feature/validate-flag

Feature/validate flag
This commit is contained in:
Alejandro Celaya 2020-12-06 13:21:08 +01:00 committed by GitHub
commit 920effb4c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 13 deletions

View file

@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
## [Unreleased] ## [Unreleased]
### Added ### Added
* [#309](https://github.com/shlinkio/shlink-web-client/issues/309) Added new domain selector component in create URL form which allows selecting from previously used domains or set a new one. * [#309](https://github.com/shlinkio/shlink-web-client/issues/309) Added new domain selector component in create URL form which allows selecting from previously used domains or set a new one.
* [#315](https://github.com/shlinkio/shlink-web-client/issues/315) Now you can tell if you want to validate the long URL when using Shlink >=2.4.
### Changed ### Changed
* *Nothing* * *Nothing*

View file

@ -8,9 +8,9 @@ import {
Input, Input,
InputGroup, InputGroup,
InputGroupAddon, InputGroupAddon,
InputProps,
UncontrolledTooltip, UncontrolledTooltip,
} from 'reactstrap'; } from 'reactstrap';
import { InputProps } from 'reactstrap/lib/Input';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faUndo } from '@fortawesome/free-solid-svg-icons'; import { faUndo } from '@fortawesome/free-solid-svg-icons';
import { isEmpty, pipe } from 'ramda'; import { isEmpty, pipe } from 'ramda';

View file

@ -38,6 +38,7 @@ const initialState: ShortUrlData = {
validUntil: undefined, validUntil: undefined,
maxVisits: undefined, maxVisits: undefined,
findIfExists: false, findIfExists: false,
validateUrl: true,
}; };
type NonDateFields = 'longUrl' | 'customSlug' | 'shortCodeLength' | 'domain' | 'maxVisits'; type NonDateFields = 'longUrl' | 'customSlug' | 'shortCodeLength' | 'domain' | 'maxVisits';
@ -154,16 +155,29 @@ const CreateShortUrl = (
</div> </div>
<ForServerVersion minVersion="1.16.0"> <ForServerVersion minVersion="1.16.0">
<div className="mb-4 text-right"> <div className="mb-4 row">
<Checkbox <div className="col-sm-6 text-center text-sm-left mb-2 mb-sm-0">
inline <ForServerVersion minVersion="2.4.0">
className="mr-2" <Checkbox
checked={shortUrlCreation.findIfExists} inline
onChange={(findIfExists) => setShortUrlCreation({ ...shortUrlCreation, findIfExists })} checked={shortUrlCreation.validateUrl}
> onChange={(validateUrl) => setShortUrlCreation({ ...shortUrlCreation, validateUrl })}
Use existing URL if found >
</Checkbox> Validate URL
<UseExistingIfFoundInfoIcon /> </Checkbox>
</ForServerVersion>
</div>
<div className="col-sm-6 text-center text-sm-right">
<Checkbox
inline
className="mr-2"
checked={shortUrlCreation.findIfExists}
onChange={(findIfExists) => setShortUrlCreation({ ...shortUrlCreation, findIfExists })}
>
Use existing URL if found
</Checkbox>
<UseExistingIfFoundInfoIcon />
</div>
</div> </div>
</ForServerVersion> </ForServerVersion>
</Collapse> </Collapse>

View file

@ -11,6 +11,7 @@ export interface ShortUrlData {
validUntil?: m.Moment | string; validUntil?: m.Moment | string;
maxVisits?: number; maxVisits?: number;
findIfExists?: boolean; findIfExists?: boolean;
validateUrl?: boolean;
} }
export interface ShortUrl { export interface ShortUrl {

View file

@ -1,4 +1,4 @@
import { ChangeEvent, FC } from 'react'; import { ChangeEvent, FC, useRef } from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import { v4 as uuid } from 'uuid'; import { v4 as uuid } from 'uuid';
import { identity } from 'ramda'; import { identity } from 'ramda';
@ -17,7 +17,7 @@ interface BooleanControlWithTypeProps extends BooleanControlProps {
const BooleanControl: FC<BooleanControlWithTypeProps> = ( const BooleanControl: FC<BooleanControlWithTypeProps> = (
{ checked = false, onChange = identity, className, children, type, inline = false }, { checked = false, onChange = identity, className, children, type, inline = false },
) => { ) => {
const id = uuid(); const { current: id } = useRef(uuid());
const onChecked = (e: ChangeEvent<HTMLInputElement>) => onChange(e.target.checked, e); const onChecked = (e: ChangeEvent<HTMLInputElement>) => onChange(e.target.checked, e);
const typeClasses = { const typeClasses = {
'custom-switch': type === 'switch', 'custom-switch': type === 'switch',

View file

@ -52,6 +52,7 @@ describe('<CreateShortUrl />', () => {
maxVisits: '20', maxVisits: '20',
findIfExists: false, findIfExists: false,
shortCodeLength: 15, shortCodeLength: 15,
validateUrl: true,
}); });
}); });
}); });