@perses-dev/components 0.46.0 → 0.47.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.
Files changed (136) hide show
  1. package/dist/AlignSelector/AlignSelector.d.ts +8 -0
  2. package/dist/AlignSelector/AlignSelector.d.ts.map +1 -0
  3. package/dist/AlignSelector/AlignSelector.js +45 -0
  4. package/dist/AlignSelector/AlignSelector.js.map +1 -0
  5. package/dist/AlignSelector/index.d.ts +2 -0
  6. package/dist/AlignSelector/index.d.ts.map +1 -0
  7. package/dist/AlignSelector/index.js +15 -0
  8. package/dist/AlignSelector/index.js.map +1 -0
  9. package/dist/ColorPicker/OptionsColorPicker.d.ts +7 -0
  10. package/dist/ColorPicker/OptionsColorPicker.d.ts.map +1 -0
  11. package/dist/{ThresholdsEditor/ThresholdColorPicker.js → ColorPicker/OptionsColorPicker.js} +5 -5
  12. package/dist/ColorPicker/OptionsColorPicker.js.map +1 -0
  13. package/dist/ColorPicker/index.d.ts +1 -0
  14. package/dist/ColorPicker/index.d.ts.map +1 -1
  15. package/dist/ColorPicker/index.js +1 -0
  16. package/dist/ColorPicker/index.js.map +1 -1
  17. package/dist/DensitySelector/DensitySelector.d.ts +7 -0
  18. package/dist/DensitySelector/DensitySelector.d.ts.map +1 -0
  19. package/dist/DensitySelector/DensitySelector.js +46 -0
  20. package/dist/DensitySelector/DensitySelector.js.map +1 -0
  21. package/dist/DensitySelector/index.d.ts +2 -0
  22. package/dist/DensitySelector/index.d.ts.map +1 -0
  23. package/dist/DensitySelector/index.js +15 -0
  24. package/dist/DensitySelector/index.js.map +1 -0
  25. package/dist/Dialog/Dialog.d.ts +2 -7
  26. package/dist/Dialog/Dialog.d.ts.map +1 -1
  27. package/dist/Dialog/Dialog.js +7 -2
  28. package/dist/Dialog/Dialog.js.map +1 -1
  29. package/dist/LinksEditor/LinksEditor.d.ts +6 -1
  30. package/dist/LinksEditor/LinksEditor.d.ts.map +1 -1
  31. package/dist/LinksEditor/LinksEditor.js +15 -8
  32. package/dist/LinksEditor/LinksEditor.js.map +1 -1
  33. package/dist/Overlay/Overlay.d.ts +15 -0
  34. package/dist/Overlay/Overlay.d.ts.map +1 -0
  35. package/dist/Overlay/Overlay.js +52 -0
  36. package/dist/Overlay/Overlay.js.map +1 -0
  37. package/dist/Overlay/index.d.ts +2 -0
  38. package/dist/Overlay/index.d.ts.map +1 -0
  39. package/dist/Overlay/index.js +15 -0
  40. package/dist/Overlay/index.js.map +1 -0
  41. package/dist/SortSelector/SortSelectorButtons.d.ts +8 -0
  42. package/dist/SortSelector/SortSelectorButtons.d.ts.map +1 -0
  43. package/dist/SortSelector/SortSelectorButtons.js +45 -0
  44. package/dist/SortSelector/SortSelectorButtons.js.map +1 -0
  45. package/dist/SortSelector/index.d.ts +1 -0
  46. package/dist/SortSelector/index.d.ts.map +1 -1
  47. package/dist/SortSelector/index.js +2 -1
  48. package/dist/SortSelector/index.js.map +1 -1
  49. package/dist/Table/InnerTable.d.ts.map +1 -1
  50. package/dist/Table/InnerTable.js +2 -1
  51. package/dist/Table/InnerTable.js.map +1 -1
  52. package/dist/Table/TableCell.d.ts +1 -1
  53. package/dist/Table/TableCell.d.ts.map +1 -1
  54. package/dist/Table/TableCell.js +3 -1
  55. package/dist/Table/TableCell.js.map +1 -1
  56. package/dist/Table/TableHeaderCell.d.ts +1 -1
  57. package/dist/Table/TableHeaderCell.d.ts.map +1 -1
  58. package/dist/Table/TableHeaderCell.js.map +1 -1
  59. package/dist/Table/model/table-model.d.ts +1 -1
  60. package/dist/Table/model/table-model.d.ts.map +1 -1
  61. package/dist/Table/model/table-model.js +25 -20
  62. package/dist/Table/model/table-model.js.map +1 -1
  63. package/dist/ThresholdsEditor/ThresholdInput.js +2 -2
  64. package/dist/ThresholdsEditor/ThresholdInput.js.map +1 -1
  65. package/dist/ThresholdsEditor/ThresholdsEditor.d.ts.map +1 -1
  66. package/dist/ThresholdsEditor/ThresholdsEditor.js +2 -2
  67. package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -1
  68. package/dist/TimeRangeSelector/DateTimeRangePicker.d.ts +18 -0
  69. package/dist/TimeRangeSelector/DateTimeRangePicker.d.ts.map +1 -0
  70. package/dist/{DateTimeRangePicker/AbsoluteTimePicker.js → TimeRangeSelector/DateTimeRangePicker.js} +45 -28
  71. package/dist/TimeRangeSelector/DateTimeRangePicker.js.map +1 -0
  72. package/dist/TimeRangeSelector/TimeRangeSelector.d.ts +35 -0
  73. package/dist/TimeRangeSelector/TimeRangeSelector.d.ts.map +1 -0
  74. package/dist/TimeRangeSelector/TimeRangeSelector.js +119 -0
  75. package/dist/TimeRangeSelector/TimeRangeSelector.js.map +1 -0
  76. package/dist/{DateTimeRangePicker → TimeRangeSelector}/index.d.ts +1 -2
  77. package/dist/TimeRangeSelector/index.d.ts.map +1 -0
  78. package/dist/{DateTimeRangePicker → TimeRangeSelector}/index.js +2 -3
  79. package/dist/TimeRangeSelector/index.js.map +1 -0
  80. package/dist/TimeRangeSelector/utils.d.ts +25 -0
  81. package/dist/TimeRangeSelector/utils.d.ts.map +1 -0
  82. package/dist/{DateTimeRangePicker → TimeRangeSelector}/utils.js +23 -2
  83. package/dist/TimeRangeSelector/utils.js.map +1 -0
  84. package/dist/cjs/AlignSelector/AlignSelector.js +53 -0
  85. package/dist/cjs/AlignSelector/index.js +30 -0
  86. package/dist/cjs/{ThresholdsEditor/ThresholdColorPicker.js → ColorPicker/OptionsColorPicker.js} +6 -6
  87. package/dist/cjs/ColorPicker/index.js +1 -0
  88. package/dist/cjs/DensitySelector/DensitySelector.js +54 -0
  89. package/dist/cjs/DensitySelector/index.js +30 -0
  90. package/dist/cjs/Dialog/Dialog.js +7 -2
  91. package/dist/cjs/LinksEditor/LinksEditor.js +15 -8
  92. package/dist/cjs/Overlay/Overlay.js +71 -0
  93. package/dist/cjs/Overlay/index.js +30 -0
  94. package/dist/cjs/SortSelector/SortSelectorButtons.js +53 -0
  95. package/dist/cjs/SortSelector/index.js +2 -1
  96. package/dist/cjs/Table/InnerTable.js +2 -1
  97. package/dist/cjs/Table/TableCell.js +3 -1
  98. package/dist/cjs/Table/model/table-model.js +25 -20
  99. package/dist/cjs/ThresholdsEditor/ThresholdInput.js +2 -2
  100. package/dist/cjs/ThresholdsEditor/ThresholdsEditor.js +2 -2
  101. package/dist/cjs/{DateTimeRangePicker/AbsoluteTimePicker.js → TimeRangeSelector/DateTimeRangePicker.js} +39 -30
  102. package/dist/cjs/TimeRangeSelector/TimeRangeSelector.js +127 -0
  103. package/dist/cjs/{DateTimeRangePicker → TimeRangeSelector}/index.js +2 -3
  104. package/dist/cjs/{DateTimeRangePicker → TimeRangeSelector}/utils.js +24 -1
  105. package/dist/cjs/index.js +4 -1
  106. package/dist/cjs/model/timeOption.js +19 -1
  107. package/dist/index.d.ts +4 -1
  108. package/dist/index.d.ts.map +1 -1
  109. package/dist/index.js +4 -1
  110. package/dist/index.js.map +1 -1
  111. package/dist/model/timeOption.d.ts +2 -1
  112. package/dist/model/timeOption.d.ts.map +1 -1
  113. package/dist/model/timeOption.js +13 -2
  114. package/dist/model/timeOption.js.map +1 -1
  115. package/package.json +7 -6
  116. package/dist/DateTimeRangePicker/AbsoluteTimePicker.d.ts +0 -9
  117. package/dist/DateTimeRangePicker/AbsoluteTimePicker.d.ts.map +0 -1
  118. package/dist/DateTimeRangePicker/AbsoluteTimePicker.js.map +0 -1
  119. package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts +0 -11
  120. package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts.map +0 -1
  121. package/dist/DateTimeRangePicker/DateTimeRangePicker.js +0 -80
  122. package/dist/DateTimeRangePicker/DateTimeRangePicker.js.map +0 -1
  123. package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts +0 -13
  124. package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts.map +0 -1
  125. package/dist/DateTimeRangePicker/TimeRangeSelector.js +0 -67
  126. package/dist/DateTimeRangePicker/TimeRangeSelector.js.map +0 -1
  127. package/dist/DateTimeRangePicker/index.d.ts.map +0 -1
  128. package/dist/DateTimeRangePicker/index.js.map +0 -1
  129. package/dist/DateTimeRangePicker/utils.d.ts +0 -7
  130. package/dist/DateTimeRangePicker/utils.d.ts.map +0 -1
  131. package/dist/DateTimeRangePicker/utils.js.map +0 -1
  132. package/dist/ThresholdsEditor/ThresholdColorPicker.d.ts +0 -3
  133. package/dist/ThresholdsEditor/ThresholdColorPicker.d.ts.map +0 -1
  134. package/dist/ThresholdsEditor/ThresholdColorPicker.js.map +0 -1
  135. package/dist/cjs/DateTimeRangePicker/DateTimeRangePicker.js +0 -88
  136. package/dist/cjs/DateTimeRangePicker/TimeRangeSelector.js +0 -80
