@perses-dev/components 0.0.0-snapshot-time-zone-selector-946f408 → 0.0.0-snapshot-timeseries-panel-actions-e28c1fe
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/EChart/EChart.d.ts.map +1 -1
- package/dist/EChart/EChart.js +2 -1
- package/dist/EChart/EChart.js.map +1 -1
- package/dist/FormatControls/FormatControls.d.ts.map +1 -1
- package/dist/FormatControls/FormatControls.js +8 -7
- package/dist/FormatControls/FormatControls.js.map +1 -1
- package/dist/TimeRangeSelector/DateTimeRangePicker.d.ts +1 -2
- package/dist/TimeRangeSelector/DateTimeRangePicker.d.ts.map +1 -1
- package/dist/TimeRangeSelector/DateTimeRangePicker.js +6 -5
- package/dist/TimeRangeSelector/DateTimeRangePicker.js.map +1 -1
- package/dist/TimeRangeSelector/TimeRangeSelector.d.ts +1 -5
- package/dist/TimeRangeSelector/TimeRangeSelector.d.ts.map +1 -1
- package/dist/TimeRangeSelector/TimeRangeSelector.js +10 -14
- package/dist/TimeRangeSelector/TimeRangeSelector.js.map +1 -1
- package/dist/cjs/EChart/EChart.js +1 -0
- package/dist/cjs/FormatControls/FormatControls.js +7 -6
- package/dist/cjs/TimeRangeSelector/DateTimeRangePicker.js +6 -5
- package/dist/cjs/TimeRangeSelector/TimeRangeSelector.js +8 -12
- package/dist/cjs/context/TimeZoneProvider.js +98 -0
- package/dist/cjs/context/index.js +1 -0
- package/dist/cjs/index.js +0 -1
- package/dist/cjs/model/index.js +0 -1
- 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/context/index.d.ts +1 -0
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +1 -0
- package/dist/context/index.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/model/index.d.ts +0 -1
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +0 -1
- package/dist/model/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/TimeZoneSelector/TimeZoneSelector.d.ts +0 -10
- package/dist/TimeZoneSelector/TimeZoneSelector.d.ts.map +0 -1
- package/dist/TimeZoneSelector/TimeZoneSelector.js +0 -143
- package/dist/TimeZoneSelector/TimeZoneSelector.js.map +0 -1
- package/dist/TimeZoneSelector/index.d.ts +0 -2
- package/dist/TimeZoneSelector/index.d.ts.map +0 -1
- package/dist/TimeZoneSelector/index.js +0 -15
- package/dist/TimeZoneSelector/index.js.map +0 -1
- package/dist/cjs/TimeZoneSelector/TimeZoneSelector.js +0 -156
- package/dist/cjs/TimeZoneSelector/index.js +0 -30
- package/dist/cjs/model/timeZoneOption.js +0 -100
- package/dist/model/timeZoneOption.d.ts +0 -10
- package/dist/model/timeZoneOption.d.ts.map +0 -1
- package/dist/model/timeZoneOption.js +0 -79
- package/dist/model/timeZoneOption.js.map +0 -1
|
@@ -1,156 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "TimeZoneSelector", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function() {
|
|
20
|
-
return TimeZoneSelector;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
const _jsxruntime = require("react/jsx-runtime");
|
|
24
|
-
const _material = require("@mui/material");
|
|
25
|
-
const _ClickAwayListener = /*#__PURE__*/ _interop_require_default(require("@mui/material/ClickAwayListener"));
|
|
26
|
-
const _Earth = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/Earth"));
|
|
27
|
-
const _Magnify = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/Magnify"));
|
|
28
|
-
const _react = require("react");
|
|
29
|
-
const _core = require("@perses-dev/core");
|
|
30
|
-
const _ToolbarIconButton = require("../ToolbarIconButton");
|
|
31
|
-
const _InfoTooltip = require("../InfoTooltip");
|
|
32
|
-
const _timeZoneOption = require("../model/timeZoneOption");
|
|
33
|
-
function _interop_require_default(obj) {
|
|
34
|
-
return obj && obj.__esModule ? obj : {
|
|
35
|
-
default: obj
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function TimeZoneSelector({ heightPx = '34px', timeZoneOptions: defaultTimeZoneOptions, onChange, value = _core.DEFAULT_DASHBOARD_TIMEZONE }) {
|
|
39
|
-
const isMobile = (0, _material.useMediaQuery)((0, _material.useTheme)().breakpoints.down('md'));
|
|
40
|
-
const [open, setOpen] = (0, _react.useState)(false);
|
|
41
|
-
const localTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
42
|
-
const [searchValue, setSearchValue] = (0, _react.useState)('');
|
|
43
|
-
const [timeZoneOptions, setTimeZoneOptions] = (0, _react.useState)(defaultTimeZoneOptions);
|
|
44
|
-
function handleSearchChange(event) {
|
|
45
|
-
setSearchValue(event.target.value);
|
|
46
|
-
if (event.target.value === '') {
|
|
47
|
-
setTimeZoneOptions(defaultTimeZoneOptions);
|
|
48
|
-
} else {
|
|
49
|
-
setTimeZoneOptions(defaultTimeZoneOptions.filter((option)=>option.label.toLowerCase().includes(event.target.value.toLowerCase())));
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
function handleTimeZoneSelection(timeZone) {
|
|
53
|
-
setOpen(false);
|
|
54
|
-
setTimeZoneOptions(defaultTimeZoneOptions);
|
|
55
|
-
setSearchValue('');
|
|
56
|
-
onChange?.(timeZone);
|
|
57
|
-
}
|
|
58
|
-
function handleOnClickAway() {
|
|
59
|
-
setOpen(false);
|
|
60
|
-
setSearchValue('');
|
|
61
|
-
setTimeZoneOptions(defaultTimeZoneOptions);
|
|
62
|
-
}
|
|
63
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_ClickAwayListener.default, {
|
|
64
|
-
onClickAway: handleOnClickAway,
|
|
65
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Box, {
|
|
66
|
-
children: [
|
|
67
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Box, {
|
|
68
|
-
sx: {
|
|
69
|
-
position: 'relative'
|
|
70
|
-
},
|
|
71
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_InfoTooltip.InfoTooltip, {
|
|
72
|
-
description: value === _core.DEFAULT_DASHBOARD_TIMEZONE ? localTimeZone : value,
|
|
73
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsxs)(_ToolbarIconButton.ToolbarIconButton, {
|
|
74
|
-
"data-testid": "current-timezone",
|
|
75
|
-
"aria-label": "Timezone",
|
|
76
|
-
onClick: ()=>setOpen(!open),
|
|
77
|
-
sx: (theme)=>({
|
|
78
|
-
height: heightPx,
|
|
79
|
-
paddingLeft: isMobile ? 0 : theme.spacing(1),
|
|
80
|
-
// Hide the timezone text on mobile
|
|
81
|
-
'& .timezone-text': {
|
|
82
|
-
display: isMobile ? 'none' : 'inline'
|
|
83
|
-
}
|
|
84
|
-
}),
|
|
85
|
-
children: [
|
|
86
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
|
|
87
|
-
className: "timezone-text",
|
|
88
|
-
children: value === _core.DEFAULT_DASHBOARD_TIMEZONE ? (0, _timeZoneOption.getTimeZoneOffset)(localTimeZone)?.value : (0, _timeZoneOption.getTimeZoneOffset)(value)?.value
|
|
89
|
-
}),
|
|
90
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_Earth.default, {
|
|
91
|
-
sx: (theme)=>({
|
|
92
|
-
marginLeft: theme.spacing(0.5)
|
|
93
|
-
})
|
|
94
|
-
})
|
|
95
|
-
]
|
|
96
|
-
})
|
|
97
|
-
})
|
|
98
|
-
}),
|
|
99
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Paper, {
|
|
100
|
-
sx: (theme)=>({
|
|
101
|
-
width: 350,
|
|
102
|
-
height: 355,
|
|
103
|
-
position: 'absolute',
|
|
104
|
-
top: isMobile ? 160 : 110,
|
|
105
|
-
right: 10,
|
|
106
|
-
zIndex: 1,
|
|
107
|
-
boxShadow: 3,
|
|
108
|
-
backgroundColor: theme.palette.background.paper,
|
|
109
|
-
display: open ? 'block' : 'none'
|
|
110
|
-
}),
|
|
111
|
-
children: [
|
|
112
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Input, {
|
|
113
|
-
"data-testid": "search-timezone",
|
|
114
|
-
sx: (theme)=>({
|
|
115
|
-
height: 45,
|
|
116
|
-
padding: theme.spacing(1)
|
|
117
|
-
}),
|
|
118
|
-
value: searchValue,
|
|
119
|
-
fullWidth: true,
|
|
120
|
-
placeholder: "Search timezone",
|
|
121
|
-
startAdornment: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.InputAdornment, {
|
|
122
|
-
position: "start",
|
|
123
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_Magnify.default, {})
|
|
124
|
-
}),
|
|
125
|
-
onChange: handleSearchChange
|
|
126
|
-
}),
|
|
127
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuList, {
|
|
128
|
-
sx: {
|
|
129
|
-
height: 305,
|
|
130
|
-
overflowX: 'auto'
|
|
131
|
-
},
|
|
132
|
-
children: timeZoneOptions.map((timeZoneOption)=>/*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Box, {
|
|
133
|
-
children: [
|
|
134
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.MenuItem, {
|
|
135
|
-
onClick: ()=>handleTimeZoneSelection(timeZoneOption),
|
|
136
|
-
selected: timeZoneOption.value === value,
|
|
137
|
-
children: [
|
|
138
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.ListItemText, {
|
|
139
|
-
children: timeZoneOption.label
|
|
140
|
-
}),
|
|
141
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Typography, {
|
|
142
|
-
variant: "body2",
|
|
143
|
-
children: timeZoneOption.longOffset
|
|
144
|
-
})
|
|
145
|
-
]
|
|
146
|
-
}, timeZoneOption.value),
|
|
147
|
-
timeZoneOption.value === _core.DEFAULT_DASHBOARD_TIMEZONE && /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Divider, {})
|
|
148
|
-
]
|
|
149
|
-
}, timeZoneOption.value))
|
|
150
|
-
})
|
|
151
|
-
]
|
|
152
|
-
})
|
|
153
|
-
]
|
|
154
|
-
})
|
|
155
|
-
});
|
|
156
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
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
|
-
_export_star(require("./TimeZoneSelector"), exports);
|
|
18
|
-
function _export_star(from, to) {
|
|
19
|
-
Object.keys(from).forEach(function(k) {
|
|
20
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
21
|
-
Object.defineProperty(to, k, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function() {
|
|
24
|
-
return from[k];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
return from;
|
|
30
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
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
|
-
DEFAULT_TIMEZONE_OPTIONS: function() {
|
|
25
|
-
return DEFAULT_TIMEZONE_OPTIONS;
|
|
26
|
-
},
|
|
27
|
-
getTimeZoneOffset: function() {
|
|
28
|
-
return getTimeZoneOffset;
|
|
29
|
-
},
|
|
30
|
-
getTimeZoneOptions: function() {
|
|
31
|
-
return getTimeZoneOptions;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
const _core = require("@perses-dev/core");
|
|
35
|
-
const _memoize = /*#__PURE__*/ _interop_require_default(require("lodash/memoize"));
|
|
36
|
-
function _interop_require_default(obj) {
|
|
37
|
-
return obj && obj.__esModule ? obj : {
|
|
38
|
-
default: obj
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
const DEFAULT_TIMEZONE_OPTIONS = (0, _memoize.default)(()=>Intl.supportedValuesOf('timeZone'));
|
|
42
|
-
const getTimeZoneOffset = (timeZone)=>{
|
|
43
|
-
const defaultLocale = Intl.DateTimeFormat().resolvedOptions().locale;
|
|
44
|
-
// longOffset is returned as either GMT+-<offset>, UTC+-<offset> or just GMT/UTC
|
|
45
|
-
const longOffset = Intl.DateTimeFormat(defaultLocale, {
|
|
46
|
-
timeZone,
|
|
47
|
-
timeZoneName: 'longOffset'
|
|
48
|
-
}).formatToParts(new Date()).find((part)=>part.type === 'timeZoneName');
|
|
49
|
-
return longOffset ? {
|
|
50
|
-
...longOffset,
|
|
51
|
-
// we want some consistency in the format of the offset, so if it's just GMT/UTC, we add +00:00
|
|
52
|
-
value: !(longOffset.value.includes('+') || longOffset.value.includes('-')) ? `${longOffset.value}+00:00` : longOffset.value
|
|
53
|
-
} : undefined;
|
|
54
|
-
};
|
|
55
|
-
const getTimeZoneOptions = (0, _memoize.default)(()=>{
|
|
56
|
-
const localTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
57
|
-
// define a browser time zone option
|
|
58
|
-
const BROWSER_TIME_ZONE = {
|
|
59
|
-
value: _core.DEFAULT_DASHBOARD_TIMEZONE,
|
|
60
|
-
label: `${localTimeZone} (default)`,
|
|
61
|
-
longOffset: getTimeZoneOffset(localTimeZone)?.value || ''
|
|
62
|
-
};
|
|
63
|
-
// define a UTC time zone option
|
|
64
|
-
const UTC = {
|
|
65
|
-
value: 'UTC',
|
|
66
|
-
label: 'UTC, GMT',
|
|
67
|
-
longOffset: 'UTC+00:00'
|
|
68
|
-
};
|
|
69
|
-
return(// putting UTC and local time zone options first for better user experience
|
|
70
|
-
[
|
|
71
|
-
'UTC',
|
|
72
|
-
_core.DEFAULT_DASHBOARD_TIMEZONE,
|
|
73
|
-
...DEFAULT_TIMEZONE_OPTIONS()
|
|
74
|
-
].map((timeZone)=>{
|
|
75
|
-
// return defined BROWSER_TIME_ZONE if timeZone is DEFAULT_DASHBOARD_TIMEZONE
|
|
76
|
-
if (timeZone === _core.DEFAULT_DASHBOARD_TIMEZONE) {
|
|
77
|
-
return BROWSER_TIME_ZONE;
|
|
78
|
-
}
|
|
79
|
-
// return defined UTC if timeZone is 'UTC'
|
|
80
|
-
if (timeZone === 'UTC') {
|
|
81
|
-
return UTC;
|
|
82
|
-
}
|
|
83
|
-
// return empty object if timeZone matches localTimeZone because we already returned it as BROWSER_TIME_ZONE
|
|
84
|
-
// avoid returning duplicate options
|
|
85
|
-
if (timeZone === localTimeZone) {
|
|
86
|
-
return {
|
|
87
|
-
value: '',
|
|
88
|
-
label: '',
|
|
89
|
-
longOffset: ''
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
const longOffset = getTimeZoneOffset(timeZone);
|
|
93
|
-
return {
|
|
94
|
-
value: timeZone,
|
|
95
|
-
label: timeZone.replaceAll('_', ' '),
|
|
96
|
-
longOffset: longOffset ? longOffset.value : ''
|
|
97
|
-
};
|
|
98
|
-
})// filter out objects with empty value
|
|
99
|
-
.filter((option)=>option.value !== ''));
|
|
100
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/// <reference types="lodash" />
|
|
2
|
-
export interface TimeZoneOption {
|
|
3
|
-
value: string;
|
|
4
|
-
label: string;
|
|
5
|
-
longOffset: string;
|
|
6
|
-
}
|
|
7
|
-
export declare const DEFAULT_TIMEZONE_OPTIONS: (() => string[]) & import("lodash").MemoizedFunction;
|
|
8
|
-
export declare const getTimeZoneOffset: (timeZone: string) => Intl.DateTimeFormatPart | undefined;
|
|
9
|
-
export declare const getTimeZoneOptions: (() => TimeZoneOption[]) & import("lodash").MemoizedFunction;
|
|
10
|
-
//# sourceMappingURL=timeZoneOption.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"timeZoneOption.d.ts","sourceRoot":"","sources":["../../src/model/timeZoneOption.ts"],"names":[],"mappings":";AAgBA,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB;AAID,eAAO,MAAM,wBAAwB,sDAAoD,CAAC;AAG1F,eAAO,MAAM,iBAAiB,aAAc,MAAM,KAAG,KAAK,kBAAkB,GAAG,SAe9E,CAAC;AAEF,eAAO,MAAM,kBAAkB,SAAe,cAAc,EAAE,qCAsC5D,CAAC"}
|
|
@@ -1,79 +0,0 @@
|
|
|
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
|
-
import { DEFAULT_DASHBOARD_TIMEZONE } from '@perses-dev/core';
|
|
14
|
-
import memoize from 'lodash/memoize';
|
|
15
|
-
// Instead of adding another dependency which returns an array of time zones, we can use the built-in Intl object
|
|
16
|
-
// memoizing this because the list of time zones is relatively expensive to compute with 400+ entries
|
|
17
|
-
export const DEFAULT_TIMEZONE_OPTIONS = memoize(()=>Intl.supportedValuesOf('timeZone'));
|
|
18
|
-
// Get the time zone offset for a given time zone
|
|
19
|
-
export const getTimeZoneOffset = (timeZone)=>{
|
|
20
|
-
const defaultLocale = Intl.DateTimeFormat().resolvedOptions().locale;
|
|
21
|
-
// longOffset is returned as either GMT+-<offset>, UTC+-<offset> or just GMT/UTC
|
|
22
|
-
const longOffset = Intl.DateTimeFormat(defaultLocale, {
|
|
23
|
-
timeZone,
|
|
24
|
-
timeZoneName: 'longOffset'
|
|
25
|
-
}).formatToParts(new Date()).find((part)=>part.type === 'timeZoneName');
|
|
26
|
-
return longOffset ? {
|
|
27
|
-
...longOffset,
|
|
28
|
-
// we want some consistency in the format of the offset, so if it's just GMT/UTC, we add +00:00
|
|
29
|
-
value: !(longOffset.value.includes('+') || longOffset.value.includes('-')) ? `${longOffset.value}+00:00` : longOffset.value
|
|
30
|
-
} : undefined;
|
|
31
|
-
};
|
|
32
|
-
export const getTimeZoneOptions = memoize(()=>{
|
|
33
|
-
const localTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
34
|
-
// define a browser time zone option
|
|
35
|
-
const BROWSER_TIME_ZONE = {
|
|
36
|
-
value: DEFAULT_DASHBOARD_TIMEZONE,
|
|
37
|
-
label: `${localTimeZone} (default)`,
|
|
38
|
-
longOffset: getTimeZoneOffset(localTimeZone)?.value || ''
|
|
39
|
-
};
|
|
40
|
-
// define a UTC time zone option
|
|
41
|
-
const UTC = {
|
|
42
|
-
value: 'UTC',
|
|
43
|
-
label: 'UTC, GMT',
|
|
44
|
-
longOffset: 'UTC+00:00'
|
|
45
|
-
};
|
|
46
|
-
return(// putting UTC and local time zone options first for better user experience
|
|
47
|
-
[
|
|
48
|
-
'UTC',
|
|
49
|
-
DEFAULT_DASHBOARD_TIMEZONE,
|
|
50
|
-
...DEFAULT_TIMEZONE_OPTIONS()
|
|
51
|
-
].map((timeZone)=>{
|
|
52
|
-
// return defined BROWSER_TIME_ZONE if timeZone is DEFAULT_DASHBOARD_TIMEZONE
|
|
53
|
-
if (timeZone === DEFAULT_DASHBOARD_TIMEZONE) {
|
|
54
|
-
return BROWSER_TIME_ZONE;
|
|
55
|
-
}
|
|
56
|
-
// return defined UTC if timeZone is 'UTC'
|
|
57
|
-
if (timeZone === 'UTC') {
|
|
58
|
-
return UTC;
|
|
59
|
-
}
|
|
60
|
-
// return empty object if timeZone matches localTimeZone because we already returned it as BROWSER_TIME_ZONE
|
|
61
|
-
// avoid returning duplicate options
|
|
62
|
-
if (timeZone === localTimeZone) {
|
|
63
|
-
return {
|
|
64
|
-
value: '',
|
|
65
|
-
label: '',
|
|
66
|
-
longOffset: ''
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
const longOffset = getTimeZoneOffset(timeZone);
|
|
70
|
-
return {
|
|
71
|
-
value: timeZone,
|
|
72
|
-
label: timeZone.replaceAll('_', ' '),
|
|
73
|
-
longOffset: longOffset ? longOffset.value : ''
|
|
74
|
-
};
|
|
75
|
-
})// filter out objects with empty value
|
|
76
|
-
.filter((option)=>option.value !== ''));
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
//# sourceMappingURL=timeZoneOption.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/timeZoneOption.ts"],"sourcesContent":["// Copyright 2025 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 { DEFAULT_DASHBOARD_TIMEZONE } from '@perses-dev/core';\nimport memoize from 'lodash/memoize';\n\nexport interface TimeZoneOption {\n value: string;\n label: string;\n longOffset: string;\n}\n\n// Instead of adding another dependency which returns an array of time zones, we can use the built-in Intl object\n// memoizing this because the list of time zones is relatively expensive to compute with 400+ entries\nexport const DEFAULT_TIMEZONE_OPTIONS = memoize(() => Intl.supportedValuesOf('timeZone'));\n\n// Get the time zone offset for a given time zone\nexport const getTimeZoneOffset = (timeZone: string): Intl.DateTimeFormatPart | undefined => {\n const defaultLocale = Intl.DateTimeFormat().resolvedOptions().locale;\n // longOffset is returned as either GMT+-<offset>, UTC+-<offset> or just GMT/UTC\n const longOffset = Intl.DateTimeFormat(defaultLocale, { timeZone, timeZoneName: 'longOffset' })\n .formatToParts(new Date())\n .find((part) => part.type === 'timeZoneName');\n return longOffset\n ? {\n ...longOffset,\n // we want some consistency in the format of the offset, so if it's just GMT/UTC, we add +00:00\n value: !(longOffset.value.includes('+') || longOffset.value.includes('-'))\n ? `${longOffset.value}+00:00`\n : longOffset.value,\n }\n : undefined;\n};\n\nexport const getTimeZoneOptions = memoize((): TimeZoneOption[] => {\n const localTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;\n // define a browser time zone option\n const BROWSER_TIME_ZONE: TimeZoneOption = {\n value: DEFAULT_DASHBOARD_TIMEZONE,\n label: `${localTimeZone} (default)`,\n longOffset: getTimeZoneOffset(localTimeZone)?.value || '',\n };\n // define a UTC time zone option\n const UTC: TimeZoneOption = { value: 'UTC', label: 'UTC, GMT', longOffset: 'UTC+00:00' };\n\n return (\n // putting UTC and local time zone options first for better user experience\n ['UTC', DEFAULT_DASHBOARD_TIMEZONE, ...DEFAULT_TIMEZONE_OPTIONS()]\n .map((timeZone) => {\n // return defined BROWSER_TIME_ZONE if timeZone is DEFAULT_DASHBOARD_TIMEZONE\n if (timeZone === DEFAULT_DASHBOARD_TIMEZONE) {\n return BROWSER_TIME_ZONE;\n }\n // return defined UTC if timeZone is 'UTC'\n if (timeZone === 'UTC') {\n return UTC;\n }\n // return empty object if timeZone matches localTimeZone because we already returned it as BROWSER_TIME_ZONE\n // avoid returning duplicate options\n if (timeZone === localTimeZone) {\n return { value: '', label: '', longOffset: '' };\n }\n const longOffset = getTimeZoneOffset(timeZone);\n return {\n value: timeZone,\n label: timeZone.replaceAll('_', ' '),\n longOffset: longOffset ? longOffset.value : '',\n };\n })\n // filter out objects with empty value\n .filter((option) => option.value !== '')\n );\n});\n"],"names":["DEFAULT_DASHBOARD_TIMEZONE","memoize","DEFAULT_TIMEZONE_OPTIONS","Intl","supportedValuesOf","getTimeZoneOffset","timeZone","defaultLocale","DateTimeFormat","resolvedOptions","locale","longOffset","timeZoneName","formatToParts","Date","find","part","type","value","includes","undefined","getTimeZoneOptions","localTimeZone","BROWSER_TIME_ZONE","label","UTC","map","replaceAll","filter","option"],"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,0BAA0B,QAAQ,mBAAmB;AAC9D,OAAOC,aAAa,iBAAiB;AAQrC,iHAAiH;AACjH,qGAAqG;AACrG,OAAO,MAAMC,2BAA2BD,QAAQ,IAAME,KAAKC,iBAAiB,CAAC,aAAa;AAE1F,iDAAiD;AACjD,OAAO,MAAMC,oBAAoB,CAACC;IAChC,MAAMC,gBAAgBJ,KAAKK,cAAc,GAAGC,eAAe,GAAGC,MAAM;IACpE,gFAAgF;IAChF,MAAMC,aAAaR,KAAKK,cAAc,CAACD,eAAe;QAAED;QAAUM,cAAc;IAAa,GAC1FC,aAAa,CAAC,IAAIC,QAClBC,IAAI,CAAC,CAACC,OAASA,KAAKC,IAAI,KAAK;IAChC,OAAON,aACH;QACE,GAAGA,UAAU;QACb,+FAA+F;QAC/FO,OAAO,CAAEP,CAAAA,WAAWO,KAAK,CAACC,QAAQ,CAAC,QAAQR,WAAWO,KAAK,CAACC,QAAQ,CAAC,IAAG,IACpE,GAAGR,WAAWO,KAAK,CAAC,MAAM,CAAC,GAC3BP,WAAWO,KAAK;IACtB,IACAE;AACN,EAAE;AAEF,OAAO,MAAMC,qBAAqBpB,QAAQ;IACxC,MAAMqB,gBAAgBnB,KAAKK,cAAc,GAAGC,eAAe,GAAGH,QAAQ;IACtE,oCAAoC;IACpC,MAAMiB,oBAAoC;QACxCL,OAAOlB;QACPwB,OAAO,GAAGF,cAAc,UAAU,CAAC;QACnCX,YAAYN,kBAAkBiB,gBAAgBJ,SAAS;IACzD;IACA,gCAAgC;IAChC,MAAMO,MAAsB;QAAEP,OAAO;QAAOM,OAAO;QAAYb,YAAY;IAAY;IAEvF,OACE,2EAA2E;IAC3E;QAAC;QAAOX;WAA+BE;KAA2B,CAC/DwB,GAAG,CAAC,CAACpB;QACJ,6EAA6E;QAC7E,IAAIA,aAAaN,4BAA4B;YAC3C,OAAOuB;QACT;QACA,0CAA0C;QAC1C,IAAIjB,aAAa,OAAO;YACtB,OAAOmB;QACT;QACA,4GAA4G;QAC5G,oCAAoC;QACpC,IAAInB,aAAagB,eAAe;YAC9B,OAAO;gBAAEJ,OAAO;gBAAIM,OAAO;gBAAIb,YAAY;YAAG;QAChD;QACA,MAAMA,aAAaN,kBAAkBC;QACrC,OAAO;YACLY,OAAOZ;YACPkB,OAAOlB,SAASqB,UAAU,CAAC,KAAK;YAChChB,YAAYA,aAAaA,WAAWO,KAAK,GAAG;QAC9C;IACF,EACA,sCAAsC;KACrCU,MAAM,CAAC,CAACC,SAAWA,OAAOX,KAAK,KAAK;AAE3C,GAAG"}
|