@perses-dev/components 0.6.0 → 0.7.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 (34) hide show
  1. package/dist/Drawer/Drawer.d.ts +10 -0
  2. package/dist/Drawer/Drawer.d.ts.map +1 -0
  3. package/dist/Drawer/Drawer.js +1 -0
  4. package/dist/Drawer/index.d.ts +2 -0
  5. package/dist/Drawer/index.d.ts.map +1 -0
  6. package/dist/Drawer/index.js +1 -0
  7. package/dist/EChart.d.ts.map +1 -1
  8. package/dist/EChart.js +1 -1
  9. package/dist/TimeRangeSelector/AbsoluteTimePicker.d.ts +9 -0
  10. package/dist/TimeRangeSelector/AbsoluteTimePicker.d.ts.map +1 -0
  11. package/dist/TimeRangeSelector/AbsoluteTimePicker.js +1 -0
  12. package/dist/TimeRangeSelector/TimeRangeSelector.d.ts +17 -0
  13. package/dist/TimeRangeSelector/TimeRangeSelector.d.ts.map +1 -0
  14. package/dist/TimeRangeSelector/TimeRangeSelector.js +1 -0
  15. package/dist/TimeRangeSelector/index.d.ts +3 -0
  16. package/dist/TimeRangeSelector/index.d.ts.map +1 -0
  17. package/dist/TimeRangeSelector/index.js +1 -0
  18. package/dist/TimeRangeSelector/utils.d.ts +7 -0
  19. package/dist/TimeRangeSelector/utils.d.ts.map +1 -0
  20. package/dist/TimeRangeSelector/utils.js +1 -0
  21. package/dist/cjs/Drawer/Drawer.js +28 -0
  22. package/dist/cjs/Drawer/index.js +29 -0
  23. package/dist/cjs/EChart.js +8 -0
  24. package/dist/cjs/TimeRangeSelector/AbsoluteTimePicker.js +101 -0
  25. package/dist/cjs/TimeRangeSelector/TimeRangeSelector.js +30 -0
  26. package/dist/cjs/TimeRangeSelector/index.js +30 -0
  27. package/dist/cjs/TimeRangeSelector/utils.js +41 -0
  28. package/dist/cjs/index.js +2 -0
  29. package/dist/cjs/model/units.js +3 -1
  30. package/dist/index.d.ts +2 -0
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +1 -1
  33. package/dist/model/units.js +1 -1
  34. package/package.json +4 -2
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ interface DrawerProps {
3
+ isOpen: boolean;
4
+ onClose: () => void;
5
+ anchor?: 'left' | 'right';
6
+ children?: React.ReactNode;
7
+ }
8
+ export declare const Drawer: ({ anchor, isOpen, onClose, children }: DrawerProps) => JSX.Element;
9
+ export {};
10
+ //# sourceMappingURL=Drawer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Drawer.d.ts","sourceRoot":"","sources":["../../src/Drawer/Drawer.tsx"],"names":[],"mappings":";AAeA,UAAU,WAAW;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC1B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAID,eAAO,MAAM,MAAM,0CAAqD,WAAW,gBAiBlF,CAAC"}
@@ -0,0 +1 @@
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{Drawer as MuiDrawer}from"@mui/material";const DRAWER_DEFAULT_WIDTH=900;export const Drawer=({anchor:r="right",isOpen:e,onClose:o,children:i})=>_jsx(MuiDrawer,{open:e,onClose:o,anchor:r,PaperProps:{sx:{width:"900px",padding:r=>r.spacing(2),overflow:"hidden"}},children:i});
@@ -0,0 +1,2 @@
1
+ export * from './Drawer';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Drawer/index.ts"],"names":[],"mappings":"AAaA,cAAc,UAAU,CAAC"}
@@ -0,0 +1 @@
1
+ export*from"./Drawer";
@@ -1 +1 @@
1
- {"version":3,"file":"EChart.d.ts","sourceRoot":"","sources":["../src/EChart.tsx"],"names":[],"mappings":"AAaA,OAAO,KAA6C,MAAM,OAAO,CAAC;AAElE,OAAO,EAAE,O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M,WAAW,qBAAqB;IACpC,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,wBAAwB,EAAE,GAAG,yBAAyB,EAAE,CAAC;CACjE;AAED,aAAK,oBAAoB,GAAG,CAAC,MAAM,EAAE,qBAAqB,KAAK,IAAI,CAAC;AAEpE,QAAA,MAAM,WAAW,gDAAiD,CAAC;AAEnE,oBAAY,cAAc,GAAG,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;AAExD,aAAK,cAAc,GAAG,UAAU,CAAC;AAIjC,oBAAY,YAAY,CAAC,CAAC,IAAI;KAC3B,cAAc,IAAI,cAAc,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC;CACxD,GAAG;KACD,cAAc,IAAI,cAAc,CAAC,CAAC,EAAE,oBAAoB;CAC1D,GAAG;KACD,SAAS,IAAI,cAAc,CAAC,CAAC,EAAE,MAAM,IAAI;CAC3C,CAAC;AAEF,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,MAAM,EAAE,iBAAiB,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC;IAC9B,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;IAC5B,EAAE,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACpB,QAAQ,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAC3B,SAAS,CAAC,EAAE,KAAK,CAAC,gBAAgB,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC;IACxD,kBAAkB,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;CAClD;AAED,eAAO,MAAM,MAAM,6IA0EjB,CAAC"}
package/dist/EChart.js CHANGED
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import React,{useEffect,useLayoutEffect,useRef}from"react";import debounce from"lodash/debounce";import{init}from"echarts/core";import{Box}from"@mui/material";import{isEqual}from"lodash-es";const mouseEvents=["click","dblclick","mousedown","mousemove","mouseup","mouseover","mouseout","globalout","contextmenu"],batchEvents=["datazoom","downplay","highlight"];export const EChart=React.memo((function({option:e,theme:n,renderer:t,sx:r,onEvents:o,_instance:u,onChartInitialized:s}){const c=useRef(e),i=useRef(e),l=useRef(null),f=useRef(null);return useLayoutEffect((()=>{if(null!==l.current&&null===f.current)return f.current=init(l.current,n,{renderer:null!=t?t:"canvas"}),f.current.setOption(c.current,!0),null==s||s(f.current),void 0!==u&&(u.current=f.current),()=>{null!==f.current&&(f.current.dispose(),f.current=null)}}),[u,s,n,t]),useEffect((()=>{void 0===i.current||isEqual(i.current,e)||null!==f.current&&(f.current.setOption(e,!0),i.current=e)}),[e]),useLayoutEffect((()=>{const e=debounce((()=>{null!==f.current&&f.current.resize()}),200);return window.addEventListener("resize",e),e(),()=>{window.removeEventListener("resize",e)}}),[]),useEffect((()=>{const e=f.current;if(null!==e&&void 0!==o)return bindEvents(e,o),()=>{if(void 0!==e&&!0!==e.isDisposed())for(const n in o)e.off(n)}}),[o]),_jsx(Box,{ref:l,sx:r})}));function bindEvents(e,n){var t;if(void 0!==n)for(const e in n)if(Object.prototype.hasOwnProperty.call(n,e)){const o=null!==(t=n[e])&&void 0!==t?t:null;o&&r(e,o)}function r(n,t){"function"==typeof t&&(isMouseEvent(n)?e.on(n,(n=>t(n,e))):isBatchEvent(n)?e.on(n,(e=>t(e))):e.on(n,(()=>t(null,e))))}}function isMouseEvent(e){return mouseEvents.includes(e)}function isBatchEvent(e){return batchEvents.includes(e)}
1
+ import{jsx as _jsx}from"react/jsx-runtime";import React,{useEffect,useLayoutEffect,useRef}from"react";import debounce from"lodash/debounce";import{init}from"echarts/core";import{Box}from"@mui/material";import{isEqual}from"lodash-es";const mouseEvents=["click","dblclick","mousedown","mousemove","mouseup","mouseover","mouseout","globalout","contextmenu"],batchEvents=["datazoom","downplay","highlight"];export const EChart=React.memo((function({option:e,theme:n,renderer:t,sx:r,onEvents:u,_instance:o,onChartInitialized:s}){const c=useRef(e),i=useRef(e),l=useRef(null),f=useRef(null);return useLayoutEffect((()=>{if(null!==l.current&&null===f.current)return f.current=init(l.current,n,{renderer:null!=t?t:"canvas"}),f.current.setOption(c.current,!0),null==s||s(f.current),void 0!==o&&(o.current=f.current),()=>{null!==f.current&&(f.current.dispose(),f.current=null)}}),[o,s,n,t]),useEffect((()=>{void 0===i.current||isEqual(i.current,e)||null!==f.current&&(f.current.setOption(e,!0),i.current=e)}),[e]),useLayoutEffect((()=>{const e=debounce((()=>{null!==f.current&&f.current.resize()}),200);return window.addEventListener("resize",e),e(),()=>{window.removeEventListener("resize",e)}}),[]),useEffect((()=>{const e=f.current;if(null!==e&&void 0!==u)return bindEvents(e,u),()=>{if(void 0!==e&&!0!==e.isDisposed())for(const n in u)e.off(n)}}),[u]),useEffect((()=>{debounce((()=>{null!==f.current&&f.current.resize()}),200)()}),[r]),_jsx(Box,{ref:l,sx:r})}));function bindEvents(e,n){var t;if(void 0!==n)for(const e in n)if(Object.prototype.hasOwnProperty.call(n,e)){const u=null!==(t=n[e])&&void 0!==t?t:null;u&&r(e,u)}function r(n,t){"function"==typeof t&&(isMouseEvent(n)?e.on(n,(n=>t(n,e))):isBatchEvent(n)?e.on(n,(e=>t(e))):e.on(n,(()=>t(null,e))))}}function isMouseEvent(e){return mouseEvents.includes(e)}function isBatchEvent(e){return batchEvents.includes(e)}
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { AbsoluteTimeRange } from '@perses-dev/core';
3
+ interface AbsoluteTimeFormProps {
4
+ initialTimeRange: AbsoluteTimeRange;
5
+ onChange: (timeRange: AbsoluteTimeRange) => void;
6
+ }
7
+ export declare const AbsoluteTimePicker: ({ initialTimeRange, onChange }: AbsoluteTimeFormProps) => JSX.Element;
8
+ export {};
9
+ //# sourceMappingURL=AbsoluteTimePicker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AbsoluteTimePicker.d.ts","sourceRoot":"","sources":["../../src/TimeRangeSelector/AbsoluteTimePicker.tsx"],"names":[],"mappings":";AAkBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAKrD,UAAU,qBAAqB;IAC7B,gBAAgB,EAAE,iBAAiB,CAAC;IACpC,QAAQ,EAAE,CAAC,SAAS,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAClD;AAED,eAAO,MAAM,kBAAkB,mCAAoC,qBAAqB,gBAmIvF,CAAC"}
@@ -0,0 +1 @@
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useState}from"react";import{Box,Stack,TextField,Divider}from"@mui/material";import{LocalizationProvider,StaticDateTimePicker}from"@mui/x-date-pickers";import{AdapterDateFns}from"@mui/x-date-pickers/AdapterDateFns";import{format}from"date-fns";import{validateDateRange}from"./utils";const DATE_TIME_FORMAT="yyyy-MM-dd HH:mm:ss";export const AbsoluteTimePicker=({initialTimeRange:e,onChange:t})=>{const[a,i]=useState(e),[r,n]=useState(!0),o=(e,r)=>{const n=new Date(e);!0===r?!0===validateDateRange(n,a.end)&&i((e=>{const a={start:n,end:e.end};return t(a),a})):!0===validateDateRange(a.start,n)&&i((e=>{const a={start:e.start,end:n};return t(a),a}))};return _jsx(LocalizationProvider,{dateAdapter:AdapterDateFns,children:_jsxs(Stack,{spacing:3,sx:{padding:e=>e.spacing(1,2,3)},children:[r&&_jsxs(Box,{sx:e=>({".MuiPickerStaticWrapper-content":{backgroundColor:e.palette.background.default},".MuiIconButton-sizeMedium":{top:80,bottom:"auto",margin:e.spacing(0,3)}}),children:[_jsx("h3",{children:"Select Start Time"}),_jsx(StaticDateTimePicker,{displayStaticWrapperAs:"desktop",openTo:"day",disableHighlightToday:!0,value:e.start,onChange:e=>{null!==e&&i((t=>({start:e,end:t.end})))},onAccept:()=>{n(!1)},renderInput:e=>_jsx(TextField,{...e})})]}),!r&&_jsxs(Box,{sx:e=>({".MuiPickerStaticWrapper-content":{backgroundColor:e.palette.background.default},".MuiIconButton-sizeMedium":{top:80,bottom:"auto",margin:e.spacing(0,3)}}),children:[_jsx("h3",{children:"Select End Time"}),_jsx(StaticDateTimePicker,{displayStaticWrapperAs:"desktop",openTo:"day",disableHighlightToday:!0,value:e.end,minDateTime:a.start,onChange:e=>{null!==e&&i((t=>({start:t.start,end:e})))},onAccept:()=>{n(!0),t(a)},renderInput:e=>_jsx(TextField,{...e})})]}),_jsx(TextField,{fullWidth:!0,onChange:e=>{o(e.target.value,!0)},value:format(a.start,DATE_TIME_FORMAT),label:"Start Time",placeholder:"mm/dd/yyyy hh:mm",type:"tel"}),_jsx(Divider,{sx:e=>({margin:e.spacing(2,0),borderColor:e.palette.grey[500]})}),_jsx(TextField,{fullWidth:!0,onChange:e=>{o(e.target.value,!1)},value:format(a.end,DATE_TIME_FORMAT),label:"End Time",placeholder:"mm/dd/yyyy hh:mm",type:"tel"})]})})};
@@ -0,0 +1,17 @@
1
+ /// <reference types="react" />
2
+ import { SelectChangeEvent } from '@mui/material';
3
+ import { TimeRangeValue, RelativeTimeRange } from '@perses-dev/core';
4
+ export interface TimeOption {
5
+ value: RelativeTimeRange;
6
+ display: string;
7
+ }
8
+ interface TimeRangeSelectorProps {
9
+ inputLabel: string;
10
+ value: TimeRangeValue;
11
+ timeOptions: TimeOption[];
12
+ onSelectChange: (event: SelectChangeEvent<string>) => void;
13
+ onCustomClick: () => void;
14
+ }
15
+ export declare function TimeRangeSelector(props: TimeRangeSelectorProps): JSX.Element;
16
+ export {};
17
+ //# sourceMappingURL=TimeRangeSelector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TimeRangeSelector.d.ts","sourceRoot":"","sources":["../../src/TimeRangeSelector/TimeRangeSelector.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAoB,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAmB,MAAM,kBAAkB,CAAC;AAKtF,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,iBAAiB,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,sBAAsB;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,cAAc,CAAC;IACtB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,cAAc,EAAE,CAAC,KAAK,EAAE,iBAAiB,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IAC3D,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,eA+B9D"}
@@ -0,0 +1 @@
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{MenuItem,Select}from"@mui/material";import{isRelativeValue}from"@perses-dev/core";import{formatAbsoluteRange}from"./utils";const DATE_TIME_FORMAT="yyyy-MM-dd HH:mm:ss";export function TimeRangeSelector(e){const{inputLabel:t,value:a,timeOptions:s,onSelectChange:i,onCustomClick:l}=e,n=isRelativeValue(a)?a.pastDuration:formatAbsoluteRange(a,DATE_TIME_FORMAT);return _jsxs(Select,{value:n,label:t,onChange:i,children:[s.map(((e,t)=>_jsx(MenuItem,{value:e.value.pastDuration,children:e.display},t))),isRelativeValue(a)?_jsx(MenuItem,{onClick:()=>{l()},children:"Custom time range"}):_jsx(MenuItem,{value:n,onClick:()=>{l()},children:n})]})}
@@ -0,0 +1,3 @@
1
+ export * from './TimeRangeSelector';
2
+ export * from './AbsoluteTimePicker';
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,sBAAsB,CAAC"}
@@ -0,0 +1 @@
1
+ export*from"./TimeRangeSelector";export*from"./AbsoluteTimePicker";
@@ -0,0 +1,7 @@
1
+ import { AbsoluteTimeRange } from '@perses-dev/core';
2
+ export declare function validateDateRange(startDate: Date, endDate: Date): boolean;
3
+ /**
4
+ * Format start and end time based on provided date format
5
+ */
6
+ export declare function formatAbsoluteRange(timeRange: AbsoluteTimeRange, dateFormat: string): string;
7
+ //# 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,EAAE,MAAM,kBAAkB,CAAC;AAKrD,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,WAW/D;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,UAInF"}
@@ -0,0 +1 @@
1
+ import{isBefore,isValid,format}from"date-fns";export function validateDateRange(e,r){return isValid(e)&&isValid(r)?!!isBefore(e,r)||(console.error("End Time is before Start Time"),!1):(console.error("Invalid Date"),!1)}export function formatAbsoluteRange(e,r){return`${format(e.start,r)} - ${format(e.end,r)}`}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Drawer = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ // Copyright 2022 The Perses Authors
6
+ // Licensed under the Apache License, Version 2.0 (the "License");
7
+ // you may not use this file except in compliance with the License.
8
+ // You may obtain a copy of the License at
9
+ //
10
+ // http://www.apache.org/licenses/LICENSE-2.0
11
+ //
12
+ // Unless required by applicable law or agreed to in writing, software
13
+ // distributed under the License is distributed on an "AS IS" BASIS,
14
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ // See the License for the specific language governing permissions and
16
+ // limitations under the License.
17
+ const material_1 = require("@mui/material");
18
+ const DRAWER_DEFAULT_WIDTH = 900;
19
+ const Drawer = ({ anchor = 'right', isOpen, onClose, children }) => {
20
+ return ((0, jsx_runtime_1.jsx)(material_1.Drawer, { open: isOpen, onClose: onClose, anchor: anchor, PaperProps: {
21
+ sx: {
22
+ width: `${DRAWER_DEFAULT_WIDTH}px`,
23
+ padding: (theme) => theme.spacing(2),
24
+ overflow: 'hidden',
25
+ },
26
+ }, children: children }));
27
+ };
28
+ exports.Drawer = Drawer;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ // Copyright 2022 The Perses Authors
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ var desc = Object.getOwnPropertyDescriptor(m, k);
17
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
+ desc = { enumerable: true, get: function() { return m[k]; } };
19
+ }
20
+ Object.defineProperty(o, k2, desc);
21
+ }) : (function(o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ }));
25
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ __exportStar(require("./Drawer"), exports);
@@ -117,6 +117,14 @@ exports.EChart = react_1.default.memo(function EChart({ option, theme, renderer,
117
117
  }
118
118
  };
119
119
  }, [onEvents]);