@@ -0,0 +1,18 @@
1
+ import { AbsoluteTimeRange } from '@perses-dev/core';
2
+ interface AbsoluteTimeFormProps {
3
+ initialTimeRange: AbsoluteTimeRange;
4
+ onChange: (timeRange: AbsoluteTimeRange) => void;
5
+ onCancel: () => void;
6
+ }
7
+ /**
8
+ * Start and End datetime picker, allowing use to select a specific time range selecting two absolute dates and times.
9
+ * TODO: Use directly the MUI X ``DateTimePicker`` for datetime selection which is better. https://next.mui.com/x/react-date-pickers/date-time-picker/
10
+ * Use ``DateTimeRangePicker`` directly would be cool but paid https://next.mui.com/x/react-date-pickers/date-time-range-picker/
11
+ * @param initialTimeRange initial time range to pre-select.
12
+ * @param onChange event received when start and end has been selected (click on apply)
13
+ * @param onCancel event received when user click on cancel
14
+ * @constructor
15
+ */
16
+ export declare const DateTimeRangePicker: ({ initialTimeRange, onChange, onCancel }: AbsoluteTimeFormProps) => import("react/jsx-runtime").JSX.Element;
17
+ export {};
18
+ //# sourceMappingURL=DateTimeRangePicker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DateTimeRangePicker.d.ts","sourceRoot":"","sources":["../../src/TimeRangeSelector/DateTimeRangePicker.tsx"],"names":[],"mappings":"AAiBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAMrD,UAAU,qBAAqB;IAC7B,gBAAgB,EAAE,iBAAiB,CAAC;IACpC,QAAQ,EAAE,CAAC,SAAS,EAAE,iBAAiB,KAAK,IAAI,CAAC;IACjD,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AAMD;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,6CAA8C,qBAAqB,4CA4KlG,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2023 The Perses Authors
1
+ // Copyright 2024 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
@@ -12,13 +12,22 @@
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import { useState } from 'react';
15
- import { Box, Stack, TextField, Typography, Button } from '@mui/material';
16
- import { LocalizationProvider, StaticDateTimePicker } from '@mui/x-date-pickers';
15
+ import { Box, Stack, Typography, Button } from '@mui/material';
16
+ import { DateTimeField, LocalizationProvider, StaticDateTimePicker } from '@mui/x-date-pickers';
17
17
  import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
