mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-07-23 12:11:59 +00:00
Move more components to shlink-web-component when applicable
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
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}`)}`;
|
||||
@@ -1,6 +1,5 @@
|
||||
import { endOfDay, startOfDay, subDays } from 'date-fns';
|
||||
import { cond, filter, isEmpty, T } from 'ramda';
|
||||
import { equals } from '../utils';
|
||||
import type { DateOrString } from './date';
|
||||
import { dateOrNull, formatInternational, isBeforeOrEqual, now, parseISO } from './date';
|
||||
|
||||
@@ -68,6 +67,7 @@ export const rangeOrIntervalToString = (range?: DateRange | DateInterval): strin
|
||||
|
||||
const startOfDaysAgo = (daysAgo: number) => startOfDay(subDays(now(), daysAgo));
|
||||
const endingToday = (startDate: Date): DateRange => ({ startDate, endDate: endOfDay(now()) });
|
||||
const equals = (value: any) => (otherValue: any) => value === otherValue;
|
||||
|
||||
export const intervalToDateRange = cond<[DateInterval | undefined], DateRange>([
|
||||
[equals('today'), () => endingToday(startOfDay(now()))],
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
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;
|
||||
@@ -1,39 +0,0 @@
|
||||
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}`
|
||||
);
|
||||
@@ -1,23 +0,0 @@
|
||||
import { isEmpty } from 'ramda';
|
||||
import { stringifyQuery } from '../../../shlink-web-component/utils/helpers/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}`}`;
|
||||
};
|
||||
@@ -1,18 +1,20 @@
|
||||
import { compare } from 'compare-versions';
|
||||
import { identity, memoizeWith } from 'ramda';
|
||||
import type { Empty } from '../utils';
|
||||
import { hasValue } from '../utils';
|
||||
import { identity, isEmpty, isNil, memoizeWith } from 'ramda';
|
||||
|
||||
type Empty = null | undefined | '' | never[];
|
||||
|
||||
const hasValue = <T>(value: T | Empty): value is T => !isNil(value) && !isEmpty(value);
|
||||
|
||||
type SemVerPatternFragment = `${bigint | '*'}`;
|
||||
|
||||
export type SemVerPattern = SemVerPatternFragment
|
||||
type SemVerPattern = SemVerPatternFragment
|
||||
| `${SemVerPatternFragment}.${SemVerPatternFragment}`
|
||||
| `${SemVerPatternFragment}.${SemVerPatternFragment}.${SemVerPatternFragment}`;
|
||||
|
||||
export interface Versions {
|
||||
type Versions = {
|
||||
maxVersion?: SemVerPattern;
|
||||
minVersion?: SemVerPattern;
|
||||
}
|
||||
};
|
||||
|
||||
export type SemVer = `${bigint}.${bigint}.${bigint}` | 'latest';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user