120
+ (0, react_1.useEffect)(() => {
121
+ const updateSize = (0, debounce_1.default)(() => {
122
+ if (chartElement.current === null)
123
+ return;
124
+ chartElement.current.resize();
125
+ }, 200);
126
+ updateSize();
127
+ }, [sx]);
120
128
  return (0, jsx_runtime_1.jsx)(material_1.Box, { ref: containerRef, sx: sx });
121
129
  });
122
130
  // Validate event config and bind custom events
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AbsoluteTimePicker = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ // Copyright 2022 The Perses Authors
6
+ // Licensed under the Apache License, Version 2.0 (the "License");
7
+ // you may not use this file except in compliance with the License.
8
+ // You may obtain a copy of the License at
9
+ //
10
+ // http://www.apache.org/licenses/LICENSE-2.0
11
+ //
12
+ // Unless required by applicable law or agreed to in writing, software
13
+ // distributed under the License is distributed on an "AS IS" BASIS,
14
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ // See the License for the specific language governing permissions and
16
+ // limitations under the License.
17
+ const react_1 = require("react");
18
+ const material_1 = require("@mui/material");
19
+ const x_date_pickers_1 = require("@mui/x-date-pickers");
20
+ const AdapterDateFns_1 = require("@mui/x-date-pickers/AdapterDateFns");
21
+ const date_fns_1 = require("date-fns");
22
+ const utils_1 = require("./utils");
23
+ const DATE_TIME_FORMAT = 'yyyy-MM-dd HH:mm:ss';
24
+ const AbsoluteTimePicker = ({ initialTimeRange, onChange }) => {
25
+ const [timeRange, setTimeRange] = (0, react_1.useState)(initialTimeRange);
26
+ const [showStartCalendar, setShowStartCalendar] = (0, react_1.useState)(true);
27
+ // validate start and end time, propagate changes
28
+ const updateDateRange = (input, isStartDate) => {
29
+ const newDate = new Date(input);
30
+ if (isStartDate === true) {
31
+ const isValidDateRange = (0, utils_1.validateDateRange)(newDate, timeRange.end);
32
+ if (isValidDateRange === true) {
33
+ setTimeRange((current) => {
34
+ const updatedRange = { start: newDate, end: current.end };
35
+ onChange(updatedRange);
36
+ return updatedRange;
37
+ });
38
+ }
39
+ }
40
+ else {
41
+ const isValidDateRange = (0, utils_1.validateDateRange)(timeRange.start, newDate);
42
+ if (isValidDateRange === true) {
43
+ setTimeRange((current) => {
44
+ const updatedRange = { start: current.start, end: newDate };
45
+ onChange(updatedRange);
46
+ return updatedRange;
47
+ });
48
+ }
49
+ }
50
+ };
51
+ return ((0, jsx_runtime_1.jsx)(x_date_pickers_1.LocalizationProvider, { dateAdapter: AdapterDateFns_1.AdapterDateFns, children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { spacing: 3, sx: { padding: (theme) => theme.spacing(1, 2, 3) }, children: [showStartCalendar && ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: (theme) => ({
52
+ // TODO: create separate reusable calendar component
53
+ '.MuiPickerStaticWrapper-content': {
54
+ backgroundColor: theme.palette.background.default,
55
+ },
56
+ // reposition AM and PM buttons
57
+ '.MuiIconButton-sizeMedium': {
58
+ top: 80,
59
+ bottom: 'auto',
60
+ margin: theme.spacing(0, 3),
61
+ },
62
+ }), children: [(0, jsx_runtime_1.jsx)("h3", { children: "Select Start Time" }), (0, jsx_runtime_1.jsx)(x_date_pickers_1.StaticDateTimePicker, { displayStaticWrapperAs: "desktop", openTo: "day", disableHighlightToday: true, value: initialTimeRange.start, onChange: (newValue) => {
63
+ if (newValue === null)
64
+ return;
65
+ setTimeRange((current) => {
66
+ return { start: newValue, end: current.end };
67
+ });
68
+ }, onAccept: () => {
69
+ setShowStartCalendar(false);
70
+ }, renderInput: (params) => (0, jsx_runtime_1.jsx)(material_1.TextField, { ...params }) })] })), !showStartCalendar && ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: (theme) => ({
71
+ '.MuiPickerStaticWrapper-content': {
72
+ backgroundColor: theme.palette.background.default,
73
+ },
74
+ // reposition AM and PM buttons
75
+ '.MuiIconButton-sizeMedium': {
76
+ top: 80,
77
+ bottom: 'auto',
78
+ margin: theme.spacing(0, 3),
79
+ },
80
+ }), children: [(0, jsx_runtime_1.jsx)("h3", { children: "Select End Time" }), (0, jsx_runtime_1.jsx)(x_date_pickers_1.StaticDateTimePicker, { displayStaticWrapperAs: "desktop", openTo: "day", disableHighlightToday: true, value: initialTimeRange.end, minDateTime: timeRange.start, onChange: (newValue) => {
81
+ if (newValue === null)
82
+ return;
83
+ setTimeRange((current) => {
84
+ return { start: current.start, end: newValue };
85
+ });
86
+ }, onAccept: () => {
87
+ setShowStartCalendar(true);
88
+ onChange(timeRange);
89
+ }, renderInput: (params) => (0, jsx_runtime_1.jsx)(material_1.TextField, { ...params }) })] })), (0, jsx_runtime_1.jsx)(material_1.TextField, { fullWidth: true, onChange: (event) => {
90
+ // TODO: add helperText, fix validation after we decide on form state solution
91
+ updateDateRange(event.target.value, true);
92
+ }, value: (0, date_fns_1.format)(timeRange.start, DATE_TIME_FORMAT), label: "Start Time", placeholder: "mm/dd/yyyy hh:mm",
93
+ // tel used to match MUI DateTimePicker, may change in future: https://github.com/mui/material-ui/issues/27590
94
+ type: "tel" }), (0, jsx_runtime_1.jsx)(material_1.Divider, { sx: (theme) => ({
95
+ margin: theme.spacing(2, 0),
96
+ borderColor: theme.palette.grey['500'],
97
+ }) }), (0, jsx_runtime_1.jsx)(material_1.TextField, { fullWidth: true, onChange: (event) => {
98
+ updateDateRange(event.target.value, false);
99
+ }, value: (0, date_fns_1.format)(timeRange.end, DATE_TIME_FORMAT), label: "End Time", placeholder: "mm/dd/yyyy hh:mm", type: "tel" })] }) }));
100
+ };
101
+ exports.AbsoluteTimePicker = AbsoluteTimePicker;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TimeRangeSelector = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ // Copyright 2022 The Perses Authors
6
+ // Licensed under the Apache License, Version 2.0 (the "License");
7
+ // you may not use this file except in compliance with the License.
8
+ // You may obtain a copy of the License at
9
+ //
10
+ // http://www.apache.org/licenses/LICENSE-2.0
11
+ //
12
+ // Unless required by applicable law or agreed to in writing, software
13
+ // distributed under the License is distributed on an "AS IS" BASIS,
14
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ // See the License for the specific language governing permissions and
16
+ // limitations under the License.
17
+ const material_1 = require("@mui/material");
18
+ const core_1 = require("@perses-dev/core");
19
+ const utils_1 = require("./utils");
20
+ const DATE_TIME_FORMAT = 'yyyy-MM-dd HH:mm:ss';
21
+ function TimeRangeSelector(props) {
22
+ const { inputLabel, value, timeOptions, onSelectChange, onCustomClick } = props;
23
+ const formattedValue = !(0, core_1.isRelativeValue)(value) ? (0, utils_1.formatAbsoluteRange)(value, DATE_TIME_FORMAT) : value.pastDuration;
24
+ return ((0, jsx_runtime_1.jsxs)(material_1.Select, { value: formattedValue, label: inputLabel, onChange: onSelectChange, children: [timeOptions.map((item, idx) => ((0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: item.value.pastDuration, children: item.display }, idx))), (0, core_1.isRelativeValue)(value) ? ((0, jsx_runtime_1.jsx)(material_1.MenuItem, { onClick: () => {
25
+ onCustomClick();
26
+ }, children: "Custom time range" })) : ((0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: formattedValue, onClick: () => {
27
+ onCustomClick();
28
+ }, children: formattedValue }))] }));
29
+ }
30
+ exports.TimeRangeSelector = TimeRangeSelector;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ // Copyright 2022 The Perses Authors
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ var desc = Object.getOwnPropertyDescriptor(m, k);
17
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
+ desc = { enumerable: true, get: function() { return m[k]; } };
19
+ }
20
+ Object.defineProperty(o, k2, desc);
21
+ }) : (function(o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ }));
25
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ __exportStar(require("./TimeRangeSelector"), exports);
30
+ __exportStar(require("./AbsoluteTimePicker"), exports);
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ // Copyright 2022 The Perses Authors
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.formatAbsoluteRange = exports.validateDateRange = void 0;
16
+ const date_fns_1 = require("date-fns");
17
+ /*
18
+ * Date validation and check if end is after start
19
+ */
20
+ function validateDateRange(startDate, endDate) {
21
+ // TODO: display error as helperText
22
+ if (!(0, date_fns_1.isValid)(startDate) || !(0, date_fns_1.isValid)(endDate)) {
23
+ console.error('Invalid Date');
24
+ return false;
25
+ }
26
+ if (!(0, date_fns_1.isBefore)(startDate, endDate)) {
27
+ console.error('End Time is before Start Time');
28
+ return false;
29
+ }
30
+ return true;
31
+ }
32
+ exports.validateDateRange = validateDateRange;
33
+ /**
34
+ * Format start and end time based on provided date format
35
+ */
36
+ function formatAbsoluteRange(timeRange, dateFormat) {
37
+ const formattedStart = (0, date_fns_1.format)(timeRange.start, dateFormat);
38
+ const formattedEnd = (0, date_fns_1.format)(timeRange.end, dateFormat);
39
+ return `${formattedStart} - ${formattedEnd}`;
40
+ }
41
+ exports.formatAbsoluteRange = formatAbsoluteRange;
package/dist/cjs/index.js CHANGED
@@ -26,6 +26,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
26
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
+ __exportStar(require("./Drawer"), exports);
29
30
  __exportStar(require("./EChart"), exports);