18
- import { useTimeZone } from '../context/TimeZoneProvider';
19
- import { validateDateRange } from './utils';
20
- const DATE_TIME_FORMAT = 'yyyy-MM-dd HH:mm:ss';
21
- export const AbsoluteTimePicker = ({ initialTimeRange, onChange, onCancel })=>{
18
+ import { useTimeZone } from '../context';
19
+ import { ErrorBoundary } from '../ErrorBoundary';
20
+ import { ErrorAlert } from '../ErrorAlert';
21
+ import { DATE_TIME_FORMAT, validateDateRange } from './utils';
22
+ /**
23
+ * Start and End datetime picker, allowing use to select a specific time range selecting two absolute dates and times.
24
+ * TODO: Use directly the MUI X ``DateTimePicker`` for datetime selection which is better. https://next.mui.com/x/react-date-pickers/date-time-picker/
25
+ * Use ``DateTimeRangePicker`` directly would be cool but paid https://next.mui.com/x/react-date-pickers/date-time-range-picker/
26
+ * @param initialTimeRange initial time range to pre-select.
27
+ * @param onChange event received when start and end has been selected (click on apply)
28
+ * @param onCancel event received when user click on cancel
29
+ * @constructor
30
+ */ export const DateTimeRangePicker = ({ initialTimeRange, onChange, onCancel })=>{
22
31
  const { formatWithUserTimeZone } = useTimeZone();
23
32
  // Time range values as dates that can be used as a time range.
24
33
  const [timeRange, setTimeRange] = useState(initialTimeRange);
@@ -149,27 +158,35 @@ export const AbsoluteTimePicker = ({ initialTimeRange, onChange, onCancel })=>{
149
158
  pl: 1,
150
159
  pr: 1,
151
160
  children: [
152
- /*#__PURE__*/ _jsx(TextField, {
153
- onChange: (event)=>{
154
- // TODO: add helperText, fix validation after we decide on form state solution
155
- onChangeStartTime(event.target.value);
156
- },
157
- onBlur: ()=>updateDateRange(),
158
- value: timeRangeInputs.start,
159
- label: "Start Time",
160
- placeholder: DATE_TIME_FORMAT,
161
- // tel used to match MUI DateTimePicker, may change in future: https://github.com/mui/material-ui/issues/27590
162
- type: "tel"
161
+ /*#__PURE__*/ _jsx(ErrorBoundary, {
162
+ FallbackComponent: ErrorAlert,
163
+ children: /*#__PURE__*/ _jsx(DateTimeField, {
164
+ label: "Start Time",
165
+ // @ts-expect-error: because the value is a Date, but the component expects a string
166
+ value: new Date(timeRangeInputs.start),
167
+ onChange: (event)=>{
168
+ if (event) {
169
+ onChangeStartTime(event);
170
+ }
171
+ },
172
+ onBlur: ()=>updateDateRange(),
173
+ format: DATE_TIME_FORMAT
174
+ })
163
175
  }),
164
- /*#__PURE__*/ _jsx(TextField, {
165
- onChange: (event)=>{
166
- onChangeEndTime(event.target.value);
167
- },
168
- onBlur: ()=>updateDateRange(),
169
- value: timeRangeInputs.end,
170
- label: "End Time",
171
- placeholder: DATE_TIME_FORMAT,
172
- type: "tel"
176
+ /*#__PURE__*/ _jsx(ErrorBoundary, {
177
+ FallbackComponent: ErrorAlert,
178
+ children: /*#__PURE__*/ _jsx(DateTimeField, {
179
+ label: "End Time",
180
+ // @ts-expect-error: because the value is a Date, but the component expects a string
181
+ value: new Date(timeRangeInputs.end),
182
+ onChange: (event)=>{
183
+ if (event) {
184
+ onChangeEndTime(event);
185
+ }
186
+ },
187
+ onBlur: ()=>updateDateRange(),
188
+ format: DATE_TIME_FORMAT
189
+ })
173
190
  })
174
191
  ]
175
192
  }),
@@ -199,4 +216,4 @@ export const AbsoluteTimePicker = ({ initialTimeRange, onChange, onCancel })=>{
199
216
  });
200
217
  };
201
218
 
202
- //# sourceMappingURL=AbsoluteTimePicker.js.map
219
+ //# sourceMappingURL=DateTimeRangePicker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/TimeRangeSelector/DateTimeRangePicker.tsx"],"sourcesContent":["// Copyright 2024 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 { useState } from 'react';\nimport { Box, Stack, Typography, Button } from '@mui/material';\nimport { DateTimeField, LocalizationProvider, StaticDateTimePicker } from '@mui/x-date-pickers';\nimport { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';\nimport { AbsoluteTimeRange } from '@perses-dev/core';\nimport { useTimeZone } from '../context';\nimport { ErrorBoundary } from '../ErrorBoundary';\nimport { ErrorAlert } from '../ErrorAlert';\nimport { DATE_TIME_FORMAT, validateDateRange } from './utils';\n\ninterface AbsoluteTimeFormProps {\n initialTimeRange: AbsoluteTimeRange;\n onChange: (timeRange: AbsoluteTimeRange) => void;\n onCancel: () => void;\n}\n\ntype AbsoluteTimeRangeInputValue = {\n [Property in keyof AbsoluteTimeRange]: string;\n};\n\n/**\n * Start and End datetime picker, allowing use to select a specific time range selecting two absolute dates and times.\n * TODO: Use directly the MUI X ``DateTimePicker`` for datetime selection which is better. https://next.mui.com/x/react-date-pickers/date-time-picker/\n * Use ``DateTimeRangePicker`` directly would be cool but paid https://next.mui.com/x/react-date-pickers/date-time-range-picker/\n * @param initialTimeRange initial time range to pre-select.\n * @param onChange event received when start and end has been selected (click on apply)\n * @param onCancel event received when user click on cancel\n * @constructor\n */\nexport const DateTimeRangePicker = ({ initialTimeRange, onChange, onCancel }: AbsoluteTimeFormProps) => {\n const { formatWithUserTimeZone } = useTimeZone();\n\n // Time range values as dates that can be used as a time range.\n const [timeRange, setTimeRange] = useState<AbsoluteTimeRange>(initialTimeRange);\n\n // Time range values as strings used to populate the text inputs. May not\n // be valid as dates when the user is typing.\n const [timeRangeInputs, setTimeRangeInputs] = useState<AbsoluteTimeRangeInputValue>({\n start: formatWithUserTimeZone(initialTimeRange.start, DATE_TIME_FORMAT),\n end: formatWithUserTimeZone(initialTimeRange.end, DATE_TIME_FORMAT),\n });\n\n const [showStartCalendar, setShowStartCalendar] = useState<boolean>(true);\n\n const changeTimeRange = (newTime: string | Date, segment: keyof AbsoluteTimeRange) => {\n const isInputChange = typeof newTime === 'string';\n const newInputTime = isInputChange ? newTime : formatWithUserTimeZone(newTime, DATE_TIME_FORMAT);\n\n setTimeRangeInputs((prevTimeRangeInputs) => {\n return {\n ...prevTimeRangeInputs,\n [segment]: newInputTime,\n };\n });\n\n // When the change is a string from an input, do not try to convert it to\n // a date because there are likely to be interim stages of editing where it\n // is not valid as a date. When the change is a Date from the calendar/clock\n // interface, we can be sure it is a date.\n if (!isInputChange) {\n setTimeRange((prevTimeRange) => {\n return {\n ...prevTimeRange,\n [segment]: newTime,\n };\n });\n }\n };\n\n const onChangeStartTime = (newStartTime: string | Date) => {\n changeTimeRange(newStartTime, 'start');\n };\n\n const onChangeEndTime = (newEndTime: string | Date) => {\n changeTimeRange(newEndTime, 'end');\n };\n\n const updateDateRange = () => {\n const newDates = {\n start: new Date(timeRangeInputs.start),\n end: new Date(timeRangeInputs.end),\n };\n const isValidDateRange = validateDateRange(newDates.start, newDates.end);\n if (isValidDateRange) {\n setTimeRange(newDates);\n return newDates;\n }\n };\n\n const onApply = () => {\n const newDates = updateDateRange();\n if (newDates) {\n onChange(newDates);\n }\n };\n\n return (\n <LocalizationProvider dateAdapter={AdapterDateFns}>\n <Stack\n spacing={2}\n sx={(theme) => ({\n padding: theme.spacing(1, 0, 2),\n })}\n >\n {showStartCalendar && (\n <Box\n sx={(theme) => ({\n // TODO: create separate reusable calendar component\n '.MuiPickersLayout-contentWrapper': {\n backgroundColor: theme.palette.background.default,\n },\n })}\n >\n <Typography variant=\"h3\" padding={1} paddingLeft={2}>\n Select Start Time\n </Typography>\n <StaticDateTimePicker\n displayStaticWrapperAs=\"desktop\"\n openTo=\"day\"\n disableHighlightToday={true}\n value={initialTimeRange.start}\n onChange={(newValue) => {\n if (newValue === null) return;\n onChangeStartTime(newValue);\n }}\n onAccept={() => {\n setShowStartCalendar(false);\n }}\n />\n </Box>\n )}\n {!showStartCalendar && (\n <Box\n sx={(theme) => ({\n '.MuiPickersLayout-contentWrapper': {\n backgroundColor: theme.palette.background.default,\n },\n })}\n >\n <Typography variant=\"h3\" padding={1} paddingLeft={2}>\n Select End Time\n </Typography>\n <StaticDateTimePicker\n displayStaticWrapperAs=\"desktop\"\n openTo=\"day\"\n disableHighlightToday={true}\n value={initialTimeRange.end}\n minDateTime={timeRange.start}\n onChange={(newValue) => {\n if (newValue === null) return;\n onChangeEndTime(newValue);\n }}\n onAccept={(newValue) => {\n if (newValue === null) return;\n setShowStartCalendar(true);\n onChangeEndTime(newValue);\n }}\n />\n </Box>\n )}\n <Stack direction=\"row\" alignItems=\"center\" gap={1} pl={1} pr={1}>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <DateTimeField\n label=\"Start Time\"\n // @ts-expect-error: because the value is a Date, but the component expects a string\n value={new Date(timeRangeInputs.start)}\n onChange={(event: string | null) => {\n if (event) {\n onChangeStartTime(event);\n }\n }}\n onBlur={() => updateDateRange()}\n format={DATE_TIME_FORMAT}\n />\n </ErrorBoundary>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <DateTimeField\n label=\"End Time\"\n // @ts-expect-error: because the value is a Date, but the component expects a string\n value={new Date(timeRangeInputs.end)}\n onChange={(event: string | null) => {\n if (event) {\n onChangeEndTime(event);\n }\n }}\n onBlur={() => updateDateRange()}\n format={DATE_TIME_FORMAT}\n />\n </ErrorBoundary>\n </Stack>\n <Stack direction=\"row\" sx={{ padding: (theme) => theme.spacing(0, 1) }} gap={1}>\n <Button variant=\"contained\" onClick={() => onApply()} fullWidth>\n Apply\n </Button>\n <Button variant=\"outlined\" onClick={() => onCancel()} fullWidth>\n Cancel\n </Button>\n </Stack>\n </Stack>\n </LocalizationProvider>\n );\n};\n"],"names":["useState","Box","Stack","Typography","Button","DateTimeField","LocalizationProvider","StaticDateTimePicker","AdapterDateFns","useTimeZone","ErrorBoundary","ErrorAlert","DATE_TIME_FORMAT","validateDateRange","DateTimeRangePicker","initialTimeRange","onChange","onCancel","formatWithUserTimeZone","timeRange","setTimeRange","timeRangeInputs","setTimeRangeInputs","start","end","showStartCalendar","setShowStartCalendar","changeTimeRange","newTime","segment","isInputChange","newInputTime","prevTimeRangeInputs","prevTimeRange","onChangeStartTime","newStartTime","onChangeEndTime","newEndTime","updateDateRange","newDates","Date","isValidDateRange","onApply","dateAdapter","spacing","sx","theme","padding","backgroundColor","palette","background","default","variant","paddingLeft","displayStaticWrapperAs","openTo","disableHighlightToday","value","newValue","onAccept","minDateTime","direction","alignItems","gap","pl","pr","FallbackComponent","label","event","onBlur","format","onClick","fullWidth"],"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,QAAQ,QAAQ,QAAQ;AACjC,SAASC,GAAG,E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ption } from '../model';
3
+ interface TimeRangeSelectorProps {
4
+ /**
5
+ * The current value of the time range.
6
+ */
7
+ value: TimeRangeValue;
8
+ /**
9
+ * The list of time options to display in the dropdown.
10
+ * The component will automatically add the last option as a custom absolute time range.
11
+ */
12
+ timeOptions: TimeOption[];
13
+ /**
14
+ * The callback to call when the time range changes.
15
+ */
16
+ onChange: (value: TimeRangeValue) => void;
17
+ /**
18
+ * Custom line height for the select component.
19
+ */
20
+ height?: string;
21
+ /**
22
+ * Whether to show the custom time range option.
23
+ * Defaults to true.
24
+ */
25
+ showCustomTimeRange?: boolean;
26
+ }
27
+ /**
28
+ * Date & time selection component to customize what data renders on dashboard.
29
+ * This includes relative shortcuts and the ability to pick absolute start and end times.
30
+ * @param props
31
+ * @constructor
32
+ */
33
+ export declare function TimeRangeSelector({ value, timeOptions, onChange, height, showCustomTimeRange, }: TimeRangeSelectorProps): import("react/jsx-runtime").JSX.Element;
34
+ export {};
35
+ //# sourceMappingURL=TimeRangeSelector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TimeRangeSelector.d.ts","sourceRoot":"","sources":["../../src/TimeRangeSelector/TimeRangeSelector.tsx"],"names":[],"mappings":"AAeA,OAAO,EAAE,cAAc,EAA+D,MAAM,kBAAkB,CAAC;AAG/G,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAItC,UAAU,sBAAsB;IAC9B;;OAEG;IACH,KAAK,EAAE,cAAc,CAAC;IACtB;;;OAGG;IACH,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B;;OAEG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;IAC1C;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,KAAK,EACL,WAAW,EACX,QAAQ,EACR,MAAM,EACN,mBAA0B,GAC3B,EAAE,sBAAsB,2CAkGxB"}
@@ -0,0 +1,119 @@
1
+ // Copyright 2024 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 { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
14
+ import { Box, MenuItem, Popover, Select } from '@mui/material';
15
+ import Calendar from 'mdi-material-ui/Calendar';
16
+ import { isRelativeTimeRange, toAbsoluteTimeRange } from '@perses-dev/core';
17
+ import { useMemo, useRef, useState } from 'react';
18
+ import { useTimeZone } from '../context';
19
+ import { DateTimeRangePicker } from './DateTimeRangePicker';
20
+ import { buildCustomTimeOption, formatTimeRange } from './utils';
21
+ /**
22
+ * Date & time selection component to customize what data renders on dashboard.
23
+ * This includes relative shortcuts and the ability to pick absolute start and end times.
24
+ * @param props
25
+ * @constructor
26
+ */ export function TimeRangeSelector({ value, timeOptions, onChange, height, showCustomTimeRange = true }) {
27
+ const { timeZone } = useTimeZone();
28
+ const anchorEl = useRef(); // Used to position the absolute time range picker
29
+ // Control the open state of the absolute time range picker
30
+ const [showCustomDateSelector, setShowCustomDateSelector] = useState(false);
31
+ // Build the initial value of the absolute time range picker
32
+ const convertedTimeRange = useMemo(()=>{
33
+ return isRelativeTimeRange(value) ? toAbsoluteTimeRange(value) : value;
34
+ }, [
35
+ value
36
+ ]);
37
+ // Last option is the absolute time range option (custom)
38
+ // If the value is an absolute time range, we display this time range
39
+ // If the value is a relative time range, we make a default CustomTimeOption built from undefined value
40
+ const lastOption = useMemo(()=>buildCustomTimeOption(isRelativeTimeRange(value) ? undefined : value, timeZone), [
41
+ value,
42
+ timeZone
43
+ ]);
44
+ // Control the open state of the select component to prevent the menu from closing when the custom date picker is
45
+ // opened.
46
+ //
47
+ // Note that the value state of the select is here for display only. The real value (the one from props) is managed
48
+ // by click events on each menu item.
49
+ // This is a trick to get around the limitation of select with menu item that doesn't support objects as value...
50
+ const [open, setOpen] = useState(false);
51
+ return /*#__PURE__*/ _jsxs(_Fragment, {
52
+ children: [
53
+ /*#__PURE__*/ _jsx(Popover, {
54
+ anchorEl: anchorEl.current,
55
+ anchorOrigin: {
56
+ vertical: 'bottom',
57
+ horizontal: 'center'
58
+ },
59
+ open: showCustomDateSelector,
60
+ onClose: ()=>setShowCustomDateSelector(false),
61
+ sx: (theme)=>({
62
+ padding: theme.spacing(2)
63
+ }),
64
+ children: /*#__PURE__*/ _jsx(DateTimeRangePicker, {
65
+ initialTimeRange: convertedTimeRange,
66
+ onChange: (value)=>{
67
+ onChange(value);
68
+ setShowCustomDateSelector(false);
69
+ setOpen(false);
70
+ },
71
+ onCancel: ()=>setShowCustomDateSelector(false)
72
+ })
73
+ }),
74
+ /*#__PURE__*/ _jsx(Box, {
75
+ ref: anchorEl,
76
+ children: /*#__PURE__*/ _jsxs(Select, {
77
+ open: open,
78
+ value: formatTimeRange(value, timeZone),
79
+ onClick: ()=>setOpen(!open),
80
+ IconComponent: Calendar,
81
+ inputProps: {
82
+ 'aria-label': `Select time range. Currently set to ${value}`
83
+ },
84
+ sx: {
85
+ // `transform: none` prevents calendar icon from flipping over when menu is open
86
+ '.MuiSelect-icon': {
87
+ marginTop: '1px',
88
+ transform: 'none'
89
+ },
90
+ // paddingRight creates more space for the calendar icon (it's a bigger icon)
91
+ '.MuiSelect-select.MuiSelect-outlined.MuiInputBase-input': {
92
+ paddingRight: '36px'
93
+ },
94
+ '.MuiSelect-select': height ? {
95
+ lineHeight: height,
96
+ paddingY: 0
97
+ } : {}
98
+ },
99
+ children: [
100
+ timeOptions.map((item, idx)=>/*#__PURE__*/ _jsx(MenuItem, {
101
+ value: formatTimeRange(item.value, timeZone),
102
+ onClick: ()=>{
103
+ onChange(item.value);
104
+ },
105
+ children: item.display
106
+ }, idx)),
107
+ showCustomTimeRange && /*#__PURE__*/ _jsx(MenuItem, {
108
+ value: formatTimeRange(lastOption.value, timeZone),
109
+ onClick: ()=>setShowCustomDateSelector(true),
110
+ children: lastOption.display
111
+ })
112
+ ]
113
+ })
114
+ })
115
+ ]
116
+ });
117
+ }
118
+
119
+ //# sourceMappingURL=TimeRangeSelector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/TimeRangeSelector/TimeRangeSelector.tsx"],"sourcesContent":["// Copyright 2024 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 { Box, MenuItem, Popover, Select } from '@mui/material';\nimport Calendar from 'mdi-material-ui/Calendar';\nimport { TimeRangeValue, isRelativeTimeRange, AbsoluteTimeRange, toAbsoluteTimeRange } from '@perses-dev/core';\nimport { useMemo, useRef, useState } from 'react';\nimport { useTimeZone } from '../context';\nimport { TimeOption } from '../model';\nimport { DateTimeRangePicker } from './DateTimeRangePicker';\nimport { buildCustomTimeOption, formatTimeRange } from './utils';\n\ninterface TimeRangeSelectorProps {\n /**\n * The current value of the time range.\n */\n value: TimeRangeValue;\n /**\n * The list of time options to display in the dropdown.\n * The component will automatically add the last option as a custom absolute time range.\n */\n timeOptions: TimeOption[];\n /**\n * The callback to call when the time range changes.\n */\n onChange: (value: TimeRangeValue) => void;\n /**\n * Custom line height for the select component.\n */\n height?: string;\n /**\n * Whether to show the custom time range option.\n * Defaults to true.\n */\n showCustomTimeRange?: boolean;\n}\n\n/**\n * Date & time selection component to customize what data renders on dashboard.\n * This includes relative shortcuts and the ability to pick absolute start and end times.\n * @param props\n * @constructor\n */\nexport function TimeRangeSelector({\n value,\n timeOptions,\n onChange,\n height,\n showCustomTimeRange = true,\n}: TimeRangeSelectorProps) {\n const { timeZone } = useTimeZone();\n\n const anchorEl = useRef(); // Used to position the absolute time range picker\n\n // Control the open state of the absolute time range picker\n const [showCustomDateSelector, setShowCustomDateSelector] = useState(false);\n\n // Build the initial value of the absolute time range picker\n const convertedTimeRange = useMemo(() => {\n return isRelativeTimeRange(value) ? toAbsoluteTimeRange(value) : value;\n }, [value]);\n\n // Last option is the absolute time range option (custom)\n // If the value is an absolute time range, we display this time range\n // If the value is a relative time range, we make a default CustomTimeOption built from undefined value\n const lastOption = useMemo(\n () => buildCustomTimeOption(isRelativeTimeRange(value) ? undefined : value, timeZone),\n [value, timeZone]\n );\n\n // Control the open state of the select component to prevent the menu from closing when the custom date picker is\n // opened.\n //\n // Note that the value state of the select is here for display only. The real value (the one from props) is managed\n // by click events on each menu item.\n // This is a trick to get around the limitation of select with menu item that doesn't support objects as value...\n const [open, setOpen] = useState(false);\n\n return (\n <>\n <Popover\n anchorEl={anchorEl.current}\n anchorOrigin={{\n vertical: 'bottom',\n horizontal: 'center',\n }}\n open={showCustomDateSelector}\n onClose={() => setShowCustomDateSelector(false)}\n sx={(theme) => ({\n padding: theme.spacing(2),\n })}\n >\n <DateTimeRangePicker\n initialTimeRange={convertedTimeRange}\n onChange={(value: AbsoluteTimeRange) => {\n onChange(value);\n setShowCustomDateSelector(false);\n setOpen(false);\n }}\n onCancel={() => setShowCustomDateSelector(false)}\n />\n </Popover>\n <Box ref={anchorEl}>\n <Select\n open={open}\n value={formatTimeRange(value, timeZone)}\n onClick={() => setOpen(!open)}\n IconComponent={Calendar}\n inputProps={{\n 'aria-label': `Select time range. Currently set to ${value}`,\n }}\n sx={{\n // `transform: none` prevents calendar icon from flipping over when menu is open\n '.MuiSelect-icon': {\n marginTop: '1px',\n transform: 'none',\n },\n // paddingRight creates more space for the calendar icon (it's a bigger icon)\n '.MuiSelect-select.MuiSelect-outlined.MuiInputBase-input': {\n paddingRight: '36px',\n },\n '.MuiSelect-select': height ? { lineHeight: height, paddingY: 0 } : {},\n }}\n >\n {timeOptions.map((item, idx) => (\n <MenuItem\n key={idx}\n value={formatTimeRange(item.value, timeZone)}\n onClick={() => {\n onChange(item.value);\n }}\n >\n {item.display}\n </MenuItem>\n ))}\n {showCustomTimeRange && (\n <MenuItem\n value={formatTimeRange(lastOption.value, timeZone)}\n onClick={() => setShowCustomDateSelector(true)}\n >\n {lastOption.display}\n </MenuItem>\n )}\n </Select>\n </Box>\n </>\n );\n}\n"],"names":["Box","MenuItem","Popover","Select","Calendar","isRelativeTimeRange","toAbsoluteTimeRange","useMemo","useRef","useState","useTimeZone","DateTimeRangePicker","buildCustomTimeOption","formatTimeRange","TimeRangeSelector","value","timeOptions","onChange","height","showCustomTimeRange","timeZone","anchorEl","showCustomDateSelector","setShowCustomDateSelector","convertedTimeRange","lastOption","undefined","open","setOpen","current","anchorOrigin","vertical","horizontal","onClose","sx","theme","padding","spacing","initialTimeRange","onCancel","ref","onClick","IconComponent","inputProps","marginTop","transform","paddingRight","lineHeight","paddingY","map","item","idx","display"],"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,GAAG,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,MAAM,QAAQ,gBAAgB;AAC/D,OAAOC,cAAc,2BAA2B;AAChD,SAAyBC,mBAAmB,EAAqBC,mBAAmB,QAAQ,mBAAmB;AAC/G,SAASC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAClD,SAASC,WAAW,QAAQ,aAAa;A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CAACD;oBACxBe,eAAetC;oBACfuC,YAAY;wBACV,cAAc,CAAC,oCAAoC,EAAE5B,MAAM,CAAC;oBAC9D;oBACAmB,IAAI;wBACF,gFAAgF;wBAChF,mBAAmB;4BACjBU,WAAW;4BACXC,WAAW;wBACb;wBACA,6EAA6E;wBAC7E,2DAA2D;4BACzDC,cAAc;wBAChB;wBACA,qBAAqB5B,SAAS;4BAAE6B,YAAY7B;4BAAQ8B,UAAU;wBAAE,IAAI,CAAC;oBACvE;;wBAEChC,YAAYiC,GAAG,CAAC,CAACC,MAAMC,oBACtB,KAAClD;gCAECc,OAAOF,gBAAgBqC,KAAKnC,KAAK,EAAEK;gCACnCqB,SAAS;oCACPxB,SAASiC,KAAKnC,KAAK;gCACrB;0CAECmC,KAAKE,OAAO;+BANRD;wBASRhC,qCACC,KAAClB;4BACCc,OAAOF,gBAAgBY,WAAWV,KAAK,EAAEK;4BACzCqB,SAAS,IAAMlB,0BAA0B;sCAExCE,WAAW2B,OAAO;;;;;;;AAOjC"}
@@ -1,4 +1,3 @@
1
- export * from './DateTimeRangePicker';
2
1
  export * from './TimeRangeSelector';
3
- export * from './AbsoluteTimePicker';
2
+ export * from './DateTimeRangePicker';
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/TimeRangeSelector/index.ts"],"names":[],"mappings":"AAaA,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2023 The Perses Authors
1
+ // Copyright 2024 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
@@ -10,8 +10,7 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- export * from './DateTimeRangePicker';
14
13
  export * from './TimeRangeSelector';
15
- export * from './AbsoluteTimePicker';
14
+ export * from './DateTimeRangePicker';
16
15
 
17
16
  //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/TimeRangeSelector/index.ts"],"sourcesContent":["// Copyright 2024 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 './TimeRangeSelector';\nexport * from './DateTimeRangePicker';\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,sBAAsB;AACpC,cAAc,wBAAwB"}
@@ -0,0 +1,25 @@
1
+ import { AbsoluteTimeRange, TimeRangeValue } from '@perses-dev/core';
2
+ export declare const DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
3
+ export interface CustomTimeOption {
4
+ value: TimeRangeValue | undefined;
5
+ display: string;
6
+ }
7
+ export declare function buildCustomTimeOption(value: AbsoluteTimeRange | undefined, timeZone: string): CustomTimeOption;
8
+ /**
9
+ * Date validation and check if end is after start
10
+ */
11
+ export declare function validateDateRange(startDate: Date, endDate: Date): boolean;
12
+ /**
13
+ * Format start and end time based on provided date format
14
+ * @param timeRange absolute time range with a start and end datetime
15
+ * @param dateFormat date format string
16
+ * @param timeZone
17
+ */
18
+ export declare function formatAbsoluteRange(timeRange: AbsoluteTimeRange, dateFormat: string, timeZone?: string): string;
19
+ /**
20
+ * Format the time range for display purpose only (e.g. in the selector)
21
+ * @param value
22
+ * @param timeZone
23
+ */
24
+ export declare function formatTimeRange(value: TimeRangeValue | undefined, timeZone: string): string;
25
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/TimeRangeSelector/utils.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,iBAAiB,EAAuB,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAG1F,eAAO,MAAM,gBAAgB,wBAAwB,CAAC;AAEtD,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,cAAc,GAAG,SAAS,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,iBAAiB,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,gBAAgB,CAE9G;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,WAW/D;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,UAItG;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,UAKlF"}
@@ -1,4 +1,4 @@
1
- // Copyright 2023 The Perses Authors
1
+ // Copyright 2024 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
@@ -11,8 +11,16 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { isBefore, isValid } from 'date-fns';
14
+ import { isRelativeTimeRange } from '@perses-dev/core';
14
15
  import { formatWithTimeZone } from '../utils';
15
- /*
16
+ export const DATE_TIME_FORMAT = 'yyyy-MM-dd HH:mm:ss';
17
+ export function buildCustomTimeOption(value, timeZone) {
18
+ return {
19
+ value,
20
+ display: formatTimeRange(value, timeZone)
21
+ };
22
+ }
23
+ /**
16
24
  * Date validation and check if end is after start
17
25
  */ export function validateDateRange(startDate, endDate) {
18
26
  // TODO: display error as helperText
@@ -28,10 +36,23 @@ import { formatWithTimeZone } from '../utils';
28
36
  }
29
37
  /**
30
38
  * Format start and end time based on provided date format
39
+ * @param timeRange absolute time range with a start and end datetime
40
+ * @param dateFormat date format string
41
+ * @param timeZone
31
42
  */ export function formatAbsoluteRange(timeRange, dateFormat, timeZone) {
32
43
  const formattedStart = formatWithTimeZone(timeRange.start, dateFormat, timeZone);
33
44
  const formattedEnd = formatWithTimeZone(timeRange.end, dateFormat, timeZone);
34
45
  return `${formattedStart} - ${formattedEnd}`;
35
46
  }
47
+ /**
48
+ * Format the time range for display purpose only (e.g. in the selector)
49
+ * @param value
50
+ * @param timeZone
51
+ */ export function formatTimeRange(value, timeZone) {
52
+ if (!value) {
53
+ return 'Custom Time Range';
54
+ }
55
+ return !isRelativeTimeRange(value) ? formatAbsoluteRange(value, DATE_TIME_FORMAT, timeZone) : value.pastDuration;
56
+ }
36
57
 
37
58
  //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/TimeRangeSelector/utils.ts"],"sourcesContent":["// Copyright 2024 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 { isBefore, isValid } from 'date-fns';\nimport { AbsoluteTimeRange, isRelativeTimeRange, TimeRangeValue } from '@perses-dev/core';\nimport { formatWithTimeZone } from '../utils';\n\nexport const DATE_TIME_FORMAT = 'yyyy-MM-dd HH:mm:ss';\n\nexport interface CustomTimeOption {\n value: TimeRangeValue | undefined;\n display: string;\n}\n\nexport function buildCustomTimeOption(value: AbsoluteTimeRange | undefined, timeZone: string): CustomTimeOption {\n return { value, display: formatTimeRange(value, timeZone) };\n}\n\n/**\n * Date validation and check if end is after start\n */\nexport function validateDateRange(startDate: Date, endDate: Date) {\n // TODO: display error as helperText\n if (!isValid(startDate) || !isValid(endDate)) {\n console.error('Invalid Date');\n return false;\n }\n if (!isBefore(startDate, endDate)) {\n console.error('End Time is before Start Time');\n return false;\n }\n return true;\n}\n\n/**\n * Format start and end time based on provided date format\n * @param timeRange absolute time range with a start and end datetime\n * @param dateFormat date format string\n * @param timeZone\n */\nexport function formatAbsoluteRange(timeRange: AbsoluteTimeRange, dateFormat: string, timeZone?: string) {\n const formattedStart = formatWithTimeZone(timeRange.start, dateFormat, timeZone);\n const formattedEnd = formatWithTimeZone(timeRange.end, dateFormat, timeZone);\n return `${formattedStart} - ${formattedEnd}`;\n}\n\n/**\n * Format the time range for display purpose only (e.g. in the selector)\n * @param value\n * @param timeZone\n */\nexport function formatTimeRange(value: TimeRangeValue | undefined, timeZone: string) {\n if (!value) {\n return 'Custom Time Range';\n }\n return !isRelativeTimeRange(value) ? formatAbsoluteRange(value, DATE_TIME_FORMAT, timeZone) : value.pastDuration;\n}\n"],"names":["isBefore","isValid","isRelativeTimeRange","formatWithTimeZone","DATE_TIME_FORMAT","buildCustomTimeOption","value","timeZone","display","formatTimeRange","validateDateRange","startDate","endDate","console","error","formatAbsoluteRange","timeRange","dateFormat","formattedStart","start","formattedEnd","end","pastDuration"],"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,QAAQ,EAAEC,OAAO,QAAQ,WAAW;AAC7C,SAA4BC,mBAAmB,QAAwB,mBAAmB;AAC1F,SAASC,kBAAkB,QAAQ,WAAW;AAE9C,OAAO,MAAMC,mBAAmB,sBAAsB;AAOtD,OAAO,SAASC,sBAAsBC,KAAoC,EAAEC,QAAgB;IAC1F,OAAO;QAAED;QAAOE,SAASC,gBAAgBH,OAAOC;IAAU;AAC5D;AAEA;;CAEC,GACD,OAAO,SAASG,kBAAkBC,SAAe,EAAEC,OAAa;IAC9D,oCAAoC;IACpC,IAAI,CAACX,QAAQU,cAAc,CAACV,QAAQW,UAAU;QAC5CC,QAAQC,KAAK,CAAC;QACd,OAAO;IACT;IACA,IAAI,CAACd,SAASW,WAAWC,UAAU;QACjCC,QAAQC,KAAK,CAAC;QACd,OAAO;IACT;IACA,OAAO;AACT;AAEA;;;;;CAKC,GACD,OAAO,SAASC,oBAAoBC,SAA4B,EAAEC,UAAkB,EAAEV,QAAiB;IACrG,MAAMW,iBAAiBf,mBAAmBa,UAAUG,KAAK,EAAEF,YAAYV;IACvE,MAAMa,eAAejB,mBAAmBa,UAAUK,GAAG,EAAEJ,YAAYV;IACnE,OAAO,CAAC,EAAEW,eAAe,GAAG,EAAEE,aAAa,CAAC;AAC9C;AAEA;;;;CAIC,GACD,OAAO,SAASX,gBAAgBH,KAAiC,EAAEC,QAAgB;IACjF,IAAI,CAACD,OAAO;QACV,OAAO;IACT;IACA,OAAO,CAACJ,oBAAoBI,SAASS,oBAAoBT,OAAOF,kBAAkBG,YAAYD,MAAMgB,YAAY;AAClH"}
@@ -0,0 +1,53 @@
1
+ // Copyright 2024 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, "AlignSelector", {
18
+ enumerable: true,
19
+ get: function() {
20
+ return AlignSelector;
21
+ }
22
+ });
23
+ const _jsxruntime = require("react/jsx-runtime");
24
+ const _material = require("@mui/material");
25
+ function AlignSelector({ onChange, value = 'left', ...props }) {
26
+ const handleSortChange = (option)=>{
27
+ onChange(option);
28
+ };
29
+ return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.ButtonGroup, {
30
+ "aria-label": "Alignement",
31
+ sx: {
32
+ margin: 1
33
+ },
34
+ ...props,
35
+ children: [
36
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
37
+ onClick: ()=>handleSortChange('left'),
38
+ variant: value === 'left' ? 'contained' : 'outlined',
39
+ children: "Left"
40
+ }, "left"),
41
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
42
+ onClick: ()=>handleSortChange('center'),
43
+ variant: value === 'center' ? 'contained' : 'outlined',
44
+ children: "Center"
45
+ }, "center"),
46
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
47
+ onClick: ()=>handleSortChange('right'),
48
+ variant: value === 'right' ? 'contained' : 'outlined',
49
+ children: "Right"
50
+ }, "right")
51
+ ]
52
+ });
53
+ }
@@ -0,0 +1,30 @@
1
+ // Copyright 2024 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("./AlignSelector"), 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
+ }
@@ -14,10 +14,10 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- Object.defineProperty(exports, "ThresholdColorPicker", {
17
+ Object.defineProperty(exports, "OptionsColorPicker", {
18
18
  enumerable: true,
19
19
  get: function() {
20
- return ThresholdColorPicker;
20
+ return OptionsColorPicker;
21
21
  }
22
22
  });
23
23
  const _jsxruntime = require("react/jsx-runtime");
@@ -25,13 +25,13 @@ const _react = /*#__PURE__*/ _interop_require_default(require("react"));
25
25
  const _material = require("@mui/material");
26
26
  const _Circle = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/Circle"));
27
27
  const _ChartsProvider = require("../context/ChartsProvider");
28
- const _ColorPicker = require("../ColorPicker");
28
+ const _ColorPicker = require("./ColorPicker");
29
29
  function _interop_require_default(obj) {
30
30
  return obj && obj.__esModule ? obj : {
31
31
  default: obj
32
32
  };
33
33
  }
34
- function ThresholdColorPicker({ color, onColorChange, label }) {
34
+ function OptionsColorPicker({ color, onColorChange, label }) {
35
35
  const [anchorEl, setAnchorEl] = _react.default.useState(null);
36
36
  const isOpen = Boolean(anchorEl);
37
37
  const openColorPicker = (event)=>{
@@ -45,14 +45,14 @@ function ThresholdColorPicker({ color, onColorChange, label }) {
45
45
  children: [
46
46
  /*#__PURE__*/ (0, _jsxruntime.jsx)(ColorIconButton, {
47
47
  size: "small",
48
- "aria-label": `change threshold ${label} color`,
48
+ "aria-label": `change ${label} color`,
49
49
  isSelected: isOpen,
50
50
  iconColor: color,
51
51
  onClick: openColorPicker,
52
52
  children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_Circle.default, {})
53
53
  }),
54
54
  /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Popover, {
55
- "data-testid": "threshold color picker",
55
+ "data-testid": "options color picker",
56
56
  open: isOpen,
57
57
  anchorEl: anchorEl,
58
58
  onClose: closeColorPicker,
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
17
  _export_star(require("./ColorPicker"), exports);
18
+ _export_star(require("./OptionsColorPicker"), exports);
18
19
  function _export_star(from, to) {
19
20
  Object.keys(from).forEach(function(k) {
20
21
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {