Skip to content

Commit

Permalink
Merge pull request #192 from acelaya-forks/feature/version-constraints
Browse files Browse the repository at this point in the history
Feature/version constraints
  • Loading branch information
acelaya committed Jan 19, 2020
2 parents e89b68f + 5762342 commit 44aca4a
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 21 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018-2019 shlinkio
Copyright (c) 2018-2020 shlinkio

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
26 changes: 16 additions & 10 deletions src/short-urls/SearchBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@ import moment from 'moment';
import SearchField from '../utils/SearchField';
import Tag from '../tags/helpers/Tag';
import DateRangeRow from '../utils/DateRangeRow';
import { formatDate } from '../utils/utils';
import { compareVersions, formatDate } from '../utils/utils';
import { serverType } from '../servers/prop-types';
import { shortUrlsListParamsType } from './reducers/shortUrlsListParams';
import './SearchBar.scss';

const propTypes = {
listShortUrls: PropTypes.func,
shortUrlsListParams: shortUrlsListParamsType,
selectedServer: serverType,
};

const dateOrUndefined = (date) => date ? moment(date) : undefined;

const SearchBar = (colorGenerator) => {
const SearchBar = ({ listShortUrls, shortUrlsListParams }) => {
const SearchBar = ({ listShortUrls, shortUrlsListParams, selectedServer }) => {
const currentServerVersion = selectedServer ? selectedServer.version : '';
const enableDateFiltering = !isEmpty(currentServerVersion) && compareVersions(currentServerVersion, '>=', '1.21.0');
const selectedTags = shortUrlsListParams.tags || [];
const setDate = (dateName) => pipe(
formatDate(),
Expand All @@ -34,14 +38,16 @@ const SearchBar = (colorGenerator) => {
}
/>

<div className="mt-3">
<DateRangeRow
startDate={dateOrUndefined(shortUrlsListParams.startDate)}
endDate={dateOrUndefined(shortUrlsListParams.endDate)}
onStartDateChange={setDate('startDate')}
onEndDateChange={setDate('endDate')}
/>
</div>
{enableDateFiltering && (
<div className="mt-3">
<DateRangeRow
startDate={dateOrUndefined(shortUrlsListParams.startDate)}
endDate={dateOrUndefined(shortUrlsListParams.endDate)}
onStartDateChange={setDate('startDate')}
onEndDateChange={setDate('endDate')}
/>
</div>
)}

{!isEmpty(selectedTags) && (
<h4 className="search-bar__selected-tag mt-3">
Expand Down
13 changes: 9 additions & 4 deletions src/short-urls/helpers/ShortUrlsRowMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const ShortUrlsRowMenu = (
const { onCopyToClipboard, shortUrl, selectedServer } = this.props;
const completeShortUrl = shortUrl && shortUrl.shortUrl ? shortUrl.shortUrl : '';
const currentServerVersion = selectedServer ? selectedServer.version : '';
const showEditMetaBtn = !isEmpty(currentServerVersion) && compareVersions(currentServerVersion, '>=', '1.18.0');
const showPreviewBtn = !isEmpty(currentServerVersion) && compareVersions(currentServerVersion, '<', '2.0.0');
const toggleModal = (prop) => () => this.setState((prevState) => ({ [prop]: !prevState[prop] }));
const toggleQrCode = toggleModal('isQrModalOpen');
Expand All @@ -69,10 +70,14 @@ const ShortUrlsRowMenu = (
</DropdownItem>
<EditTagsModal shortUrl={shortUrl} isOpen={this.state.isTagsModalOpen} toggle={toggleTags} />

<DropdownItem onClick={toggleMeta}>
<FontAwesomeIcon icon={editIcon} fixedWidth /> Edit metadata
</DropdownItem>
<EditMetaModal shortUrl={shortUrl} isOpen={this.state.isMetaModalOpen} toggle={toggleMeta} />
{showEditMetaBtn && (
<React.Fragment>
<DropdownItem onClick={toggleMeta}>
<FontAwesomeIcon icon={editIcon} fixedWidth /> Edit metadata
</DropdownItem>
<EditMetaModal shortUrl={shortUrl} isOpen={this.state.isMetaModalOpen} toggle={toggleMeta} />
</React.Fragment>
)}

<DropdownItem className="short-urls-row-menu__dropdown-item--danger" onClick={toggleDelete}>
<FontAwesomeIcon icon={deleteIcon} fixedWidth /> Delete short URL
Expand Down
2 changes: 1 addition & 1 deletion src/short-urls/services/provideServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const provideServices = (bottle, connect) => {
));

bottle.serviceFactory('SearchBar', SearchBar, 'ColorGenerator');
bottle.decorator('SearchBar', connect([ 'shortUrlsListParams' ], [ 'listShortUrls' ]));
bottle.decorator('SearchBar', connect([ 'shortUrlsListParams', 'selectedServer' ], [ 'listShortUrls' ]));

bottle.serviceFactory('ShortUrlsList', ShortUrlsList, 'ShortUrlsRow');
bottle.decorator('ShortUrlsList', connect(
Expand Down
17 changes: 12 additions & 5 deletions test/short-urls/SearchBar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ describe('<SearchBar />', () => {
expect(wrapper.find(SearchField)).toHaveLength(1);
});

it('renders a DateRangeRow', () => {
wrapper = shallow(<SearchBar shortUrlsListParams={{}} />);

expect(wrapper.find(DateRangeRow)).toHaveLength(1);
each([
[ '2.0.0', 1 ],
[ '1.21.2', 1 ],
[ '1.21.0', 1 ],
[ '1.20.0', 0 ],
]).it('renders a DateRangeRow when proper version is run', (version, expectedLength) => {
wrapper = shallow(<SearchBar shortUrlsListParams={{}} selectedServer={{ version }} />);

expect(wrapper.find(DateRangeRow)).toHaveLength(expectedLength);
});

it('renders no tags when the list of tags is empty', () => {
Expand Down Expand Up @@ -63,7 +68,9 @@ describe('<SearchBar />', () => {
});

each([ 'startDateChange', 'endDateChange' ]).it('updates short URLs list when date range changes', (event) => {
wrapper = shallow(<SearchBar shortUrlsListParams={{}} listShortUrls={listShortUrlsMock} />);
wrapper = shallow(
<SearchBar shortUrlsListParams={{}} listShortUrls={listShortUrlsMock} selectedServer={{ version: '2.0.0' }} />
);
const dateRange = wrapper.find(DateRangeRow);

expect(listShortUrlsMock).not.toHaveBeenCalled();
Expand Down
5 changes: 5 additions & 0 deletions test/short-urls/helpers/ShortUrlsRowMenu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ describe('<ShortUrlsRowMenu />', () => {
});

each([
[ '1.17.0', 6, 2 ],
[ '1.17.2', 6, 2 ],
[ '1.18.0', 7, 2 ],
[ '1.18.1', 7, 2 ],
[ '1.19.0', 7, 2 ],
[ '1.20.3', 7, 2 ],
[ '1.21.0', 7, 2 ],
[ '1.21.1', 7, 2 ],
Expand Down

0 comments on commit 44aca4a

Please sign in to comment.