@iotready/nextjs-components-library 1.0.0-preview5 → 1.0.0-preview7
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.
@@ -222,6 +222,7 @@ const TrendChart = ({ deviceId, measures, enableExportData, enableDatePicker, ha
|
|
222
222
|
}
|
223
223
|
});
|
224
224
|
const [zoomed, setZoomed] = useState(false);
|
225
|
+
const prevMeasures = useRef();
|
225
226
|
const resetChart = () => {
|
226
227
|
setOptions({
|
227
228
|
...options,
|
@@ -245,6 +246,7 @@ const TrendChart = ({ deviceId, measures, enableExportData, enableDatePicker, ha
|
|
245
246
|
setSpanGapsOption(spanG);
|
246
247
|
};
|
247
248
|
const handleChange = (event, newPeriod) => {
|
249
|
+
setChartLoading(true);
|
248
250
|
setZoomed(false);
|
249
251
|
setDatePickerUsed(false);
|
250
252
|
setCsvData('');
|
@@ -277,7 +279,6 @@ const TrendChart = ({ deviceId, measures, enableExportData, enableDatePicker, ha
|
|
277
279
|
}
|
278
280
|
}, [csvData]);
|
279
281
|
const loadDatasets = async (chartPeriod) => {
|
280
|
-
setChartLoading(true);
|
281
282
|
let intervalInSeconds = chartPeriod === "ALL" && !datePickerUsed && !zoomed ? 31536000 : timeEnd - timeStart;
|
282
283
|
const rawQuery = intervalInSeconds < 86400; //
|
283
284
|
// Inizializza un array di promesse per ottenere i dati per ciascuna misura
|
@@ -293,7 +294,7 @@ const TrendChart = ({ deviceId, measures, enableExportData, enableDatePicker, ha
|
|
293
294
|
pointRadius: 1,
|
294
295
|
pointHoverRadius: 5,
|
295
296
|
pointHoverBackgroundColor: 'rgba(52, 125, 236, 0.5)',
|
296
|
-
|
297
|
+
change: !measure.polltime,
|
297
298
|
fill: false
|
298
299
|
};
|
299
300
|
});
|
@@ -368,10 +369,17 @@ const TrendChart = ({ deviceId, measures, enableExportData, enableDatePicker, ha
|
|
368
369
|
newChartPeriod = '1Y'; // Set to 1 year
|
369
370
|
}
|
370
371
|
setChartPeriodConfig(chartConfigByPeriod[newChartPeriod]);
|
372
|
+
// check prev measures value in order to show the loader
|
373
|
+
// hide the loader if measure is the same (for interval get measure value)
|
374
|
+
const prevMeasuresValue = prevMeasures.current;
|
375
|
+
prevMeasures.current = measures;
|
376
|
+
if (!prevMeasuresValue || prevMeasuresValue.length !== measures.length || (prevMeasuresValue[0] && prevMeasuresValue[0].name !== measures[0].name)) {
|
377
|
+
setChartLoading(true);
|
378
|
+
}
|
371
379
|
loadDatasets(chartPeriod).then(() => {
|
372
380
|
setChartLoading(false);
|
373
381
|
});
|
374
|
-
}, [timeEnd, timeStart]);
|
382
|
+
}, [measures, timeEnd, timeStart]);
|
375
383
|
useEffect(() => {
|
376
384
|
const loadZoomPlugin = async () => {
|
377
385
|
const zoomPlugin = (await import('chartjs-plugin-zoom')).default;
|
@@ -401,6 +409,7 @@ const TrendChart = ({ deviceId, measures, enableExportData, enableDatePicker, ha
|
|
401
409
|
resetChart();
|
402
410
|
}, []);
|
403
411
|
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) => {
|
412
|
+
setChartLoading(true);
|
404
413
|
setDatePickerUsed(true);
|
405
414
|
setZoomed(false);
|
406
415
|
setPickerTimeStart(moment(newValue).unix());
|
@@ -408,6 +417,7 @@ const TrendChart = ({ deviceId, measures, enableExportData, enableDatePicker, ha
|
|
408
417
|
}, maxDateTime: moment(timeEnd * 1000), slotProps: {
|
409
418
|
textField: { size: 'small', sx: { width: { sm: 210 } } }
|
410
419
|
} }), " \u00A0\u00A0 ", _jsx(Box, { children: "\u2013" }), " \u00A0\u00A0", _jsx(DateTimePicker, { value: moment(timeEnd * 1000), onChange: (newValue) => {
|
420
|
+
setChartLoading(true);
|
411
421
|
setDatePickerUsed(true);
|
412
422
|
setZoomed(false);
|
413
423
|
setPickerTimeEnd(moment(newValue).unix());
|
@@ -420,6 +430,7 @@ const TrendChart = ({ deviceId, measures, enableExportData, enableDatePicker, ha
|
|
420
430
|
, {
|
421
431
|
//@ts-ignore
|
422
432
|
ref: csvLinkRef, data: csvData, filename: `export_${moment().toISOString()}.csv`, separator: ';' })] })), zoomed && (_jsxs(Button, { sx: { minWidth: '40px !important', boxShadow: 1, px: 1 }, variant: "contained", color: "secondary", size: 'small', onClick: () => {
|
433
|
+
setChartLoading(true);
|
423
434
|
setZoomed(false);
|
424
435
|
if (chartPeriod === "ALL") {
|
425
436
|
setDatePickerUsed(false);
|
@@ -446,6 +457,7 @@ const TrendChart = ({ deviceId, measures, enableExportData, enableDatePicker, ha
|
|
446
457
|
_jsx(_Fragment, { children: dataMeasures && dataMeasures[0]?.data?.length ?
|
447
458
|
(_jsx(Line, { options: options, data: {
|
448
459
|
datasets: dataMeasures || [{ data: [] }]
|
460
|
+
// datasets: dataMeasures.map(d => ({ ...d, showLine: spanGapsOption || !d.change })) || [{ data: [] }]
|
449
461
|
} })) : _jsxs(Box, { sx: {
|
450
462
|
display: 'flex',
|
451
463
|
flexDirection: 'column',
|
@@ -459,7 +471,7 @@ const TrendChart = ({ deviceId, measures, enableExportData, enableDatePicker, ha
|
|
459
471
|
alignItems: 'center',
|
460
472
|
justifyContent: 'center',
|
461
473
|
textAlign: 'center',
|
462
|
-
height: '100%'
|
474
|
+
height: 'calc(100% - 50px)'
|
463
475
|
}, children: _jsx(CircularProgress, {}) })) })] }));
|
464
476
|
};
|
465
477
|
export default TrendChart;
|
@@ -14,7 +14,7 @@ declare const GroupsDevices: ({ userInfo, handleGetUsersList, handleAddUserToGro
|
|
14
14
|
handleGetGroups: (productID: number, userInfo?: UserType) => Promise<any>;
|
15
15
|
handleGetUsersGroup: (groupID: string) => Promise<any>;
|
16
16
|
handleCreateGroup: (group: any) => Promise<any>;
|
17
|
-
handleGetDevices: (user: UserType,
|
17
|
+
handleGetDevices: (user: UserType, query: string) => Promise<any>;
|
18
18
|
handleGetPositions: (devices: any) => Promise<any>;
|
19
19
|
handleAddDevicesToGroup: (user: UserType, group: string, devicesToPatch: any[]) => Promise<any>;
|
20
20
|
handleRemoveDevicesFromGroup: (user: UserType, group: string, devicesToPatch: any[]) => Promise<any>;
|
@@ -73,7 +73,20 @@ const GroupsDevices = ({ userInfo, handleGetUsersList, handleAddUserToGroup, han
|
|
73
73
|
const fetchDevices = async (group, selected) => {
|
74
74
|
try {
|
75
75
|
setLoadingDevices(true);
|
76
|
-
|
76
|
+
let queryParams = "last_handshake_at!=null";
|
77
|
+
if (group !== "all") {
|
78
|
+
queryParams = `last_handshake_at!=null&state.groups=/${group}/`;
|
79
|
+
if (userInfo.role === "admin") {
|
80
|
+
queryParams += "&quarantined=false";
|
81
|
+
}
|
82
|
+
}
|
83
|
+
else if (selected !== "all") {
|
84
|
+
queryParams = `last_handshake_at!=null&state.groups!=/${selected}/`;
|
85
|
+
if (userInfo.role === "admin") {
|
86
|
+
queryParams += "&quarantined=false";
|
87
|
+
}
|
88
|
+
}
|
89
|
+
const devices = await handleGetDevices(userInfo, queryParams);
|
77
90
|
setDevices(devices);
|
78
91
|
if (enableMaps) {
|
79
92
|
const positions = await handleGetPositions(devices);
|
package/package.json
CHANGED
@@ -13,7 +13,7 @@ export declare function createCustomer(trackleConfig: TrackleConfig, uid: string
|
|
13
13
|
organization: string;
|
14
14
|
uid: string;
|
15
15
|
}>;
|
16
|
-
export declare function getDevices(trackleConfig: TrackleConfig, productId?: number, uid?: string,
|
16
|
+
export declare function getDevices(trackleConfig: TrackleConfig, productId?: number, uid?: string, query?: string): Promise<{
|
17
17
|
devices: any[];
|
18
18
|
}>;
|
19
19
|
export declare function getDevice(trackleConfig: TrackleConfig, id: string, productId?: number, uid?: string): Promise<{
|
@@ -55,25 +55,12 @@ export async function createCustomer(trackleConfig, uid) {
|
|
55
55
|
.post({ uid })
|
56
56
|
.json();
|
57
57
|
}
|
58
|
-
export async function getDevices(trackleConfig, productId, uid,
|
59
|
-
let queryParams = "last_handshake_at!=null";
|
60
|
-
if (group !== "all") {
|
61
|
-
queryParams = `last_handshake_at!=null&state.groups=/${group}/`;
|
62
|
-
if (!uid) {
|
63
|
-
queryParams += "&quarantined=false";
|
64
|
-
}
|
65
|
-
}
|
66
|
-
else if (selected !== "all") {
|
67
|
-
queryParams = `last_handshake_at!=null&state.groups!=/${selected}/`;
|
68
|
-
if (!uid) {
|
69
|
-
queryParams += "&quarantined=false";
|
70
|
-
}
|
71
|
-
}
|
58
|
+
export async function getDevices(trackleConfig, productId, uid, query) {
|
72
59
|
const api = uid ? wretchApi(trackleConfig, uid) : wretchApi(trackleConfig);
|
73
60
|
const response = await api
|
74
61
|
.get(uid
|
75
|
-
? `/devices
|
76
|
-
: `/products/${productId}/devices
|
62
|
+
? `/devices${query ? "?" + query : ""}`
|
63
|
+
: `/products/${productId}/devices${query ? "?" + query : ""}`)
|
77
64
|
.setTimeout(trackleConfig.apiTimeout)
|
78
65
|
.json();
|
79
66
|
return (uid ? { devices: response } : response);
|