@iotready/nextjs-components-library 1.0.0-preview26 → 1.0.0-preview27

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.
@@ -10,15 +10,27 @@ type Measure = {
10
10
  unit: string;
11
11
  stepped: boolean;
12
12
  };
13
- declare const TrendChart: ({ deviceId, measures1, annotationsDataFn, measures2, enableDatePicker, handleGetInfluxData, handleGetDwSlotsCB, handleExportDataCB, theme, initialTimeStart, initialTimeEnd }: {
14
- deviceId: string;
13
+ declare const TrendChart: ({ filter, measures1, annotationsDataFn, measures2, enableDatePicker, handleGetInfluxData, handleGetDwSlotsCB, handleExportDataCB, theme, initialTimeStart, initialTimeEnd }: {
14
+ filter: {
15
+ field: string;
16
+ value: string;
17
+ };
15
18
  annotationsDataFn?: () => Promise<any>;
16
19
  measures1?: Array<Measure>;
17
20
  measures2?: Array<Measure>;
18
21
  enableDatePicker: boolean;
19
- handleGetInfluxData: (measure: string, timeStart: number, timeEnd: number, deviceId: string, timeGroup: string, raw: boolean, fill?: InfluxFillType, filterTag?: number, includeTag?: FilterTagMode) => Promise<any>;
20
- handleGetDwSlotsCB?: (timeStart: number, timeEnd: number, deviceID: string) => Promise<any>;
21
- handleExportDataCB?: (measure: string, timeStart: number, timeEnd: number, deviceId: string) => Promise<any>;
22
+ handleGetInfluxData: (measure: string, timeStart: number, timeEnd: number, filter: {
23
+ field: string;
24
+ value: string;
25
+ }, timeGroup: string, raw: boolean, fill?: InfluxFillType, filterTag?: number, includeTag?: FilterTagMode) => Promise<any>;
26
+ handleGetDwSlotsCB?: (timeStart: number, timeEnd: number, filter: {
27
+ field: string;
28
+ value: string;
29
+ }) => Promise<any>;
30
+ handleExportDataCB?: (measure: string, timeStart: number, timeEnd: number, filter: {
31
+ field: string;
32
+ value: string;
33
+ }) => Promise<any>;
22
34
  theme: Theme;
23
35
  initialTimeStart?: number;
24
36
  initialTimeEnd?: number;
@@ -184,7 +184,7 @@ function getCsvData(data, measures) {
184
184
  .join('\n');
185
185
  }
186
186
  // eslint-disable-next-line no-unused-vars
187
- const TrendChart = ({ deviceId, measures1, annotationsDataFn, measures2, enableDatePicker, handleGetInfluxData, handleGetDwSlotsCB, handleExportDataCB, theme, initialTimeStart, initialTimeEnd }) => {
187
+ const TrendChart = ({ filter, measures1, annotationsDataFn, measures2, enableDatePicker, handleGetInfluxData, handleGetDwSlotsCB, handleExportDataCB, theme, initialTimeStart, initialTimeEnd }) => {
188
188
  const [chartJsLoaded, setChartJsLoaded] = useState(false);
189
189
  // Dichiarazione di annotationsData come funzione che ritorna una Promise<any>
190
190
  const [annotationsData, setAnnotationsData] = useState(null);
@@ -297,7 +297,7 @@ const TrendChart = ({ deviceId, measures1, annotationsDataFn, measures2, enableD
297
297
  setLoadingButton(true);
298
298
  if (handleExportDataCB) {
299
299
  const data = await Promise.all(measures.map(async (measure) => {
300
- return await handleExportDataCB(measure.name, timeStart, timeEnd, deviceId);
300
+ return await handleExportDataCB(measure.name, timeStart, timeEnd, filter);
301
301
  }));
302
302
  const csvData = getCsvData(data, measures);
303
303
  setCsvData(csvData);
@@ -336,7 +336,7 @@ const TrendChart = ({ deviceId, measures1, annotationsDataFn, measures2, enableD
336
336
  const rawQuery = intervalInSeconds < 86400;
337
337
  let tempSlots = [];
338
338
  if (handleGetDwSlotsCB) {
339
- const dwValues = await handleGetDwSlotsCB(timeStart, timeEnd, deviceId);
339
+ const dwValues = await handleGetDwSlotsCB(timeStart, timeEnd, filter);
340
340
  tempSlots = getDwSlotsFromValues(dwValues);
341
341
  }
342
342
  // Combine measures and track their source
@@ -351,7 +351,7 @@ const TrendChart = ({ deviceId, measures1, annotationsDataFn, measures2, enableD
351
351
  if (measure.dwPolltime) {
352
352
  const dwPolltime = getPollTime(intervalInSeconds, measure.dwPolltime);
353
353
  // Query DW solo tag=100
354
- const rawDwPoints = await handleGetInfluxData(measure.name, timeStart, timeEnd, deviceId, dwPolltime, false, "previous", 100, FilterTagMode.DW);
354
+ const rawDwPoints = await handleGetInfluxData(measure.name, timeStart, timeEnd, filter, dwPolltime, false, "previous", 100, FilterTagMode.DW);
355
355
  dwSlots = tempSlots;
356
356
  if (dwSlots.length > 0) {
357
357
  dwPoints = rawDwPoints.filter((p) => dwSlots.some(slot => p.x >= slot.start && p.x <= slot.end));
@@ -360,7 +360,7 @@ const TrendChart = ({ deviceId, measures1, annotationsDataFn, measures2, enableD
360
360
  dwPoints = rawDwPoints;
361
361
  }
362
362
  }
363
- const stdPoints = await handleGetInfluxData(measure.name, timeStart, timeEnd, deviceId, polltime, !measure.polltime && rawQuery, !measure.polltime ? "none" : "null", 100, FilterTagMode.Exclude);
363
+ const stdPoints = await handleGetInfluxData(measure.name, timeStart, timeEnd, filter, polltime, !measure.polltime && rawQuery, !measure.polltime ? "none" : "null", 100, FilterTagMode.Exclude);
364
364
  const filtered = dwSlots.length
365
365
  ? stdPoints.filter((p) => !dwSlots.some(slot => p.x >= slot.start && p.x <= slot.end))
366
366
  : stdPoints;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iotready/nextjs-components-library",
3
- "version": "1.0.0-preview26",
3
+ "version": "1.0.0-preview27",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "build": "rm -rf dist && tsc --project tsconfig.build.json && cp package.json dist/",
@@ -1,5 +1,17 @@
1
1
  import { FilterTagMode, InfluxConfig, InfluxFillType } from "./types";
2
- export declare function getInfluxAlerts(influxConfig: InfluxConfig, fields: string[], limit: number, offset: number, sort: any, deviceID: string, timeStart: number, timeEnd: number): Promise<any>;
3
- export declare function getDwSlots(influxConfig: InfluxConfig, timeStart: number, timeEnd: number, deviceID: string): Promise<any>;
4
- export declare function getInfluxDataV1(influxConfig: InfluxConfig, field: string, timeStart: number, timeEnd: number, deviceID: string, timeGroup: string, raw: boolean, fill?: InfluxFillType, filterTag?: number, tagInclude?: FilterTagMode): Promise<any>;
5
- export declare function exportDataV1(influxConfig: InfluxConfig, field: string, timeStart: number, timeEnd: number, deviceID: string): Promise<any>;
2
+ export declare function getInfluxAlerts(influxConfig: InfluxConfig, fields: string[], limit: number, offset: number, sort: any, filter: {
3
+ field: string;
4
+ value: string;
5
+ }, timeStart: number, timeEnd: number): Promise<any>;
6
+ export declare function getDwSlots(influxConfig: InfluxConfig, timeStart: number, timeEnd: number, filter: {
7
+ field: string;
8
+ value: string;
9
+ }): Promise<any>;
10
+ export declare function getInfluxDataV1(influxConfig: InfluxConfig, field: string, timeStart: number, timeEnd: number, filter: {
11
+ field: string;
12
+ value: string;
13
+ }, timeGroup: string, raw: boolean, fill?: InfluxFillType, filterTag?: number, tagInclude?: FilterTagMode): Promise<any>;
14
+ export declare function exportDataV1(influxConfig: InfluxConfig, field: string, timeStart: number, timeEnd: number, filter: {
15
+ field: string;
16
+ value: string;
17
+ }): Promise<any>;
@@ -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, deviceID, timeStart, timeEnd) {
5
+ export async function getInfluxAlerts(influxConfig, fields, limit, offset, sort, filter, timeStart, timeEnd) {
6
6
  const conditions = fields
7
7
  .map((field) => `r["valueName"] == "${field}"`)
8
8
  .join(" or ");
@@ -13,7 +13,7 @@ export async function getInfluxAlerts(influxConfig, fields, limit, offset, sort,
13
13
  query += ` |> range(start: ${timeStart}, stop: ${timeEnd})`;
14
14
  }
15
15
  query += `
16
- |> filter(fn: (r) => r["_measurement"] == "${influxConfig.measurement}" and r["deviceid"] == "${deviceID}" and (${conditions}))
16
+ |> filter(fn: (r) => r["_measurement"] == "${influxConfig.measurement}" and r["${filter.field}"] == "${filter.value}" and (${conditions}))
17
17
  `;
18
18
  // Add filter for tag d === 3
19
19
  query += `
@@ -80,11 +80,11 @@ export async function getInfluxAlerts(influxConfig, fields, limit, offset, sort,
80
80
  count: countData
81
81
  };
82
82
  }
83
- export async function getDwSlots(influxConfig, timeStart, timeEnd, deviceID) {
83
+ export async function getDwSlots(influxConfig, timeStart, timeEnd, filter) {
84
84
  const field = "dw";
85
85
  const query = `
86
86
  SELECT ("value") FROM "${influxConfig.measurement}"
87
- WHERE "deviceid" = '${deviceID}'
87
+ WHERE "${filter.field}" = '${filter.value}'
88
88
  AND "valueName" = '${field}'
89
89
  AND time >= '${moment.unix(timeStart).toISOString()}'
90
90
  AND time <= '${moment.unix(timeEnd).toISOString()}'
@@ -116,7 +116,7 @@ export async function getDwSlots(influxConfig, timeStart, timeEnd, deviceID) {
116
116
  }
117
117
  return data; // stessa struttura di Influx, con values modificati
118
118
  }
119
- export async function getInfluxDataV1(influxConfig, field, timeStart, timeEnd, deviceID, timeGroup, raw, fill, filterTag, tagInclude = FilterTagMode.Include) {
119
+ export async function getInfluxDataV1(influxConfig, field, timeStart, timeEnd, filter, timeGroup, raw, fill, filterTag, tagInclude = FilterTagMode.Include) {
120
120
  let query;
121
121
  let preStartValue = null;
122
122
  // Costruzione filtro tag
@@ -135,12 +135,12 @@ export async function getInfluxDataV1(influxConfig, field, timeStart, timeEnd, d
135
135
  }
136
136
  }
137
137
  if (raw) {
138
- query = `SELECT ("value") FROM "${influxConfig.measurement}" WHERE "deviceid" = '${deviceID}' AND "valueName" = '${field}'${filterTagCondition} AND time >= '${moment
138
+ query = `SELECT ("value") FROM "${influxConfig.measurement}" WHERE "${filter.field}" = '${filter.value}' AND "valueName" = '${field}'${filterTagCondition} AND time >= '${moment
139
139
  .unix(timeStart)
140
140
  .toISOString()}' AND time <= '${moment.unix(timeEnd).toISOString()}'`;
141
141
  }
142
142
  else {
143
- query = `SELECT last("value") FROM "${influxConfig.measurement}" WHERE "deviceid" = '${deviceID}' AND "valueName" = '${field}'${filterTagCondition} AND time >= '${moment
143
+ query = `SELECT last("value") FROM "${influxConfig.measurement}" WHERE "${filter.field}" = '${filter.value}' AND "valueName" = '${field}'${filterTagCondition} AND time >= '${moment
144
144
  .unix(timeStart)
145
145
  .toISOString()}' AND time <= '${moment
146
146
  .unix(timeEnd)
@@ -157,7 +157,7 @@ export async function getInfluxDataV1(influxConfig, field, timeStart, timeEnd, d
157
157
  }
158
158
  if (fill !== "null") {
159
159
  // Query to get the last data point before timeStart
160
- const preStartQuery = `SELECT last("value") FROM "${influxConfig.measurement}" WHERE "deviceid" = '${deviceID}' AND "valueName" = '${field}'${filterTagCondition} AND time < '${moment
160
+ const preStartQuery = `SELECT last("value") FROM "${influxConfig.measurement}" WHERE "${filter.field}" = '${filter.value}' AND "valueName" = '${field}'${filterTagCondition} AND time < '${moment
161
161
  .unix(timeStart)
162
162
  .toISOString()}'`;
163
163
  const preStartResponse = await fetch(encodeURI(`${influxConfig.url}/query?db=${influxConfig.dbName}&epoch=s&q=${preStartQuery}`), {
@@ -215,8 +215,8 @@ export async function getInfluxDataV1(influxConfig, field, timeStart, timeEnd, d
215
215
  }
216
216
  return data;
217
217
  }
218
- export async function exportDataV1(influxConfig, field, timeStart, timeEnd, deviceID) {
219
- const query = `SELECT ("value") FROM "${influxConfig.measurement}" WHERE "deviceid" = '${deviceID}' AND "valueName" = '${field}' AND time >= '${moment
218
+ export async function exportDataV1(influxConfig, field, timeStart, timeEnd, filter) {
219
+ const query = `SELECT ("value") FROM "${influxConfig.measurement}" WHERE "${filter.field}" = '${filter.value}' AND "valueName" = '${field}' AND time >= '${moment
220
220
  .unix(timeStart)
221
221
  .toISOString()}' AND time <= '${moment.unix(timeEnd).toISOString()}'`;
222
222
  const response = await fetch(encodeURI(`${influxConfig.url}/query?db=${influxConfig.dbName}&epoch=s&q=${query}`), {