@perses-dev/components 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DateTimeRangePicker/AbsoluteTimePicker.d.ts.map +1 -1
- package/dist/DateTimeRangePicker/AbsoluteTimePicker.js +4 -3
- package/dist/DateTimeRangePicker/AbsoluteTimePicker.js.map +1 -1
- package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts +1 -0
- package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts.map +1 -1
- package/dist/DateTimeRangePicker/DateTimeRangePicker.js +3 -1
- package/dist/DateTimeRangePicker/DateTimeRangePicker.js.map +1 -1
- package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts +1 -0
- package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts.map +1 -1
- package/dist/DateTimeRangePicker/TimeRangeSelector.js +9 -3
- package/dist/DateTimeRangePicker/TimeRangeSelector.js.map +1 -1
- package/dist/DateTimeRangePicker/utils.d.ts +1 -1
- package/dist/DateTimeRangePicker/utils.d.ts.map +1 -1
- package/dist/DateTimeRangePicker/utils.js +5 -4
- package/dist/DateTimeRangePicker/utils.js.map +1 -1
- package/dist/GaugeChart/GaugeChart.d.ts +11 -2
- package/dist/GaugeChart/GaugeChart.d.ts.map +1 -1
- package/dist/GaugeChart/GaugeChart.js +58 -10
- package/dist/GaugeChart/GaugeChart.js.map +1 -1
- package/dist/InfoTooltip/InfoTooltip.d.ts +3 -1
- package/dist/InfoTooltip/InfoTooltip.d.ts.map +1 -1
- package/dist/InfoTooltip/InfoTooltip.js +4 -2
- package/dist/InfoTooltip/InfoTooltip.js.map +1 -1
- package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts +8 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.js +82 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.test.d.ts +2 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.test.d.ts.map +1 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.test.js +41 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.test.js.map +1 -0
- package/dist/LegendOptionsEditor/index.d.ts +2 -0
- package/dist/LegendOptionsEditor/index.d.ts.map +1 -0
- package/dist/LegendOptionsEditor/index.js +15 -0
- package/dist/LegendOptionsEditor/index.js.map +1 -0
- package/dist/LineChart/LineChart.d.ts +2 -3
- package/dist/LineChart/LineChart.d.ts.map +1 -1
- package/dist/LineChart/LineChart.js +38 -32
- package/dist/LineChart/LineChart.js.map +1 -1
- package/dist/LineChart/utils.d.ts +1 -1
- package/dist/LineChart/utils.d.ts.map +1 -1
- package/dist/LineChart/utils.js +4 -3
- package/dist/LineChart/utils.js.map +1 -1
- package/dist/StatChart/StatChart.test.js +9 -2
- package/dist/StatChart/StatChart.test.js.map +1 -1
- package/dist/Tooltip/TooltipContent.d.ts.map +1 -1
- package/dist/Tooltip/TooltipContent.js +8 -9
- package/dist/Tooltip/TooltipContent.js.map +1 -1
- package/dist/UnitSelector/UnitSelector.test.js +3 -4
- package/dist/UnitSelector/UnitSelector.test.js.map +1 -1
- package/dist/cjs/DateTimeRangePicker/AbsoluteTimePicker.js +4 -3
- package/dist/cjs/DateTimeRangePicker/DateTimeRangePicker.js +3 -1
- package/dist/cjs/DateTimeRangePicker/TimeRangeSelector.js +9 -3
- package/dist/cjs/DateTimeRangePicker/utils.js +4 -3
- package/dist/cjs/GaugeChart/GaugeChart.js +66 -15
- package/dist/cjs/InfoTooltip/InfoTooltip.js +4 -2
- package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.js +88 -0
- package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.test.js +48 -0
- package/dist/cjs/LegendOptionsEditor/index.js +28 -0
- package/dist/cjs/LineChart/LineChart.js +37 -31
- package/dist/cjs/LineChart/utils.js +4 -3
- package/dist/cjs/StatChart/StatChart.test.js +9 -2
- package/dist/cjs/Tooltip/TooltipContent.js +8 -9
- package/dist/cjs/UnitSelector/UnitSelector.test.js +3 -4
- package/dist/cjs/context/TimeZoneProvider.js +90 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/model/graph.js +14 -3
- package/dist/cjs/model/units/bytes.js +32 -6
- package/dist/cjs/model/units/time.js +1 -1
- package/dist/cjs/model/units/units.js +1 -4
- package/dist/cjs/model/units/units.test.js +153 -0
- package/dist/cjs/utils/format.js +56 -0
- package/dist/cjs/utils/format.test.js +47 -0
- package/dist/cjs/utils/index.js +1 -0
- package/dist/context/TimeZoneProvider.d.ts +13 -0
- package/dist/context/TimeZoneProvider.d.ts.map +1 -0
- package/dist/context/TimeZoneProvider.js +38 -0
- package/dist/context/TimeZoneProvider.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/model/graph.d.ts +4 -2
- package/dist/model/graph.d.ts.map +1 -1
- package/dist/model/graph.js +4 -0
- package/dist/model/graph.js.map +1 -1
- package/dist/model/units/bytes.d.ts +6 -1
- package/dist/model/units/bytes.d.ts.map +1 -1
- package/dist/model/units/bytes.js +35 -7
- package/dist/model/units/bytes.js.map +1 -1
- package/dist/model/units/time.js +1 -1
- package/dist/model/units/time.js.map +1 -1
- package/dist/model/units/units.d.ts.map +1 -1
- package/dist/model/units/units.js +1 -4
- package/dist/model/units/units.js.map +1 -1
- package/dist/model/units/units.test.d.ts +2 -0
- package/dist/model/units/units.test.d.ts.map +1 -0
- package/dist/model/units/units.test.js +151 -0
- package/dist/model/units/units.test.js.map +1 -0
- package/dist/utils/format.d.ts +3 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +44 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/format.test.d.ts +2 -0
- package/dist/utils/format.test.d.ts.map +1 -0
- package/dist/utils/format.test.js +45 -0
- package/dist/utils/format.test.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { formatValue } from './units';
|
|
14
|
+
describe('formatValue()', ()=>{
|
|
15
|
+
const tests = [
|
|
16
|
+
{
|
|
17
|
+
value: 100000,
|
|
18
|
+
unit: {
|
|
19
|
+
kind: 'Decimal'
|
|
20
|
+
},
|
|
21
|
+
expected: '100,000.00'
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
value: 155900,
|
|
25
|
+
unit: {
|
|
26
|
+
kind: 'Decimal',
|
|
27
|
+
decimal_places: 4
|
|
28
|
+
},
|
|
29
|
+
expected: '155,900.0000'
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
value: 10,
|
|
33
|
+
unit: {
|
|
34
|
+
kind: 'Percent'
|
|
35
|
+
},
|
|
36
|
+
expected: '10.00%'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
value: 50,
|
|
40
|
+
unit: {
|
|
41
|
+
kind: 'Percent',
|
|
42
|
+
decimal_places: 0
|
|
43
|
+
},
|
|
44
|
+
expected: '50%'
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
value: 0.1,
|
|
48
|
+
unit: {
|
|
49
|
+
kind: 'PercentDecimal'
|
|
50
|
+
},
|
|
51
|
+
expected: '10.00%'
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
value: 100,
|
|
55
|
+
unit: {
|
|
56
|
+
kind: 'Bytes',
|
|
57
|
+
decimal_places: 0,
|
|
58
|
+
abbreviate: false
|
|
59
|
+
},
|
|
60
|
+
expected: '100 bytes'
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
value: 100,
|
|
64
|
+
unit: {
|
|
65
|
+
kind: 'Bytes',
|
|
66
|
+
decimal_places: -1,
|
|
67
|
+
abbreviate: false
|
|
68
|
+
},
|
|
69
|
+
expected: '100 bytes'
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
value: 225000,
|
|
73
|
+
unit: {
|
|
74
|
+
kind: 'Bytes',
|
|
75
|
+
decimal_places: 0,
|
|
76
|
+
abbreviate: true
|
|
77
|
+
},
|
|
78
|
+
expected: '220 KB'
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
value: 505200,
|
|
82
|
+
unit: {
|
|
83
|
+
kind: 'Bytes'
|
|
84
|
+
},
|
|
85
|
+
expected: '505,200.00 bytes'
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
value: 8000,
|
|
89
|
+
unit: {
|
|
90
|
+
kind: 'Milliseconds'
|
|
91
|
+
},
|
|
92
|
+
expected: '8,000.00 milliseconds'
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
value: 200900,
|
|
96
|
+
unit: {
|
|
97
|
+
kind: 'Seconds'
|
|
98
|
+
},
|
|
99
|
+
expected: '200,900.00 seconds'
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
value: 300,
|
|
103
|
+
unit: {
|
|
104
|
+
kind: 'Minutes'
|
|
105
|
+
},
|
|
106
|
+
expected: '300.00 minutes'
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
value: 300,
|
|
110
|
+
unit: {
|
|
111
|
+
kind: 'Hours'
|
|
112
|
+
},
|
|
113
|
+
expected: '300.00 hours'
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
value: 300,
|
|
117
|
+
unit: {
|
|
118
|
+
kind: 'Days'
|
|
119
|
+
},
|
|
120
|
+
expected: '300.00 days'
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
value: 300,
|
|
124
|
+
unit: {
|
|
125
|
+
kind: 'Weeks'
|
|
126
|
+
},
|
|
127
|
+
expected: '300.00 weeks'
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
value: 300,
|
|
131
|
+
unit: {
|
|
132
|
+
kind: 'Months'
|
|
133
|
+
},
|
|
134
|
+
expected: '300.00 months'
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
value: 300,
|
|
138
|
+
unit: {
|
|
139
|
+
kind: 'Years'
|
|
140
|
+
},
|
|
141
|
+
expected: '300.00 years'
|
|
142
|
+
}
|
|
143
|
+
];
|
|
144
|
+
tests.forEach(({ value , unit , expected })=>{
|
|
145
|
+
it(`formats ${value} as ${JSON.stringify(unit)}`, ()=>{
|
|
146
|
+
expect(formatValue(value, unit)).toEqual(expected);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
//# sourceMappingURL=units.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/units.test.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { formatValue, UnitOptions } from './units';\n\ndescribe('formatValue()', () => {\n const tests = [\n {\n value: 100000,\n unit: { kind: 'Decimal' },\n expected: '100,000.00',\n },\n {\n value: 155900,\n unit: { kind: 'Decimal', decimal_places: 4 },\n expected: '155,900.0000',\n },\n {\n value: 10,\n unit: { kind: 'Percent' },\n expected: '10.00%',\n },\n {\n value: 50,\n unit: { kind: 'Percent', decimal_places: 0 },\n expected: '50%',\n },\n {\n value: 0.1,\n unit: { kind: 'PercentDecimal' },\n expected: '10.00%',\n },\n {\n value: 100,\n unit: { kind: 'Bytes', decimal_places: 0, abbreviate: false },\n expected: '100 bytes',\n },\n {\n value: 100,\n unit: { kind: 'Bytes', decimal_places: -1, abbreviate: false },\n expected: '100 bytes',\n },\n {\n value: 225000,\n unit: { kind: 'Bytes', decimal_places: 0, abbreviate: true },\n expected: '220 KB',\n },\n {\n value: 505200,\n unit: { kind: 'Bytes' },\n expected: '505,200.00 bytes',\n },\n {\n value: 8000,\n unit: { kind: 'Milliseconds' },\n expected: '8,000.00 milliseconds',\n },\n {\n value: 200900,\n unit: { kind: 'Seconds' },\n expected: '200,900.00 seconds',\n },\n {\n value: 300,\n unit: { kind: 'Minutes' },\n expected: '300.00 minutes',\n },\n {\n value: 300,\n unit: { kind: 'Hours' },\n expected: '300.00 hours',\n },\n {\n value: 300,\n unit: { kind: 'Days' },\n expected: '300.00 days',\n },\n {\n value: 300,\n unit: { kind: 'Weeks' },\n expected: '300.00 weeks',\n },\n {\n value: 300,\n unit: { kind: 'Months' },\n expected: '300.00 months',\n },\n {\n value: 300,\n unit: { kind: 'Years' },\n expected: '300.00 years',\n },\n ];\n\n tests.forEach(({ value, unit, expected }) => {\n it(`formats ${value} as ${JSON.stringify(unit)}`, () => {\n expect(formatValue(value, unit as UnitOptions)).toEqual(expected);\n });\n });\n});\n"],"names":["formatValue","describe","tests","value","unit","kind","expected","decimal_places","abbreviate","forEach","it","JSON","stringify","expect","toEqual"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,m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IAAI,CAAA,EAAEE,QAAQ,CAAA,EAAE,GAAK;QAC3CI,EAAE,CAAC,CAAC,QAAQ,EAAEP,KAAK,CAAC,IAAI,EAAEQ,IAAI,CAACC,SAAS,CAACR,IAAI,CAAC,CAAC,CAAC,EAAE,IAAM;YACtDS,MAAM,CAACb,WAAW,CAACG,KAAK,EAAEC,IAAI,CAAgB,CAAC,CAACU,OAAO,CAACR,QAAQ,CAAC,CAAC;QACpE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function dateFormatOptionsWithTimeZone(dateFormatOptions: Intl.DateTimeFormatOptions, timeZone?: string): Intl.DateTimeFormatOptions;
|
|
2
|
+
export declare function formatWithTimeZone(date: Date, formatString: string, timeZone?: string): string;
|
|
3
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/utils/format.ts"],"names":[],"mappings":"AAgBA,wBAAgB,6BAA6B,CAAC,iBAAiB,EAAE,IAAI,CAAC,qBAAqB,EAAE,QAAQ,CAAC,EAAE,MAAM,8BAgB7G;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,UAYrF"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { formatInTimeZone } from 'date-fns-tz';
|
|
14
|
+
import { format } from 'date-fns';
|
|
15
|
+
export function dateFormatOptionsWithTimeZone(dateFormatOptions, timeZone) {
|
|
16
|
+
/*
|
|
17
|
+
* if timeZone is provided, and is not local|browser,
|
|
18
|
+
* then set timeZone option (recognize UTC regardless of uppercase/lowercase)
|
|
19
|
+
* otherwise, default to browser timeZone setting
|
|
20
|
+
*/ if (timeZone) {
|
|
21
|
+
const lowerTimeZone = timeZone.toLowerCase();
|
|
22
|
+
if (lowerTimeZone !== 'local' && lowerTimeZone !== 'browser') {
|
|
23
|
+
return {
|
|
24
|
+
...dateFormatOptions,
|
|
25
|
+
timeZone: lowerTimeZone === 'utc' ? 'UTC' : timeZone
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return dateFormatOptions;
|
|
30
|
+
}
|
|
31
|
+
export function formatWithTimeZone(date, formatString, timeZone) {
|
|
32
|
+
/*
|
|
33
|
+
* if timeZone is provided, and is not local|browser,
|
|
34
|
+
* then format using timeZone option (recognize UTC regardless of uppercase/lowercase)
|
|
35
|
+
* otherwise, format without timeZone option, defaulting to browser timeZone setting
|
|
36
|
+
*/ const lowerTimeZone = timeZone === null || timeZone === void 0 ? void 0 : timeZone.toLowerCase();
|
|
37
|
+
if (!timeZone || lowerTimeZone === 'local' || lowerTimeZone === 'browser') {
|
|
38
|
+
return format(date, formatString);
|
|
39
|
+
} else {
|
|
40
|
+
return formatInTimeZone(date, lowerTimeZone === 'utc' ? 'UTC' : timeZone, formatString);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/format.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { formatInTimeZone } from 'date-fns-tz';\nimport { format } from 'date-fns';\n\nexport function dateFormatOptionsWithTimeZone(dateFormatOptions: Intl.DateTimeFormatOptions, timeZone?: string) {\n /*\n * if timeZone is provided, and is not local|browser,\n * then set timeZone option (recognize UTC regardless of uppercase/lowercase)\n * otherwise, default to browser timeZone setting\n */\n if (timeZone) {\n const lowerTimeZone = timeZone.toLowerCase();\n if (lowerTimeZone !== 'local' && lowerTimeZone !== 'browser') {\n return {\n ...dateFormatOptions,\n timeZone: lowerTimeZone === 'utc' ? 'UTC' : timeZone,\n };\n }\n }\n return dateFormatOptions;\n}\n\nexport function formatWithTimeZone(date: Date, formatString: string, timeZone?: string) {\n /*\n * if timeZone is provided, and is not local|browser,\n * then format using timeZone option (recognize UTC regardless of uppercase/lowercase)\n * otherwise, format without timeZone option, defaulting to browser timeZone setting\n */\n const lowerTimeZone = timeZone?.toLowerCase();\n if (!timeZone || lowerTimeZone === 'local' || lowerTimeZone === 'browser') {\n return format(date, formatString);\n } else {\n return formatInTimeZone(date, lowerTimeZone === 'utc' ? 'UTC' : timeZone, formatString);\n }\n}\n"],"names":["formatInTimeZone","format","dateFormatOptionsWithTimeZone","dateFormatOptions","timeZone","lowerTimeZone","toLowerCase","formatWithTimeZone","date","formatString"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,gBAAgB,QAAQ,aAAa,CAAC;AAC/C,SAASC,MAAM,QAAQ,UAAU,CAAC;AAElC,OAAO,SAASC,6BAA6B,CAACC,iBAA6C,EAAEC,QAAiB,EAAE;IAC9G;;;;GAIC,GACD,IAAIA,QAAQ,EAAE;QACZ,MAAMC,aAAa,GAAGD,QAAQ,CAACE,WAAW,EAAE,AAAC;QAC7C,IAAID,aAAa,KAAK,OAAO,IAAIA,aAAa,KAAK,SAAS,EAAE;YAC5D,OAAO;gBACL,GAAGF,iBAAiB;gBACpBC,QAAQ,EAAEC,aAAa,KAAK,KAAK,GAAG,KAAK,GAAGD,QAAQ;aACrD,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAOD,iBAAiB,CAAC;AAC3B,CAAC;AAED,OAAO,SAASI,kBAAkB,CAACC,IAAU,EAAEC,YAAoB,EAAEL,QAAiB,EAAE;IACtF;;;;GAIC,GACD,MAAMC,aAAa,GAAGD,QAAQ,aAARA,QAAQ,WAAa,GAArBA,KAAAA,CAAqB,GAArBA,QAAQ,CAAEE,WAAW,EAAE,AAAC;IAC9C,IAAI,CAACF,QAAQ,IAAIC,aAAa,KAAK,OAAO,IAAIA,aAAa,KAAK,SAAS,EAAE;QACzE,OAAOJ,MAAM,CAACO,IAAI,EAAEC,YAAY,CAAC,CAAC;IACpC,OAAO;QACL,OAAOT,gBAAgB,CAACQ,IAAI,EAAEH,aAAa,KAAK,KAAK,GAAG,KAAK,GAAGD,QAAQ,EAAEK,YAAY,CAAC,CAAC;IAC1F,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.test.d.ts","sourceRoot":"","sources":["../../src/utils/format.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { dateFormatOptionsWithTimeZone, formatWithTimeZone } from './format';
|
|
14
|
+
const DATE = new Date(168523200000);
|
|
15
|
+
const DATE_FORMAT_OPTIONS = {
|
|
16
|
+
hour: 'numeric',
|
|
17
|
+
minute: 'numeric',
|
|
18
|
+
hourCycle: 'h23'
|
|
19
|
+
};
|
|
20
|
+
describe('formatWithTimeZone', ()=>{
|
|
21
|
+
it('should format in Los Angeles timezone', ()=>{
|
|
22
|
+
expect(formatWithTimeZone(DATE, 'yyyy-MM-dd HH:mm:ss', 'America/Los_Angeles')).toBe('1975-05-05 05:00:00');
|
|
23
|
+
});
|
|
24
|
+
it('should format in UTC timezone', ()=>{
|
|
25
|
+
expect(formatWithTimeZone(DATE, 'yyyy-MM-dd HH:mm:ss', 'UTC')).toBe('1975-05-05 12:00:00');
|
|
26
|
+
expect(formatWithTimeZone(DATE, 'yyyy-MM-dd HH:mm:ss', 'utc')).toBe('1975-05-05 12:00:00');
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
describe('dateFormatOptionsWithTimeZone', ()=>{
|
|
30
|
+
it('should format in Los Angeles timezone', ()=>{
|
|
31
|
+
const dateFormatOptions = dateFormatOptionsWithTimeZone(DATE_FORMAT_OPTIONS, 'America/Los_Angeles');
|
|
32
|
+
expect(new Intl.DateTimeFormat(undefined, dateFormatOptions).format(DATE)).toBe('05:00');
|
|
33
|
+
});
|
|
34
|
+
it('should format in UTC timezone', ()=>{
|
|
35
|
+
const dateFormatOptions = dateFormatOptionsWithTimeZone(DATE_FORMAT_OPTIONS, 'utc');
|
|
36
|
+
expect(new Intl.DateTimeFormat(undefined, dateFormatOptions).format(DATE)).toBe('12:00');
|
|
37
|
+
});
|
|
38
|
+
it('should use browser local timezone', ()=>{
|
|
39
|
+
expect(dateFormatOptionsWithTimeZone(DATE_FORMAT_OPTIONS, 'browser').timeZone).toBeUndefined();
|
|
40
|
+
expect(dateFormatOptionsWithTimeZone(DATE_FORMAT_OPTIONS, 'local').timeZone).toBeUndefined();
|
|
41
|
+
expect(dateFormatOptionsWithTimeZone(DATE_FORMAT_OPTIONS).timeZone).toBeUndefined();
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=format.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/format.test.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\nimport { dateFormatOptionsWithTimeZone, formatWithTimeZone } from './format';\n\nconst DATE = new Date(168523200000);\n\nconst DATE_FORMAT_OPTIONS: Intl.DateTimeFormatOptions = {\n hour: 'numeric',\n minute: 'numeric',\n hourCycle: 'h23',\n};\n\ndescribe('formatWithTimeZone', () => {\n it('should format in Los Angeles timezone', () => {\n expect(formatWithTimeZone(DATE, 'yyyy-MM-dd HH:mm:ss', 'America/Los_Angeles')).toBe('1975-05-05 05:00:00');\n });\n it('should format in UTC timezone', () => {\n expect(formatWithTimeZone(DATE, 'yyyy-MM-dd HH:mm:ss', 'UTC')).toBe('1975-05-05 12:00:00');\n expect(formatWithTimeZone(DATE, 'yyyy-MM-dd HH:mm:ss', 'utc')).toBe('1975-05-05 12:00:00');\n });\n});\n\ndescribe('dateFormatOptionsWithTimeZone', () => {\n it('should format in Los Angeles timezone', () => {\n const dateFormatOptions = dateFormatOptionsWithTimeZone(DATE_FORMAT_OPTIONS, 'America/Los_Angeles');\n expect(new Intl.DateTimeFormat(undefined, dateFormatOptions).format(DATE)).toBe('05:00');\n });\n it('should format in UTC timezone', () => {\n const dateFormatOptions = dateFormatOptionsWithTimeZone(DATE_FORMAT_OPTIONS, 'utc');\n expect(new Intl.DateTimeFormat(undefined, dateFormatOptions).format(DATE)).toBe('12:00');\n });\n it('should use browser local timezone', () => {\n expect(dateFormatOptionsWithTimeZone(DATE_FORMAT_OPTIONS, 'browser').timeZone).toBeUndefined();\n expect(dateFormatOptionsWithTimeZone(DATE_FORMAT_OPTIONS, 'local').timeZone).toBeUndefined();\n expect(dateFormatOptionsWithTimeZone(DATE_FORMAT_OPTIONS).timeZone).toBeUndefined();\n });\n});\n"],"names":["dateFormatOptionsWithTimeZone","formatWithTimeZone","DATE","Date","DATE_FORMAT_OPTIONS","hour","minute","hourCycle","describe","it","expect","toBe","dateFormatOptions","Intl","DateTimeFormat","undefined","format","timeZone","toBeUndefined"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,SAASA,6BAA6B,EAAEC,kBAAkB,QAAQ,UAAU,CAAC;AAE7E,MAAMC,IAAI,GAAG,IAAIC,IAAI,CAAC,YAAY,CAAC,AAAC;AAEpC,MAAMC,mBAAmB,GAA+B;IACtDC,IAAI,EAAE,SAAS;IACfC,MAAM,EAAE,SAAS;IACjBC,SAAS,EAAE,KAAK;CACjB,AAAC;AAEFC,QAAQ,CAAC,oBAAoB,EAAE,IAAM;IACnCC,EAAE,CAAC,uCAAuC,EAAE,IAAM;QAChDC,MAAM,CAACT,kBAAkB,CA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6B,CAACI,mBAAmB,EAAE,OAAO,CAAC,CAACa,QAAQ,CAAC,CAACC,aAAa,EAAE,CAAC;QAC7FR,MAAM,CAACV,6BAA6B,CAACI,mBAAmB,CAAC,CAACa,QAAQ,CAAC,CAACC,aAAa,EAAE,CAAC;IACtF,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAaA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAaA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC"}
|
package/dist/utils/index.js
CHANGED
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './combine-sx';\nexport * from './theme-gen';\nexport * from './component-ids';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './combine-sx';\nexport * from './theme-gen';\nexport * from './component-ids';\nexport * from './format';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "Common UI components used across Perses features",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/perses/perses/blob/main/README.md",
|
|
@@ -34,8 +34,9 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@fontsource/lato": "^4.5.10",
|
|
36
36
|
"@mui/x-date-pickers": "^5.0.0-beta.1",
|
|
37
|
-
"@perses-dev/core": "
|
|
37
|
+
"@perses-dev/core": "0.21.0",
|
|
38
38
|
"date-fns": "^2.28.0",
|
|
39
|
+
"date-fns-tz": "^1.3.7",
|
|
39
40
|
"echarts": "^5.3.3",
|
|
40
41
|
"lodash-es": "^4.17.21",
|
|
41
42
|
"mathjs": "^10.6.4",
|