@iotready/nextjs-components-library 1.0.0-preview22 → 1.0.0-preview24
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/components/charts/TrendChart.js +8 -20
- package/package.json +2 -2
- package/server-actions/annotations.d.ts +2 -2
- package/server-actions/annotations.js +7 -10
- package/server-actions/groups.d.ts +9 -9
- package/server-actions/groups.js +59 -72
- package/server-actions/influx.js +2 -2
- package/server-actions/types.d.ts +0 -8
|
@@ -21,6 +21,7 @@ import { ThemeProvider } from '@mui/material/styles';
|
|
|
21
21
|
import TimelineIcon from '@mui/icons-material/Timeline';
|
|
22
22
|
import MuiTooltip from '@mui/material/Tooltip';
|
|
23
23
|
import EditNoteIcon from '@mui/icons-material/EditNote';
|
|
24
|
+
// import AspectRatioIcon from '@mui/icons-material/AspectRatio';
|
|
24
25
|
import { FilterTagMode } from '../../server-actions/types';
|
|
25
26
|
const lineOptions = {
|
|
26
27
|
parsing: false,
|
|
@@ -126,15 +127,6 @@ const chartConfigByPeriod = {
|
|
|
126
127
|
scaleUnit: 'year',
|
|
127
128
|
}
|
|
128
129
|
};
|
|
129
|
-
// function getChartPoints(data: any): Point[] {
|
|
130
|
-
// const points: Point[] = data.results[0].series[0].values.map((row: any) => {
|
|
131
|
-
// return {
|
|
132
|
-
// x: moment.unix(row[0]),
|
|
133
|
-
// y: row[1]
|
|
134
|
-
// }
|
|
135
|
-
// });
|
|
136
|
-
// return points;
|
|
137
|
-
// }
|
|
138
130
|
function getPollTime(intervalInSeconds, pollTime) {
|
|
139
131
|
const CalculatedPollTime = Math.round(intervalInSeconds / 2880);
|
|
140
132
|
if (CalculatedPollTime <= pollTime) {
|
|
@@ -196,7 +188,7 @@ const TrendChart = ({ deviceId, measures1, annotationsDataFn, measures2, enableD
|
|
|
196
188
|
const [chartJsLoaded, setChartJsLoaded] = useState(false);
|
|
197
189
|
// Dichiarazione di annotationsData come funzione che ritorna una Promise<any>
|
|
198
190
|
const [annotationsData, setAnnotationsData] = useState([]);
|
|
199
|
-
const [
|
|
191
|
+
const [annotationsEnabled, setAnnotationsEnabled] = useState(true);
|
|
200
192
|
const [dataMeasures, setDataMeasures] = useState(null);
|
|
201
193
|
const [chartPeriod, setChartPeriod] = useState('1D');
|
|
202
194
|
const [chartPeriodConfig, setChartPeriodConfig] = useState(chartConfigByPeriod['1D']);
|
|
@@ -318,13 +310,13 @@ const TrendChart = ({ deviceId, measures1, annotationsDataFn, measures2, enableD
|
|
|
318
310
|
}
|
|
319
311
|
}, [csvData]);
|
|
320
312
|
useEffect(() => {
|
|
321
|
-
if (annotationsDataFn &&
|
|
313
|
+
if (annotationsDataFn && annotationsEnabled) {
|
|
322
314
|
(async () => {
|
|
323
315
|
const resp = await annotationsDataFn();
|
|
324
316
|
setAnnotationsData(resp);
|
|
325
317
|
})();
|
|
326
318
|
}
|
|
327
|
-
}, [annotationsDataFn,
|
|
319
|
+
}, [annotationsDataFn, annotationsEnabled]);
|
|
328
320
|
function getDwSlotsFromValues(dwValues) {
|
|
329
321
|
const slots = [];
|
|
330
322
|
let start = null;
|
|
@@ -368,11 +360,7 @@ const TrendChart = ({ deviceId, measures1, annotationsDataFn, measures2, enableD
|
|
|
368
360
|
dwPoints = rawDwPoints;
|
|
369
361
|
}
|
|
370
362
|
}
|
|
371
|
-
const
|
|
372
|
-
// Mappa sul formato Point
|
|
373
|
-
const stdPoints = stdRaw
|
|
374
|
-
.map((r) => ({ x: Number(r.x), y: r.y }))
|
|
375
|
-
.filter((p) => p.y !== null);
|
|
363
|
+
const stdPoints = await handleGetInfluxData(measure.name, timeStart, timeEnd, deviceId, polltime, !measure.polltime && rawQuery, !measure.polltime ? "none" : "null", 100, FilterTagMode.Exclude);
|
|
376
364
|
const filtered = dwSlots.length
|
|
377
365
|
? stdPoints.filter((p) => !dwSlots.some(slot => p.x >= slot.start && p.x <= slot.end))
|
|
378
366
|
: stdPoints;
|
|
@@ -443,7 +431,7 @@ const TrendChart = ({ deviceId, measures1, annotationsDataFn, measures2, enableD
|
|
|
443
431
|
const { paddedMin: paddedMin2, paddedMax: paddedMax2 } = getPaddedMinMax(min2, max2);
|
|
444
432
|
// Handle undefined/null annotationsData
|
|
445
433
|
let dynamicAnnotations = {};
|
|
446
|
-
if (Array.isArray(annotationsData) && annotationsData.length > 0 &&
|
|
434
|
+
if (Array.isArray(annotationsData) && annotationsData.length > 0 && annotationsEnabled) {
|
|
447
435
|
dynamicAnnotations = annotationsData.reduce((acc, [timestamp, label], index) => {
|
|
448
436
|
const yVal = paddedMin1 !== null && paddedMin1 !== undefined
|
|
449
437
|
? paddedMin1 + 0.01 * (paddedMax1 - paddedMin1)
|
|
@@ -579,7 +567,7 @@ const TrendChart = ({ deviceId, measures1, annotationsDataFn, measures2, enableD
|
|
|
579
567
|
loadDatasets(chartPeriod).then(() => {
|
|
580
568
|
setChartLoading(false);
|
|
581
569
|
});
|
|
582
|
-
}, [measures1, timeEnd, timeStart, measures2,
|
|
570
|
+
}, [measures1, timeEnd, timeStart, measures2, annotationsEnabled, annotationsData]);
|
|
583
571
|
useEffect(() => {
|
|
584
572
|
const loadZoomPlugin = async () => {
|
|
585
573
|
const zoomPlugin = (await import('chartjs-plugin-zoom')).default;
|
|
@@ -671,7 +659,7 @@ const TrendChart = ({ deviceId, measures1, annotationsDataFn, measures2, enableD
|
|
|
671
659
|
'& .MuiToggleButton-root': {
|
|
672
660
|
color: 'text.primary', fontSize: '0.95rem', fontWeight: 'normal', paddingTop: '6px', paddingBottom: '6px'
|
|
673
661
|
}
|
|
674
|
-
}, disabled: chartLoading, children: [_jsx(ToggleButton, { value: "1D", sx: { px: 1 }, children: "1d" }), _jsx(ToggleButton, { value: "1W", sx: { px: 1 }, children: "1w" }), _jsx(ToggleButton, { value: "1M", sx: { px: 1 }, children: "1M" }), _jsx(ToggleButton, { value: "3M", sx: { px: 1 }, children: "3M" }), _jsx(ToggleButton, { value: "6M", sx: { px: 1 }, children: "6M" }), _jsx(ToggleButton, { value: "1Y", sx: { px: 1 }, children: "1Y" }), _jsx(ToggleButton, { value: "ALL", sx: { px: 1 }, children: "ALL" })] }), _jsx(MuiTooltip, { placement: "top", arrow: true, title: "Connect point values", children: _jsx(ToggleButton, { value: "check", color: "primary", size: "small", selected: spanGapsOption, disabled: chartLoading, onChange: () => handleSpanGaps(!spanGapsOption), sx: { ml: 1 }, children: _jsx(TimelineIcon, {}) }) }), annotationsData !== undefined && (_jsx(MuiTooltip, { placement: "top", arrow: true, title: "Show annotations", children: _jsx(ToggleButton, { value: "check", color: "primary", size: "small", selected:
|
|
662
|
+
}, disabled: chartLoading, children: [_jsx(ToggleButton, { value: "1D", sx: { px: 1 }, children: "1d" }), _jsx(ToggleButton, { value: "1W", sx: { px: 1 }, children: "1w" }), _jsx(ToggleButton, { value: "1M", sx: { px: 1 }, children: "1M" }), _jsx(ToggleButton, { value: "3M", sx: { px: 1 }, children: "3M" }), _jsx(ToggleButton, { value: "6M", sx: { px: 1 }, children: "6M" }), _jsx(ToggleButton, { value: "1Y", sx: { px: 1 }, children: "1Y" }), _jsx(ToggleButton, { value: "ALL", sx: { px: 1 }, children: "ALL" })] }), _jsx(MuiTooltip, { placement: "top", arrow: true, title: "Connect point values", children: _jsx("span", { children: _jsx(ToggleButton, { value: "check", color: "primary", size: "small", selected: spanGapsOption, disabled: chartLoading, onChange: () => handleSpanGaps(!spanGapsOption), sx: { ml: 1 }, children: _jsx(TimelineIcon, {}) }) }) }), annotationsData !== undefined && (_jsx(MuiTooltip, { placement: "top", arrow: true, title: "Show annotations", children: _jsx("span", { children: _jsx(ToggleButton, { value: "check", color: "primary", size: "small", selected: annotationsEnabled, disabled: chartLoading, onChange: () => setAnnotationsEnabled(!annotationsEnabled), sx: { ml: 1 }, children: _jsx(EditNoteIcon, {}) }) }) }))] })] }), _jsx(Box, { component: 'div', className: "chart-container", sx: { mt: 2, height: '100%' }, children: chartJsLoaded && !chartLoading && typeof window !== 'undefined' ?
|
|
675
663
|
_jsx(_Fragment, { children: dataMeasures && (dataMeasures.length > 1 || (dataMeasures.length === 1 && dataMeasures[0].data?.length)) ?
|
|
676
664
|
(_jsx(Line, { options: options, data: {
|
|
677
665
|
// datasets: dataMeasures || [{ data: [] }]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iotready/nextjs-components-library",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-preview24",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "rm -rf dist && tsc --project tsconfig.build.json && cp package.json dist/",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"chartjs-plugin-annotation": "^3.1.0",
|
|
21
21
|
"chartjs-plugin-zoom": "^2.0.1",
|
|
22
22
|
"csv-parse": "^5.6.0",
|
|
23
|
-
"firebase": "^
|
|
23
|
+
"firebase-admin": "^13.4.0",
|
|
24
24
|
"leaflet": "^1.9.4",
|
|
25
25
|
"leaflet-defaulticon-compatibility": "^0.1.2",
|
|
26
26
|
"material-ui-confirm": "^3.0.16",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const getAnnotations: (
|
|
1
|
+
import { Firestore } from "firebase-admin/firestore";
|
|
2
|
+
export declare const getAnnotations: (db: Firestore, deviceID: number) => Promise<{
|
|
3
3
|
id: string;
|
|
4
4
|
}[]>;
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use server";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const annotationsQuery = query(collection(db, "annotations"), where("target", "==", deviceID), orderBy("createdAt", "desc"));
|
|
10
|
-
const groupsSnapshot = await getDocs(annotationsQuery);
|
|
11
|
-
return groupsSnapshot.docs.map((doc) => ({
|
|
2
|
+
export const getAnnotations = async (db, deviceID) => {
|
|
3
|
+
const annotationsRef = db.collection("annotations");
|
|
4
|
+
const snapshot = await annotationsRef
|
|
5
|
+
.where("target", "==", deviceID)
|
|
6
|
+
.orderBy("createdAt", "desc")
|
|
7
|
+
.get();
|
|
8
|
+
return snapshot.docs.map((doc) => ({
|
|
12
9
|
id: doc.id,
|
|
13
10
|
...doc.data()
|
|
14
11
|
}));
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const getGroups: (
|
|
1
|
+
import { Firestore } from "firebase-admin/firestore";
|
|
2
|
+
export declare const getGroups: (db: Firestore, productID: number, userID?: string) => Promise<{
|
|
3
3
|
id: string;
|
|
4
4
|
}[]>;
|
|
5
|
-
export declare const getGroupById: (
|
|
5
|
+
export declare const getGroupById: (db: Firestore, id: string) => Promise<{
|
|
6
6
|
id: string;
|
|
7
7
|
}>;
|
|
8
|
-
export declare const createGroup: (
|
|
9
|
-
export declare const updateGroup: (
|
|
10
|
-
export declare const deleteGroup: (
|
|
11
|
-
export declare const getUsersGroup: (
|
|
8
|
+
export declare const createGroup: (db: Firestore, group: any) => Promise<string>;
|
|
9
|
+
export declare const updateGroup: (db: Firestore, id: string, group: any) => Promise<any>;
|
|
10
|
+
export declare const deleteGroup: (db: Firestore, id: string) => Promise<void>;
|
|
11
|
+
export declare const getUsersGroup: (db: Firestore, groupID: string) => Promise<{
|
|
12
12
|
id: string;
|
|
13
13
|
}[]>;
|
|
14
|
-
export declare const addUsersGroup: (
|
|
15
|
-
export declare const removeUserGroup: (
|
|
14
|
+
export declare const addUsersGroup: (db: Firestore, groupID: string, userName: string, userID: string) => Promise<string>;
|
|
15
|
+
export declare const removeUserGroup: (db: Firestore, groupID: string, userID: string) => Promise<string | undefined>;
|
package/server-actions/groups.js
CHANGED
|
@@ -1,87 +1,74 @@
|
|
|
1
1
|
"use server";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const db = getFirestore(app);
|
|
9
|
-
const groupsQuery = query(collection(db, "groups"), where("productID", "==", productID), orderBy("created", "desc"));
|
|
2
|
+
// 1. GET GROUPS
|
|
3
|
+
export const getGroups = async (db, productID, userID) => {
|
|
4
|
+
const groupsRef = db
|
|
5
|
+
.collection("groups")
|
|
6
|
+
.where("productID", "==", productID)
|
|
7
|
+
.orderBy("created", "desc");
|
|
10
8
|
let groupIds = null;
|
|
11
9
|
if (userID) {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
const userGroupsSnapshot = await db
|
|
11
|
+
.collection("userGroups")
|
|
12
|
+
.where("user.userId", "==", userID)
|
|
13
|
+
.get();
|
|
14
|
+
groupIds = userGroupsSnapshot.docs.map((doc) => doc.data().groupId);
|
|
15
15
|
}
|
|
16
|
-
const groupsSnapshot = await
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
.map((doc) => ({
|
|
21
|
-
id: doc.id,
|
|
22
|
-
...doc.data()
|
|
23
|
-
}));
|
|
24
|
-
}
|
|
25
|
-
return groupsSnapshot.docs.map((doc) => ({
|
|
16
|
+
const groupsSnapshot = await groupsRef.get();
|
|
17
|
+
return groupsSnapshot.docs
|
|
18
|
+
.filter((doc) => !groupIds || groupIds.includes(doc.id))
|
|
19
|
+
.map((doc) => ({
|
|
26
20
|
id: doc.id,
|
|
27
21
|
...doc.data()
|
|
28
22
|
}));
|
|
29
23
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
const groupSnapshot = await getDoc(doc(db, "groups", id));
|
|
24
|
+
// 2. GET GROUP BY ID
|
|
25
|
+
export const getGroupById = async (db, id) => {
|
|
26
|
+
const docSnapshot = await db.collection("groups").doc(id).get();
|
|
34
27
|
return {
|
|
35
|
-
id:
|
|
36
|
-
...
|
|
28
|
+
id: docSnapshot.id,
|
|
29
|
+
...docSnapshot.data()
|
|
37
30
|
};
|
|
38
31
|
};
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
// 3. CREATE GROUP
|
|
33
|
+
export const createGroup = async (db, group) => {
|
|
41
34
|
const newGroup = {
|
|
42
35
|
...group,
|
|
43
|
-
created
|
|
36
|
+
created: new Date().toISOString()
|
|
44
37
|
};
|
|
45
|
-
const
|
|
46
|
-
const db = getFirestore(app);
|
|
47
|
-
const docRef = await addDoc(collection(db, "groups"), newGroup);
|
|
38
|
+
const docRef = await db.collection("groups").add(newGroup);
|
|
48
39
|
return docRef.id;
|
|
49
40
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const groupRef = doc(db, "groups", id);
|
|
54
|
-
await updateDoc(groupRef, group);
|
|
41
|
+
// 4. UPDATE GROUP
|
|
42
|
+
export const updateGroup = async (db, id, group) => {
|
|
43
|
+
await db.collection("groups").doc(id).update(group);
|
|
55
44
|
return group;
|
|
56
45
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
46
|
+
// 5. DELETE GROUP
|
|
47
|
+
export const deleteGroup = async (db, id) => {
|
|
48
|
+
const userGroupsSnapshot = await db
|
|
49
|
+
.collection("userGroups")
|
|
50
|
+
.where("groupId", "==", id)
|
|
51
|
+
.get();
|
|
52
|
+
const batch = db.batch();
|
|
53
|
+
userGroupsSnapshot.docs.forEach((doc) => {
|
|
54
|
+
batch.delete(doc.ref);
|
|
65
55
|
});
|
|
66
|
-
|
|
67
|
-
await
|
|
56
|
+
batch.delete(db.collection("groups").doc(id));
|
|
57
|
+
await batch.commit();
|
|
68
58
|
};
|
|
69
|
-
// USERS
|
|
70
|
-
export const getUsersGroup = async (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return groupsSnapshot.docs.map((doc) => ({
|
|
59
|
+
// 6. GET USERS GROUP
|
|
60
|
+
export const getUsersGroup = async (db, groupID) => {
|
|
61
|
+
const snapshot = await db
|
|
62
|
+
.collection("userGroups")
|
|
63
|
+
.where("groupId", "==", groupID)
|
|
64
|
+
.get();
|
|
65
|
+
return snapshot.docs.map((doc) => ({
|
|
77
66
|
id: doc.id,
|
|
78
67
|
...doc.data()
|
|
79
68
|
}));
|
|
80
69
|
};
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const app = initializeApp(firebaseConfig);
|
|
84
|
-
const db = getFirestore(app);
|
|
70
|
+
// 7. ADD USER TO GROUP
|
|
71
|
+
export const addUsersGroup = async (db, groupID, userName, userID) => {
|
|
85
72
|
const created = new Date().toISOString();
|
|
86
73
|
const newUserGroup = {
|
|
87
74
|
user: {
|
|
@@ -91,19 +78,19 @@ export const addUsersGroup = async (firebaseConfig, groupID, userName, userID) =
|
|
|
91
78
|
groupId: groupID,
|
|
92
79
|
created
|
|
93
80
|
};
|
|
94
|
-
const docRef = await
|
|
81
|
+
const docRef = await db.collection("userGroups").add(newUserGroup);
|
|
95
82
|
return docRef.id;
|
|
96
83
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
await
|
|
107
|
-
return
|
|
84
|
+
// 8. REMOVE USER FROM GROUP
|
|
85
|
+
export const removeUserGroup = async (db, groupID, userID) => {
|
|
86
|
+
const snapshot = await db
|
|
87
|
+
.collection("userGroups")
|
|
88
|
+
.where("groupId", "==", groupID)
|
|
89
|
+
.where("user.userId", "==", userID)
|
|
90
|
+
.get();
|
|
91
|
+
const doc = snapshot.docs[0];
|
|
92
|
+
if (doc) {
|
|
93
|
+
await doc.ref.delete();
|
|
94
|
+
return doc.id;
|
|
108
95
|
}
|
|
109
96
|
};
|
package/server-actions/influx.js
CHANGED
|
@@ -155,7 +155,7 @@ export async function getInfluxDataV1(influxConfig, field, timeStart, timeEnd, d
|
|
|
155
155
|
query += ` fill(null)`;
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
-
if (fill) {
|
|
158
|
+
if (fill !== "null") {
|
|
159
159
|
// Query to get the last data point before timeStart
|
|
160
160
|
const preStartQuery = `SELECT last("value") FROM "${influxConfig.measurement}" WHERE "deviceid" = '${deviceID}' AND "valueName" = '${field}'${filterTagCondition} AND time < '${moment
|
|
161
161
|
.unix(timeStart)
|
|
@@ -196,7 +196,7 @@ export async function getInfluxDataV1(influxConfig, field, timeStart, timeEnd, d
|
|
|
196
196
|
series.name = field; // Force the series name to be the field name
|
|
197
197
|
});
|
|
198
198
|
// 1000000 REMOVED AND ADDED TO MOVE THE POINT AWAY IN THE CHART
|
|
199
|
-
if (fill) {
|
|
199
|
+
if (fill !== "null") {
|
|
200
200
|
if (preStartValue !== null && preStartValue !== undefined) {
|
|
201
201
|
// Insert the pre-start value at the beginning of the dataset
|
|
202
202
|
data.results[0].series[0].values.unshift([
|