@perses-dev/components 0.0.0-snapshot-profile-89b306f → 0.0.0-snapshot-time-zone-selector-946f408
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/README.md +1 -5
- package/dist/EChart/EChart.d.ts.map +1 -1
- package/dist/EChart/EChart.js +9 -4
- package/dist/EChart/EChart.js.map +1 -1
- package/dist/TimeRangeSelector/DateTimeRangePicker.d.ts +2 -1
- package/dist/TimeRangeSelector/DateTimeRangePicker.d.ts.map +1 -1
- package/dist/TimeRangeSelector/DateTimeRangePicker.js +5 -6
- package/dist/TimeRangeSelector/DateTimeRangePicker.js.map +1 -1
- package/dist/TimeRangeSelector/TimeRangeSelector.d.ts +5 -1
- package/dist/TimeRangeSelector/TimeRangeSelector.d.ts.map +1 -1
- package/dist/TimeRangeSelector/TimeRangeSelector.js +14 -10
- package/dist/TimeRangeSelector/TimeRangeSelector.js.map +1 -1
- package/dist/TimeSeriesTooltip/index.d.ts +0 -1
- package/dist/TimeSeriesTooltip/index.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/index.js +0 -1
- package/dist/TimeSeriesTooltip/index.js.map +1 -1
- package/dist/TimeZoneSelector/TimeZoneSelector.d.ts +10 -0
- package/dist/TimeZoneSelector/TimeZoneSelector.d.ts.map +1 -0
- package/dist/TimeZoneSelector/TimeZoneSelector.js +143 -0
- package/dist/TimeZoneSelector/TimeZoneSelector.js.map +1 -0
- package/dist/TimeZoneSelector/index.d.ts +2 -0
- package/dist/TimeZoneSelector/index.d.ts.map +1 -0
- package/dist/{LineChart → TimeZoneSelector}/index.js +2 -2
- package/dist/TimeZoneSelector/index.js.map +1 -0
- package/dist/cjs/EChart/EChart.js +7 -2
- package/dist/cjs/TimeRangeSelector/DateTimeRangePicker.js +5 -6
- package/dist/cjs/TimeRangeSelector/TimeRangeSelector.js +12 -8
- package/dist/cjs/TimeSeriesTooltip/index.js +0 -1
- package/dist/cjs/TimeZoneSelector/TimeZoneSelector.js +156 -0
- package/dist/cjs/{LineChart → TimeZoneSelector}/index.js +2 -2
- package/dist/cjs/context/index.js +0 -1
- package/dist/cjs/index.js +1 -2
- package/dist/cjs/model/index.js +1 -0
- package/dist/cjs/model/timeZoneOption.js +100 -0
- package/dist/cjs/utils/axis.js +3 -18
- package/dist/cjs/utils/format.js +0 -21
- package/dist/context/index.d.ts +0 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +0 -1
- package/dist/context/index.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/model/graph.d.ts +0 -1
- package/dist/model/graph.d.ts.map +1 -1
- package/dist/model/graph.js.map +1 -1
- package/dist/model/index.d.ts +1 -0
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +1 -0
- package/dist/model/index.js.map +1 -1
- package/dist/model/timeZoneOption.d.ts +10 -0
- package/dist/model/timeZoneOption.d.ts.map +1 -0
- package/dist/model/timeZoneOption.js +79 -0
- package/dist/model/timeZoneOption.js.map +1 -0
- package/dist/utils/axis.d.ts +0 -4
- package/dist/utils/axis.d.ts.map +1 -1
- package/dist/utils/axis.js +0 -9
- package/dist/utils/axis.js.map +1 -1
- package/dist/utils/chart-actions.d.ts +0 -2
- package/dist/utils/chart-actions.d.ts.map +1 -1
- package/dist/utils/chart-actions.js.map +1 -1
- package/dist/utils/format.d.ts +0 -1
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/format.js +0 -20
- package/dist/utils/format.js.map +1 -1
- package/package.json +4 -7
- package/dist/LineChart/LineChart.d.ts +0 -22
- package/dist/LineChart/LineChart.d.ts.map +0 -1
- package/dist/LineChart/LineChart.js +0 -266
- package/dist/LineChart/LineChart.js.map +0 -1
- package/dist/LineChart/index.d.ts +0 -2
- package/dist/LineChart/index.d.ts.map +0 -1
- package/dist/LineChart/index.js.map +0 -1
- package/dist/TimeChart/TimeChart.d.ts +0 -24
- package/dist/TimeChart/TimeChart.d.ts.map +0 -1
- package/dist/TimeChart/TimeChart.js +0 -394
- package/dist/TimeChart/TimeChart.js.map +0 -1
- package/dist/TimeChart/index.d.ts +0 -2
- package/dist/TimeChart/index.d.ts.map +0 -1
- package/dist/TimeChart/index.js +0 -15
- package/dist/TimeChart/index.js.map +0 -1
- package/dist/TimeSeriesTooltip/LineChartTooltip.d.ts +0 -21
- package/dist/TimeSeriesTooltip/LineChartTooltip.d.ts.map +0 -1
- package/dist/TimeSeriesTooltip/LineChartTooltip.js +0 -101
- package/dist/TimeSeriesTooltip/LineChartTooltip.js.map +0 -1
- package/dist/cjs/LineChart/LineChart.js +0 -274
- package/dist/cjs/TimeChart/TimeChart.js +0 -407
- package/dist/cjs/TimeChart/index.js +0 -30
- package/dist/cjs/TimeSeriesTooltip/LineChartTooltip.js +0 -114
- package/dist/cjs/context/TimeZoneProvider.js +0 -98
- package/dist/context/TimeZoneProvider.d.ts +0 -13
- package/dist/context/TimeZoneProvider.d.ts.map +0 -1
- package/dist/context/TimeZoneProvider.js +0 -38
- package/dist/context/TimeZoneProvider.js.map +0 -1
package/README.md
CHANGED
|
@@ -7,9 +7,5 @@ This [package](https://www.npmjs.com/package/@perses-dev/components) includes in
|
|
|
7
7
|
To import components from the components package use the syntax below:
|
|
8
8
|
|
|
9
9
|
```typescript
|
|
10
|
-
import {
|
|
10
|
+
import { ContentWithLegend } from "@perses-dev/components";
|
|
11
11
|
```
|
|
12
|
-
|
|
13
|
-
For detailed examples of how to use certain components, see individual docs for:
|
|
14
|
-
|
|
15
|
-
- [LineChart.md](./src/LineChart/LineChart.md)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EChart.d.ts","sourceRoot":"","sources":["../../src/EChart/EChart.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAA4C,MAAM,OAAO,CAAC;AAChF,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAsB,MAAM,cAAc,CAAC;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AG,SAAS,CAAC,CAAC;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;CAClD;AAED,eAAO,MAAM,MAAM,wIAUhB,aAAa,CAAC,CAAC,8CAsFhB,CAAC"}
|
package/dist/EChart/EChart.js
CHANGED
|
@@ -16,15 +16,16 @@ import { init, connect, use } from 'echarts/core';
|
|
|
16
16
|
import { Box } from '@mui/material';
|
|
17
17
|
import isEqual from 'lodash/isEqual';
|
|
18
18
|
import debounce from 'lodash/debounce';
|
|
19
|
-
import { GaugeChart as EChartsGaugeChart, PieChart as EChartsPieChart, ScatterChart as EChartsScatterChart, CustomChart as EChartsCustomChart, HeatmapChart as EChartsHeatmapChart } from 'echarts/charts';
|
|
20
|
-
import { DatasetComponent, DataZoomComponent, LegendComponent, GridComponent, TitleComponent, TooltipComponent, VisualMapComponent } from 'echarts/components';
|
|
19
|
+
import { LineChart as EChartsLineChart, GaugeChart as EChartsGaugeChart, PieChart as EChartsPieChart, ScatterChart as EChartsScatterChart, CustomChart as EChartsCustomChart, HeatmapChart as EChartsHeatmapChart } from 'echarts/charts';
|
|
20
|
+
import { DatasetComponent, DataZoomComponent, LegendComponent, GridComponent, TitleComponent, TooltipComponent, VisualMapComponent, ToolboxComponent, MarkPointComponent, MarkAreaComponent, MarkLineComponent } from 'echarts/components';
|
|
21
21
|
import { CanvasRenderer } from 'echarts/renderers';
|
|
22
|
-
// Loading the ECharts extensions should happen in the respective
|
|
22
|
+
// Loading the ECharts extensions should happen in the respective plugins.
|
|
23
23
|
// This is a workaround for https://github.com/perses/plugins/issues/83.
|
|
24
24
|
use([
|
|
25
25
|
DatasetComponent,
|
|
26
26
|
DataZoomComponent,
|
|
27
27
|
LegendComponent,
|
|
28
|
+
EChartsLineChart,
|
|
28
29
|
EChartsGaugeChart,
|
|
29
30
|
EChartsPieChart,
|
|
30
31
|
EChartsScatterChart,
|
|
@@ -32,9 +33,13 @@ use([
|
|
|
32
33
|
EChartsHeatmapChart,
|
|
33
34
|
GridComponent,
|
|
34
35
|
TitleComponent,
|
|
36
|
+
ToolboxComponent,
|
|
35
37
|
TooltipComponent,
|
|
36
38
|
CanvasRenderer,
|
|
37
|
-
VisualMapComponent
|
|
39
|
+
VisualMapComponent,
|
|
40
|
+
MarkAreaComponent,
|
|
41
|
+
MarkLineComponent,
|
|
42
|
+
MarkPointComponent
|
|
38
43
|
]);
|
|
39
44
|
const mouseEvents = [
|
|
40
45
|
'click',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/EChart/EChart.tsx"],"sourcesContent":["// Copyright 2023 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 { CSSProperties, memo, useEffect, useLayoutEffect, useRef } from 'react';\nimport { ECharts, EChartsCoreOption, init, connect, use } from 'echarts/core';\nimport { Box, SxProps, Theme } from '@mui/material';\nimport isEqual from 'lodash/isEqual';\nimport debounce from 'lodash/debounce';\n\nimport {\n GaugeChart as EChartsGaugeChart,\n PieChart as EChartsPieChart,\n ScatterChart as EChartsScatterChart,\n CustomChart as EChartsCustomChart,\n HeatmapChart as EChartsHeatmapChart,\n} from 'echarts/charts';\nimport {\n DatasetComponent,\n DataZoomComponent,\n LegendComponent,\n GridComponent,\n TitleComponent,\n TooltipComponent,\n VisualMapComponent,\n} from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { EChartsTheme } from '../model';\n\n// Loading the ECharts extensions should happen in the respective plugin (in this case, the scatterplot + custom plugin).\n// This is a workaround for https://github.com/perses/plugins/issues/83.\nuse([\n DatasetComponent,\n DataZoomComponent,\n LegendComponent,\n EChartsGaugeChart,\n EChartsPieChart,\n EChartsScatterChart,\n EChartsCustomChart,\n EChartsHeatmapChart,\n GridComponent,\n TitleComponent,\n TooltipComponent,\n CanvasRenderer,\n VisualMapComponent,\n]);\n\n// see docs for info about each property: https://echarts.apache.org/en/api.html#events\nexport interface MouseEventsParameters<T> {\n componentType: string;\n seriesType: string;\n seriesIndex: number;\n seriesName: string;\n name: string;\n dataIndex: number;\n data: Record<string, unknown> & T;\n dataType: string;\n value: number | number[];\n color: string;\n info: Record<string, unknown>;\n}\n\ntype OnEventFunction<T> = (\n params: MouseEventsParameters<T>,\n // This is potentially undefined for testing purposes\n instance?: ECharts\n) => void;\n\nconst mouseEvents = [\n 'click',\n 'dblclick',\n 'mousedown',\n 'mousemove',\n 'mouseup',\n 'mouseover',\n 'mouseout',\n 'globalout',\n 'contextmenu',\n] as const;\n\nexport type MouseEventName = (typeof mouseEvents)[number];\n\n// batch event types\nexport interface DataZoomPayloadBatchItem {\n dataZoomId: string;\n // start and end not returned unless dataZoom is based on percentProp,\n // which is for cases when a dataZoom component controls multiple axes\n start?: number;\n end?: number;\n // startValue and endValue return data index for 'category' axes,\n // for axis types 'value' and 'time', actual values are returned\n startValue?: number;\n endValue?: number;\n}\n\nexport interface HighlightPayloadBatchItem {\n dataIndex: number;\n dataIndexInside: number;\n seriesIndex: number;\n // highlight action can effect multiple connected charts\n escapeConnect?: boolean;\n // whether blur state was triggered\n notBlur?: boolean;\n}\n\nexport interface BatchEventsParameters {\n type: BatchEventName;\n batch: DataZoomPayloadBatchItem[] & HighlightPayloadBatchItem[];\n}\n\ntype OnBatchEventFunction = (params: BatchEventsParameters) => void;\n\nconst batchEvents = ['datazoom', 'downplay', 'highlight'] as const;\n\nexport type BatchEventName = (typeof batchEvents)[number];\n\ntype ChartEventName = 'finished';\n\ntype EventName = MouseEventName | ChartEventName | BatchEventName;\n\nexport type OnEventsType<T> = {\n [mouseEventName in MouseEventName]?: OnEventFunction<T>;\n} & {\n [batchEventName in BatchEventName]?: OnBatchEventFunction;\n} & {\n [eventName in ChartEventName]?: () => void;\n};\n\nexport interface EChartsProps<T> {\n option: EChartsCoreOption;\n theme?: string | EChartsTheme;\n renderer?: 'canvas' | 'svg';\n sx?: SxProps<Theme>;\n style?: CSSProperties;\n onEvents?: OnEventsType<T>;\n _instance?: React.MutableRefObject<ECharts | undefined>;\n syncGroup?: string;\n onChartInitialized?: (instance: ECharts) => void;\n}\n\nexport const EChart = memo(function EChart<T>({\n option,\n theme,\n renderer,\n sx,\n style,\n onEvents,\n _instance,\n syncGroup,\n onChartInitialized,\n}: EChartsProps<T>) {\n const initialOption = useRef<EChartsCoreOption>(option);\n const prevOption = useRef<EChartsCoreOption>(option);\n const containerRef = useRef<HTMLDivElement | null>(null);\n const chartElement = useRef<ECharts | null>(null);\n\n // Initialize chart, dispose on unmount\n useLayoutEffect(() => {\n if (containerRef.current === null || chartElement.current !== null) return;\n chartElement.current = init(containerRef.current, theme, { renderer: renderer ?? 'canvas' });\n if (chartElement.current === undefined) return;\n chartElement.current.setOption(initialOption.current, true);\n onChartInitialized?.(chartElement.current);\n if (_instance !== undefined) {\n _instance.current = chartElement.current;\n }\n return (): void => {\n if (chartElement.current === null) return;\n chartElement.current.dispose();\n chartElement.current = null;\n };\n }, [_instance, onChartInitialized, theme, renderer]);\n\n // When syncGroup is explicitly set, charts within same group share interactions such as crosshair\n useEffect(() => {\n if (!chartElement.current || !syncGroup) return;\n chartElement.current.group = syncGroup;\n connect([chartElement.current]); // more info: https://echarts.apache.org/en/api.html#echarts.connect\n }, [syncGroup, chartElement]);\n\n // Update chart data when option changes\n useEffect(() => {\n if (prevOption.current === undefined || isEqual(prevOption.current, option)) return;\n if (!chartElement.current) return;\n chartElement.current.setOption(option, true);\n prevOption.current = option;\n }, [option]);\n\n // Resize chart, cleanup listener on unmount\n useLayoutEffect(() => {\n const updateSize = debounce(() => {\n if (!chartElement.current) return;\n chartElement.current.resize();\n }, 200);\n window.addEventListener('resize', updateSize);\n updateSize();\n return (): void => {\n window.removeEventListener('resize', updateSize);\n };\n }, []);\n\n // Bind and unbind chart events passed as prop\n useEffect(() => {\n const chart = chartElement.current;\n if (!chart || onEvents === undefined) return;\n bindEvents(chart, onEvents);\n return (): void => {\n if (chart === undefined) return;\n if (chart.isDisposed() === true) return;\n for (const event in onEvents) {\n chart.off(event);\n }\n };\n }, [onEvents]);\n\n // TODO: re-evaluate how this is triggered. It's technically working right\n // now because the sx prop is an object that gets re-created, but that also\n // means it runs unnecessarily some of the time and theoretically might\n // not run in some other cases. Maybe it should use a resize observer?\n useEffect(() => {\n // TODO: fix this debouncing. This likely isn't working as intended because\n // the debounced function is re-created every time this useEffect is called.\n const updateSize = debounce(\n () => {\n if (!chartElement.current) return;\n chartElement.current.resize();\n },\n 200,\n {\n leading: true,\n }\n );\n updateSize();\n }, [sx, style]);\n\n return <Box ref={containerRef} sx={sx} style={style}></Box>;\n});\n\n// Validate event config and bind custom events\nfunction bindEvents<T>(instance: ECharts, events?: OnEventsType<T>): void {\n if (events === undefined) return;\n\n function bindEvent(eventName: EventName, OnEventFunction: unknown): void {\n if (typeof OnEventFunction === 'function') {\n if (isMouseEvent(eventName)) {\n instance.on(eventName, (params) => OnEventFunction(params, instance));\n } else if (isBatchEvent(eventName)) {\n instance.on(eventName, (params) => OnEventFunction(params));\n } else {\n instance.on(eventName, () => OnEventFunction(null, instance));\n }\n }\n }\n\n for (const eventName in events) {\n if (Object.prototype.hasOwnProperty.call(events, eventName)) {\n const customEvent = events[eventName as EventName] ?? null;\n if (customEvent) {\n bindEvent(eventName as EventName, customEvent);\n }\n }\n }\n}\n\nfunction isMouseEvent(eventName: EventName): eventName is MouseEventName {\n return (mouseEvents as readonly string[]).includes(eventName);\n}\n\nfunction isBatchEvent(eventName: EventName): eventName is BatchEventName {\n return (batchEvents as readonly string[]).includes(eventName);\n}\n"],"names":["memo","useEffect","useLayoutEffect","useRef","init","connect","use","Box","isEqual","debounce","GaugeChart","EChartsGaugeChart","PieChart","EChartsPieChart","ScatterChart","EChartsScatterChart","CustomChart","EChartsCustomChart","HeatmapChart","EChartsHeatmapChart","DatasetComponent","DataZoomComponent","LegendComponent","GridComponent","TitleComponent","TooltipComponent","VisualMapComponent","CanvasRenderer","mouseEvents","batchEvents","EChart","option","theme","renderer","sx","style","onEvents","_instance","syncGroup","onChartInitialized","initialOption","prevOption","containerRef","chartElement","current","undefined","setOption","dispose","group","updateSize","resize","window","addEventListener","removeEventListener","chart","bindEvents","isDisposed","event","off","leading","ref","instance","events","bindEvent","eventName","OnEventFunction","isMouseEvent","on","params","isBatchEvent","Object","prototype","hasOwnProperty","call","customEvent","includes"],"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,SAAwBA,IAAI,EAAEC,SAAS,EAAEC,eAAe,EAAEC,MAAM,QAAQ,QAAQ;AAChF,SAAqCC,IAAI,EAAEC,OAAO,EAAEC,GAAG,QAAQ,eAAe;AAC9E,SAASC,GAAG,QAAwB,gBAAgB;AACpD,OAAOC,aAAa,iBAAiB;AACrC,OAAOC,cAAc,kBAAkB;AAEvC,SACEC,cAAcC,iBAAiB,EAC/BC,YAAYC,eAAe,EAC3BC,gBAAgBC,mBAAmB,EACnCC,eAAeC,kBAAkB,EACjCC,gBAAgBC,mBAAmB,QAC9B,iBAAiB;AACxB,SACEC,gBAAgB,EAChBC,iBAAiB,EACjBC,eAAe,EACfC,aAAa,EACbC,cAAc,EACdC,gBAAgB,EAChBC,kBAAkB,QACb,qBAAqB;AAC5B,SAASC,cAAc,QAAQ,oBAAoB;AAGnD,yHAAyH;AACzH,wEAAwE;AACxErB,IAAI;IACFc;IACAC;IACAC;IACAX;IACAE;IACAE;IACAE;IACAE;IACAI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oB,EAAEC,eAAwB;QAC/D,IAAI,OAAOA,oBAAoB,YAAY;YACzC,IAAIC,aAAaF,YAAY;gBAC3BH,SAASM,EAAE,CAACH,WAAW,CAACI,SAAWH,gBAAgBG,QAAQP;YAC7D,OAAO,IAAIQ,aAAaL,YAAY;gBAClCH,SAASM,EAAE,CAACH,WAAW,CAACI,SAAWH,gBAAgBG;YACrD,OAAO;gBACLP,SAASM,EAAE,CAACH,WAAW,IAAMC,gBAAgB,MAAMJ;YACrD;QACF;IACF;IAEA,IAAK,MAAMG,aAAaF,OAAQ;QAC9B,IAAIQ,OAAOC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACX,QAAQE,YAAY;YAC3D,MAAMU,cAAcZ,MAAM,CAACE,UAAuB,IAAI;YACtD,IAAIU,aAAa;gBACfX,UAAUC,WAAwBU;YACpC;QACF;IACF;AACF;AAEA,SAASR,aAAaF,SAAoB;IACxC,OAAO,AAACpC,YAAkC+C,QAAQ,CAACX;AACrD;AAEA,SAASK,aAAaL,SAAoB;IACxC,OAAO,AAACnC,YAAkC8C,QAAQ,CAACX;AACrD"}
|
|
1
|
+
{"version":3,"sources":["../../src/EChart/EChart.tsx"],"sourcesContent":["// Copyright 2023 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 { CSSProperties, memo, useEffect, useLayoutEffect, useRef } from 'react';\nimport { ECharts, EChartsCoreOption, init, connect, use } from 'echarts/core';\nimport { Box, SxProps, Theme } from '@mui/material';\nimport isEqual from 'lodash/isEqual';\nimport debounce from 'lodash/debounce';\n\nimport {\n LineChart as EChartsLineChart,\n GaugeChart as EChartsGaugeChart,\n PieChart as EChartsPieChart,\n ScatterChart as EChartsScatterChart,\n CustomChart as EChartsCustomChart,\n HeatmapChart as EChartsHeatmapChart,\n} from 'echarts/charts';\nimport {\n DatasetComponent,\n DataZoomComponent,\n LegendComponent,\n GridComponent,\n TitleComponent,\n TooltipComponent,\n VisualMapComponent,\n ToolboxComponent,\n MarkPointComponent,\n MarkAreaComponent,\n MarkLineComponent,\n} from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { EChartsTheme } from '../model';\n\n// Loading the ECharts extensions should happen in the respective plugins.\n// This is a workaround for https://github.com/perses/plugins/issues/83.\nuse([\n DatasetComponent,\n DataZoomComponent,\n LegendComponent,\n EChartsLineChart,\n EChartsGaugeChart,\n EChartsPieChart,\n EChartsScatterChart,\n EChartsCustomChart,\n EChartsHeatmapChart,\n GridComponent,\n TitleComponent,\n ToolboxComponent,\n TooltipComponent,\n CanvasRenderer,\n VisualMapComponent,\n MarkAreaComponent,\n MarkLineComponent,\n MarkPointComponent,\n]);\n\n// see docs for info about each property: https://echarts.apache.org/en/api.html#events\nexport interface MouseEventsParameters<T> {\n componentType: string;\n seriesType: string;\n seriesIndex: number;\n seriesName: string;\n name: string;\n dataIndex: number;\n data: Record<string, unknown> & T;\n dataType: string;\n value: number | number[];\n color: string;\n info: Record<string, unknown>;\n}\n\ntype OnEventFunction<T> = (\n params: MouseEventsParameters<T>,\n // This is potentially undefined for testing purposes\n instance?: ECharts\n) => void;\n\nconst mouseEvents = [\n 'click',\n 'dblclick',\n 'mousedown',\n 'mousemove',\n 'mouseup',\n 'mouseover',\n 'mouseout',\n 'globalout',\n 'contextmenu',\n] as const;\n\nexport type MouseEventName = (typeof mouseEvents)[number];\n\n// batch event types\nexport interface DataZoomPayloadBatchItem {\n dataZoomId: string;\n // start and end not returned unless dataZoom is based on percentProp,\n // which is for cases when a dataZoom component controls multiple axes\n start?: number;\n end?: number;\n // startValue and endValue return data index for 'category' axes,\n // for axis types 'value' and 'time', actual values are returned\n startValue?: number;\n endValue?: number;\n}\n\nexport interface HighlightPayloadBatchItem {\n dataIndex: number;\n dataIndexInside: number;\n seriesIndex: number;\n // highlight action can effect multiple connected charts\n escapeConnect?: boolean;\n // whether blur state was triggered\n notBlur?: boolean;\n}\n\nexport interface BatchEventsParameters {\n type: BatchEventName;\n batch: DataZoomPayloadBatchItem[] & HighlightPayloadBatchItem[];\n}\n\ntype OnBatchEventFunction = (params: BatchEventsParameters) => void;\n\nconst batchEvents = ['datazoom', 'downplay', 'highlight'] as const;\n\nexport type BatchEventName = (typeof batchEvents)[number];\n\ntype ChartEventName = 'finished';\n\ntype EventName = MouseEventName | ChartEventName | BatchEventName;\n\nexport type OnEventsType<T> = {\n [mouseEventName in MouseEventName]?: OnEventFunction<T>;\n} & {\n [batchEventName in BatchEventName]?: OnBatchEventFunction;\n} & {\n [eventName in ChartEventName]?: () => void;\n};\n\nexport interface EChartsProps<T> {\n option: EChartsCoreOption;\n theme?: string | EChartsTheme;\n renderer?: 'canvas' | 'svg';\n sx?: SxProps<Theme>;\n style?: CSSProperties;\n onEvents?: OnEventsType<T>;\n _instance?: React.MutableRefObject<ECharts | undefined>;\n syncGroup?: string;\n onChartInitialized?: (instance: ECharts) => void;\n}\n\nexport const EChart = memo(function EChart<T>({\n option,\n theme,\n renderer,\n sx,\n style,\n onEvents,\n _instance,\n syncGroup,\n onChartInitialized,\n}: EChartsProps<T>) {\n const initialOption = useRef<EChartsCoreOption>(option);\n const prevOption = useRef<EChartsCoreOption>(option);\n const containerRef = useRef<HTMLDivElement | null>(null);\n const chartElement = useRef<ECharts | null>(null);\n\n // Initialize chart, dispose on unmount\n useLayoutEffect(() => {\n if (containerRef.current === null || chartElement.current !== null) return;\n chartElement.current = init(containerRef.current, theme, { renderer: renderer ?? 'canvas' });\n if (chartElement.current === undefined) return;\n chartElement.current.setOption(initialOption.current, true);\n onChartInitialized?.(chartElement.current);\n if (_instance !== undefined) {\n _instance.current = chartElement.current;\n }\n return (): void => {\n if (chartElement.current === null) return;\n chartElement.current.dispose();\n chartElement.current = null;\n };\n }, [_instance, onChartInitialized, theme, renderer]);\n\n // When syncGroup is explicitly set, charts within same group share interactions such as crosshair\n useEffect(() => {\n if (!chartElement.current || !syncGroup) return;\n chartElement.current.group = syncGroup;\n connect([chartElement.current]); // more info: https://echarts.apache.org/en/api.html#echarts.connect\n }, [syncGroup, chartElement]);\n\n // Update chart data when option changes\n useEffect(() => {\n if (prevOption.current === undefined || isEqual(prevOption.current, option)) return;\n if (!chartElement.current) return;\n chartElement.current.setOption(option, true);\n prevOption.current = option;\n }, [option]);\n\n // Resize chart, cleanup listener on unmount\n useLayoutEffect(() => {\n const updateSize = debounce(() => {\n if (!chartElement.current) return;\n chartElement.current.resize();\n }, 200);\n window.addEventListener('resize', updateSize);\n updateSize();\n return (): void => {\n window.removeEventListener('resize', updateSize);\n };\n }, []);\n\n // Bind and unbind chart events passed as prop\n useEffect(() => {\n const chart = chartElement.current;\n if (!chart || onEvents === undefined) return;\n bindEvents(chart, onEvents);\n return (): void => {\n if (chart === undefined) return;\n if (chart.isDisposed() === true) return;\n for (const event in onEvents) {\n chart.off(event);\n }\n };\n }, [onEvents]);\n\n // TODO: re-evaluate how this is triggered. It's technically working right\n // now because the sx prop is an object that gets re-created, but that also\n // means it runs unnecessarily some of the time and theoretically might\n // not run in some other cases. Maybe it should use a resize observer?\n useEffect(() => {\n // TODO: fix this debouncing. This likely isn't working as intended because\n // the debounced function is re-created every time this useEffect is called.\n const updateSize = debounce(\n () => {\n if (!chartElement.current) return;\n chartElement.current.resize();\n },\n 200,\n {\n leading: true,\n }\n );\n updateSize();\n }, [sx, style]);\n\n return <Box ref={containerRef} sx={sx} style={style}></Box>;\n});\n\n// Validate event config and bind custom events\nfunction bindEvents<T>(instance: ECharts, events?: OnEventsType<T>): void {\n if (events === undefined) return;\n\n function bindEvent(eventName: EventName, OnEventFunction: unknown): void {\n if (typeof OnEventFunction === 'function') {\n if (isMouseEvent(eventName)) {\n instance.on(eventName, (params) => OnEventFunction(params, instance));\n } else if (isBatchEvent(eventName)) {\n instance.on(eventName, (params) => OnEventFunction(params));\n } else {\n instance.on(eventName, () => OnEventFunction(null, instance));\n }\n }\n }\n\n for (const eventName in events) {\n if (Object.prototype.hasOwnProperty.call(events, eventName)) {\n const customEvent = events[eventName as EventName] ?? null;\n if (customEvent) {\n bindEvent(eventName as EventName, customEvent);\n }\n }\n }\n}\n\nfunction isMouseEvent(eventName: EventName): eventName is MouseEventName {\n return (mouseEvents as readonly string[]).includes(eventName);\n}\n\nfunction isBatchEvent(eventName: EventName): eventName is BatchEventName {\n return (batchEvents as readonly string[]).includes(eventName);\n}\n"],"names":["memo","useEffect","useLayoutEffect","useRef","init","connect","use","Box","isEqual","debounce","LineChart","EChartsLineChart","GaugeChart","EChartsGaugeChart","PieChart","EChartsPieChart","ScatterChart","EChartsScatterChart","CustomChart","EChartsCustomChart","HeatmapChart","EChartsHeatmapChart","DatasetComponent","DataZoomComponent","LegendComponent","GridComponent","TitleComponent","TooltipComponent","VisualMapComponent","ToolboxComponent","MarkPointComponent","MarkAreaComponent","MarkLineComponent","CanvasRenderer","mouseEvents","batchEvents","EChart","option","theme","renderer","sx","style","onEvents","_instance","syncGroup","onChartInitialized","initialOption","prevOption","containerRef","chartElement","current","undefined","setOption","dispose","group","updateSize","resize","window","addEventListener","removeEventListener","chart","bindEvents","isDisposed","event","off","leading","ref","instance","events","bindEvent","eventName","OnEventFunction","isMouseEvent","on","params","isBatchEvent","Object","prototype","hasOwnProperty","call","customEvent","includes"],"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,SAAwBA,IAAI,EAAEC,SAAS,EAAEC,eAAe,EAAEC,MAAM,QAAQ,QAAQ;AAChF,SAAqCC,IAAI,EAAEC,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ACX;AACrD;AAEA,SAASK,aAAaL,SAAoB;IACxC,OAAO,AAACnC,YAAkC8C,QAAQ,CAACX;AACrD"}
|
|
@@ -4,6 +4,7 @@ interface AbsoluteTimeFormProps {
|
|
|
4
4
|
initialTimeRange: AbsoluteTimeRange;
|
|
5
5
|
onChange: (timeRange: AbsoluteTimeRange) => void;
|
|
6
6
|
onCancel: () => void;
|
|
7
|
+
timeZone: string;
|
|
7
8
|
}
|
|
8
9
|
/**
|
|
9
10
|
* Start and End datetime picker, allowing use to select a specific time range selecting two absolute dates and times.
|
|
@@ -14,6 +15,6 @@ interface AbsoluteTimeFormProps {
|
|
|
14
15
|
* @param onCancel event received when user click on cancel
|
|
15
16
|
* @constructor
|
|
16
17
|
*/
|
|
17
|
-
export declare const DateTimeRangePicker: ({ initialTimeRange, onChange, onCancel }: AbsoluteTimeFormProps) => ReactElement;
|
|
18
|
+
export declare const DateTimeRangePicker: ({ initialTimeRange, onChange, onCancel, timeZone, }: AbsoluteTimeFormProps) => ReactElement;
|
|
18
19
|
export {};
|
|
19
20
|
//# sourceMappingURL=DateTimeRangePicker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateTimeRangePicker.d.ts","sourceRoot":"","sources":["../../src/TimeRangeSelector/DateTimeRangePicker.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAY,MAAM,OAAO,CAAC;AAI/C,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;
|
|
1
|
+
{"version":3,"file":"DateTimeRangePicker.d.ts","sourceRoot":"","sources":["../../src/TimeRangeSelector/DateTimeRangePicker.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAY,MAAM,OAAO,CAAC;AAI/C,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;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAMD;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,wDAK7B,qBAAqB,KAAG,YAwK1B,CAAC"}
|
|
@@ -15,9 +15,9 @@ import { useState } from 'react';
|
|
|
15
15
|
import { Box, Stack, Typography, Button } from '@mui/material';
|
|
16
16
|
import { DateTimeField, LocalizationProvider, StaticDateTimePicker } from '@mui/x-date-pickers';
|
|
17
17
|
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFnsV3';
|
|
18
|
-
import { useTimeZone } from '../context';
|
|
19
18
|
import { ErrorBoundary } from '../ErrorBoundary';
|
|
20
19
|
import { ErrorAlert } from '../ErrorAlert';
|
|
20
|
+
import { formatWithTimeZone } from '../utils/format';
|
|
21
21
|
import { DATE_TIME_FORMAT, validateDateRange } from './utils';
|
|
22
22
|
/**
|
|
23
23
|
* Start and End datetime picker, allowing use to select a specific time range selecting two absolute dates and times.
|
|
@@ -27,20 +27,19 @@ import { DATE_TIME_FORMAT, validateDateRange } from './utils';
|
|
|
27
27
|
* @param onChange event received when start and end has been selected (click on apply)
|
|
28
28
|
* @param onCancel event received when user click on cancel
|
|
29
29
|
* @constructor
|
|
30
|
-
*/ export const DateTimeRangePicker = ({ initialTimeRange, onChange, onCancel })=>{
|
|
31
|
-
const { formatWithUserTimeZone } = useTimeZone();
|
|
30
|
+
*/ export const DateTimeRangePicker = ({ initialTimeRange, onChange, onCancel, timeZone })=>{
|
|
32
31
|
// Time range values as dates that can be used as a time range.
|
|
33
32
|
const [timeRange, setTimeRange] = useState(initialTimeRange);
|
|
34
33
|
// Time range values as strings used to populate the text inputs. May not
|
|
35
34
|
// be valid as dates when the user is typing.
|
|
36
35
|
const [timeRangeInputs, setTimeRangeInputs] = useState({
|
|
37
|
-
start:
|
|
38
|
-
end:
|
|
36
|
+
start: formatWithTimeZone(initialTimeRange.start, DATE_TIME_FORMAT, timeZone),
|
|
37
|
+
end: formatWithTimeZone(initialTimeRange.end, DATE_TIME_FORMAT, timeZone)
|
|
39
38
|
});
|
|
40
39
|
const [showStartCalendar, setShowStartCalendar] = useState(true);
|
|
41
40
|
const changeTimeRange = (newTime, segment)=>{
|
|
42
41
|
const isInputChange = typeof newTime === 'string';
|
|
43
|
-
const newInputTime = isInputChange ? newTime :
|
|
42
|
+
const newInputTime = isInputChange ? newTime : formatWithTimeZone(newTime, DATE_TIME_FORMAT, timeZone);
|
|
44
43
|
setTimeRangeInputs((prevTimeRangeInputs)=>{
|
|
45
44
|
return {
|
|
46
45
|
...prevTimeRangeInputs,
|
|
@@ -1 +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 { ReactElement, 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/AdapterDateFnsV3';\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): ReactElement => {\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): void => {\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): void => {\n changeTimeRange(newStartTime, 'start');\n };\n\n const onChangeEndTime = (newEndTime: string | Date): void => {\n changeTimeRange(newEndTime, 'end');\n };\n\n const updateDateRange = (): { start: Date; end: Date } | undefined => {\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 = (): void => {\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 value={new Date(timeRangeInputs.start)}\n onChange={(event: Date | 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 value={new Date(timeRangeInputs.end)}\n onChange={(event: Date | 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":"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AAM7B;4BAAW8B,SAAS;sCAAC;;sCAGhE,KAACpE;4BAAOgD,SAAQ;4BAAWmB,SAAS,IAAMtD;4BAAYuD,SAAS;sCAAC;;;;;;;AAO1E,EAAE"}
|
|
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 { ReactElement, 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/AdapterDateFnsV3';\nimport { AbsoluteTimeRange } from '@perses-dev/core';\nimport { ErrorBoundary } from '../ErrorBoundary';\nimport { ErrorAlert } from '../ErrorAlert';\nimport { formatWithTimeZone } from '../utils/format';\nimport { DATE_TIME_FORMAT, validateDateRange } from './utils';\n\ninterface AbsoluteTimeFormProps {\n initialTimeRange: AbsoluteTimeRange;\n onChange: (timeRange: AbsoluteTimeRange) => void;\n onCancel: () => void;\n timeZone: string;\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 = ({\n initialTimeRange,\n onChange,\n onCancel,\n timeZone,\n}: AbsoluteTimeFormProps): ReactElement => {\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: formatWithTimeZone(initialTimeRange.start, DATE_TIME_FORMAT, timeZone),\n end: formatWithTimeZone(initialTimeRange.end, DATE_TIME_FORMAT, timeZone),\n });\n\n const [showStartCalendar, setShowStartCalendar] = useState<boolean>(true);\n\n const changeTimeRange = (newTime: string | Date, segment: keyof AbsoluteTimeRange): void => {\n const isInputChange = typeof newTime === 'string';\n const newInputTime = isInputChange ? newTime : formatWithTimeZone(newTime, DATE_TIME_FORMAT, timeZone);\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): void => {\n changeTimeRange(newStartTime, 'start');\n };\n\n const onChangeEndTime = (newEndTime: string | Date): void => {\n changeTimeRange(newEndTime, 'end');\n };\n\n const updateDateRange = (): { start: Date; end: Date } | undefined => {\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 = (): void => {\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 value={new Date(timeRangeInputs.start)}\n onChange={(event: Date | 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 value={new Date(timeRangeInputs.end)}\n onChange={(event: Date | 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","ErrorBoundary","ErrorAlert","formatWithTimeZone","DATE_TIME_FORMAT","validateDateRange","DateTimeRangePicker","initialTimeRange","onChange","onCancel","timeZone","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,SAAuBA,QAAQ,QAAQ,QAAQ;AAC/C,SAASC,GAAG,EAAEC,KAAK,EAAEC,UAAU,EAAEC,MAAM,QAAQ,gBAAgB;AAC/D,SAASC,aAAa,EAAEC,oBAAoB,EAAEC,oBAAoB,QAAQ,sBAAsB;AAChG,SAASC,cAAc,QAAQ,uCAAuC;AAEtE,SAASC,aAAa,QAAQ,mBAAmB;AACjD,SAASC,UAAU,QAAQ,gBAAgB;AA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aAAa,MAAM;gCACvBhC,qBAAqB;gCACrBU,gBAAgBsB;4BAClB;;;;8BAIN,MAACxD;oBAAM2D,WAAU;oBAAMC,YAAW;oBAASC,KAAK;oBAAGC,IAAI;oBAAGC,IAAI;;sCAC5D,KAACxD;4BAAcyD,mBAAmBxD;sCAChC,cAAA,KAACL;gCACC8D,OAAM;gCACNV,OAAO,IAAIjB,KAAKnB,gBAAgBE,KAAK;gCACrCP,UAAU,CAACoD;oCACT,IAAIA,OAAO;wCACTlC,kBAAkBkC;oCACpB;gCACF;gCACAC,QAAQ,IAAM/B;gCACdgC,QAAQ1D;;;sCAGZ,KAACH;4BAAcyD,mBAAmBxD;sCAChC,cAAA,KAACL;gCACC8D,OAAM;gCACNV,OAAO,IAAIjB,KAAKnB,gBAAgBG,GAAG;gCACnCR,UAAU,CAACoD;oCACT,IAAIA,OAAO;wCACThC,gBAAgBgC;oCAClB;gCACF;gCACAC,QAAQ,IAAM/B;gCACdgC,QAAQ1D;;;;;8BAId,MAACV;oBAAM2D,WAAU;oBAAMhB,IAAI;wBAAEE,SAAS,CAACD,QAAUA,MAAMF,OAAO,CAAC,GAAG;oBAAG;oBAAGmB,KAAK;;sCAC3E,KAAC3D;4BAAOgD,SAAQ;4BAAYmB,SAAS,IAAM7B;4BAAW8B,SAAS;sCAAC;;sCAGhE,KAACpE;4BAAOgD,SAAQ;4BAAWmB,SAAS,IAAMtD;4BAAYuD,SAAS;sCAAC;;;;;;;AAO1E,EAAE"}
|
|
@@ -24,6 +24,10 @@ interface TimeRangeSelectorProps {
|
|
|
24
24
|
* Defaults to true.
|
|
25
25
|
*/
|
|
26
26
|
showCustomTimeRange?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The time zone to use for the time range selector.
|
|
29
|
+
*/
|
|
30
|
+
timeZone?: string;
|
|
27
31
|
}
|
|
28
32
|
/**
|
|
29
33
|
* Date & time selection component to customize what data renders on dashboard.
|
|
@@ -31,6 +35,6 @@ interface TimeRangeSelectorProps {
|
|
|
31
35
|
* @param props
|
|
32
36
|
* @constructor
|
|
33
37
|
*/
|
|
34
|
-
export declare function TimeRangeSelector({ value, timeOptions, onChange, height, showCustomTimeRange, }: TimeRangeSelectorProps): ReactElement;
|
|
38
|
+
export declare function TimeRangeSelector({ value, timeOptions, onChange, height, showCustomTimeRange, timeZone, }: TimeRangeSelectorProps): ReactElement;
|
|
35
39
|
export {};
|
|
36
40
|
//# sourceMappingURL=TimeRangeSelector.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimeRangeSelector.d.ts","sourceRoot":"","sources":["../../src/TimeRangeSelector/TimeRangeSelector.tsx"],"names":[],"mappings":"AAeA,OAAO,
|
|
1
|
+
{"version":3,"file":"TimeRangeSelector.d.ts","sourceRoot":"","sources":["../../src/TimeRangeSelector/TimeRangeSelector.tsx"],"names":[],"mappings":"AAeA,OAAO,EACL,cAAc,EAKf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,YAAY,EAA6B,MAAM,OAAO,CAAC;AAChE,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;IAC9B;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,KAAK,EACL,WAAW,EACX,QAAQ,EACR,MAAM,EACN,mBAA0B,EAC1B,QAAqC,GACtC,EAAE,sBAAsB,GAAG,YAAY,CAyGvC"}
|
|
@@ -11,11 +11,10 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
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
|
|
16
|
-
import { isRelativeTimeRange, toAbsoluteTimeRange } from '@perses-dev/core';
|
|
14
|
+
import { Box, MenuItem, Popover, Select, useMediaQuery, useTheme } from '@mui/material';
|
|
15
|
+
import ClockTimeFiveOutline from 'mdi-material-ui/ClockTimeFiveOutline';
|
|
16
|
+
import { isRelativeTimeRange, toAbsoluteTimeRange, DEFAULT_DASHBOARD_TIMEZONE } from '@perses-dev/core';
|
|
17
17
|
import { useMemo, useRef, useState } from 'react';
|
|
18
|
-
import { useTimeZone } from '../context';
|
|
19
18
|
import { DateTimeRangePicker } from './DateTimeRangePicker';
|
|
20
19
|
import { buildCustomTimeOption, formatTimeRange } from './utils';
|
|
21
20
|
/**
|
|
@@ -23,8 +22,8 @@ import { buildCustomTimeOption, formatTimeRange } from './utils';
|
|
|
23
22
|
* This includes relative shortcuts and the ability to pick absolute start and end times.
|
|
24
23
|
* @param props
|
|
25
24
|
* @constructor
|
|
26
|
-
*/ export function TimeRangeSelector({ value, timeOptions, onChange, height, showCustomTimeRange = true }) {
|
|
27
|
-
const
|
|
25
|
+
*/ export function TimeRangeSelector({ value, timeOptions, onChange, height, showCustomTimeRange = true, timeZone = DEFAULT_DASHBOARD_TIMEZONE }) {
|
|
26
|
+
const isMobile = useMediaQuery(useTheme().breakpoints.down('md'));
|
|
28
27
|
const anchorEl = useRef(); // Used to position the absolute time range picker
|
|
29
28
|
// Control the open state of the absolute time range picker
|
|
30
29
|
const [showCustomDateSelector, setShowCustomDateSelector] = useState(false);
|
|
@@ -68,7 +67,8 @@ import { buildCustomTimeOption, formatTimeRange } from './utils';
|
|
|
68
67
|
setShowCustomDateSelector(false);
|
|
69
68
|
setOpen(false);
|
|
70
69
|
},
|
|
71
|
-
onCancel: ()=>setShowCustomDateSelector(false)
|
|
70
|
+
onCancel: ()=>setShowCustomDateSelector(false),
|
|
71
|
+
timeZone: timeZone
|
|
72
72
|
})
|
|
73
73
|
}),
|
|
74
74
|
/*#__PURE__*/ _jsx(Box, {
|
|
@@ -77,18 +77,22 @@ import { buildCustomTimeOption, formatTimeRange } from './utils';
|
|
|
77
77
|
open: open,
|
|
78
78
|
value: formatTimeRange(value, timeZone),
|
|
79
79
|
onClick: ()=>setOpen(!open),
|
|
80
|
-
IconComponent:
|
|
80
|
+
IconComponent: ClockTimeFiveOutline,
|
|
81
81
|
inputProps: {
|
|
82
82
|
'aria-label': `Select time range. Currently set to ${value}`
|
|
83
83
|
},
|
|
84
84
|
sx: {
|
|
85
85
|
// `transform: none` prevents calendar icon from flipping over when menu is open
|
|
86
86
|
'.MuiSelect-icon': {
|
|
87
|
-
marginTop: '1px',
|
|
88
87
|
transform: 'none'
|
|
89
88
|
},
|
|
90
89
|
// paddingRight creates more space for the calendar icon (it's a bigger icon)
|
|
91
|
-
'.MuiSelect-select.MuiSelect-outlined.MuiInputBase-input': {
|
|
90
|
+
'.MuiSelect-select.MuiSelect-outlined.MuiInputBase-input': isMobile ? {
|
|
91
|
+
paddingRight: '25px',
|
|
92
|
+
textIndent: '-9999px',
|
|
93
|
+
whiteSpace: 'nowrap',
|
|
94
|
+
overflow: 'hidden'
|
|
95
|
+
} : {
|
|
92
96
|
paddingRight: '36px'
|
|
93
97
|
},
|
|
94
98
|
'.MuiSelect-select': height ? {
|
|
@@ -1 +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
|
|
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, useMediaQuery, useTheme } from '@mui/material';\nimport ClockTimeFiveOutline from 'mdi-material-ui/ClockTimeFiveOutline';\nimport {\n TimeRangeValue,\n isRelativeTimeRange,\n AbsoluteTimeRange,\n toAbsoluteTimeRange,\n DEFAULT_DASHBOARD_TIMEZONE,\n} from '@perses-dev/core';\nimport { ReactElement, useMemo, useRef, useState } from 'react';\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 two options as a zoom out x2 and 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 * The time zone to use for the time range selector.\n */\n timeZone?: string;\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 timeZone = DEFAULT_DASHBOARD_TIMEZONE,\n}: TimeRangeSelectorProps): ReactElement {\n const isMobile = useMediaQuery(useTheme().breakpoints.down('md'));\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 timeZone={timeZone}\n />\n </Popover>\n <Box ref={anchorEl}>\n <Select\n open={open}\n value={formatTimeRange(value, timeZone)}\n onClick={() => setOpen(!open)}\n IconComponent={ClockTimeFiveOutline}\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 transform: 'none',\n },\n // paddingRight creates more space for the calendar icon (it's a bigger icon)\n '.MuiSelect-select.MuiSelect-outlined.MuiInputBase-input': isMobile\n ? {\n paddingRight: '25px',\n textIndent: '-9999px', // Hide text by moving it far off screen\n whiteSpace: 'nowrap', // Prevent text from wrapping\n overflow: 'hidden', // Hide any overflow\n }\n : {\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","useMediaQuery","useTheme","ClockTimeFiveOutline","isRelativeTimeRange","toAbsoluteTimeRange","DEFAULT_DASHBOARD_TIMEZONE","useMemo","useRef","useState","DateTimeRangePicker","buildCustomTimeOption","formatTimeRange","TimeRangeSelector","value","timeOptions","onChange","height","showCustomTimeRange","timeZone","isMobile","breakpoints","down","anchorEl","showCustomDateSelector","setShowCustomDateSelector","convertedTimeRange","lastOption","undefined","open","setOpen","current","anchorOrigin","vertical","horizontal","onClose","sx","theme","padding","spacing","initialTimeRange","onCancel","ref","onClick","IconComponent","inputProps","transform","paddingRight","textIndent","whiteSpace","overflow","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,EAAEC,aAAa,EAAEC,QAAQ,QAAQ,gBA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;wBACTE,SAASF;wBACTW,0BAA0B;wBAC1BK,QAAQ;oBACV;oBACAW,UAAU,IAAMhB,0BAA0B;oBAC1CN,UAAUA;;;0BAGd,KAACtB;gBAAI6C,KAAKnB;0BACR,cAAA,MAACvB;oBACC6B,MAAMA;oBACNf,OAAOF,gBAAgBE,OAAOK;oBAC9BwB,SAAS,IAAMb,QAAQ,CAACD;oBACxBe,eAAezC;oBACf0C,YAAY;wBACV,cAAc,CAAC,oCAAoC,EAAE/B,OAAO;oBAC9D;oBACAsB,IAAI;wBACF,gFAAgF;wBAChF,mBAAmB;4BACjBU,WAAW;wBACb;wBACA,6EAA6E;wBAC7E,2DAA2D1B,WACvD;4BACE2B,cAAc;4BACdC,YAAY;4BACZC,YAAY;4BACZC,UAAU;wBACZ,IACA;4BACEH,cAAc;wBAChB;wBACJ,qBAAqB9B,SAAS;4BAAEkC,YAAYlC;4BAAQmC,UAAU;wBAAE,IAAI,CAAC;oBACvE;;wBAECrC,YAAYsC,GAAG,CAAC,CAACC,MAAMC,oBACtB,KAACzD;gCAECgB,OAAOF,gBAAgB0C,KAAKxC,KAAK,EAAEK;gCACnCwB,SAAS;oCACP3B,SAASsC,KAAKxC,KAAK;gCACrB;0CAECwC,KAAKE,OAAO;+BANRD;wBASRrC,qCACC,KAACpB;4BACCgB,OAAOF,gBAAgBe,WAAWb,KAAK,EAAEK;4BACzCwB,SAAS,IAAMlB,0BAA0B;sCAExCE,WAAW6B,OAAO;;;;;;;AAOjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/index.ts"],"names":[],"mappings":"AAaA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/index.ts"],"names":[],"mappings":"AAaA,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC"}
|
|
@@ -10,7 +10,6 @@
|
|
|
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 './LineChartTooltip';
|
|
14
13
|
export * from './SeriesInfo';
|
|
15
14
|
export * from './SeriesLabelsStack';
|
|
16
15
|
export * from './SeriesMarker';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/TimeSeriesTooltip/index.ts"],"sourcesContent":["// Copyright 2023 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 './
|
|
1
|
+
{"version":3,"sources":["../../src/TimeSeriesTooltip/index.ts"],"sourcesContent":["// Copyright 2023 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 './SeriesInfo';\nexport * from './SeriesLabelsStack';\nexport * from './SeriesMarker';\nexport * from './TimeChartTooltip';\nexport * from './TooltipContent';\nexport * from './TooltipHeader';\nexport * from './nearby-series';\nexport * from './tooltip-model';\nexport * from './utils';\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,eAAe;AAC7B,cAAc,sBAAsB;AACpC,cAAc,iBAAiB;AAC/B,cAAc,qBAAqB;AACnC,cAAc,mBAAmB;AACjC,cAAc,kBAAkB;AAChC,cAAc,kBAAkB;AAChC,cAAc,kBAAkB;AAChC,cAAc,UAAU"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { TimeZoneOption } from '../model/timeZoneOption';
|
|
3
|
+
export interface TimeZoneSelectorProps {
|
|
4
|
+
heightPx?: string;
|
|
5
|
+
timeZoneOptions: TimeZoneOption[];
|
|
6
|
+
value: string;
|
|
7
|
+
onChange?: (timeZone: TimeZoneOption) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare function TimeZoneSelector({ heightPx, timeZoneOptions: defaultTimeZoneOptions, onChange, value, }: TimeZoneSelectorProps): ReactElement;
|
|
10
|
+
//# sourceMappingURL=TimeZoneSelector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TimeZoneSelector.d.ts","sourceRoot":"","sources":["../../src/TimeZoneSelector/TimeZoneSelector.tsx"],"names":[],"mappings":"AA6BA,OAAO,EAAe,YAAY,EAAY,MAAM,OAAO,CAAC;AAI5D,OAAO,EAAqB,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAE5E,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,cAAc,EAAE,CAAC;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,CAAC;CAC/C;AAED,wBAAgB,gBAAgB,CAAC,EAC/B,QAAiB,EACjB,eAAe,EAAE,sBAAsB,EACvC,QAAQ,EACR,KAAkC,GACnC,EAAE,qBAAqB,GAAG,YAAY,CA2GtC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
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 { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
import { MenuItem, Box, Paper, ListItemText, Typography, MenuList, Input, InputAdornment, Divider, useTheme, useMediaQuery } from '@mui/material';
|
|
15
|
+
import ClickAwayListener from '@mui/material/ClickAwayListener';
|
|
16
|
+
import EarthIcon from 'mdi-material-ui/Earth';
|
|
17
|
+
import MagnifyIcon from 'mdi-material-ui/Magnify';
|
|
18
|
+
import { useState } from 'react';
|
|
19
|
+
import { DEFAULT_DASHBOARD_TIMEZONE } from '@perses-dev/core';
|
|
20
|
+
import { ToolbarIconButton } from '../ToolbarIconButton';
|
|
21
|
+
import { InfoTooltip } from '../InfoTooltip';
|
|
22
|
+
import { getTimeZoneOffset } from '../model/timeZoneOption';
|
|
23
|
+
export function TimeZoneSelector({ heightPx = '34px', timeZoneOptions: defaultTimeZoneOptions, onChange, value = DEFAULT_DASHBOARD_TIMEZONE }) {
|
|
24
|
+
const isMobile = useMediaQuery(useTheme().breakpoints.down('md'));
|
|
25
|
+
const [open, setOpen] = useState(false);
|
|
26
|
+
const localTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
27
|
+
const [searchValue, setSearchValue] = useState('');
|
|
28
|
+
const [timeZoneOptions, setTimeZoneOptions] = useState(defaultTimeZoneOptions);
|
|
29
|
+
function handleSearchChange(event) {
|
|
30
|
+
setSearchValue(event.target.value);
|
|
31
|
+
if (event.target.value === '') {
|
|
32
|
+
setTimeZoneOptions(defaultTimeZoneOptions);
|
|
33
|
+
} else {
|
|
34
|
+
setTimeZoneOptions(defaultTimeZoneOptions.filter((option)=>option.label.toLowerCase().includes(event.target.value.toLowerCase())));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function handleTimeZoneSelection(timeZone) {
|
|
38
|
+
setOpen(false);
|
|
39
|
+
setTimeZoneOptions(defaultTimeZoneOptions);
|
|
40
|
+
setSearchValue('');
|
|
41
|
+
onChange?.(timeZone);
|
|
42
|
+
}
|
|
43
|
+
function handleOnClickAway() {
|
|
44
|
+
setOpen(false);
|
|
45
|
+
setSearchValue('');
|
|
46
|
+
setTimeZoneOptions(defaultTimeZoneOptions);
|
|
47
|
+
}
|
|
48
|
+
return /*#__PURE__*/ _jsx(ClickAwayListener, {
|
|
49
|
+
onClickAway: handleOnClickAway,
|
|
50
|
+
children: /*#__PURE__*/ _jsxs(Box, {
|
|
51
|
+
children: [
|
|
52
|
+
/*#__PURE__*/ _jsx(Box, {
|
|
53
|
+
sx: {
|
|
54
|
+
position: 'relative'
|
|
55
|
+
},
|
|
56
|
+
children: /*#__PURE__*/ _jsx(InfoTooltip, {
|
|
57
|
+
description: value === DEFAULT_DASHBOARD_TIMEZONE ? localTimeZone : value,
|
|
58
|
+
children: /*#__PURE__*/ _jsxs(ToolbarIconButton, {
|
|
59
|
+
"data-testid": "current-timezone",
|
|
60
|
+
"aria-label": "Timezone",
|
|
61
|
+
onClick: ()=>setOpen(!open),
|
|
62
|
+
sx: (theme)=>({
|
|
63
|
+
height: heightPx,
|
|
64
|
+
paddingLeft: isMobile ? 0 : theme.spacing(1),
|
|
65
|
+
// Hide the timezone text on mobile
|
|
66
|
+
'& .timezone-text': {
|
|
67
|
+
display: isMobile ? 'none' : 'inline'
|
|
68
|
+
}
|
|
69
|
+
}),
|
|
70
|
+
children: [
|
|
71
|
+
/*#__PURE__*/ _jsx("span", {
|
|
72
|
+
className: "timezone-text",
|
|
73
|
+
children: value === DEFAULT_DASHBOARD_TIMEZONE ? getTimeZoneOffset(localTimeZone)?.value : getTimeZoneOffset(value)?.value
|
|
74
|
+
}),
|
|
75
|
+
/*#__PURE__*/ _jsx(EarthIcon, {
|
|
76
|
+
sx: (theme)=>({
|
|
77
|
+
marginLeft: theme.spacing(0.5)
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
]
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
}),
|
|
84
|
+
/*#__PURE__*/ _jsxs(Paper, {
|
|
85
|
+
sx: (theme)=>({
|
|
86
|
+
width: 350,
|
|
87
|
+
height: 355,
|
|
88
|
+
position: 'absolute',
|
|
89
|
+
top: isMobile ? 160 : 110,
|
|
90
|
+
right: 10,
|
|
91
|
+
zIndex: 1,
|
|
92
|
+
boxShadow: 3,
|
|
93
|
+
backgroundColor: theme.palette.background.paper,
|
|
94
|
+
display: open ? 'block' : 'none'
|
|
95
|
+
}),
|
|
96
|
+
children: [
|
|
97
|
+
/*#__PURE__*/ _jsx(Input, {
|
|
98
|
+
"data-testid": "search-timezone",
|
|
99
|
+
sx: (theme)=>({
|
|
100
|
+
height: 45,
|
|
101
|
+
padding: theme.spacing(1)
|
|
102
|
+
}),
|
|
103
|
+
value: searchValue,
|
|
104
|
+
fullWidth: true,
|
|
105
|
+
placeholder: "Search timezone",
|
|
106
|
+
startAdornment: /*#__PURE__*/ _jsx(InputAdornment, {
|
|
107
|
+
position: "start",
|
|
108
|
+
children: /*#__PURE__*/ _jsx(MagnifyIcon, {})
|
|
109
|
+
}),
|
|
110
|
+
onChange: handleSearchChange
|
|
111
|
+
}),
|
|
112
|
+
/*#__PURE__*/ _jsx(MenuList, {
|
|
113
|
+
sx: {
|
|
114
|
+
height: 305,
|
|
115
|
+
overflowX: 'auto'
|
|
116
|
+
},
|
|
117
|
+
children: timeZoneOptions.map((timeZoneOption)=>/*#__PURE__*/ _jsxs(Box, {
|
|
118
|
+
children: [
|
|
119
|
+
/*#__PURE__*/ _jsxs(MenuItem, {
|
|
120
|
+
onClick: ()=>handleTimeZoneSelection(timeZoneOption),
|
|
121
|
+
selected: timeZoneOption.value === value,
|
|
122
|
+
children: [
|
|
123
|
+
/*#__PURE__*/ _jsx(ListItemText, {
|
|
124
|
+
children: timeZoneOption.label
|
|
125
|
+
}),
|
|
126
|
+
/*#__PURE__*/ _jsx(Typography, {
|
|
127
|
+
variant: "body2",
|
|
128
|
+
children: timeZoneOption.longOffset
|
|
129
|
+
})
|
|
130
|
+
]
|
|
131
|
+
}, timeZoneOption.value),
|
|
132
|
+
timeZoneOption.value === DEFAULT_DASHBOARD_TIMEZONE && /*#__PURE__*/ _jsx(Divider, {})
|
|
133
|
+
]
|
|
134
|
+
}, timeZoneOption.value))
|
|
135
|
+
})
|
|
136
|
+
]
|
|
137
|
+
})
|
|
138
|
+
]
|
|
139
|
+
})
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
//# sourceMappingURL=TimeZoneSelector.js.map
|