@iotready/nextjs-components-library 1.0.0-preview14 → 1.0.0-preview16
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.
@@ -3,11 +3,12 @@ import 'moment/locale/it';
|
|
3
3
|
import { Theme } from "@emotion/react";
|
4
4
|
type Measure = {
|
5
5
|
name: string;
|
6
|
+
description: string;
|
6
7
|
polltime: number;
|
7
8
|
unit: string;
|
8
9
|
stepped: boolean;
|
9
10
|
};
|
10
|
-
declare const TrendChart: ({ deviceId, measures1, measures2, enableDatePicker, handleGetInfluxData, handleExportDataCB, theme }: {
|
11
|
+
declare const TrendChart: ({ deviceId, measures1, measures2, enableDatePicker, handleGetInfluxData, handleExportDataCB, theme, initialTimeStart, initialTimeEnd }: {
|
11
12
|
deviceId: string;
|
12
13
|
measures1?: Array<Measure>;
|
13
14
|
measures2?: Array<Measure>;
|
@@ -15,5 +16,7 @@ declare const TrendChart: ({ deviceId, measures1, measures2, enableDatePicker, h
|
|
15
16
|
handleGetInfluxData: (measure: string, timeStart: number, timeEnd: number, deviceId: string, timeGroup: string, raw: boolean, fill?: boolean) => Promise<any>;
|
16
17
|
handleExportDataCB?: (measure: string, timeStart: number, timeEnd: number, deviceId: string) => Promise<any>;
|
17
18
|
theme: Theme;
|
19
|
+
initialTimeStart?: number;
|
20
|
+
initialTimeEnd?: number;
|
18
21
|
}) => import("react/jsx-runtime").JSX.Element;
|
19
22
|
export default TrendChart;
|
@@ -144,7 +144,7 @@ function getPollTime(intervalInSeconds, pollTime) {
|
|
144
144
|
}
|
145
145
|
function getCsvData(data, measures) {
|
146
146
|
// Initialize the header with timestamp and measure names
|
147
|
-
const headers = ["timestamp", ...measures.map(measure => measure.name)];
|
147
|
+
const headers = ["timestamp", ...measures.map(measure => measure.description || measure.name)];
|
148
148
|
const csvData = [];
|
149
149
|
// Add the header to the csvData
|
150
150
|
csvData.push(headers);
|
@@ -186,18 +186,18 @@ function getCsvData(data, measures) {
|
|
186
186
|
return csvData.map(row => row.join(',')).join('\n');
|
187
187
|
}
|
188
188
|
// eslint-disable-next-line no-unused-vars
|
189
|
-
const TrendChart = ({ deviceId, measures1, measures2, enableDatePicker, handleGetInfluxData, handleExportDataCB, theme }) => {
|
189
|
+
const TrendChart = ({ deviceId, measures1, measures2, enableDatePicker, handleGetInfluxData, handleExportDataCB, theme, initialTimeStart, initialTimeEnd }) => {
|
190
190
|
const [chartJsLoaded, setChartJsLoaded] = useState(false);
|
191
191
|
const [dataMeasures, setDataMeasures] = useState(null);
|
192
192
|
const [chartPeriod, setChartPeriod] = useState('1D');
|
193
193
|
const [chartPeriodConfig, setChartPeriodConfig] = useState(chartConfigByPeriod['1D']);
|
194
194
|
const [chartLoading, setChartLoading] = useState(false);
|
195
|
-
const [timeStartPicker, setTimeStartPicker] = useState(moment().subtract(1, 'day').unix());
|
196
|
-
const [timeStart, setTimeStart] = useState(moment().subtract(1, 'day').unix());
|
197
|
-
const [timeEnd, setTimeEnd] = useState(moment().unix());
|
198
|
-
const [datePickerUsed, setDatePickerUsed] = useState(false);
|
199
|
-
const [pickerTimeStart, setPickerTimeStart] = useState(moment().subtract(1, 'day').unix());
|
200
|
-
const [pickerTimeEnd, setPickerTimeEnd] = useState(moment().unix());
|
195
|
+
const [timeStartPicker, setTimeStartPicker] = useState(initialTimeStart || moment().subtract(1, 'day').unix());
|
196
|
+
const [timeStart, setTimeStart] = useState(initialTimeStart || moment().subtract(1, 'day').unix());
|
197
|
+
const [timeEnd, setTimeEnd] = useState(initialTimeEnd || moment().unix());
|
198
|
+
const [datePickerUsed, setDatePickerUsed] = useState(initialTimeStart || initialTimeEnd ? true : false);
|
199
|
+
const [pickerTimeStart, setPickerTimeStart] = useState(initialTimeStart || moment().subtract(1, 'day').unix());
|
200
|
+
const [pickerTimeEnd, setPickerTimeEnd] = useState(initialTimeEnd || moment().unix());
|
201
201
|
const [loadingButton, setLoadingButton] = useState(false);
|
202
202
|
const csvLinkRef = useRef(null);
|
203
203
|
const [csvData, setCsvData] = useState('');
|
@@ -305,7 +305,7 @@ const TrendChart = ({ deviceId, measures1, measures2, enableDatePicker, handleGe
|
|
305
305
|
const influxData = await handleGetInfluxData(measure.name, timeStart, timeEnd, deviceId, polltime, !measure.polltime && rawQuery, !measure.polltime);
|
306
306
|
const points = getChartPoints(influxData);
|
307
307
|
return {
|
308
|
-
label: measure.name,
|
308
|
+
label: measure.description || measure.name,
|
309
309
|
data: points,
|
310
310
|
unit: measure.unit,
|
311
311
|
borderWidth: 2,
|
@@ -484,7 +484,7 @@ const TrendChart = ({ deviceId, measures1, measures2, enableDatePicker, handleGe
|
|
484
484
|
}, minDateTime: moment(timeStart * 1000), slotProps: {
|
485
485
|
textField: { size: 'small', sx: { width: { sm: 210 } } }
|
486
486
|
} })] }) });
|
487
|
-
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].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
|
487
|
+
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
|
488
488
|
//@ts-ignore
|
489
489
|
, {
|
490
490
|
//@ts-ignore
|
package/package.json
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
export type TrackleConfig = {
|
2
|
+
orgName: string;
|
2
3
|
apiUrl: string;
|
3
|
-
createCustomerUrl: string;
|
4
4
|
clientId: string;
|
5
5
|
clientSecret: string;
|
6
6
|
tokenUrl: string;
|
7
7
|
cookieName: string;
|
8
8
|
cookieSecure: boolean;
|
9
9
|
apiTimeout: number;
|
10
|
+
productID: number;
|
10
11
|
};
|
11
12
|
export declare function logOut(trackleConfig: TrackleConfig): Promise<void>;
|
12
13
|
export declare function createCustomer(trackleConfig: TrackleConfig, uid: string): Promise<{
|
@@ -48,7 +48,7 @@ export async function logOut(trackleConfig) {
|
|
48
48
|
cookies().delete(trackleConfig.cookieName);
|
49
49
|
}
|
50
50
|
export async function createCustomer(trackleConfig, uid) {
|
51
|
-
return await wretch(trackleConfig.
|
51
|
+
return await wretch(`${trackleConfig.apiUrl}/orgs/${trackleConfig.orgName}/customers`)
|
52
52
|
.headers({
|
53
53
|
Authorization: `Basic ${btoa(`${trackleConfig.clientId}:${trackleConfig.clientSecret}`)}`
|
54
54
|
})
|