@perses-dev/core 0.53.0-beta.0 → 0.53.0-beta.2
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/cjs/model/datasource-api.js +16 -0
- package/dist/cjs/model/external-variable.js +16 -0
- package/dist/cjs/model/index.js +4 -1
- package/dist/cjs/{utils/event.js → model/panel-group.js} +5 -10
- package/dist/cjs/model/units/date.js +297 -0
- package/dist/cjs/model/units/temperature.js +64 -0
- package/dist/cjs/model/units/time.js +16 -2
- package/dist/cjs/model/units/units.js +27 -3
- package/dist/cjs/utils/index.js +0 -2
- package/dist/cjs/utils/transform-data.js +0 -10
- package/dist/model/datasource-api.d.ts +41 -0
- package/dist/model/datasource-api.d.ts.map +1 -0
- package/dist/model/datasource-api.js +19 -0
- package/dist/model/datasource-api.js.map +1 -0
- package/dist/model/external-variable.d.ts +29 -0
- package/dist/model/external-variable.d.ts.map +1 -0
- package/dist/model/external-variable.js +20 -0
- package/dist/model/external-variable.js.map +1 -0
- package/dist/model/index.d.ts +3 -0
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +4 -1
- package/dist/model/index.js.map +1 -1
- package/dist/model/otlp/common/v1/common.d.ts +3 -1
- package/dist/model/otlp/common/v1/common.d.ts.map +1 -1
- package/dist/model/otlp/common/v1/common.js.map +1 -1
- package/dist/model/panel-group.d.ts +63 -0
- package/dist/model/panel-group.d.ts.map +1 -0
- package/dist/model/panel-group.js +19 -0
- package/dist/model/panel-group.js.map +1 -0
- package/dist/model/units/date.d.ts +28 -0
- package/dist/model/units/date.d.ts.map +1 -0
- package/dist/model/units/date.js +278 -0
- package/dist/model/units/date.js.map +1 -0
- package/dist/model/units/temperature.d.ts +11 -0
- package/dist/model/units/temperature.d.ts.map +1 -0
- package/dist/model/units/temperature.js +45 -0
- package/dist/model/units/temperature.js.map +1 -0
- package/dist/model/units/time.d.ts +3 -1
- package/dist/model/units/time.d.ts.map +1 -1
- package/dist/model/units/time.js +16 -2
- package/dist/model/units/time.js.map +1 -1
- package/dist/model/units/types.d.ts +1 -1
- package/dist/model/units/types.d.ts.map +1 -1
- package/dist/model/units/types.js.map +1 -1
- package/dist/model/units/units.d.ts +21 -1
- package/dist/model/units/units.d.ts.map +1 -1
- package/dist/model/units/units.js +21 -3
- package/dist/model/units/units.js.map +1 -1
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +0 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/transform-data.d.ts +0 -1
- package/dist/utils/transform-data.d.ts.map +1 -1
- package/dist/utils/transform-data.js +0 -7
- package/dist/utils/transform-data.js.map +1 -1
- package/package.json +1 -5
- package/dist/cjs/utils/memo.js +0 -64
- package/dist/utils/event.d.ts +0 -8
- package/dist/utils/event.d.ts.map +0 -1
- package/dist/utils/event.js +0 -27
- package/dist/utils/event.js.map +0 -1
- package/dist/utils/memo.d.ts +0 -13
- package/dist/utils/memo.d.ts.map +0 -1
- package/dist/utils/memo.js +0 -50
- package/dist/utils/memo.js.map +0 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright 2025 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
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright 2025 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
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
package/dist/cjs/model/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2025 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -17,9 +17,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
17
17
|
_export_star(require("./calculations"), exports);
|
|
18
18
|
_export_star(require("./dashboard"), exports);
|
|
19
19
|
_export_star(require("./datasource"), exports);
|
|
20
|
+
_export_star(require("./datasource-api"), exports);
|
|
20
21
|
_export_star(require("./definitions"), exports);
|
|
21
22
|
_export_star(require("./display"), exports);
|
|
22
23
|
_export_star(require("./ephemeraldashboard"), exports);
|
|
24
|
+
_export_star(require("./external-variable"), exports);
|
|
23
25
|
_export_star(require("./http"), exports);
|
|
24
26
|
_export_star(require("./http-proxy"), exports);
|
|
25
27
|
_export_star(require("./kind"), exports);
|
|
@@ -27,6 +29,7 @@ _export_star(require("./layout"), exports);
|
|
|
27
29
|
_export_star(require("./legend"), exports);
|
|
28
30
|
_export_star(require("./notice"), exports);
|
|
29
31
|
_export_star(require("./otlp"), exports);
|
|
32
|
+
_export_star(require("./panel-group"), exports);
|
|
30
33
|
_export_star(require("./panels"), exports);
|
|
31
34
|
_export_star(require("./project"), exports);
|
|
32
35
|
_export_star(require("./query"), exports);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2025 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -14,17 +14,12 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
-
Object.defineProperty(exports, "
|
|
17
|
+
Object.defineProperty(exports, "isPanelGroupItemIdEqual", {
|
|
18
18
|
enumerable: true,
|
|
19
19
|
get: function() {
|
|
20
|
-
return
|
|
20
|
+
return isPanelGroupItemIdEqual;
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const handlerRef = (0, _react.useRef)(handler);
|
|
26
|
-
(0, _react.useLayoutEffect)(()=>{
|
|
27
|
-
handlerRef.current = handler;
|
|
28
|
-
});
|
|
29
|
-
return (0, _react.useCallback)((...args)=>handlerRef.current(...args), []);
|
|
23
|
+
function isPanelGroupItemIdEqual(a, b) {
|
|
24
|
+
return a?.panelGroupId === b?.panelGroupId && a?.panelGroupItemLayoutId === b?.panelGroupItemLayoutId;
|
|
30
25
|
}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
// Copyright 2025 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
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: all[name]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
DATE_GROUP_CONFIG: function() {
|
|
25
|
+
return DATE_GROUP_CONFIG;
|
|
26
|
+
},
|
|
27
|
+
DATE_UNIT_CONFIG: function() {
|
|
28
|
+
return DATE_UNIT_CONFIG;
|
|
29
|
+
},
|
|
30
|
+
formatDate: function() {
|
|
31
|
+
return formatDate;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
const DATE_GROUP = 'Date';
|
|
35
|
+
const DATE_GROUP_CONFIG = {
|
|
36
|
+
label: 'Date & Time'
|
|
37
|
+
};
|
|
38
|
+
const DATE_UNIT_CONFIG = {
|
|
39
|
+
'datetime-iso': {
|
|
40
|
+
group: DATE_GROUP,
|
|
41
|
+
label: 'DateTime (GMT)'
|
|
42
|
+
},
|
|
43
|
+
'datetime-us': {
|
|
44
|
+
group: DATE_GROUP,
|
|
45
|
+
label: 'DateTime (US-East)'
|
|
46
|
+
},
|
|
47
|
+
'datetime-local': {
|
|
48
|
+
group: DATE_GROUP,
|
|
49
|
+
label: 'DateTime (Browser Local)'
|
|
50
|
+
},
|
|
51
|
+
'date-iso': {
|
|
52
|
+
group: DATE_GROUP,
|
|
53
|
+
label: 'Date (GMT)'
|
|
54
|
+
},
|
|
55
|
+
'date-us': {
|
|
56
|
+
group: DATE_GROUP,
|
|
57
|
+
label: 'Date (US-East)'
|
|
58
|
+
},
|
|
59
|
+
'date-local': {
|
|
60
|
+
group: DATE_GROUP,
|
|
61
|
+
label: 'Date (Browser Local)'
|
|
62
|
+
},
|
|
63
|
+
'time-local': {
|
|
64
|
+
group: DATE_GROUP,
|
|
65
|
+
label: 'Time (Browser Local)'
|
|
66
|
+
},
|
|
67
|
+
'time-iso': {
|
|
68
|
+
group: DATE_GROUP,
|
|
69
|
+
label: 'Time (GMT)'
|
|
70
|
+
},
|
|
71
|
+
'time-us': {
|
|
72
|
+
group: DATE_GROUP,
|
|
73
|
+
label: 'Time (US-East)'
|
|
74
|
+
},
|
|
75
|
+
'relative-time': {
|
|
76
|
+
group: DATE_GROUP,
|
|
77
|
+
label: 'Relative Time'
|
|
78
|
+
},
|
|
79
|
+
'unix-timestamp': {
|
|
80
|
+
group: DATE_GROUP,
|
|
81
|
+
label: 'Unix Timestamp (s)'
|
|
82
|
+
},
|
|
83
|
+
'unix-timestamp-ms': {
|
|
84
|
+
group: DATE_GROUP,
|
|
85
|
+
label: 'Unix Timestamp (ms)'
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Converts a numeric value to a Date object.
|
|
90
|
+
* Handles both Unix timestamps (seconds) and millisecond timestamps.
|
|
91
|
+
*/ function valueToDate(value) {
|
|
92
|
+
// Timestamp detection logic with special case handling
|
|
93
|
+
// Main threshold stays at 10 billion to maintain existing behavior
|
|
94
|
+
// Handle special edge cases explicitly
|
|
95
|
+
// Special case: negative timestamps
|
|
96
|
+
if (value < 0) {
|
|
97
|
+
// For negative values, check magnitude to distinguish seconds vs milliseconds
|
|
98
|
+
// Large negative values (> 1 billion in magnitude) are likely milliseconds
|
|
99
|
+
// Small negative values are likely seconds (rare edge case)
|
|
100
|
+
if (Math.abs(value) > 10000000000) {
|
|
101
|
+
return new Date(value); // milliseconds
|
|
102
|
+
} else {
|
|
103
|
+
return new Date(value * 1000); // seconds
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Special case: year 9999 in seconds (~253402300799)
|
|
107
|
+
// This is a very specific edge case for far-future timestamps
|
|
108
|
+
if (value >= 250000000000 && value <= 260000000000) {
|
|
109
|
+
// Check if this looks like year 9999 in seconds
|
|
110
|
+
const asSeconds = new Date(value * 1000);
|
|
111
|
+
const year = asSeconds.getUTCFullYear();
|
|
112
|
+
if (year >= 9999) {
|
|
113
|
+
return asSeconds; // seconds
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const SECONDS_THRESHOLD = 10000000000; // ~year 2286 - original threshold
|
|
117
|
+
if (value < SECONDS_THRESHOLD) {
|
|
118
|
+
// Assume it's in seconds
|
|
119
|
+
return new Date(value * 1000);
|
|
120
|
+
} else {
|
|
121
|
+
// Assume it's in milliseconds
|
|
122
|
+
return new Date(value);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Formats a relative time string using the Intl.RelativeTimeFormat API.
|
|
127
|
+
*/ function formatRelativeTime(date, referenceTime, locale) {
|
|
128
|
+
const referenceDate = new Date(referenceTime);
|
|
129
|
+
const diffMs = date.getTime() - referenceDate.getTime();
|
|
130
|
+
const units = [
|
|
131
|
+
{
|
|
132
|
+
unit: 'year',
|
|
133
|
+
ms: 1000 * 60 * 60 * 24 * 365
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
unit: 'month',
|
|
137
|
+
ms: 1000 * 60 * 60 * 24 * 30
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
unit: 'week',
|
|
141
|
+
ms: 1000 * 60 * 60 * 24 * 7
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
unit: 'day',
|
|
145
|
+
ms: 1000 * 60 * 60 * 24
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
unit: 'hour',
|
|
149
|
+
ms: 1000 * 60 * 60
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
unit: 'minute',
|
|
153
|
+
ms: 1000 * 60
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
unit: 'second',
|
|
157
|
+
ms: 1000
|
|
158
|
+
}
|
|
159
|
+
];
|
|
160
|
+
for (const { unit, ms } of units){
|
|
161
|
+
// Determine the value for the current unit, ensuring it's an integer for Intl.RelativeTimeFormat
|
|
162
|
+
const value = Math.round(diffMs / ms);
|
|
163
|
+
// If the absolute value is 1 or more, use this unit
|
|
164
|
+
if (Math.abs(value) >= 1) {
|
|
165
|
+
const rtf = new Intl.RelativeTimeFormat(locale, {
|
|
166
|
+
numeric: 'auto'
|
|
167
|
+
});
|
|
168
|
+
return rtf.format(value, unit);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// If less than a second, show "now" or "0 seconds"
|
|
172
|
+
const rtf = new Intl.RelativeTimeFormat(locale, {
|
|
173
|
+
numeric: 'auto'
|
|
174
|
+
});
|
|
175
|
+
return rtf.format(0, 'second');
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Gets the browser's preferred locale with comprehensive fallbacks.
|
|
179
|
+
*/ const getBrowserLocale = ()=>{
|
|
180
|
+
if (typeof navigator !== 'undefined') {
|
|
181
|
+
if (navigator.language) return navigator.language;
|
|
182
|
+
if (navigator.languages && navigator.languages.length > 0) {
|
|
183
|
+
const firstLanguage = navigator.languages[0];
|
|
184
|
+
if (firstLanguage) return firstLanguage;
|
|
185
|
+
}
|
|
186
|
+
// Legacy fallbacks for older browsers
|
|
187
|
+
const nav = navigator;
|
|
188
|
+
if (nav.userLanguage) return nav.userLanguage;
|
|
189
|
+
if (nav.browserLanguage) return nav.browserLanguage;
|
|
190
|
+
if (nav.systemLanguage) return nav.systemLanguage;
|
|
191
|
+
}
|
|
192
|
+
// Node.js or server-side fallback, or if navigator is not available/empty
|
|
193
|
+
return Intl.DateTimeFormat().resolvedOptions().locale || 'en-US';
|
|
194
|
+
};
|
|
195
|
+
function formatDate(value, options = {}) {
|
|
196
|
+
const systemTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
197
|
+
const { unit = 'datetime-local', locale = getBrowserLocale(), timeZone = systemTimeZone, referenceTime = Date.now() } = options;
|
|
198
|
+
// Handle raw timestamp display
|
|
199
|
+
if (unit === 'unix-timestamp') {
|
|
200
|
+
// Ensure it's in seconds. If it looks like milliseconds, convert.
|
|
201
|
+
const timestamp = value > 1000000000000 ? Math.floor(value / 1000) : value;
|
|
202
|
+
return timestamp.toString();
|
|
203
|
+
}
|
|
204
|
+
if (unit === 'unix-timestamp-ms') {
|
|
205
|
+
// Ensure it's in milliseconds. If it looks like seconds, convert.
|
|
206
|
+
// Use 100 billion as threshold - values < 100B are likely seconds, >= 100B are likely milliseconds
|
|
207
|
+
// This distinguishes between 999999999 (seconds) and 999999999000 (milliseconds)
|
|
208
|
+
const MILLISECONDS_THRESHOLD = 100000000000; // 100 billion
|
|
209
|
+
const timestamp = value < MILLISECONDS_THRESHOLD ? value * 1000 : value;
|
|
210
|
+
return Math.floor(timestamp).toString();
|
|
211
|
+
}
|
|
212
|
+
const date = valueToDate(value);
|
|
213
|
+
// Handle relative time
|
|
214
|
+
if (unit === 'relative-time') {
|
|
215
|
+
return formatRelativeTime(date, referenceTime, locale);
|
|
216
|
+
}
|
|
217
|
+
// Configure Intl.DateTimeFormat options based on unit
|
|
218
|
+
const formatOptions = {
|
|
219
|
+
timeZone
|
|
220
|
+
};
|
|
221
|
+
switch(unit){
|
|
222
|
+
case 'datetime-iso':
|
|
223
|
+
// datetime-iso should ALWAYS show GMT/UTC time
|
|
224
|
+
return date.toISOString();
|
|
225
|
+
case 'datetime-us':
|
|
226
|
+
{
|
|
227
|
+
// datetime-us should ALWAYS show date in US Eastern timezone
|
|
228
|
+
formatOptions.timeZone = 'America/New_York';
|
|
229
|
+
formatOptions.year = 'numeric';
|
|
230
|
+
formatOptions.month = '2-digit';
|
|
231
|
+
formatOptions.day = '2-digit';
|
|
232
|
+
formatOptions.hour = '2-digit';
|
|
233
|
+
formatOptions.minute = '2-digit';
|
|
234
|
+
formatOptions.second = '2-digit';
|
|
235
|
+
formatOptions.hour12 = true; // 12-hour format with AM/PM
|
|
236
|
+
const formatter = new Intl.DateTimeFormat('en-US', formatOptions);
|
|
237
|
+
return formatter.format(date);
|
|
238
|
+
}
|
|
239
|
+
case 'datetime-local':
|
|
240
|
+
// datetime-local should use the browser's local timezone (detected automatically)
|
|
241
|
+
// Don't override timeZone - let it use the detected system timezone
|
|
242
|
+
formatOptions.year = 'numeric';
|
|
243
|
+
formatOptions.month = '2-digit';
|
|
244
|
+
formatOptions.day = '2-digit';
|
|
245
|
+
formatOptions.hour = '2-digit';
|
|
246
|
+
formatOptions.minute = '2-digit';
|
|
247
|
+
formatOptions.second = '2-digit';
|
|
248
|
+
formatOptions.hour12 = false; // 24-hour format
|
|
249
|
+
break;
|
|
250
|
+
case 'date-iso':
|
|
251
|
+
// date-iso should ALWAYS show GMT/UTC date
|
|
252
|
+
return date.toISOString().split('T')[0];
|
|
253
|
+
case 'date-us':
|
|
254
|
+
{
|
|
255
|
+
// date-us should ALWAYS show date in US Eastern timezone
|
|
256
|
+
formatOptions.timeZone = 'America/New_York';
|
|
257
|
+
formatOptions.year = 'numeric';
|
|
258
|
+
formatOptions.month = '2-digit';
|
|
259
|
+
formatOptions.day = '2-digit';
|
|
260
|
+
const formatter = new Intl.DateTimeFormat('en-US', formatOptions);
|
|
261
|
+
return formatter.format(date);
|
|
262
|
+
}
|
|
263
|
+
case 'date-local':
|
|
264
|
+
formatOptions.year = 'numeric';
|
|
265
|
+
formatOptions.month = '2-digit';
|
|
266
|
+
formatOptions.day = '2-digit';
|
|
267
|
+
break;
|
|
268
|
+
case 'time-local':
|
|
269
|
+
formatOptions.hour = '2-digit';
|
|
270
|
+
formatOptions.minute = '2-digit';
|
|
271
|
+
formatOptions.second = '2-digit';
|
|
272
|
+
formatOptions.hour12 = false; // 24-hour format
|
|
273
|
+
break;
|
|
274
|
+
case 'time-iso':
|
|
275
|
+
// time-iso should ALWAYS show GMT/UTC time
|
|
276
|
+
return date.toISOString().split('T')[1].replace('Z', '');
|
|
277
|
+
case 'time-us':
|
|
278
|
+
{
|
|
279
|
+
// time-us should show time in US-East timezone (Eastern Time)
|
|
280
|
+
formatOptions.timeZone = 'America/New_York';
|
|
281
|
+
formatOptions.hour = '2-digit';
|
|
282
|
+
formatOptions.minute = '2-digit';
|
|
283
|
+
formatOptions.second = '2-digit';
|
|
284
|
+
formatOptions.hour12 = true;
|
|
285
|
+
return new Intl.DateTimeFormat('en-US', formatOptions).format(date);
|
|
286
|
+
}
|
|
287
|
+
default:
|
|
288
|
+
{
|
|
289
|
+
// This ensures that all DateUnits are handled at compile time.
|
|
290
|
+
const exhaustive = unit;
|
|
291
|
+
throw new Error(`Unknown date unit: ${exhaustive}`);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
// For all other units, use Intl.DateTimeFormat with the specified locale and options
|
|
295
|
+
const formatter = new Intl.DateTimeFormat(locale, formatOptions);
|
|
296
|
+
return formatter.format(date);
|
|
297
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Copyright 2025 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
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: all[name]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
TEMPERATURE_GROUP_CONFIG: function() {
|
|
25
|
+
return TEMPERATURE_GROUP_CONFIG;
|
|
26
|
+
},
|
|
27
|
+
TEMPERATURE_UNIT_CONFIG: function() {
|
|
28
|
+
return TEMPERATURE_UNIT_CONFIG;
|
|
29
|
+
},
|
|
30
|
+
formatTemperature: function() {
|
|
31
|
+
return formatTemperature;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
const _constants = require("./constants");
|
|
35
|
+
const _utils = require("./utils");
|
|
36
|
+
const TEMPERATURE_GROUP = 'Temperature';
|
|
37
|
+
const TEMPERATURE_GROUP_CONFIG = {
|
|
38
|
+
label: TEMPERATURE_GROUP,
|
|
39
|
+
decimalPlaces: true
|
|
40
|
+
};
|
|
41
|
+
const TEMPERATURE_UNIT_CONFIG = {
|
|
42
|
+
celsius: {
|
|
43
|
+
group: TEMPERATURE_GROUP,
|
|
44
|
+
label: 'Celsius (°C)'
|
|
45
|
+
},
|
|
46
|
+
fahrenheit: {
|
|
47
|
+
group: TEMPERATURE_GROUP,
|
|
48
|
+
label: 'Fahrenheit (°F)'
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const formatTemperature = (value, { unit, decimalPlaces })=>{
|
|
52
|
+
const formatterOptions = {
|
|
53
|
+
unit,
|
|
54
|
+
style: 'unit'
|
|
55
|
+
};
|
|
56
|
+
if ((0, _utils.hasDecimalPlaces)(decimalPlaces)) {
|
|
57
|
+
formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
|
|
58
|
+
formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
|
|
59
|
+
} else {
|
|
60
|
+
formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
|
|
61
|
+
}
|
|
62
|
+
const locals = unit === 'celsius' ? 'en-GB' : 'en-US';
|
|
63
|
+
return Intl.NumberFormat(locals, formatterOptions).format(value);
|
|
64
|
+
};
|
|
@@ -42,6 +42,14 @@ const TIME_GROUP_CONFIG = {
|
|
|
42
42
|
decimalPlaces: true
|
|
43
43
|
};
|
|
44
44
|
const TIME_UNIT_CONFIG = {
|
|
45
|
+
nanoseconds: {
|
|
46
|
+
group: TIME_GROUP,
|
|
47
|
+
label: 'Nanoseconds'
|
|
48
|
+
},
|
|
49
|
+
microseconds: {
|
|
50
|
+
group: TIME_GROUP,
|
|
51
|
+
label: 'Microseconds'
|
|
52
|
+
},
|
|
45
53
|
milliseconds: {
|
|
46
54
|
group: TIME_GROUP,
|
|
47
55
|
label: 'Milliseconds'
|
|
@@ -76,6 +84,8 @@ const TIME_UNIT_CONFIG = {
|
|
|
76
84
|
}
|
|
77
85
|
};
|
|
78
86
|
var PersesTimeToIntlTime = /*#__PURE__*/ function(PersesTimeToIntlTime) {
|
|
87
|
+
PersesTimeToIntlTime["nanoseconds"] = "nanosecond";
|
|
88
|
+
PersesTimeToIntlTime["microseconds"] = "microsecond";
|
|
79
89
|
PersesTimeToIntlTime["milliseconds"] = "millisecond";
|
|
80
90
|
PersesTimeToIntlTime["seconds"] = "second";
|
|
81
91
|
PersesTimeToIntlTime["minutes"] = "minute";
|
|
@@ -99,7 +109,9 @@ var PersesTimeToIntlTime = /*#__PURE__*/ function(PersesTimeToIntlTime) {
|
|
|
99
109
|
hours: 3600,
|
|
100
110
|
minutes: 60,
|
|
101
111
|
seconds: 1,
|
|
102
|
-
milliseconds: 0.001
|
|
112
|
+
milliseconds: 0.001,
|
|
113
|
+
microseconds: 0.000001,
|
|
114
|
+
nanoseconds: 0.000000001
|
|
103
115
|
};
|
|
104
116
|
const LARGEST_TO_SMALLEST_TIME_UNITS = [
|
|
105
117
|
'years',
|
|
@@ -109,7 +121,9 @@ const LARGEST_TO_SMALLEST_TIME_UNITS = [
|
|
|
109
121
|
'hours',
|
|
110
122
|
'minutes',
|
|
111
123
|
'seconds',
|
|
112
|
-
'milliseconds'
|
|
124
|
+
'milliseconds',
|
|
125
|
+
'microseconds',
|
|
126
|
+
'nanoseconds'
|
|
113
127
|
];
|
|
114
128
|
/**
|
|
115
129
|
* Choose the first time unit that produces a number greater than 1, starting from the biggest time unit.
|
|
@@ -45,12 +45,18 @@ _export(exports, {
|
|
|
45
45
|
isCurrencyUnit: function() {
|
|
46
46
|
return isCurrencyUnit;
|
|
47
47
|
},
|
|
48
|
+
isDateUnit: function() {
|
|
49
|
+
return isDateUnit;
|
|
50
|
+
},
|
|
48
51
|
isDecimalUnit: function() {
|
|
49
52
|
return isDecimalUnit;
|
|
50
53
|
},
|
|
51
54
|
isPercentUnit: function() {
|
|
52
55
|
return isPercentUnit;
|
|
53
56
|
},
|
|
57
|
+
isTemperatureUnit: function() {
|
|
58
|
+
return isTemperatureUnit;
|
|
59
|
+
},
|
|
54
60
|
isThroughputUnit: function() {
|
|
55
61
|
return isThroughputUnit;
|
|
56
62
|
},
|
|
@@ -67,16 +73,20 @@ _export(exports, {
|
|
|
67
73
|
const _bytes = require("./bytes");
|
|
68
74
|
const _decimal = require("./decimal");
|
|
69
75
|
const _percent = require("./percent");
|
|
76
|
+
const _temperature = require("./temperature");
|
|
70
77
|
const _time = require("./time");
|
|
71
78
|
const _throughput = require("./throughput");
|
|
72
79
|
const _currency = require("./currency");
|
|
80
|
+
const _date = require("./date");
|
|
73
81
|
const UNIT_GROUP_CONFIG = {
|
|
74
82
|
Time: _time.TIME_GROUP_CONFIG,
|
|
75
83
|
Percent: _percent.PERCENT_GROUP_CONFIG,
|
|
76
84
|
Decimal: _decimal.DECIMAL_GROUP_CONFIG,
|
|
77
85
|
Bytes: _bytes.BYTES_GROUP_CONFIG,
|
|
78
86
|
Throughput: _throughput.THROUGHPUT_GROUP_CONFIG,
|
|
79
|
-
Currency: _currency.CURRENCY_GROUP_CONFIG
|
|
87
|
+
Currency: _currency.CURRENCY_GROUP_CONFIG,
|
|
88
|
+
Temperature: _temperature.TEMPERATURE_GROUP_CONFIG,
|
|
89
|
+
Date: _date.DATE_GROUP_CONFIG
|
|
80
90
|
};
|
|
81
91
|
const UNIT_CONFIG = {
|
|
82
92
|
..._time.TIME_UNIT_CONFIG,
|
|
@@ -84,10 +94,12 @@ const UNIT_CONFIG = {
|
|
|
84
94
|
..._decimal.DECIMAL_UNIT_CONFIG,
|
|
85
95
|
..._bytes.BYTES_UNIT_CONFIG,
|
|
86
96
|
..._throughput.THROUGHPUT_UNIT_CONFIG,
|
|
87
|
-
..._currency.CURRENCY_UNIT_CONFIG
|
|
97
|
+
..._currency.CURRENCY_UNIT_CONFIG,
|
|
98
|
+
..._temperature.TEMPERATURE_UNIT_CONFIG,
|
|
99
|
+
..._date.DATE_UNIT_CONFIG
|
|
88
100
|
};
|
|
89
101
|
function formatValue(value, formatOptions) {
|
|
90
|
-
if (formatOptions
|
|
102
|
+
if (!formatOptions) {
|
|
91
103
|
return value.toString();
|
|
92
104
|
}
|
|
93
105
|
if (isBytesUnit(formatOptions)) {
|
|
@@ -108,6 +120,12 @@ function formatValue(value, formatOptions) {
|
|
|
108
120
|
if (isCurrencyUnit(formatOptions)) {
|
|
109
121
|
return (0, _currency.formatCurrency)(value, formatOptions);
|
|
110
122
|
}
|
|
123
|
+
if (isDateUnit(formatOptions)) {
|
|
124
|
+
return (0, _date.formatDate)(value, formatOptions);
|
|
125
|
+
}
|
|
126
|
+
if (isTemperatureUnit(formatOptions)) {
|
|
127
|
+
return (0, _temperature.formatTemperature)(value, formatOptions);
|
|
128
|
+
}
|
|
111
129
|
const exhaustive = formatOptions;
|
|
112
130
|
throw new Error(`Unknown unit options ${exhaustive}`);
|
|
113
131
|
}
|
|
@@ -148,3 +166,9 @@ function isThroughputUnit(formatOptions) {
|
|
|
148
166
|
function isCurrencyUnit(formatOptions) {
|
|
149
167
|
return getUnitGroup(formatOptions) === 'Currency';
|
|
150
168
|
}
|
|
169
|
+
function isDateUnit(formatOptions) {
|
|
170
|
+
return getUnitGroup(formatOptions) === 'Date';
|
|
171
|
+
}
|
|
172
|
+
function isTemperatureUnit(formatOptions) {
|
|
173
|
+
return getUnitGroup(formatOptions) === 'Temperature';
|
|
174
|
+
}
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -14,10 +14,8 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
-
_export_star(require("./event"), exports);
|
|
18
17
|
_export_star(require("./fetch"), exports);
|
|
19
18
|
_export_star(require("./is-empty-object"), exports);
|
|
20
|
-
_export_star(require("./memo"), exports);
|
|
21
19
|
_export_star(require("./panel-refs"), exports);
|
|
22
20
|
_export_star(require("./text"), exports);
|
|
23
21
|
_export_star(require("./time-series-data"), exports);
|
|
@@ -35,12 +35,8 @@ _export(exports, {
|
|
|
35
35
|
},
|
|
36
36
|
transformData: function() {
|
|
37
37
|
return transformData;
|
|
38
|
-
},
|
|
39
|
-
useTransformData: function() {
|
|
40
|
-
return useTransformData;
|
|
41
38
|
}
|
|
42
39
|
});
|
|
43
|
-
const _react = require("react");
|
|
44
40
|
function applyJoinTransform(data, columns) {
|
|
45
41
|
// If column is undefined or empty, return data as is
|
|
46
42
|
if (columns.length === 0) {
|
|
@@ -159,9 +155,3 @@ function transformData(data, transforms) {
|
|
|
159
155
|
});
|
|
160
156
|
return result;
|
|
161
157
|
}
|
|
162
|
-
function useTransformData(data, transforms) {
|
|
163
|
-
return (0, _react.useMemo)(()=>transformData(data, transforms), [
|
|
164
|
-
data,
|
|
165
|
-
transforms
|
|
166
|
-
]);
|
|
167
|
-
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { DatasourceResource, DatasourceSelector, GlobalDatasourceResource } from './datasource';
|
|
2
|
+
/**
|
|
3
|
+
* Parameters for building a datasource proxy URL
|
|
4
|
+
*/
|
|
5
|
+
export interface BuildDatasourceProxyUrlParams {
|
|
6
|
+
project?: string;
|
|
7
|
+
dashboard?: string;
|
|
8
|
+
name: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Function type for building datasource proxy URLs
|
|
12
|
+
*/
|
|
13
|
+
export type BuildDatasourceProxyUrlFunc = (params: BuildDatasourceProxyUrlParams) => string;
|
|
14
|
+
/**
|
|
15
|
+
* The external API contract for fetching datasource resources.
|
|
16
|
+
* This defines the interface that must be implemented to provide
|
|
17
|
+
* datasource functionality to the dashboard.
|
|
18
|
+
*/
|
|
19
|
+
export interface DatasourceApi {
|
|
20
|
+
/**
|
|
21
|
+
* Optional function to build proxy URLs for datasources
|
|
22
|
+
*/
|
|
23
|
+
buildProxyUrl?: BuildDatasourceProxyUrlFunc;
|
|
24
|
+
/**
|
|
25
|
+
* Get a datasource resource for a specific project
|
|
26
|
+
*/
|
|
27
|
+
getDatasource: (project: string, selector: DatasourceSelector) => Promise<DatasourceResource | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* Get a global datasource resource
|
|
30
|
+
*/
|
|
31
|
+
getGlobalDatasource: (selector: DatasourceSelector) => Promise<GlobalDatasourceResource | undefined>;
|
|
32
|
+
/**
|
|
33
|
+
* List all datasources for a project, optionally filtered by plugin kind
|
|
34
|
+
*/
|
|
35
|
+
listDatasources: (project: string, pluginKind?: string) => Promise<DatasourceResource[]>;
|
|
36
|
+
/**
|
|
37
|
+
* List all global datasources, optionally filtered by plugin kind
|
|
38
|
+
*/
|
|
39
|
+
listGlobalDatasources: (pluginKind?: string) => Promise<GlobalDatasourceResource[]>;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=datasource-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datasource-api.d.ts","sourceRoot":"","sources":["../../src/model/datasource-api.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAEhG;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG,CAAC,MAAM,EAAE,6BAA6B,KAAK,MAAM,CAAC;AAE5F;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,aAAa,CAAC,EAAE,2BAA2B,CAAC;IAC5C;;OAEG;IACH,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,kBAAkB,KAAK,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC,CAAC;IAC1G;;OAEG;IACH,mBAAmB,EAAE,CAAC,QAAQ,EAAE,kBAAkB,KAAK,OAAO,CAAC,wBAAwB,GAAG,SAAS,CAAC,CAAC;IACrG;;OAEG;IACH,eAAe,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;IACzF;;OAEG;IACH,qBAAqB,EAAE,CAAC,UAAU,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,wBAAwB,EAAE,CAAC,CAAC;CACrF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright 2025 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
|
+
/**
|
|
14
|
+
* The external API contract for fetching datasource resources.
|
|
15
|
+
* This defines the interface that must be implemented to provide
|
|
16
|
+
* datasource functionality to the dashboard.
|
|
17
|
+
*/ export { };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=datasource-api.js.map
|