ydb-embedded-ui 6.29.1 → 6.29.3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/components/ButtonWithConfirmDialog/ButtonWithConfirmDialog.d.ts +2 -1
- package/dist/components/ButtonWithConfirmDialog/ButtonWithConfirmDialog.js +2 -2
- package/dist/components/ButtonWithConfirmDialog/ButtonWithConfirmDialog.js.map +1 -1
- package/dist/components/FormattedBytes/FormattedBytes.d.ts +3 -2
- package/dist/components/FormattedBytes/FormattedBytes.js.map +1 -1
- package/dist/components/FormattedBytes/utils.d.ts +3 -2
- package/dist/components/FormattedBytes/utils.js.map +1 -1
- package/dist/components/PaginatedTable/PaginatedTable.d.ts +2 -2
- package/dist/components/PaginatedTable/PaginatedTable.js +10 -15
- package/dist/components/PaginatedTable/PaginatedTable.js.map +1 -1
- package/dist/components/PaginatedTable/PaginatedTable.scss +5 -1
- package/dist/components/PaginatedTable/TableChunk.d.ts +3 -3
- package/dist/components/PaginatedTable/TableChunk.js +7 -10
- package/dist/components/PaginatedTable/TableChunk.js.map +1 -1
- package/dist/components/PaginatedTable/constants.d.ts +1 -1
- package/dist/components/PaginatedTable/constants.js +1 -1
- package/dist/components/PaginatedTable/useScrollBasedChunks.d.ts +5 -3
- package/dist/components/PaginatedTable/useScrollBasedChunks.js +43 -23
- package/dist/components/PaginatedTable/useScrollBasedChunks.js.map +1 -1
- package/dist/components/PaginatedTable/utils.d.ts +18 -0
- package/dist/components/PaginatedTable/utils.js +27 -0
- package/dist/components/PaginatedTable/utils.js.map +1 -1
- package/dist/containers/Cluster/ClusterDashboard/components/ClusterMetricsCores.js +9 -2
- package/dist/containers/Cluster/ClusterDashboard/components/ClusterMetricsCores.js.map +1 -1
- package/dist/containers/Node/Node.js +2 -2
- package/dist/containers/Node/Node.js.map +1 -1
- package/dist/containers/Nodes/NodesWrapper.d.ts +1 -1
- package/dist/containers/Nodes/PaginatedNodes.d.ts +1 -1
- package/dist/containers/PDiskPage/PDiskPage.js +3 -2
- package/dist/containers/PDiskPage/PDiskPage.js.map +1 -1
- package/dist/containers/Storage/PaginatedStorage.d.ts +1 -1
- package/dist/containers/Storage/PaginatedStorageGroups.js +2 -2
- package/dist/containers/Storage/PaginatedStorageGroups.js.map +1 -1
- package/dist/containers/Storage/PaginatedStorageNodes.js +2 -2
- package/dist/containers/Storage/PaginatedStorageNodes.js.map +1 -1
- package/dist/containers/Storage/StorageGroups/PaginatedStorageGroupsTable.d.ts +1 -1
- package/dist/containers/Storage/StorageNodes/PaginatedStorageNodesTable.d.ts +1 -1
- package/dist/containers/Storage/StorageWrapper.d.ts +1 -1
- package/dist/containers/StorageGroupPage/StorageGroupPage.js +3 -2
- package/dist/containers/StorageGroupPage/StorageGroupPage.js.map +1 -1
- package/dist/containers/Tablets/TabletsTable.js +3 -3
- package/dist/containers/Tablets/TabletsTable.js.map +1 -1
- package/dist/containers/VDiskPage/VDiskPage.js +3 -2
- package/dist/containers/VDiskPage/VDiskPage.js.map +1 -1
- package/dist/services/settings.d.ts +1 -1
- package/dist/services/settings.js +1 -1
- package/dist/services/settings.js.map +1 -1
- package/dist/utils/bytesParsers/formatBytes.d.ts +2 -13
- package/dist/utils/bytesParsers/formatBytes.js.map +1 -1
- package/dist/utils/bytesParsers/i18n/en.json +4 -0
- package/dist/utils/bytesParsers/i18n/index.d.ts +1 -1
- package/dist/utils/bytesParsers/i18n/index.js +1 -2
- package/dist/utils/bytesParsers/i18n/index.js.map +1 -1
- package/dist/utils/dataFormatters/__test__/formatNumbers.test.d.ts +1 -0
- package/dist/utils/dataFormatters/__test__/formatNumbers.test.js +37 -0
- package/dist/utils/dataFormatters/__test__/formatNumbers.test.js.map +1 -0
- package/dist/utils/dataFormatters/__test__/formatStorageValues.test.js +1 -5
- package/dist/utils/dataFormatters/__test__/formatStorageValues.test.js.map +1 -1
- package/dist/utils/dataFormatters/common.d.ts +13 -0
- package/dist/utils/dataFormatters/common.js +25 -0
- package/dist/utils/dataFormatters/common.js.map +1 -0
- package/dist/utils/dataFormatters/dataFormatters.d.ts +3 -2
- package/dist/utils/dataFormatters/dataFormatters.js +9 -41
- package/dist/utils/dataFormatters/dataFormatters.js.map +1 -1
- package/dist/utils/dataFormatters/formatNumber.d.ts +43 -0
- package/dist/utils/dataFormatters/formatNumber.js +82 -0
- package/dist/utils/dataFormatters/formatNumber.js.map +1 -0
- package/package.json +1 -1
- package/dist/utils/bytesParsers/i18n/ru.json +0 -8
@@ -1,15 +1,16 @@
|
|
1
1
|
import type { TVDiskID, TVSlotId } from '../../types/api/vdisk';
|
2
2
|
import type { BytesSizes } from '../bytesParsers/formatBytes';
|
3
|
+
import type { Digits } from './formatNumber';
|
3
4
|
export declare const formatBytes: (bytes?: string | number) => string;
|
4
5
|
export declare const formatBps: (bytes?: string | number) => string;
|
5
6
|
export declare const stringifyVdiskId: (id?: TVDiskID | TVSlotId) => string;
|
6
7
|
export declare const formatUptime: (seconds: number) => string;
|
7
8
|
export declare const formatMsToUptime: (ms?: number) => string | 0 | undefined;
|
8
|
-
export declare
|
9
|
+
export declare function formatStorageValues(value?: number, total?: number, size?: BytesSizes, delimiter?: string, withValueLabel?: boolean): string[];
|
10
|
+
export declare function formatNumericValues(value?: number, total?: number, size?: Digits, delimiter?: string, withValueLabel?: boolean): string[];
|
9
11
|
export declare const formatStorageValuesToGb: (value?: number, total?: number) => string[];
|
10
12
|
export declare const formatStorageValuesToTb: (value?: number, total?: number) => string[];
|
11
13
|
export declare const formatNumber: (number?: unknown) => string;
|
12
|
-
export declare const formatNumberCustom: (number?: number) => string;
|
13
14
|
export declare const formatPercent: (number?: unknown) => string;
|
14
15
|
export declare const formatSecondsToHours: (seconds: number) => string;
|
15
16
|
export declare const roundToPrecision: (value: number | string, precision?: number) => number;
|
@@ -3,6 +3,8 @@ import { formatBytes as formatBytesCustom, getSizeWithSignificantDigits, } from
|
|
3
3
|
import { DAY_IN_SECONDS, HOUR_IN_SECONDS } from '../constants';
|
4
4
|
import { configuredNumeral } from '../numeral';
|
5
5
|
import { isNumeric } from '../utils';
|
6
|
+
import { formatValues } from './common';
|
7
|
+
import { formatNumberWithDigits, getNumberWithSignificantDigits } from './formatNumber';
|
6
8
|
import i18n from './i18n';
|
7
9
|
// Here you can't control displayed size and precision
|
8
10
|
// If you need more custom format, use formatBytesCustom instead
|
@@ -34,39 +36,12 @@ export const formatUptime = (seconds) => {
|
|
34
36
|
export const formatMsToUptime = (ms) => {
|
35
37
|
return ms && formatUptime(ms / 1000);
|
36
38
|
};
|
37
|
-
export
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
valueWithSizeLabel = false;
|
44
|
-
valuePrecision = 1;
|
45
|
-
}
|
46
|
-
let formattedValue = formatBytesCustom({
|
47
|
-
value,
|
48
|
-
withSizeLabel: valueWithSizeLabel,
|
49
|
-
size: size || calculatedSize,
|
50
|
-
precision: valuePrecision,
|
51
|
-
});
|
52
|
-
if (value && value > 0) {
|
53
|
-
while (formattedValue === '0') {
|
54
|
-
valuePrecision += 1;
|
55
|
-
formattedValue = formatBytesCustom({
|
56
|
-
value,
|
57
|
-
withSizeLabel: valueWithSizeLabel,
|
58
|
-
size: size || calculatedSize,
|
59
|
-
precision: valuePrecision,
|
60
|
-
});
|
61
|
-
}
|
62
|
-
}
|
63
|
-
const formattedTotal = formatBytesCustom({
|
64
|
-
value: total,
|
65
|
-
size: size || calculatedSize,
|
66
|
-
delimiter,
|
67
|
-
});
|
68
|
-
return [formattedValue, formattedTotal];
|
69
|
-
};
|
39
|
+
export function formatStorageValues(value, total, size, delimiter, withValueLabel) {
|
40
|
+
return formatValues(formatBytesCustom, getSizeWithSignificantDigits, value, total, size, delimiter, withValueLabel);
|
41
|
+
}
|
42
|
+
export function formatNumericValues(value, total, size, delimiter, withValueLabel) {
|
43
|
+
return formatValues(formatNumberWithDigits, getNumberWithSignificantDigits, value, total, size, delimiter, withValueLabel);
|
44
|
+
}
|
70
45
|
export const formatStorageValuesToGb = (value, total) => {
|
71
46
|
return formatStorageValues(value, total, 'gb');
|
72
47
|
};
|
@@ -80,19 +55,12 @@ export const formatNumber = (number) => {
|
|
80
55
|
// "," in format is delimiter sign, not delimiter itself
|
81
56
|
return configuredNumeral(number).format('0,0.[00000]');
|
82
57
|
};
|
83
|
-
export const formatNumberCustom = (number) => {
|
84
|
-
return configuredNumeral(number).format('0.[0]a');
|
85
|
-
};
|
86
58
|
export const formatPercent = (number) => {
|
87
59
|
if (!isNumeric(number)) {
|
88
60
|
return '';
|
89
61
|
}
|
90
62
|
const configuredNumber = configuredNumeral(number);
|
91
|
-
const
|
92
|
-
let format = '0.[0]%';
|
93
|
-
if (numberValue && numberValue < 0.001) {
|
94
|
-
format = '0.[00]%';
|
95
|
-
}
|
63
|
+
const format = '0%';
|
96
64
|
return configuredNumber.format(format);
|
97
65
|
};
|
98
66
|
export const formatSecondsToHours = (seconds) => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"dataFormatters.js","sourceRoot":"","sources":["../../../src/utils/dataFormatters/dataFormatters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAC;AAGrD,OAAO,EACH,WAAW,IAAI,iBAAiB,EAChC,4BAA4B,GAC/B,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAC,cAAc,EAAE,eAAe,EAAC,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAC,iBAAiB,EAAC,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AAEnC,OAAO,IAAI,MAAM,QAAQ,CAAC;AAE1B,sDAAsD;AACtD,gEAAgE;AAChE,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAuB,EAAE,EAAE;IACnD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;QACpB,OAAO,EAAE,CAAC;IACd,CAAC;IAED,qDAAqD;IACrD,OAAO,iBAAiB,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAClD,CAAC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M,eAAe,GAAG,CAAC,KAAuB,EAAE,YAAY,GAAG,EAAE,EAAE,EAAE;;IAC1E,MAAM,aAAa,GAAG,MAAA,aAAa,CAAC,KAAK,CAAC,0CAAE,MAAM,CAAC,yBAAyB,CAAC,CAAC;IAE9E,OAAO,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,YAAY,CAAC;AACzC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,YAA6B,EAAE,EAAE;IACjE,MAAM,WAAW,GAAG,IAAI,IAAI,EAAE,CAAC;IAC/B,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;IAC1D,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC;AACvC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,YAA8B,EAAE,EAAE;IACzD,OAAO,YAAY,CAAC,mBAAmB,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;AACnE,CAAC,CAAC;AAEF,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC7C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACtB,OAAO,EAAE,CAAC;IACd,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;SAAM,CAAC;QACJ,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC5B,CAAC;AACL,CAAC"}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import type { FormatValuesArgs } from './common';
|
2
|
+
declare const sizes: {
|
3
|
+
thousand: {
|
4
|
+
value: number;
|
5
|
+
label: string;
|
6
|
+
};
|
7
|
+
million: {
|
8
|
+
value: number;
|
9
|
+
label: string;
|
10
|
+
};
|
11
|
+
billion: {
|
12
|
+
value: number;
|
13
|
+
label: string;
|
14
|
+
};
|
15
|
+
trillion: {
|
16
|
+
value: number;
|
17
|
+
label: string;
|
18
|
+
};
|
19
|
+
};
|
20
|
+
export type Digits = keyof typeof sizes;
|
21
|
+
/**
|
22
|
+
* This function is needed to keep more than 3 digits of the same size.
|
23
|
+
*
|
24
|
+
* @param significantDigits - number of digits above 3
|
25
|
+
* @returns size to format value to get required number of digits
|
26
|
+
*
|
27
|
+
* By default value converted to the next size when it's above 1000,
|
28
|
+
* so we have 900k and 1m. To extend it additional significantDigits could be set
|
29
|
+
*
|
30
|
+
* significantDigits value added above default 3
|
31
|
+
*
|
32
|
+
* significantDigits = 1 - 9 000k and 10m
|
33
|
+
*
|
34
|
+
* significantDigits = 2 - 90 000m and 100b
|
35
|
+
*
|
36
|
+
* significantDigits = 3 - 900 000b and 1000t
|
37
|
+
*/
|
38
|
+
export declare const getNumberWithSignificantDigits: (value: number, significantDigits: number) => "thousand" | "million" | "billion" | "trillion";
|
39
|
+
/**
|
40
|
+
* @param significantDigits - number of digits above 3
|
41
|
+
*/
|
42
|
+
export declare const formatNumberWithDigits: ({ value, size, withSizeLabel, significantDigits, delimiter, ...params }: FormatValuesArgs<Digits>) => string;
|
43
|
+
export {};
|
@@ -0,0 +1,82 @@
|
|
1
|
+
import i18n from '../bytesParsers/i18n';
|
2
|
+
import { UNBREAKABLE_GAP, isNumeric } from '../utils';
|
3
|
+
import { formatNumber, roundToPrecision } from './dataFormatters';
|
4
|
+
const sizes = {
|
5
|
+
thousand: {
|
6
|
+
value: 1000,
|
7
|
+
label: i18n('label_thousand'),
|
8
|
+
},
|
9
|
+
million: {
|
10
|
+
value: 1000000,
|
11
|
+
label: i18n('label_million'),
|
12
|
+
},
|
13
|
+
billion: {
|
14
|
+
value: 1000000000,
|
15
|
+
label: i18n('label_billion'),
|
16
|
+
},
|
17
|
+
trillion: {
|
18
|
+
value: 1000000000000,
|
19
|
+
label: i18n('label_trillion'),
|
20
|
+
},
|
21
|
+
};
|
22
|
+
/**
|
23
|
+
* This function is needed to keep more than 3 digits of the same size.
|
24
|
+
*
|
25
|
+
* @param significantDigits - number of digits above 3
|
26
|
+
* @returns size to format value to get required number of digits
|
27
|
+
*
|
28
|
+
* By default value converted to the next size when it's above 1000,
|
29
|
+
* so we have 900k and 1m. To extend it additional significantDigits could be set
|
30
|
+
*
|
31
|
+
* significantDigits value added above default 3
|
32
|
+
*
|
33
|
+
* significantDigits = 1 - 9 000k and 10m
|
34
|
+
*
|
35
|
+
* significantDigits = 2 - 90 000m and 100b
|
36
|
+
*
|
37
|
+
* significantDigits = 3 - 900 000b and 1000t
|
38
|
+
*/
|
39
|
+
export const getNumberWithSignificantDigits = (value, significantDigits) => {
|
40
|
+
const multiplier = 10 ** significantDigits;
|
41
|
+
const thousandLevel = sizes.thousand.value * multiplier;
|
42
|
+
const millionLevel = sizes.million.value * multiplier;
|
43
|
+
const billionLevel = sizes.billion.value * multiplier;
|
44
|
+
const trillionLevel = sizes.trillion.value * multiplier;
|
45
|
+
let size = 'thousand';
|
46
|
+
if (value > thousandLevel) {
|
47
|
+
size = 'thousand';
|
48
|
+
}
|
49
|
+
if (value >= millionLevel) {
|
50
|
+
size = 'million';
|
51
|
+
}
|
52
|
+
if (value >= billionLevel) {
|
53
|
+
size = 'billion';
|
54
|
+
}
|
55
|
+
if (value >= trillionLevel) {
|
56
|
+
size = 'trillion';
|
57
|
+
}
|
58
|
+
return size;
|
59
|
+
};
|
60
|
+
const formatToSize = ({ value, size = 'thousand', precision = 0 }) => {
|
61
|
+
const result = roundToPrecision(Number(value) / sizes[size].value, precision);
|
62
|
+
return formatNumber(result);
|
63
|
+
};
|
64
|
+
const addSizeLabel = (result, size, delimiter = UNBREAKABLE_GAP) => {
|
65
|
+
return result + delimiter + sizes[size].label;
|
66
|
+
};
|
67
|
+
/**
|
68
|
+
* @param significantDigits - number of digits above 3
|
69
|
+
*/
|
70
|
+
export const formatNumberWithDigits = ({ value, size, withSizeLabel = true, significantDigits = 0, delimiter, ...params }) => {
|
71
|
+
if (!isNumeric(value)) {
|
72
|
+
return '';
|
73
|
+
}
|
74
|
+
const numValue = Number(value);
|
75
|
+
const sizeToConvert = size !== null && size !== void 0 ? size : getNumberWithSignificantDigits(numValue, significantDigits);
|
76
|
+
const result = formatToSize({ value: numValue, size: sizeToConvert, ...params });
|
77
|
+
if (withSizeLabel) {
|
78
|
+
return addSizeLabel(result, sizeToConvert, delimiter);
|
79
|
+
}
|
80
|
+
return result;
|
81
|
+
};
|
82
|
+
//# sourceMappingURL=formatNumber.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"formatNumber.js","sourceRoot":"","sources":["../../../src/utils/dataFormatters/formatNumber.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,sBAAsB,CAAC;AACxC,OAAO,EAAC,eAAe,EAAE,SAAS,EAAC,MAAM,UAAU,CAAC;AAGpD,OAAO,EAAC,YAAY,EAAE,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AAEhE,MAAM,KAAK,GAAG;IACV,QAAQ,EAAE;QACN,KAAK,EAAE,IAAK;QACZ,KAAK,EAAE,IAAI,CAAC,gBAAgB,CAAC;KAChC;IACD,OAAO,EAAE;QACL,KAAK,EAAE,OAAS;QAChB,KAAK,EAAE,IAAI,CAAC,eAAe,CAAC;KAC/B;IACD,OAAO,EAAE;QACL,KAAK,EAAE,UAAa;QACpB,KAAK,EAAE,IAAI,CAAC,eAAe,CAAC;KAC/B;IACD,QAAQ,EAAE;QACN,KAAK,EAAE,aAAiB;QACxB,KAAK,EAAE,IAAI,CAAC,gBAAgB,CAAC;KAChC;CACJ,CAAC;AAIF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,KAAa,EAAE,iBAAyB,EAAE,EAAE;IACvF,MAAM,UAAU,GAAG,EAAE,IAAI,iBAAiB,CAAC;IAE3C,MAAM,aAAa,GAAG,KAAK,CAAC,Q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