30
31
  __exportStar(require("./ErrorAlert"), exports);
31
32
  __exportStar(require("./ErrorBoundary"), exports);
@@ -33,6 +34,7 @@ __exportStar(require("./InfoTooltip"), exports);
33
34
  __exportStar(require("./LineChart"), exports);
34
35
  __exportStar(require("./GaugeChart"), exports);
35
36
  __exportStar(require("./StatChart"), exports);
37
+ __exportStar(require("./TimeRangeSelector"), exports);
36
38
  __exportStar(require("./context/ChartsThemeProvider"), exports);
37
39
  __exportStar(require("./utils"), exports);
38
40
  __exportStar(require("./model"), exports);
@@ -179,6 +179,8 @@ function formatBytes(bytes, decimals = 2) {
179
179
  const k = 1024;
180
180
  const dm = decimals < 0 ? 0 : decimals;
181
181
  const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
182
- const i = Math.floor(Math.log(bytes) / Math.log(k));
182
+ // Math.max(0, ...) ensures that we don't return -1 as a value for the index.
183
+ // Why? When the number of bytes are between -1 and 1, Math.floor(Math.log(bytes)/Math.log(1024)) returns -1.
184
+ const i = Math.max(0, Math.floor(Math.log(bytes) / Math.log(k)));
183
185
  return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
184
186
  }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './Drawer';
