@iotready/nextjs-components-library 1.0.0-preview29 → 1.0.0-preview30

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.
@@ -24,6 +24,8 @@ import EditNoteIcon from '@mui/icons-material/EditNote';
24
24
  // import AspectRatioIcon from '@mui/icons-material/AspectRatio';
25
25
  import { FilterTagMode } from '../../server-actions/types';
26
26
  import { getRelativePosition } from 'chart.js/helpers';
27
+ import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRight';
28
+ import KeyboardArrowLeftIcon from '@mui/icons-material/KeyboardArrowLeft';
27
29
  function findIndexForX(arr, t) {
28
30
  if (!arr || arr.length === 0)
29
31
  return -1;
@@ -675,6 +677,20 @@ const TrendChart = ({ filter, measures1, annotationsDataFn, measures2, enableDat
675
677
  }
676
678
  });
677
679
  };
680
+ const shiftChart = ((timeToShift) => {
681
+ setChartLoading(true);
682
+ const timeInRange = timeEnd - timeStart;
683
+ const percentageToShift = 0.1; // 10%
684
+ const shiftAmount = Math.floor(timeInRange * percentageToShift);
685
+ if (timeToShift === 'timeStart') {
686
+ setTimeStart(prev => prev - shiftAmount);
687
+ setTimeEnd(prev => prev - shiftAmount);
688
+ }
689
+ else {
690
+ setTimeEnd(prev => prev + shiftAmount);
691
+ setTimeStart(prev => prev + shiftAmount);
692
+ }
693
+ });
678
694
  useEffect(() => {
679
695
  const timeDifference = Math.abs(moment(timeEnd).valueOf() - moment(timeStart).valueOf()); // Convert milliseconds to seconds
680
696
  let newChartPeriod = '1D'; // Default to 1 day
@@ -755,7 +771,7 @@ const TrendChart = ({ filter, measures1, annotationsDataFn, measures2, enableDat
755
771
  loadZoomPlugin();
756
772
  resetChart();
757
773
  }, []);
758
- const datePicker = _jsx(Box, { sx: { display: 'flex', alignItems: 'center', mr: { xs: 0, lg: 2 } }, children: _jsxs(LocalizationProvider, { dateAdapter: AdapterMoment, adapterLocale: "it", children: [_jsx(DateTimePicker, { value: moment(timeStartPicker * 1000), onChange: (newValue) => {
774
+ const datePicker = _jsx(Box, { sx: { display: 'flex', alignItems: 'center' }, children: _jsxs(LocalizationProvider, { dateAdapter: AdapterMoment, adapterLocale: "it", children: [_jsx(DateTimePicker, { value: moment(timeStartPicker * 1000), onChange: (newValue) => {
759
775
  setChartLoading(true);
760
776
  setDatePickerUsed(true);
761
777
  setZoomed(false);
@@ -772,11 +788,27 @@ const TrendChart = ({ filter, measures1, annotationsDataFn, measures2, enableDat
772
788
  }, minDateTime: moment(timeStart * 1000), slotProps: {
773
789
  textField: { size: 'small', sx: { width: { sm: 210 } } }
774
790
  } })] }) });
775
- return (_jsxs(ThemeProvider, { theme: theme, children: [enableDatePicker && _jsx(Box, { sx: { display: { xs: 'flex', lg: 'none', justifyContent: 'flex-end' }, mb: 2 }, children: datePicker }), _jsxs(Box, { sx: { display: 'flex', alignItems: 'center', justifyContent: 'space-between' }, children: [_jsxs(Box, { sx: { display: 'flex', alignItems: 'center' }, children: [!enableExportData && measures && measures.length === 1 ? _jsx(Typography, { variant: 'body1', sx: { mr: 2 }, children: measures[0].description || measures[0].name }) : '', enableExportData && (_jsxs(_Fragment, { children: [_jsxs(LoadingButton, { sx: { minWidth: '40px !important', mr: 1, px: 1 }, loading: loadingButton, type: "submit", variant: "text", color: "primary", onClick: handleExportData, disabled: !dataMeasures || !dataMeasures.length, size: 'small', children: [_jsx(LoginIcon, { fontSize: 'small', style: { transform: "rotate(90deg)" } }), _jsx(Box, { sx: { display: { xs: 'none', xl: 'block' }, ml: { md: 1 } }, children: "Export" })] }), _jsx(CSVLink
791
+ return (_jsxs(ThemeProvider, { theme: theme, children: [_jsxs(Box, { sx: { display: { xs: 'flex', lg: 'none', justifyContent: 'center' }, alignItems: 'center', mb: 3, mt: 1 }, children: [_jsx(Button, { sx: {
792
+ borderWidth: 1,
793
+ borderStyle: 'solid',
794
+ borderColor: '#c4c4c4',
795
+ color: 'text.primary',
796
+ ":hover": { backgroundColor: 'action.hover' },
797
+ mr: enableDatePicker ? 1 : 0,
798
+ p: 0.85
799
+ }, onClick: () => shiftChart('timeStart'), children: _jsx(KeyboardArrowLeftIcon, {}) }), enableDatePicker && _jsx(Box, { sx: { display: { xs: 'flex', lg: 'none', justifyContent: 'flex-end' } }, children: datePicker }), _jsx(Button, { sx: {
800
+ borderWidth: 1,
801
+ borderStyle: 'solid',
802
+ borderColor: '#c4c4c4',
803
+ color: 'text.primary',
804
+ ":hover": { backgroundColor: 'action.hover' },
805
+ ml: enableDatePicker ? 1 : 0,
806
+ p: 0.85
807
+ }, onClick: () => shiftChart('timeEnd'), children: _jsx(KeyboardArrowRightIcon, {}) })] }), _jsxs(Box, { sx: { display: 'flex', alignItems: 'center', justifyContent: 'space-between' }, children: [_jsxs(Box, { sx: { display: 'flex', alignItems: 'center' }, children: [!enableExportData && measures && measures.length === 1 ? _jsx(Typography, { variant: 'body1', sx: { mr: 2 }, children: measures[0].description || measures[0].name }) : '', enableExportData && (_jsxs(_Fragment, { children: [_jsxs(LoadingButton, { sx: { minWidth: '40px !important', mr: 1, px: 1 }, loading: loadingButton, type: "submit", variant: "text", color: "primary", onClick: handleExportData, disabled: !dataMeasures || !dataMeasures.length, size: 'small', children: [_jsx(LoginIcon, { fontSize: 'small', style: { transform: "rotate(90deg)" } }), _jsx(Box, { sx: { display: { xs: 'none', xl: 'block' }, ml: { md: 1 } }, children: "Export" })] }), _jsx(CSVLink
776
808
  //@ts-ignore
777
809
  , {
778
810
  //@ts-ignore
779
- ref: csvLinkRef, data: csvData, filename: `export_${moment().toISOString()}.csv`, separator: ';' })] })), zoomed && measures.length > 0 && (_jsxs(Button, { sx: { minWidth: '40px !important', boxShadow: 1, px: 1 }, variant: "contained", color: "secondary", size: 'small', onClick: () => {
811
+ ref: csvLinkRef, data: csvData, filename: `export_${moment().toISOString()}.csv`, separator: ';' })] })), zoomed && measures.length > 0 && (_jsx(Button, { sx: { minWidth: '40px !important', boxShadow: 1, p: 1, mr: 1 }, variant: "contained", color: "primary", size: 'small', onClick: () => {
780
812
  setChartLoading(true);
781
813
  setZoomed(false);
782
814
  if (chartPeriod === "ALL") {
@@ -798,7 +830,23 @@ const TrendChart = ({ filter, measures1, annotationsDataFn, measures2, enableDat
798
830
  : moment().subtract(1, 'day').unix());
799
831
  setTimeEnd(moment().unix());
800
832
  }
801
- }, children: [_jsx(ZoomOut, { fontSize: 'small' }), _jsx(Box, { sx: { display: { xs: 'none', lg: 'block' }, ml: { md: 1 } }, children: "Reset" })] }))] }), _jsxs(Box, { sx: { display: 'flex', justifyContent: 'flex-end' }, children: [enableDatePicker && _jsx(Box, { sx: { display: { xs: 'none', lg: 'flex' } }, children: datePicker }), _jsxs(ToggleButtonGroup, { color: "primary", value: !datePickerUsed && !zoomed ? chartPeriod : null, exclusive: true, onChange: handleChange, size: "small", sx: {
833
+ }, children: _jsx(ZoomOut, { fontSize: 'small' }) }))] }), _jsxs(Box, { sx: { display: 'flex', justifyContent: 'flex-end' }, children: [_jsxs(Box, { sx: { display: { xs: 'none', lg: 'flex' }, alignItems: 'center', mr: 1 }, children: [_jsx(Button, { sx: {
834
+ borderWidth: 1,
835
+ borderStyle: 'solid',
836
+ borderColor: '#c4c4c4',
837
+ color: 'text.primary',
838
+ ":hover": { backgroundColor: 'action.hover' },
839
+ mr: enableDatePicker ? 1 : 0,
840
+ p: 0.85
841
+ }, onClick: () => shiftChart('timeStart'), children: _jsx(KeyboardArrowLeftIcon, {}) }), enableDatePicker && _jsx(Box, { sx: { display: { xs: 'none', lg: 'flex' } }, children: datePicker }), _jsx(Button, { sx: {
842
+ borderWidth: 1,
843
+ borderStyle: 'solid',
844
+ borderColor: '#c4c4c4',
845
+ color: 'text.primary',
846
+ ":hover": { backgroundColor: 'action.hover' },
847
+ ml: 1,
848
+ p: 0.85
849
+ }, onClick: () => shiftChart('timeEnd'), children: _jsx(KeyboardArrowRightIcon, {}) })] }), _jsxs(ToggleButtonGroup, { color: "primary", value: !datePickerUsed && !zoomed ? chartPeriod : null, exclusive: true, onChange: handleChange, size: "small", sx: {
802
850
  '& .MuiToggleButton-root': {
803
851
  color: 'text.primary', fontSize: '0.95rem', fontWeight: 'normal', paddingTop: '6px', paddingBottom: '6px'
804
852
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iotready/nextjs-components-library",
3
- "version": "1.0.0-preview29",
3
+ "version": "1.0.0-preview30",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "build": "rm -rf dist && tsc --project tsconfig.build.json && cp package.json dist/",
@@ -2,7 +2,7 @@ import { FilterTagMode, InfluxConfig, InfluxFillType } from "./types";
2
2
  export declare function getInfluxAlerts(influxConfig: InfluxConfig, fields: string[], limit: number, offset: number, sort: any, filter: {
3
3
  field: string;
4
4
  value: string;
5
- }, timeStart: number, timeEnd: number): Promise<any>;
5
+ }, timeStart: number, timeEnd: number, aggregate?: boolean): Promise<any>;
6
6
  export declare function getDwSlots(influxConfig: InfluxConfig, timeStart: number, timeEnd: number, filter: {
7
7
  field: string;
8
8
  value: string;
@@ -2,7 +2,7 @@
2
2
  import { parse } from "csv-parse";
3
3
  import moment from "moment";
4
4
  import { FilterTagMode } from "./types";
5
- export async function getInfluxAlerts(influxConfig, fields, limit, offset, sort, filter, timeStart, timeEnd) {
5
+ export async function getInfluxAlerts(influxConfig, fields, limit, offset, sort, filter, timeStart, timeEnd, aggregate = false) {
6
6
  const conditions = fields
7
7
  .map((field) => `r["valueName"] == "${field}"`)
8
8
  .join(" or ");
@@ -14,15 +14,20 @@ export async function getInfluxAlerts(influxConfig, fields, limit, offset, sort,
14
14
  }
15
15
  query += `
16
16
  |> filter(fn: (r) => r["_measurement"] == "${influxConfig.measurement}" and r["${filter.field}"] == "${filter.value}" and (${conditions}))
17
- `;
18
- // Add filter for tag d === 3
19
- query += `
20
17
  |> filter(fn: (r) => r["d"] == "3" or r["d"] !~ /./) // Include only events with tag d == 3 or no tag d
21
- `;
22
- const queryCount = `${query} |> group() |> count()`;
23
- query += `
24
18
  |> sort(columns: ["_time"]) // Ordina gli eventi cronologicamente
25
19
  |> group(columns: ["valueName"]) // Raggruppa per il tag
20
+ `;
21
+ if (aggregate) {
22
+ // Aggregate same consecutive values
23
+ query += `
24
+ |> duplicate(column: "_value", as: "prev_value")
25
+ |> difference(columns: ["prev_value"], keepFirst: true)
26
+ |> filter(fn: (r) => r.prev_value != 0 or not exists r.prev_value)
27
+ `;
28
+ }
29
+ const queryCount = `${query} |> group() |> count()`;
30
+ query += `
26
31
  |> events.duration(unit: 1s, stop: 2020-01-02T00:00:00Z)
27
32
  |> keep(columns: ["_time", "valueName", "_value", "duration"])
28
33
  |> group() // Raggruppa tutti i dati in un unico gruppo
@@ -74,7 +79,7 @@ export async function getInfluxAlerts(influxConfig, fields, limit, offset, sort,
74
79
  });
75
80
  });
76
81
  const parsedCount = count.split("\n")[1].split(",");
77
- let countData = parsedCount[5];
82
+ let countData = parsedCount[3];
78
83
  return {
79
84
  data: rows,
80
85
  count: countData