mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-17 21:13:48 +00:00
Convert feature flags into hooks
This commit is contained in:
@@ -11,7 +11,7 @@ import { Checkbox } from '../utils/Checkbox';
|
||||
import type { DateTimeInputProps } from '../utils/dates/DateTimeInput';
|
||||
import { DateTimeInput } from '../utils/dates/DateTimeInput';
|
||||
import { formatIsoDate } from '../utils/helpers/date';
|
||||
import { supportsForwardQuery } from '../utils/helpers/features';
|
||||
import { useFeature } from '../utils/helpers/features';
|
||||
import { SimpleCard } from '../utils/SimpleCard';
|
||||
import type { OptionalString } from '../utils/utils';
|
||||
import { handleEventPreventingDefault, hasValue } from '../utils/utils';
|
||||
@@ -116,7 +116,7 @@ export const ShortUrlForm = (
|
||||
</>
|
||||
);
|
||||
|
||||
const showForwardQueryControl = supportsForwardQuery(selectedServer);
|
||||
const showForwardQueryControl = useFeature('forwardQuery', selectedServer);
|
||||
|
||||
return (
|
||||
<form name="shortUrlForm" className="short-url-form" onSubmit={submit}>
|
||||
|
||||
@@ -11,7 +11,7 @@ import { DateRangeSelector } from '../utils/dates/DateRangeSelector';
|
||||
import { formatIsoDate } from '../utils/helpers/date';
|
||||
import type { DateRange } from '../utils/helpers/dateIntervals';
|
||||
import { datesToDateRange } from '../utils/helpers/dateIntervals';
|
||||
import { supportsAllTagsFiltering, supportsFilterDisabledUrls } from '../utils/helpers/features';
|
||||
import { useFeature } from '../utils/helpers/features';
|
||||
import type { OrderDir } from '../utils/helpers/ordering';
|
||||
import { OrderingDropdown } from '../utils/OrderingDropdown';
|
||||
import { SearchField } from '../utils/SearchField';
|
||||
@@ -46,7 +46,7 @@ export const ShortUrlsFilteringBar = (
|
||||
excludePastValidUntil,
|
||||
tagsMode = 'any',
|
||||
} = filter;
|
||||
const supportsDisabledFiltering = supportsFilterDisabledUrls(selectedServer);
|
||||
const supportsDisabledFiltering = useFeature('filterDisabledUrls', selectedServer);
|
||||
|
||||
const setDates = pipe(
|
||||
({ startDate: theStartDate, endDate: theEndDate }: DateRange) => ({
|
||||
@@ -60,7 +60,7 @@ export const ShortUrlsFilteringBar = (
|
||||
(searchTerm) => toFirstPage({ search: searchTerm }),
|
||||
);
|
||||
const changeTagSelection = (selectedTags: string[]) => toFirstPage({ tags: selectedTags });
|
||||
const canChangeTagsMode = supportsAllTagsFiltering(selectedServer);
|
||||
const canChangeTagsMode = useFeature('allTagsFiltering', selectedServer);
|
||||
const toggleTagsMode = pipe(
|
||||
() => (tagsMode === 'any' ? 'all' : 'any'),
|
||||
(mode) => toFirstPage({ tagsMode: mode }),
|
||||
|
||||
@@ -9,7 +9,7 @@ import type { SelectedServer } from '../servers/data';
|
||||
import { getServerId } from '../servers/data';
|
||||
import type { Settings } from '../settings/reducers/settings';
|
||||
import { DEFAULT_SHORT_URLS_ORDERING } from '../settings/reducers/settings';
|
||||
import { supportsExcludeBotsOnShortUrls } from '../utils/helpers/features';
|
||||
import { useFeature } from '../utils/helpers/features';
|
||||
import type { OrderDir } from '../utils/helpers/ordering';
|
||||
import { determineOrderDir } from '../utils/helpers/ordering';
|
||||
import { TableOrderIcon } from '../utils/table/TableOrderIcon';
|
||||
@@ -52,6 +52,7 @@ export const ShortUrlsList = (
|
||||
);
|
||||
const { pagination } = shortUrlsList?.shortUrls ?? {};
|
||||
const doExcludeBots = excludeBots ?? settings.visits?.excludeBots;
|
||||
const supportsExcludingBots = useFeature('excludeBotsOnShortUrls', selectedServer);
|
||||
const handleOrderBy = (field?: ShortUrlsOrderableFields, dir?: OrderDir) => {
|
||||
toFirstPage({ orderBy: { field, dir } });
|
||||
setActualOrderBy({ field, dir });
|
||||
@@ -65,7 +66,7 @@ export const ShortUrlsList = (
|
||||
(updatedTags) => toFirstPage({ tags: updatedTags }),
|
||||
);
|
||||
const parseOrderByForShlink = ({ field, dir }: ShortUrlsOrder): ShlinkShortUrlsOrder => {
|
||||
if (supportsExcludeBotsOnShortUrls(selectedServer) && doExcludeBots && field === 'visits') {
|
||||
if (supportsExcludingBots && doExcludeBots && field === 'visits') {
|
||||
return { field: 'nonBotVisits', dir };
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Button, FormGroup, Modal, ModalBody, ModalHeader, Row } from 'reactstra
|
||||
import type { ImageDownloader } from '../../common/services/ImageDownloader';
|
||||
import type { SelectedServer } from '../../servers/data';
|
||||
import { CopyToClipboardIcon } from '../../utils/CopyToClipboardIcon';
|
||||
import { supportsNonRestCors } from '../../utils/helpers/features';
|
||||
import { useFeature } from '../../utils/helpers/features';
|
||||
import type { QrCodeFormat, QrErrorCorrection } from '../../utils/helpers/qrCodes';
|
||||
import { buildQrCodeUrl } from '../../utils/helpers/qrCodes';
|
||||
import type { ShortUrlModalProps } from '../data';
|
||||
@@ -25,7 +25,7 @@ export const QrCodeModal = (imageDownloader: ImageDownloader) => (
|
||||
const [margin, setMargin] = useState(0);
|
||||
const [format, setFormat] = useState<QrCodeFormat>('png');
|
||||
const [errorCorrection, setErrorCorrection] = useState<QrErrorCorrection>('L');
|
||||
const displayDownloadBtn = supportsNonRestCors(selectedServer);
|
||||
const displayDownloadBtn = useFeature('nonRestCors', selectedServer);
|
||||
const qrCodeUrl = useMemo(
|
||||
() => buildQrCodeUrl(shortUrl, { size, format, margin, errorCorrection }),
|
||||
[shortUrl, size, format, margin, errorCorrection],
|
||||
|
||||
Reference in New Issue
Block a user