1
2
  export * from './EChart';
2
3
  export * from './ErrorAlert';
3
4
  export * from './ErrorBoundary';
@@ -5,6 +6,7 @@ export * from './InfoTooltip';
5
6
  export * from './LineChart';
6
7
  export * from './GaugeChart';
7
8
  export * from './StatChart';
9
+ export * from './TimeRangeSelector';
8
10
  export * from './context/ChartsThemeProvider';
9
11
  export * from './utils';
10
12
  export * from './model';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export*from"./EChart";export*from"./ErrorAlert";export*from"./ErrorBoundary";export*from"./InfoTooltip";export*from"./LineChart";export*from"./GaugeChart";export*from"./StatChart";export*from"./context/ChartsThemeProvider";export*from"./utils";export*from"./model";
1
+ export*from"./Drawer";export*from"./EChart";export*from"./ErrorAlert";export*from"./ErrorBoundary";export*from"./InfoTooltip";export*from"./LineChart";export*from"./GaugeChart";export*from"./StatChart";export*from"./TimeRangeSelector";export*from"./context/ChartsThemeProvider";export*from"./utils";export*from"./model";
@@ -1 +1 @@
1
- import{milliseconds}from"date-fns";import{round}from"mathjs";export const DEFAULT_DECIMAL_PLACES=2;export function formatValue(e,t){var n;if(void 0===t)return e.toString();if(isDecimalUnit(t))return formatDecimal(e,t);if(isTimeUnit(t))return formatTime(e,t);if(isPercentUnit(t))return formatPercent(e,t);if(isBytesUnit(t))return formatBytes(e,null!==(n=t.decimal_places)&&void 0!==n?n:2);throw new Error(`Unknown unit options ${t}`)}const timeUnitKinds=["Milliseconds","Seconds","Minutes","Hours","Days","Weeks","Months","Years"],timeUnitKindsSet=new Set(timeUnitKinds);function isTimeUnit(e){return timeUnitKindsSet.has(e.kind)}function formatTime(e,t){const n={};switch(t.kind){case"Milliseconds":n.seconds=e/1e3;break;case"Seconds":n.seconds=e;break;case"Minutes":n.minutes=e;break;case"Hours":n.hours=e;break;case"Days":n.days=e;break;case"Weeks":n.weeks=e;break;case"Months":n.months=e;break;case"Years":n.years=e;break;default:const i=t.kind;throw new Error(`Unknown time unit type ${i}`)}const i=milliseconds(n),r=i/1e3;if(r<1)return`${i.toFixed()} milliseconds`;const s=r/60;if(s<1)return`${r.toFixed()} seconds`;const o=s/60;if(o<1)return`${s.toFixed()} minutes`;const a=o/24;if(a<1)return`${o.toFixed()} hours`;const c=a/7;if(c<1)return`${a.toFixed()} days`;const d=c/52;return d<1?`${c.toFixed()} weeks`:`${d.toFixed()} years`}const percentUnitKinds=["Percent","PercentDecimal","%"],percentUnitKindsSet=new Set(percentUnitKinds);function isPercentUnit(e){return percentUnitKindsSet.has(e.kind)}function formatPercent(e,t){var n;const i=null!==(n=t.decimal_places)&&void 0!==n?n:2;return"PercentDecimal"===t.kind&&(e*=100),e.toFixed(i)+"%"}const decimalUnitKinds=["Decimal"],decimalUnitKindsSet=new Set(decimalUnitKinds);function isDecimalUnit(e){return decimalUnitKindsSet.has(e.kind)}function formatDecimal(e,t){var n;const i=null!==(n=t.decimal_places)&&void 0!==n?n:2;if(!0===t.abbreviate)return abbreviateLargeNumber(e,i);const r={style:"decimal",minimumFractionDigits:0,maximumFractionDigits:i,useGrouping:!0};return new Intl.NumberFormat("en-US",r).format(e)}export function abbreviateLargeNumber(e,t=2){return formatNumber(e,(e=>round(e,t)))}export function formatNumber(e,t){const n=null!=t?t:Math.round;return e>=1e12?n(e/1e12)+"T":e>=1e9?n(e/1e9)+"B":e>=1e6?n(e/1e6)+"M":e>=1e3?n(e/1e3)+"K":e.toString()}const bytesUnitKinds=["Bytes"],bytesUnitKindsSet=new Set(bytesUnitKinds);function isBytesUnit(e){return bytesUnitKindsSet.has(e.kind)}function formatBytes(e,t=2){if(0===e)return"0 Bytes";const n=t<0?0:t,i=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,i)).toFixed(n))+" "+["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][i]}
1
+ import{milliseconds}from"date-fns";import{round}from"mathjs";export const DEFAULT_DECIMAL_PLACES=2;export function formatValue(e,t){var n;if(void 0===t)return e.toString();if(isDecimalUnit(t))return formatDecimal(e,t);if(isTimeUnit(t))return formatTime(e,t);if(isPercentUnit(t))return formatPercent(e,t);if(isBytesUnit(t))return formatBytes(e,null!==(n=t.decimal_places)&&void 0!==n?n:2);throw new Error(`Unknown unit options ${t}`)}const timeUnitKinds=["Milliseconds","Seconds","Minutes","Hours","Days","Weeks","Months","Years"],timeUnitKindsSet=new Set(timeUnitKinds);function isTimeUnit(e){return timeUnitKindsSet.has(e.kind)}function formatTime(e,t){const n={};switch(t.kind){case"Milliseconds":n.seconds=e/1e3;break;case"Seconds":n.seconds=e;break;case"Minutes":n.minutes=e;break;case"Hours":n.hours=e;break;case"Days":n.days=e;break;case"Weeks":n.weeks=e;break;case"Months":n.months=e;break;case"Years":n.years=e;break;default:const i=t.kind;throw new Error(`Unknown time unit type ${i}`)}const i=milliseconds(n),r=i/1e3;if(r<1)return`${i.toFixed()} milliseconds`;const s=r/60;if(s<1)return`${r.toFixed()} seconds`;const o=s/60;if(o<1)return`${s.toFixed()} minutes`;const a=o/24;if(a<1)return`${o.toFixed()} hours`;const c=a/7;if(c<1)return`${a.toFixed()} days`;const d=c/52;return d<1?`${c.toFixed()} weeks`:`${d.toFixed()} years`}const percentUnitKinds=["Percent","PercentDecimal","%"],percentUnitKindsSet=new Set(percentUnitKinds);function isPercentUnit(e){return percentUnitKindsSet.has(e.kind)}function formatPercent(e,t){var n;const i=null!==(n=t.decimal_places)&&void 0!==n?n:2;return"PercentDecimal"===t.kind&&(e*=100),e.toFixed(i)+"%"}const decimalUnitKinds=["Decimal"],decimalUnitKindsSet=new Set(decimalUnitKinds);function isDecimalUnit(e){return decimalUnitKindsSet.has(e.kind)}function formatDecimal(e,t){var n;const i=null!==(n=t.decimal_places)&&void 0!==n?n:2;if(!0===t.abbreviate)return abbreviateLargeNumber(e,i);const r={style:"decimal",minimumFractionDigits:0,maximumFractionDigits:i,useGrouping:!0};return new Intl.NumberFormat("en-US",r).format(e)}export function abbreviateLargeNumber(e,t=2){return formatNumber(e,(e=>round(e,t)))}export function formatNumber(e,t){const n=null!=t?t:Math.round;return e>=1e12?n(e/1e12)+"T":e>=1e9?n(e/1e9)+"B":e>=1e6?n(e/1e6)+"M":e>=1e3?n(e/1e3)+"K":e.toString()}const bytesUnitKinds=["Bytes"],bytesUnitKindsSet=new Set(bytesUnitKinds);function isBytesUnit(e){return bytesUnitKindsSet.has(e.kind)}function formatBytes(e,t=2){if(0===e)return"0 Bytes";const n=t<0?0:t,i=Math.max(0,Math.floor(Math.log(e)/Math.log(1024)));return parseFloat((e/Math.pow(1024,i)).toFixed(n))+" "+["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][i]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/components",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Common UI components used across Perses features",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/perses/perses/blob/main/README.md",
@@ -24,7 +24,9 @@
24
24
  "lint:fix": "eslint --fix src --ext .ts,.tsx"
25
25
  },
26
26
  "dependencies": {
27
- "@perses-dev/core": "^0.6.0",
27
+ "@mui/x-date-pickers": "^5.0.0-beta.1",
28
+ "@perses-dev/core": "^0.7.0",
29
+ "date-fns": "^2.28.0",
28
30
  "echarts": "^5.3.3",
29
31
  "lodash-es": "^4.17.21",
30
32
  "react-error-boundary": "^3.1.4"