mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-10 09:33:51 +00:00
Move more components to shlink-web-component when applicable
This commit is contained in:
@@ -3,9 +3,9 @@ import type Bottle from 'bottlejs';
|
||||
import type { FC, ReactNode } from 'react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { Provider } from 'react-redux';
|
||||
import type { SemVer } from '../src/utils/helpers/version';
|
||||
import type { ShlinkApiClient } from './api-contract';
|
||||
import { FeaturesProvider, useFeatures } from './utils/features';
|
||||
import type { SemVer } from './utils/helpers/version';
|
||||
import { RoutesPrefixProvider } from './utils/routesPrefix';
|
||||
import type { Settings } from './utils/settings';
|
||||
import { SettingsProvider } from './utils/settings';
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { Order } from '../../src/utils/helpers/ordering';
|
||||
import type { OptionalString } from '../../src/utils/utils';
|
||||
import type { ShortUrl, ShortUrlMeta } from '../short-urls/data';
|
||||
import type { Visit } from '../visits/types';
|
||||
|
||||
@@ -70,7 +69,7 @@ export interface ShlinkVisitsOverview {
|
||||
}
|
||||
|
||||
export interface ShlinkVisitsParams {
|
||||
domain?: OptionalString;
|
||||
domain?: string | null;
|
||||
page?: number;
|
||||
itemsPerPage?: number;
|
||||
startDate?: string;
|
||||
@@ -98,12 +97,12 @@ export interface ShlinkEditDomainRedirects extends Partial<ShlinkDomainRedirects
|
||||
export interface ShlinkDomain {
|
||||
domain: string;
|
||||
isDefault: boolean;
|
||||
redirects?: ShlinkDomainRedirects; // Optional only for Shlink older than 2.8
|
||||
redirects: ShlinkDomainRedirects;
|
||||
}
|
||||
|
||||
export interface ShlinkDomainsResponse {
|
||||
data: ShlinkDomain[];
|
||||
defaultRedirects?: ShlinkDomainRedirects; // Optional only for Shlink older than 2.10
|
||||
defaultRedirects: ShlinkDomainRedirects;
|
||||
}
|
||||
|
||||
export type TagsFilteringMode = 'all' | 'any';
|
||||
|
||||
18
shlink-web-component/common/ShlinkApiError.tsx
Normal file
18
shlink-web-component/common/ShlinkApiError.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { ProblemDetailsError } from '../api-contract';
|
||||
import { isInvalidArgumentError } from '../api-contract/utils';
|
||||
|
||||
export interface ShlinkApiErrorProps {
|
||||
errorData?: ProblemDetailsError;
|
||||
fallbackMessage?: string;
|
||||
}
|
||||
|
||||
export const ShlinkApiError = ({ errorData, fallbackMessage }: ShlinkApiErrorProps) => (
|
||||
<>
|
||||
{errorData?.detail ?? fallbackMessage}
|
||||
{isInvalidArgumentError(errorData) && (
|
||||
<p className="mb-0">
|
||||
Invalid elements: [{errorData.invalidElements.join(', ')}]
|
||||
</p>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
@@ -2,16 +2,12 @@ import type { IContainer } from 'bottlejs';
|
||||
import Bottle from 'bottlejs';
|
||||
import { pick } from 'ramda';
|
||||
import { connect as reduxConnect } from 'react-redux';
|
||||
import { HttpClient } from '../../src/common/services/HttpClient';
|
||||
import { ImageDownloader } from '../../src/common/services/ImageDownloader';
|
||||
import { csvToJson, jsonToCsv } from '../../src/utils/helpers/csvjson';
|
||||
import { provideServices as provideDomainsServices } from '../domains/services/provideServices';
|
||||
import { provideServices as provideMercureServices } from '../mercure/services/provideServices';
|
||||
import { provideServices as provideOverviewServices } from '../overview/services/provideServices';
|
||||
import { provideServices as provideShortUrlsServices } from '../short-urls/services/provideServices';
|
||||
import { provideServices as provideTagsServices } from '../tags/services/provideServices';
|
||||
import { provideServices as provideUtilsServices } from '../utils/services/provideServices';
|
||||
import { ReportExporter } from '../utils/services/ReportExporter';
|
||||
import { provideServices as provideVisitsServices } from '../visits/services/provideServices';
|
||||
import { provideServices as provideWebComponentServices } from './provideServices';
|
||||
|
||||
@@ -44,15 +40,3 @@ provideMercureServices(bottle);
|
||||
provideDomainsServices(bottle, connect);
|
||||
provideOverviewServices(bottle, connect);
|
||||
provideUtilsServices(bottle);
|
||||
|
||||
// FIXME Check which of these can be moved to shlink-web-component, and which are needed by the app too
|
||||
bottle.constant('window', window);
|
||||
bottle.constant('console', console);
|
||||
bottle.constant('fetch', window.fetch.bind(window));
|
||||
|
||||
bottle.service('HttpClient', HttpClient, 'fetch');
|
||||
bottle.service('ImageDownloader', ImageDownloader, 'HttpClient', 'window');
|
||||
bottle.service('ReportExporter', ReportExporter, 'window', 'jsonToCsv');
|
||||
|
||||
bottle.constant('csvToJson', csvToJson);
|
||||
bottle.constant('jsonToCsv', jsonToCsv);
|
||||
|
||||
@@ -3,7 +3,6 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import type { FC } from 'react';
|
||||
import { useEffect } from 'react';
|
||||
import { UncontrolledTooltip } from 'reactstrap';
|
||||
import type { OptionalString } from '../../src/utils/utils';
|
||||
import type { ShlinkDomainRedirects } from '../api-contract';
|
||||
import type { Domain } from './data';
|
||||
import { DomainDropdown } from './helpers/DomainDropdown';
|
||||
@@ -17,7 +16,7 @@ interface DomainRowProps {
|
||||
checkDomainHealth: (domain: string) => void;
|
||||
}
|
||||
|
||||
const Nr: FC<{ fallback: OptionalString }> = ({ fallback }) => (
|
||||
const Nr: FC<{ fallback?: string | null }> = ({ fallback }) => (
|
||||
<span className="text-muted">
|
||||
{!fallback && <small>No redirect</small>}
|
||||
{fallback && <>{fallback} <small>(as fallback)</small></>}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { FC } from 'react';
|
||||
import { useEffect } from 'react';
|
||||
import { ShlinkApiError } from '../../src/api/ShlinkApiError';
|
||||
import { Message } from '../../src/utils/Message';
|
||||
import { Result } from '../../src/utils/Result';
|
||||
import { SearchField } from '../../src/utils/SearchField';
|
||||
import { SimpleCard } from '../../src/utils/SimpleCard';
|
||||
import { ShlinkApiError } from '../common/ShlinkApiError';
|
||||
import { DomainRow } from './DomainRow';
|
||||
import type { EditDomainRedirects } from './reducers/domainRedirects';
|
||||
import type { DomainsList } from './reducers/domainsList';
|
||||
|
||||
@@ -8,8 +8,8 @@ import type { FC } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { ExternalLink } from 'react-external-link';
|
||||
import { UncontrolledTooltip } from 'reactstrap';
|
||||
import { useElementRef } from '../../../src/utils/helpers/hooks';
|
||||
import type { MediaMatcher } from '../../../src/utils/types';
|
||||
import { useElementRef } from '../../utils/helpers/hooks';
|
||||
import type { MediaMatcher } from '../../utils/types';
|
||||
import type { DomainStatus } from '../data';
|
||||
|
||||
interface DomainStatusIconProps {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { FC } from 'react';
|
||||
import { useState } from 'react';
|
||||
import { Button, Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap';
|
||||
import type { ShlinkDomain } from '../../../api/types';
|
||||
import type { InputFormGroupProps } from '../../../src/utils/forms/InputFormGroup';
|
||||
import { InputFormGroup } from '../../../src/utils/forms/InputFormGroup';
|
||||
import { InfoTooltip } from '../../../src/utils/InfoTooltip';
|
||||
import { handleEventPreventingDefault, nonEmptyValueOrNull } from '../../../src/utils/utils';
|
||||
import type { ShlinkDomain } from '../../api-contract';
|
||||
import { InfoTooltip } from '../../utils/components/InfoTooltip';
|
||||
import { handleEventPreventingDefault, nonEmptyValueOrNull } from '../../utils/helpers';
|
||||
import type { EditDomainRedirects } from '../reducers/domainRedirects';
|
||||
|
||||
interface EditDomainRedirectsModalProps {
|
||||
|
||||
@@ -2,7 +2,6 @@ import type { FC } from 'react';
|
||||
import { useEffect } from 'react';
|
||||
import { Link, useNavigate } from 'react-router-dom';
|
||||
import { Card, CardBody, CardHeader, Row } from 'reactstrap';
|
||||
import { prettify } from '../../src/utils/helpers/numbers';
|
||||
import type { ShlinkShortUrlsListParams } from '../api-contract';
|
||||
import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub';
|
||||
import { Topics } from '../mercure/helpers/Topics';
|
||||
@@ -11,6 +10,7 @@ import type { ShortUrlsList as ShortUrlsListState } from '../short-urls/reducers
|
||||
import { ITEMS_IN_OVERVIEW_PAGE } from '../short-urls/reducers/shortUrlsList';
|
||||
import type { ShortUrlsTableType } from '../short-urls/ShortUrlsTable';
|
||||
import type { TagsList } from '../tags/reducers/tagsList';
|
||||
import { prettify } from '../utils/helpers/numbers';
|
||||
import { useRoutesPrefix } from '../utils/routesPrefix';
|
||||
import { useSetting } from '../utils/settings';
|
||||
import type { VisitsOverview } from '../visits/reducers/visitsOverview';
|
||||
|
||||
@@ -3,7 +3,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import type { FC, PropsWithChildren, ReactNode } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { Card, CardText, CardTitle, UncontrolledTooltip } from 'reactstrap';
|
||||
import { useElementRef } from '../../../src/utils/helpers/hooks';
|
||||
import { useElementRef } from '../../utils/helpers/hooks';
|
||||
import './HighlightCard.scss';
|
||||
|
||||
export type HighlightCardProps = PropsWithChildren<{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { FC } from 'react';
|
||||
import { prettify } from '../../../src/utils/helpers/numbers';
|
||||
import { prettify } from '../../utils/helpers/numbers';
|
||||
import type { PartialVisitsSummary } from '../../visits/reducers/visitsOverview';
|
||||
import type { HighlightCardProps } from './HighlightCard';
|
||||
import { HighlightCard } from './HighlightCard';
|
||||
|
||||
@@ -5,10 +5,10 @@ import { useEffect, useMemo } from 'react';
|
||||
import { ExternalLink } from 'react-external-link';
|
||||
import { useLocation, useParams } from 'react-router-dom';
|
||||
import { Button, Card } from 'reactstrap';
|
||||
import { ShlinkApiError } from '../../src/api/ShlinkApiError';
|
||||
import { useGoBack } from '../../src/utils/helpers/hooks';
|
||||
import { Message } from '../../src/utils/Message';
|
||||
import { Result } from '../../src/utils/Result';
|
||||
import { ShlinkApiError } from '../common/ShlinkApiError';
|
||||
import { useGoBack } from '../utils/helpers/hooks';
|
||||
import { parseQuery } from '../utils/helpers/query';
|
||||
import { useSetting } from '../utils/settings';
|
||||
import type { ShortUrlIdentifier } from './data';
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { Link } from 'react-router-dom';
|
||||
import { Pagination, PaginationItem, PaginationLink } from 'reactstrap';
|
||||
import type { ShlinkPaginator } from '../api-contract';
|
||||
import type {
|
||||
NumberOrEllipsis } from '../../src/utils/helpers/pagination';
|
||||
NumberOrEllipsis } from '../utils/helpers/pagination';
|
||||
import {
|
||||
keyForPage,
|
||||
pageIsEllipsis,
|
||||
prettifyPageNumber,
|
||||
progressivePagination,
|
||||
} from '../../src/utils/helpers/pagination';
|
||||
import type { ShlinkPaginator } from '../api-contract';
|
||||
} from '../utils/helpers/pagination';
|
||||
import { useRoutesPrefix } from '../utils/routesPrefix';
|
||||
|
||||
interface PaginatorProps {
|
||||
|
||||
@@ -14,10 +14,10 @@ import { DateTimeInput } from '../../src/utils/dates/DateTimeInput';
|
||||
import { formatIsoDate } from '../../src/utils/helpers/date';
|
||||
import { IconInput } from '../../src/utils/IconInput';
|
||||
import { SimpleCard } from '../../src/utils/SimpleCard';
|
||||
import { handleEventPreventingDefault, hasValue } from '../../src/utils/utils';
|
||||
import type { DomainSelectorProps } from '../domains/DomainSelector';
|
||||
import type { TagsSelectorProps } from '../tags/helpers/TagsSelector';
|
||||
import { useFeature } from '../utils/features';
|
||||
import { handleEventPreventingDefault, hasValue } from '../utils/helpers';
|
||||
import type { DeviceLongUrls, ShortUrlData } from './data';
|
||||
import { ShortUrlFormCheckboxGroup } from './helpers/ShortUrlFormCheckboxGroup';
|
||||
import { UseExistingIfFoundInfoIcon } from './UseExistingIfFoundInfoIcon';
|
||||
|
||||
@@ -5,12 +5,12 @@ import { Card } from 'reactstrap';
|
||||
import { DEFAULT_SHORT_URLS_ORDERING } from '../../src/settings/reducers/settings';
|
||||
import type { OrderDir } from '../../src/utils/helpers/ordering';
|
||||
import { determineOrderDir } from '../../src/utils/helpers/ordering';
|
||||
import { TableOrderIcon } from '../../src/utils/table/TableOrderIcon';
|
||||
import type { ShlinkShortUrlsListParams, ShlinkShortUrlsOrder } from '../api-contract';
|
||||
import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub';
|
||||
import { Topics } from '../mercure/helpers/Topics';
|
||||
import { useFeature } from '../utils/features';
|
||||
import { useSettings } from '../utils/settings';
|
||||
import { TableOrderIcon } from '../utils/table/TableOrderIcon';
|
||||
import type { ShortUrlsOrder, ShortUrlsOrderableFields } from './data';
|
||||
import { useShortUrlsQuery } from './helpers/hooks';
|
||||
import { Paginator } from './Paginator';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { ShlinkVisitsSummary } from '../../../api/types';
|
||||
import type { Order } from '../../../src/utils/helpers/ordering';
|
||||
import type { Nullable, OptionalString } from '../../../src/utils/utils';
|
||||
import type { ShlinkVisitsSummary } from '../../api-contract';
|
||||
import type { Nullable, OptionalString } from '../../utils/helpers';
|
||||
|
||||
export interface DeviceLongUrls {
|
||||
android?: OptionalString;
|
||||
|
||||
@@ -4,9 +4,9 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { useEffect } from 'react';
|
||||
import CopyToClipboard from 'react-copy-to-clipboard';
|
||||
import { Tooltip } from 'reactstrap';
|
||||
import { ShlinkApiError } from '../../../src/api/ShlinkApiError';
|
||||
import type { TimeoutToggle } from '../../../src/utils/helpers/hooks';
|
||||
import { Result } from '../../../src/utils/Result';
|
||||
import { ShlinkApiError } from '../../common/ShlinkApiError';
|
||||
import type { TimeoutToggle } from '../../utils/helpers/hooks';
|
||||
import type { ShortUrlCreation } from '../reducers/shortUrlCreation';
|
||||
import './CreateShortUrlResult.scss';
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { pipe } from 'ramda';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap';
|
||||
import { ShlinkApiError } from '../../../src/api/ShlinkApiError';
|
||||
import { Result } from '../../../src/utils/Result';
|
||||
import { handleEventPreventingDefault } from '../../../src/utils/utils';
|
||||
import { isInvalidDeletionError } from '../../api-contract/utils';
|
||||
import { ShlinkApiError } from '../../common/ShlinkApiError';
|
||||
import { handleEventPreventingDefault } from '../../utils/helpers';
|
||||
import type { ShortUrlIdentifier, ShortUrlModalProps } from '../data';
|
||||
import type { ShortUrlDeletion } from '../reducers/shortUrlDeletion';
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { FC } from 'react';
|
||||
import { useCallback } from 'react';
|
||||
import { ExportBtn } from '../../../src/utils/ExportBtn';
|
||||
import type { ShlinkApiClient } from '../../api-contract';
|
||||
import { ExportBtn } from '../../utils/components/ExportBtn';
|
||||
import { useToggle } from '../../utils/helpers/hooks';
|
||||
import type { ReportExporter } from '../../utils/services/ReportExporter';
|
||||
import type { ShortUrl } from '../data';
|
||||
|
||||
@@ -3,10 +3,10 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { useMemo, useState } from 'react';
|
||||
import { ExternalLink } from 'react-external-link';
|
||||
import { Button, FormGroup, Modal, ModalBody, ModalHeader, Row } from 'reactstrap';
|
||||
import type { ImageDownloader } from '../../../src/common/services/ImageDownloader';
|
||||
import { CopyToClipboardIcon } from '../../../src/utils/CopyToClipboardIcon';
|
||||
import type { QrCodeFormat, QrErrorCorrection } from '../../../src/utils/helpers/qrCodes';
|
||||
import { buildQrCodeUrl } from '../../../src/utils/helpers/qrCodes';
|
||||
import { CopyToClipboardIcon } from '../../utils/components/CopyToClipboardIcon';
|
||||
import type { QrCodeFormat, QrErrorCorrection } from '../../utils/helpers/qrCodes';
|
||||
import { buildQrCodeUrl } from '../../utils/helpers/qrCodes';
|
||||
import type { ImageDownloader } from '../../utils/services/ImageDownloader';
|
||||
import type { ShortUrlModalProps } from '../data';
|
||||
import { QrErrorCorrectionDropdown } from './qr-codes/QrErrorCorrectionDropdown';
|
||||
import { QrFormatDropdown } from './qr-codes/QrFormatDropdown';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { ChangeEvent, FC, PropsWithChildren } from 'react';
|
||||
import { Checkbox } from '../../../src/utils/Checkbox';
|
||||
import { InfoTooltip } from '../../../src/utils/InfoTooltip';
|
||||
import { InfoTooltip } from '../../utils/components/InfoTooltip';
|
||||
|
||||
type ShortUrlFormCheckboxGroupProps = PropsWithChildren<{
|
||||
checked?: boolean;
|
||||
|
||||
@@ -5,7 +5,7 @@ import { isBefore } from 'date-fns';
|
||||
import type { FC, ReactNode } from 'react';
|
||||
import { UncontrolledTooltip } from 'reactstrap';
|
||||
import { formatHumanFriendly, now, parseISO } from '../../../src/utils/helpers/date';
|
||||
import { useElementRef } from '../../../src/utils/helpers/hooks';
|
||||
import { useElementRef } from '../../utils/helpers/hooks';
|
||||
import type { ShortUrl } from '../data';
|
||||
|
||||
interface ShortUrlStatusProps {
|
||||
|
||||
@@ -3,8 +3,8 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import classNames from 'classnames';
|
||||
import { UncontrolledTooltip } from 'reactstrap';
|
||||
import { formatHumanFriendly, parseISO } from '../../../src/utils/helpers/date';
|
||||
import { useElementRef } from '../../../src/utils/helpers/hooks';
|
||||
import { prettify } from '../../../src/utils/helpers/numbers';
|
||||
import { useElementRef } from '../../utils/helpers/hooks';
|
||||
import { prettify } from '../../utils/helpers/numbers';
|
||||
import type { ShortUrl } from '../data';
|
||||
import { ShortUrlDetailLink } from './ShortUrlDetailLink';
|
||||
import './ShortUrlVisitsCount.scss';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { DropdownItem } from 'reactstrap';
|
||||
import { DropdownBtn } from '../../../src/utils/DropdownBtn';
|
||||
import { hasValue } from '../../../src/utils/utils';
|
||||
import { hasValue } from '../../utils/helpers';
|
||||
import type { ShortUrlsFilter } from '../data';
|
||||
|
||||
interface ShortUrlsFilterDropdownProps {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { FC } from 'react';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { ExternalLink } from 'react-external-link';
|
||||
import { CopyToClipboardIcon } from '../../../src/utils/CopyToClipboardIcon';
|
||||
import { Time } from '../../../src/utils/dates/Time';
|
||||
import type { TimeoutToggle } from '../../../src/utils/helpers/hooks';
|
||||
import { CopyToClipboardIcon } from '../../utils/components/CopyToClipboardIcon';
|
||||
import type { ColorGenerator } from '../../utils/services/ColorGenerator';
|
||||
import { useSetting } from '../../utils/settings';
|
||||
import type { ShortUrl } from '../data';
|
||||
|
||||
@@ -2,9 +2,9 @@ import { isEmpty, pipe } from 'ramda';
|
||||
import { useMemo } from 'react';
|
||||
import { useLocation, useNavigate } from 'react-router-dom';
|
||||
import { orderToString, stringToOrder } from '../../../src/utils/helpers/ordering';
|
||||
import type { BooleanString } from '../../../src/utils/utils';
|
||||
import { parseOptionalBooleanToString } from '../../../src/utils/utils';
|
||||
import type { TagsFilteringMode } from '../../api-contract';
|
||||
import type { BooleanString } from '../../utils/helpers';
|
||||
import { parseOptionalBooleanToString } from '../../utils/helpers';
|
||||
import { parseQuery, stringifyQuery } from '../../utils/helpers/query';
|
||||
import { useRoutesPrefix } from '../../utils/routesPrefix';
|
||||
import type { ShortUrlsOrder, ShortUrlsOrderableFields } from '../data';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { isNil } from 'ramda';
|
||||
import type { OptionalString } from '../../../src/utils/utils';
|
||||
import type { OptionalString } from '../../utils/helpers';
|
||||
import type { ShortUrlCreationSettings } from '../../utils/settings';
|
||||
import { DEFAULT_DOMAIN } from '../../visits/reducers/domainVisits';
|
||||
import type { ShortUrl, ShortUrlData } from '../data';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { FC } from 'react';
|
||||
import { DropdownItem } from 'reactstrap';
|
||||
import { DropdownBtn } from '../../../../src/utils/DropdownBtn';
|
||||
import type { QrErrorCorrection } from '../../../../src/utils/helpers/qrCodes';
|
||||
import type { QrErrorCorrection } from '../../../utils/helpers/qrCodes';
|
||||
|
||||
interface QrErrorCorrectionDropdownProps {
|
||||
errorCorrection: QrErrorCorrection;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { FC } from 'react';
|
||||
import { DropdownItem } from 'reactstrap';
|
||||
import { DropdownBtn } from '../../../../src/utils/DropdownBtn';
|
||||
import type { QrCodeFormat } from '../../../../src/utils/helpers/qrCodes';
|
||||
import type { QrCodeFormat } from '../../../utils/helpers/qrCodes';
|
||||
|
||||
interface QrFormatDropdownProps {
|
||||
format: QrCodeFormat;
|
||||
|
||||
@@ -2,12 +2,12 @@ import { pipe } from 'ramda';
|
||||
import type { FC } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Row } from 'reactstrap';
|
||||
import { ShlinkApiError } from '../../src/api/ShlinkApiError';
|
||||
import { determineOrderDir, sortList } from '../../src/utils/helpers/ordering';
|
||||
import { Message } from '../../src/utils/Message';
|
||||
import { OrderingDropdown } from '../../src/utils/OrderingDropdown';
|
||||
import { Result } from '../../src/utils/Result';
|
||||
import { SearchField } from '../../src/utils/SearchField';
|
||||
import { ShlinkApiError } from '../common/ShlinkApiError';
|
||||
import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub';
|
||||
import { Topics } from '../mercure/helpers/Topics';
|
||||
import { useSettings } from '../utils/settings';
|
||||
|
||||
@@ -2,11 +2,11 @@ import { splitEvery } from 'ramda';
|
||||
import type { FC } from 'react';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import { SimplePaginator } from '../../src/common/SimplePaginator';
|
||||
import { SimpleCard } from '../../src/utils/SimpleCard';
|
||||
import { TableOrderIcon } from '../../src/utils/table/TableOrderIcon';
|
||||
import { SimplePaginator } from '../utils/components/SimplePaginator';
|
||||
import { useQueryState } from '../utils/helpers/hooks';
|
||||
import { parseQuery } from '../utils/helpers/query';
|
||||
import { TableOrderIcon } from '../utils/table/TableOrderIcon';
|
||||
import type { TagsListChildrenProps, TagsOrder, TagsOrderableFields } from './data/TagsListChildrenProps';
|
||||
import type { TagsTableRowProps } from './TagsTableRow';
|
||||
import './TagsTable.scss';
|
||||
|
||||
@@ -3,9 +3,9 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import type { FC } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { DropdownItem } from 'reactstrap';
|
||||
import { prettify } from '../../src/utils/helpers/numbers';
|
||||
import { RowDropdownBtn } from '../../src/utils/RowDropdownBtn';
|
||||
import { useToggle } from '../utils/helpers/hooks';
|
||||
import { prettify } from '../utils/helpers/numbers';
|
||||
import { useRoutesPrefix } from '../utils/routesPrefix';
|
||||
import type { ColorGenerator } from '../utils/services/ColorGenerator';
|
||||
import type { SimplifiedTag, TagModalProps } from './data';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Button, Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap';
|
||||
import { ShlinkApiError } from '../../../src/api/ShlinkApiError';
|
||||
import { Result } from '../../../src/utils/Result';
|
||||
import { ShlinkApiError } from '../../common/ShlinkApiError';
|
||||
import type { TagModalProps } from '../data';
|
||||
import type { TagDeletion } from '../reducers/tagDelete';
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ import { pipe } from 'ramda';
|
||||
import { useState } from 'react';
|
||||
import { HexColorPicker } from 'react-colorful';
|
||||
import { Button, Input, InputGroup, Modal, ModalBody, ModalFooter, ModalHeader, Popover } from 'reactstrap';
|
||||
import { ShlinkApiError } from '../../../src/api/ShlinkApiError';
|
||||
import { Result } from '../../../src/utils/Result';
|
||||
import { handleEventPreventingDefault } from '../../../src/utils/utils';
|
||||
import { ShlinkApiError } from '../../common/ShlinkApiError';
|
||||
import { handleEventPreventingDefault } from '../../utils/helpers';
|
||||
import { useToggle } from '../../utils/helpers/hooks';
|
||||
import type { ColorGenerator } from '../../utils/services/ColorGenerator';
|
||||
import type { TagModalProps } from '../data';
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
.copy-to-clipboard-icon {
|
||||
cursor: pointer;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { faClone as copyIcon } from '@fortawesome/free-regular-svg-icons';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import type { FC } from 'react';
|
||||
import CopyToClipboard from 'react-copy-to-clipboard';
|
||||
import './CopyToClipboardIcon.scss';
|
||||
|
||||
interface CopyToClipboardIconProps {
|
||||
text: string;
|
||||
onCopy?: (text: string, result: boolean) => void;
|
||||
}
|
||||
|
||||
export const CopyToClipboardIcon: FC<CopyToClipboardIconProps> = ({ text, onCopy }) => (
|
||||
<CopyToClipboard text={text} onCopy={onCopy}>
|
||||
<FontAwesomeIcon icon={copyIcon} className="ms-2 copy-to-clipboard-icon" />
|
||||
</CopyToClipboard>
|
||||
);
|
||||
17
shlink-web-component/utils/components/ExportBtn.tsx
Normal file
17
shlink-web-component/utils/components/ExportBtn.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import { faFileCsv } from '@fortawesome/free-solid-svg-icons';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import type { FC } from 'react';
|
||||
import type { ButtonProps } from 'reactstrap';
|
||||
import { Button } from 'reactstrap';
|
||||
import { prettify } from '../helpers/numbers';
|
||||
|
||||
type ExportBtnProps = Omit<ButtonProps, 'outline' | 'color' | 'disabled'> & {
|
||||
amount?: number;
|
||||
loading?: boolean;
|
||||
};
|
||||
|
||||
export const ExportBtn: FC<ExportBtnProps> = ({ amount = 0, loading = false, ...rest }) => (
|
||||
<Button {...rest} outline color="primary" disabled={loading}>
|
||||
<FontAwesomeIcon icon={faFileCsv} /> {loading ? 'Exporting...' : <>Export ({prettify(amount)})</>}
|
||||
</Button>
|
||||
);
|
||||
24
shlink-web-component/utils/components/InfoTooltip.tsx
Normal file
24
shlink-web-component/utils/components/InfoTooltip.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { faInfoCircle as infoIcon } from '@fortawesome/free-solid-svg-icons';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import type { Placement } from '@popperjs/core';
|
||||
import type { FC, PropsWithChildren } from 'react';
|
||||
import { UncontrolledTooltip } from 'reactstrap';
|
||||
import { useElementRef } from '../helpers/hooks';
|
||||
|
||||
export type InfoTooltipProps = PropsWithChildren<{
|
||||
className?: string;
|
||||
placement: Placement;
|
||||
}>;
|
||||
|
||||
export const InfoTooltip: FC<InfoTooltipProps> = ({ className = '', placement, children }) => {
|
||||
const ref = useElementRef<HTMLSpanElement>();
|
||||
|
||||
return (
|
||||
<>
|
||||
<span className={className} ref={ref}>
|
||||
<FontAwesomeIcon icon={infoIcon} />
|
||||
</span>
|
||||
<UncontrolledTooltip target={ref} placement={placement}>{children}</UncontrolledTooltip>
|
||||
</>
|
||||
);
|
||||
};
|
||||
25
shlink-web-component/utils/components/PaginationDropdown.tsx
Normal file
25
shlink-web-component/utils/components/PaginationDropdown.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
import { DropdownItem, DropdownMenu, DropdownToggle, UncontrolledDropdown } from 'reactstrap';
|
||||
|
||||
interface PaginationDropdownProps {
|
||||
ranges: number[];
|
||||
value: number;
|
||||
setValue: (newValue: number) => void;
|
||||
toggleClassName?: string;
|
||||
}
|
||||
|
||||
export const PaginationDropdown = ({ toggleClassName, ranges, value, setValue }: PaginationDropdownProps) => (
|
||||
<UncontrolledDropdown>
|
||||
<DropdownToggle caret color="link" className={toggleClassName}>Paginate</DropdownToggle>
|
||||
<DropdownMenu end>
|
||||
{ranges.map((itemsPerPage) => (
|
||||
<DropdownItem key={itemsPerPage} active={itemsPerPage === value} onClick={() => setValue(itemsPerPage)}>
|
||||
<b>{itemsPerPage}</b> items per page
|
||||
</DropdownItem>
|
||||
))}
|
||||
<DropdownItem divider />
|
||||
<DropdownItem disabled={value === Infinity} onClick={() => setValue(Infinity)}>
|
||||
<i>Clear pagination</i>
|
||||
</DropdownItem>
|
||||
</DropdownMenu>
|
||||
</UncontrolledDropdown>
|
||||
);
|
||||
@@ -0,0 +1,3 @@
|
||||
.simple-paginator {
|
||||
user-select: none;
|
||||
}
|
||||
50
shlink-web-component/utils/components/SimplePaginator.tsx
Normal file
50
shlink-web-component/utils/components/SimplePaginator.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
import classNames from 'classnames';
|
||||
import type { FC } from 'react';
|
||||
import { Pagination, PaginationItem, PaginationLink } from 'reactstrap';
|
||||
import type { NumberOrEllipsis } from '../helpers/pagination';
|
||||
import {
|
||||
keyForPage,
|
||||
pageIsEllipsis,
|
||||
prettifyPageNumber,
|
||||
progressivePagination,
|
||||
} from '../helpers/pagination';
|
||||
import './SimplePaginator.scss';
|
||||
|
||||
interface SimplePaginatorProps {
|
||||
pagesCount: number;
|
||||
currentPage: number;
|
||||
setCurrentPage: (currentPage: number) => void;
|
||||
centered?: boolean;
|
||||
}
|
||||
|
||||
export const SimplePaginator: FC<SimplePaginatorProps> = (
|
||||
{ pagesCount, currentPage, setCurrentPage, centered = true },
|
||||
) => {
|
||||
if (pagesCount < 2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const onClick = (page: NumberOrEllipsis) => () => !pageIsEllipsis(page) && setCurrentPage(page);
|
||||
|
||||
return (
|
||||
<Pagination listClassName={classNames('flex-wrap mb-0 simple-paginator', { 'justify-content-center': centered })}>
|
||||
<PaginationItem disabled={currentPage <= 1}>
|
||||
<PaginationLink previous tag="span" onClick={onClick(currentPage - 1)} />
|
||||
</PaginationItem>
|
||||
{progressivePagination(currentPage, pagesCount).map((pageNumber, index) => (
|
||||
<PaginationItem
|
||||
key={keyForPage(pageNumber, index)}
|
||||
disabled={pageIsEllipsis(pageNumber)}
|
||||
active={currentPage === pageNumber}
|
||||
>
|
||||
<PaginationLink role="link" tag="span" onClick={onClick(pageNumber)}>
|
||||
{prettifyPageNumber(pageNumber)}
|
||||
</PaginationLink>
|
||||
</PaginationItem>
|
||||
))}
|
||||
<PaginationItem disabled={currentPage >= pagesCount}>
|
||||
<PaginationLink next tag="span" onClick={onClick(currentPage + 1)} />
|
||||
</PaginationItem>
|
||||
</Pagination>
|
||||
);
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
import { createContext, useContext, useMemo } from 'react';
|
||||
import type { SemVer } from '../../src/utils/helpers/version';
|
||||
import { versionMatch } from '../../src/utils/helpers/version';
|
||||
import type { SemVer } from './helpers/version';
|
||||
import { versionMatch } from './helpers/version';
|
||||
|
||||
const supportedFeatures = {
|
||||
domainVisits: '3.1.0',
|
||||
|
||||
16
shlink-web-component/utils/helpers/charts.ts
Normal file
16
shlink-web-component/utils/helpers/charts.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import type { ActiveElement, ChartEvent, ChartType, TooltipItem } from 'chart.js';
|
||||
import { prettify } from './numbers';
|
||||
|
||||
export const pointerOnHover = ({ native }: ChartEvent, [firstElement]: ActiveElement[]) => {
|
||||
if (!native?.target) {
|
||||
return;
|
||||
}
|
||||
|
||||
const canvas = native.target as HTMLCanvasElement;
|
||||
|
||||
canvas.style.cursor = firstElement ? 'pointer' : 'default';
|
||||
};
|
||||
|
||||
export const renderChartLabel = ({ dataset, raw }: TooltipItem<ChartType>) => `${dataset.label}: ${prettify(`${raw}`)}`;
|
||||
|
||||
export const renderPieChartLabel = ({ label, raw }: TooltipItem<ChartType>) => `${label}: ${prettify(`${raw}`)}`;
|
||||
17
shlink-web-component/utils/helpers/files.ts
Normal file
17
shlink-web-component/utils/helpers/files.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
export const saveUrl = ({ document }: Window, url: string, filename: string) => {
|
||||
const link = document.createElement('a');
|
||||
|
||||
link.setAttribute('href', url);
|
||||
link.setAttribute('download', filename);
|
||||
link.style.visibility = 'hidden';
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
};
|
||||
|
||||
export const saveCsv = (window: Window, csv: string, filename: string) => {
|
||||
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
saveUrl(window, url, filename);
|
||||
};
|
||||
32
shlink-web-component/utils/helpers/index.ts
Normal file
32
shlink-web-component/utils/helpers/index.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { isEmpty, isNil, pipe, range } from 'ramda';
|
||||
import type { SyntheticEvent } from 'react';
|
||||
|
||||
type Optional<T> = T | null | undefined;
|
||||
|
||||
export type OptionalString = Optional<string>;
|
||||
|
||||
export const handleEventPreventingDefault = <T>(handler: () => T) => pipe(
|
||||
(e: SyntheticEvent) => e.preventDefault(),
|
||||
handler,
|
||||
);
|
||||
|
||||
export const rangeOf = <T>(size: number, mappingFn: (value: number) => T, startAt = 1): T[] =>
|
||||
range(startAt, size + 1).map(mappingFn);
|
||||
|
||||
export type Empty = null | undefined | '' | never[];
|
||||
|
||||
export const hasValue = <T>(value: T | Empty): value is T => !isNil(value) && !isEmpty(value);
|
||||
|
||||
export type Nullable<T> = {
|
||||
[P in keyof T]: T[P] | null
|
||||
};
|
||||
|
||||
export const nonEmptyValueOrNull = <T>(value: T): T | null => (isEmpty(value) ? null : value);
|
||||
|
||||
export type BooleanString = 'true' | 'false';
|
||||
|
||||
export const parseBooleanToString = (value: boolean): BooleanString => (value ? 'true' : 'false');
|
||||
|
||||
export const parseOptionalBooleanToString = (value?: boolean): BooleanString | undefined => (
|
||||
value === undefined ? undefined : parseBooleanToString(value)
|
||||
);
|
||||
7
shlink-web-component/utils/helpers/json.ts
Normal file
7
shlink-web-component/utils/helpers/json.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { Parser } from '@json2csv/plainjs';
|
||||
|
||||
const jsonParser = new Parser(); // This accepts options if needed
|
||||
|
||||
export const jsonToCsv = <T>(data: T[]): string => jsonParser.parse(data);
|
||||
|
||||
export type JsonToCsv = typeof jsonToCsv;
|
||||
7
shlink-web-component/utils/helpers/numbers.ts
Normal file
7
shlink-web-component/utils/helpers/numbers.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
const TEN_ROUNDING_NUMBER = 10;
|
||||
const { ceil } = Math;
|
||||
const formatter = new Intl.NumberFormat('en-US');
|
||||
|
||||
export const prettify = (number: number | string) => formatter.format(Number(number));
|
||||
|
||||
export const roundTen = (number: number) => ceil(number / TEN_ROUNDING_NUMBER) * TEN_ROUNDING_NUMBER;
|
||||
39
shlink-web-component/utils/helpers/pagination.ts
Normal file
39
shlink-web-component/utils/helpers/pagination.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { max, min, range } from 'ramda';
|
||||
import { prettify } from './numbers';
|
||||
|
||||
const DELTA = 2;
|
||||
|
||||
export const ELLIPSIS = '...';
|
||||
|
||||
type Ellipsis = typeof ELLIPSIS;
|
||||
|
||||
export type NumberOrEllipsis = number | Ellipsis;
|
||||
|
||||
export const progressivePagination = (currentPage: number, pageCount: number): NumberOrEllipsis[] => {
|
||||
const pages: NumberOrEllipsis[] = range(
|
||||
max(DELTA, currentPage - DELTA),
|
||||
min(pageCount - 1, currentPage + DELTA) + 1,
|
||||
);
|
||||
|
||||
if (currentPage - DELTA > DELTA) {
|
||||
pages.unshift(ELLIPSIS);
|
||||
}
|
||||
if (currentPage + DELTA < pageCount - 1) {
|
||||
pages.push(ELLIPSIS);
|
||||
}
|
||||
|
||||
pages.unshift(1);
|
||||
pages.push(pageCount);
|
||||
|
||||
return pages;
|
||||
};
|
||||
|
||||
export const pageIsEllipsis = (pageNumber: NumberOrEllipsis): pageNumber is Ellipsis => pageNumber === ELLIPSIS;
|
||||
|
||||
export const prettifyPageNumber = (pageNumber: NumberOrEllipsis): string => (
|
||||
pageIsEllipsis(pageNumber) ? pageNumber : prettify(pageNumber)
|
||||
);
|
||||
|
||||
export const keyForPage = (pageNumber: NumberOrEllipsis, index: number) => (
|
||||
!pageIsEllipsis(pageNumber) ? `${pageNumber}` : `${pageNumber}_${index}`
|
||||
);
|
||||
23
shlink-web-component/utils/helpers/qrCodes.ts
Normal file
23
shlink-web-component/utils/helpers/qrCodes.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { isEmpty } from 'ramda';
|
||||
import { stringifyQuery } from './query';
|
||||
|
||||
export type QrCodeFormat = 'svg' | 'png';
|
||||
|
||||
export type QrErrorCorrection = 'L' | 'M' | 'Q' | 'H';
|
||||
|
||||
export interface QrCodeOptions {
|
||||
size: number;
|
||||
format: QrCodeFormat;
|
||||
margin: number;
|
||||
errorCorrection: QrErrorCorrection;
|
||||
}
|
||||
|
||||
export const buildQrCodeUrl = (shortUrl: string, { margin, ...options }: QrCodeOptions): string => {
|
||||
const baseUrl = `${shortUrl}/qr-code`;
|
||||
const query = stringifyQuery({
|
||||
...options,
|
||||
margin: margin > 0 ? margin : undefined,
|
||||
});
|
||||
|
||||
return `${baseUrl}${isEmpty(query) ? '' : `?${query}`}`;
|
||||
};
|
||||
21
shlink-web-component/utils/helpers/version.ts
Normal file
21
shlink-web-component/utils/helpers/version.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { compare } from 'compare-versions';
|
||||
|
||||
type SemVerPatternFragment = `${bigint | '*'}`;
|
||||
|
||||
type SemVerPattern = SemVerPatternFragment
|
||||
| `${SemVerPatternFragment}.${SemVerPatternFragment}`
|
||||
| `${SemVerPatternFragment}.${SemVerPatternFragment}.${SemVerPatternFragment}`;
|
||||
|
||||
type Versions = {
|
||||
maxVersion?: SemVerPattern;
|
||||
minVersion?: SemVerPattern;
|
||||
};
|
||||
|
||||
export type SemVer = `${bigint}.${bigint}.${bigint}` | 'latest';
|
||||
|
||||
export const versionMatch = (versionToMatch: SemVer, { maxVersion, minVersion }: Versions): boolean => {
|
||||
const matchesMinVersion = !minVersion || compare(versionToMatch, minVersion, '>=');
|
||||
const matchesMaxVersion = !maxVersion || compare(versionToMatch, maxVersion, '<=');
|
||||
|
||||
return matchesMaxVersion && matchesMinVersion;
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
import { isNil } from 'ramda';
|
||||
import type { LocalStorage } from '../../../src/utils/services/LocalStorage';
|
||||
import { rangeOf } from '../../../src/utils/utils';
|
||||
import { rangeOf } from '../helpers';
|
||||
import type { LocalStorage } from './LocalStorage';
|
||||
|
||||
const HEX_COLOR_LENGTH = 6;
|
||||
const HEX_DIGITS = '0123456789ABCDEF';
|
||||
|
||||
13
shlink-web-component/utils/services/ImageDownloader.ts
Normal file
13
shlink-web-component/utils/services/ImageDownloader.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { saveUrl } from '../helpers/files';
|
||||
import type { Fetch } from '../types';
|
||||
|
||||
export class ImageDownloader {
|
||||
public constructor(private readonly fetch: Fetch, private readonly window: Window) {}
|
||||
|
||||
public async saveImage(imgUrl: string, filename: string): Promise<void> {
|
||||
const data = await this.fetch(imgUrl).then((resp) => resp.blob());
|
||||
const url = URL.createObjectURL(data);
|
||||
|
||||
saveUrl(this.window, url, filename);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { JsonToCsv } from '../../../src/utils/helpers/csvjson';
|
||||
import { saveCsv } from '../../../src/utils/helpers/files';
|
||||
import type { ExportableShortUrl } from '../../short-urls/data';
|
||||
import type { NormalizedVisit } from '../../visits/types';
|
||||
import { saveCsv } from '../helpers/files';
|
||||
import type { JsonToCsv } from '../helpers/json';
|
||||
|
||||
export class ReportExporter {
|
||||
public constructor(private readonly window: Window, private readonly jsonToCsv: JsonToCsv) {
|
||||
|
||||
@@ -1,13 +1,23 @@
|
||||
import type Bottle from 'bottlejs';
|
||||
import { useTimeoutToggle } from '../helpers/hooks';
|
||||
import { jsonToCsv } from '../helpers/json';
|
||||
import { ColorGenerator } from './ColorGenerator';
|
||||
import { ImageDownloader } from './ImageDownloader';
|
||||
import { LocalStorage } from './LocalStorage';
|
||||
import { ReportExporter } from './ReportExporter';
|
||||
|
||||
export function provideServices(bottle: Bottle) {
|
||||
bottle.constant('window', window);
|
||||
bottle.constant('fetch', window.fetch.bind(window));
|
||||
bottle.service('ImageDownloader', ImageDownloader, 'fetch', 'window');
|
||||
|
||||
bottle.constant('localStorage', window.localStorage);
|
||||
bottle.service('Storage', LocalStorage, 'localStorage');
|
||||
bottle.service('ColorGenerator', ColorGenerator, 'Storage');
|
||||
|
||||
bottle.constant('jsonToCsv', jsonToCsv);
|
||||
bottle.service('ReportExporter', ReportExporter, 'window', 'jsonToCsv');
|
||||
|
||||
bottle.constant('setTimeout', window.setTimeout);
|
||||
bottle.constant('clearTimeout', window.clearTimeout);
|
||||
bottle.serviceFactory('useTimeoutToggle', useTimeoutToggle, 'setTimeout', 'clearTimeout');
|
||||
|
||||
19
shlink-web-component/utils/table/TableOrderIcon.tsx
Normal file
19
shlink-web-component/utils/table/TableOrderIcon.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import { faCaretDown as caretDownIcon, faCaretUp as caretUpIcon } from '@fortawesome/free-solid-svg-icons';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import type { Order } from '../../../src/utils/helpers/ordering';
|
||||
|
||||
interface TableOrderIconProps<T> {
|
||||
currentOrder: Order<T>;
|
||||
field: T;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function TableOrderIcon<T extends string = string>(
|
||||
{ currentOrder, field, className = 'ms-1' }: TableOrderIconProps<T>,
|
||||
) {
|
||||
if (!currentOrder.dir || currentOrder.field !== field) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <FontAwesomeIcon icon={currentOrder.dir === 'ASC' ? caretUpIcon : caretDownIcon} className={className} />;
|
||||
}
|
||||
3
shlink-web-component/utils/types/index.ts
Normal file
3
shlink-web-component/utils/types/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export type MediaMatcher = (query: string) => MediaQueryList;
|
||||
|
||||
export type Fetch = typeof window.fetch;
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { useGoBack } from '../../src/utils/helpers/hooks';
|
||||
import type { ShlinkVisitsParams } from '../api-contract';
|
||||
import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub';
|
||||
import { Topics } from '../mercure/helpers/Topics';
|
||||
import { useGoBack } from '../utils/helpers/hooks';
|
||||
import type { ReportExporter } from '../utils/services/ReportExporter';
|
||||
import type { DomainVisits as DomainVisitsState, LoadDomainVisits } from './reducers/domainVisits';
|
||||
import type { NormalizedVisit } from './types';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useGoBack } from '../../src/utils/helpers/hooks';
|
||||
import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub';
|
||||
import { Topics } from '../mercure/helpers/Topics';
|
||||
import { useGoBack } from '../utils/helpers/hooks';
|
||||
import type { ReportExporter } from '../utils/services/ReportExporter';
|
||||
import type { LoadVisits, VisitsInfo } from './reducers/types';
|
||||
import type { NormalizedVisit, VisitsParams } from './types';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useGoBack } from '../../src/utils/helpers/hooks';
|
||||
import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub';
|
||||
import { Topics } from '../mercure/helpers/Topics';
|
||||
import { useGoBack } from '../utils/helpers/hooks';
|
||||
import type { ReportExporter } from '../utils/services/ReportExporter';
|
||||
import type { LoadOrphanVisits } from './reducers/orphanVisits';
|
||||
import type { VisitsInfo } from './reducers/types';
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useLocation, useParams } from 'react-router-dom';
|
||||
import { useGoBack } from '../../src/utils/helpers/hooks';
|
||||
import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub';
|
||||
import { Topics } from '../mercure/helpers/Topics';
|
||||
import type { ShortUrlIdentifier } from '../short-urls/data';
|
||||
import { urlDecodeShortCode } from '../short-urls/helpers';
|
||||
import type { ShortUrlDetail } from '../short-urls/reducers/shortUrlDetail';
|
||||
import { useGoBack } from '../utils/helpers/hooks';
|
||||
import { parseQuery } from '../utils/helpers/query';
|
||||
import type { ReportExporter } from '../utils/services/ReportExporter';
|
||||
import type { LoadShortUrlVisits, ShortUrlVisits as ShortUrlVisitsState } from './reducers/shortUrlVisits';
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { useGoBack } from '../../src/utils/helpers/hooks';
|
||||
import type { ShlinkVisitsParams } from '../api-contract';
|
||||
import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub';
|
||||
import { Topics } from '../mercure/helpers/Topics';
|
||||
import { useGoBack } from '../utils/helpers/hooks';
|
||||
import type { ColorGenerator } from '../utils/services/ColorGenerator';
|
||||
import type { ReportExporter } from '../utils/services/ReportExporter';
|
||||
import type { LoadTagVisits, TagVisits as TagVisitsState } from './reducers/tagVisits';
|
||||
|
||||
@@ -7,15 +7,15 @@ import type { FC, PropsWithChildren } from 'react';
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { Navigate, Route, Routes, useLocation } from 'react-router-dom';
|
||||
import { Button, Progress, Row } from 'reactstrap';
|
||||
import { ShlinkApiError } from '../../src/api/ShlinkApiError';
|
||||
import { DateRangeSelector } from '../../src/utils/dates/DateRangeSelector';
|
||||
import { ExportBtn } from '../../src/utils/ExportBtn';
|
||||
import type { DateInterval, DateRange } from '../../src/utils/helpers/dateIntervals';
|
||||
import { toDateRange } from '../../src/utils/helpers/dateIntervals';
|
||||
import { prettify } from '../../src/utils/helpers/numbers';
|
||||
import { Message } from '../../src/utils/Message';
|
||||
import { NavPillItem, NavPills } from '../../src/utils/NavPills';
|
||||
import { Result } from '../../src/utils/Result';
|
||||
import { ShlinkApiError } from '../common/ShlinkApiError';
|
||||
import { ExportBtn } from '../utils/components/ExportBtn';
|
||||
import { prettify } from '../utils/helpers/numbers';
|
||||
import { useSetting } from '../utils/settings';
|
||||
import { DoughnutChartCard } from './charts/DoughnutChartCard';
|
||||
import { LineChartCard } from './charts/LineChartCard';
|
||||
|
||||
@@ -4,14 +4,14 @@ import classNames from 'classnames';
|
||||
import { min, splitEvery } from 'ramda';
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { UncontrolledTooltip } from 'reactstrap';
|
||||
import { SimplePaginator } from '../../src/common/SimplePaginator';
|
||||
import { Time } from '../../src/utils/dates/Time';
|
||||
import { prettify } from '../../src/utils/helpers/numbers';
|
||||
import type { Order } from '../../src/utils/helpers/ordering';
|
||||
import { determineOrderDir, sortList } from '../../src/utils/helpers/ordering';
|
||||
import { SearchField } from '../../src/utils/SearchField';
|
||||
import { TableOrderIcon } from '../../src/utils/table/TableOrderIcon';
|
||||
import type { MediaMatcher } from '../../src/utils/types';
|
||||
import { SimplePaginator } from '../utils/components/SimplePaginator';
|
||||
import { prettify } from '../utils/helpers/numbers';
|
||||
import { TableOrderIcon } from '../utils/table/TableOrderIcon';
|
||||
import type { MediaMatcher } from '../utils/types';
|
||||
import type { NormalizedOrphanVisit, NormalizedVisit } from './types';
|
||||
import './VisitsTable.scss';
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ import { keys, values } from 'ramda';
|
||||
import type { FC } from 'react';
|
||||
import { memo, useState } from 'react';
|
||||
import { Doughnut } from 'react-chartjs-2';
|
||||
import { renderPieChartLabel } from '../../../src/utils/helpers/charts';
|
||||
import { isDarkThemeEnabled, PRIMARY_DARK_COLOR, PRIMARY_LIGHT_COLOR } from '../../../src/utils/theme';
|
||||
import { renderPieChartLabel } from '../../utils/helpers/charts';
|
||||
import type { Stats } from '../types';
|
||||
import { DoughnutChartLegend } from './DoughnutChartLegend';
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@ import { keys, values } from 'ramda';
|
||||
import type { FC, MutableRefObject } from 'react';
|
||||
import { useRef } from 'react';
|
||||
import { Bar, getElementAtEvent } from 'react-chartjs-2';
|
||||
import { pointerOnHover, renderChartLabel } from '../../../src/utils/helpers/charts';
|
||||
import { prettify } from '../../../src/utils/helpers/numbers';
|
||||
import { HIGHLIGHTED_COLOR, HIGHLIGHTED_COLOR_ALPHA, MAIN_COLOR, MAIN_COLOR_ALPHA } from '../../../src/utils/theme';
|
||||
import { pointerOnHover, renderChartLabel } from '../../utils/helpers/charts';
|
||||
import { prettify } from '../../utils/helpers/numbers';
|
||||
import type { Stats } from '../types';
|
||||
import { fillTheGaps } from '../utils';
|
||||
|
||||
|
||||
@@ -23,13 +23,13 @@ import {
|
||||
DropdownToggle,
|
||||
UncontrolledDropdown,
|
||||
} from 'reactstrap';
|
||||
import { pointerOnHover, renderChartLabel } from '../../../src/utils/helpers/charts';
|
||||
import { STANDARD_DATE_FORMAT } from '../../../src/utils/helpers/date';
|
||||
import { prettify } from '../../../src/utils/helpers/numbers';
|
||||
import { HIGHLIGHTED_COLOR, MAIN_COLOR } from '../../../src/utils/theme';
|
||||
import { ToggleSwitch } from '../../../src/utils/ToggleSwitch';
|
||||
import { rangeOf } from '../../../src/utils/utils';
|
||||
import { rangeOf } from '../../utils/helpers';
|
||||
import { pointerOnHover, renderChartLabel } from '../../utils/helpers/charts';
|
||||
import { useToggle } from '../../utils/helpers/hooks';
|
||||
import { prettify } from '../../utils/helpers/numbers';
|
||||
import type { NormalizedVisit, Stats } from '../types';
|
||||
import { fillTheGaps } from '../utils';
|
||||
import './LineChartCard.scss';
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { fromPairs, pipe, reverse, sortBy, splitEvery, toLower, toPairs, type, zipObj } from 'ramda';
|
||||
import type { FC, ReactNode } from 'react';
|
||||
import { useState } from 'react';
|
||||
import { SimplePaginator } from '../../../src/common/SimplePaginator';
|
||||
import { roundTen } from '../../../src/utils/helpers/numbers';
|
||||
import type { Order } from '../../../src/utils/helpers/ordering';
|
||||
import { OrderingDropdown } from '../../../src/utils/OrderingDropdown';
|
||||
import { PaginationDropdown } from '../../../src/utils/PaginationDropdown';
|
||||
import { rangeOf } from '../../../src/utils/utils';
|
||||
import { PaginationDropdown } from '../../utils/components/PaginationDropdown';
|
||||
import { SimplePaginator } from '../../utils/components/SimplePaginator';
|
||||
import { rangeOf } from '../../utils/helpers';
|
||||
import { roundTen } from '../../utils/helpers/numbers';
|
||||
import type { Stats, StatsRow } from '../types';
|
||||
import { ChartCard } from './ChartCard';
|
||||
import type { HorizontalBarChartProps } from './HorizontalBarChart';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { DropdownItemProps } from 'reactstrap';
|
||||
import { DropdownItem } from 'reactstrap';
|
||||
import { DropdownBtn } from '../../../src/utils/DropdownBtn';
|
||||
import { hasValue } from '../../../src/utils/utils';
|
||||
import { hasValue } from '../../utils/helpers';
|
||||
import type { OrphanVisitType, VisitsFilter } from '../types';
|
||||
|
||||
interface VisitsFilterDropdownProps {
|
||||
|
||||
@@ -5,8 +5,8 @@ import { useLocation, useNavigate } from 'react-router-dom';
|
||||
import { formatIsoDate } from '../../../src/utils/helpers/date';
|
||||
import type { DateRange } from '../../../src/utils/helpers/dateIntervals';
|
||||
import { datesToDateRange } from '../../../src/utils/helpers/dateIntervals';
|
||||
import type { BooleanString } from '../../../src/utils/utils';
|
||||
import { parseBooleanToString } from '../../../src/utils/utils';
|
||||
import type { BooleanString } from '../../utils/helpers';
|
||||
import { parseBooleanToString } from '../../utils/helpers';
|
||||
import { parseQuery, stringifyQuery } from '../../utils/helpers/query';
|
||||
import type { OrphanVisitType, VisitsFilter } from '../types';
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { isNil, map } from 'ramda';
|
||||
import { hasValue } from '../../../src/utils/utils';
|
||||
import { hasValue } from '../../utils/helpers';
|
||||
import type { CityStats, NormalizedVisit, Stats, Visit, VisitsStats } from '../types';
|
||||
import { isNormalizedOrphanVisit, isOrphanVisit } from '../types/helpers';
|
||||
import { extractDomain, parseUserAgent } from '../utils';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import bowser from 'bowser';
|
||||
import { zipObj } from 'ramda';
|
||||
import type { Empty } from '../../../src/utils/utils';
|
||||
import { hasValue } from '../../../src/utils/utils';
|
||||
import type { Empty } from '../../utils/helpers';
|
||||
import { hasValue } from '../../utils/helpers';
|
||||
import type { Stats, UserAgent } from '../types';
|
||||
|
||||
const DEFAULT = 'Others';
|
||||
|
||||
Reference in New Issue
Block a user