@dexteel/mesf-core 4.5.10 → 4.6.0

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.
Files changed (22) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/dist/components/shared/buttons/button-with-loading.d.ts +9 -0
  3. package/dist/index.d.ts +2 -1
  4. package/dist/index.esm.js +1006 -722
  5. package/dist/index.esm.js.map +1 -1
  6. package/dist/pages/trendings/TrendingsPage.d.ts +4 -0
  7. package/dist/pages/trendings/components/chart/TableComponent.d.ts +1 -3
  8. package/dist/pages/trendings/components/chart/Trending.d.ts +0 -2
  9. package/dist/pages/trendings/components/chart/components/modals/addTagModal/AddTagModal.d.ts +2 -2
  10. package/dist/pages/trendings/components/chart/components/modals/addTagModal/TagSelectionModal.d.ts +2 -2
  11. package/dist/pages/trendings/components/chart/components/modals/loadView/LoadViewModal.d.ts +7 -0
  12. package/dist/pages/trendings/components/chart/components/modals/saveAsView/SaveAsViewModal.d.ts +7 -0
  13. package/dist/pages/trendings/components/chart/context/TrendingContext.d.ts +47 -0
  14. package/dist/pages/trendings/components/chart/hooks/useTagsDataTable.d.ts +3 -3
  15. package/dist/pages/trendings/components/chart/models/TrendingModels.d.ts +21 -0
  16. package/dist/pages/trendings/components/chart/repository/TrendingRepository.d.ts +4 -5
  17. package/dist/pages/trendings/components/chart/sections/trending-chart.d.ts +1 -3
  18. package/dist/pages/trendings/components/chart/styles/TrendingStyles.d.ts +1 -1
  19. package/dist/pages/trendings/components/chart/utils/areRangeSimilar.d.ts +2 -2
  20. package/dist/pages/trendings/index.d.ts +3 -4
  21. package/dist/pages/trendings/reducers/trendings.reducer.d.ts +48 -0
  22. package/package.json +1 -1
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Typography, TextField, makeStyles as makeStyles$1, Button as Button$1, Grid as Grid$1, Dialog as Dialog$1, DialogTitle as DialogTitle$2, DialogContent as DialogContent$2, DialogContentText, DialogActions as DialogActions$2, FormHelperText, CircularProgress as CircularProgress$1, Badge, FormControlLabel, Checkbox, Snackbar as Snackbar$1, Paper as Paper$1, MenuItem as MenuItem$1, useTheme as useTheme$1, Box, Tooltip, IconButton as IconButton$1, FormControl as FormControl$1, Select as Select$1, debounce, createStyles as createStyles$1, List, ListItem, ListItemText } from '@material-ui/core';
1
+ import { Typography, TextField, makeStyles as makeStyles$1, Button as Button$1, Grid as Grid$1, Dialog as Dialog$1, DialogTitle as DialogTitle$2, DialogContent as DialogContent$2, DialogContentText, DialogActions as DialogActions$2, FormHelperText, CircularProgress as CircularProgress$1, Badge, FormControlLabel, Checkbox, Snackbar as Snackbar$1, Paper as Paper$1, MenuItem as MenuItem$1, useTheme as useTheme$1, Box, Divider, Tooltip, IconButton as IconButton$1, FormControl as FormControl$1, Select as Select$1, debounce, createStyles as createStyles$1, List, ListItem, ListItemText } from '@material-ui/core';
2
2
  import { values, get, isNil as isNil$1, isEmpty, isNaN } from 'lodash-es';
3
3
  import * as React from 'react';
4
4
  import React__default, { useState, useRef, useEffect, Component, createContext, useContext, useMemo, useCallback, lazy, Suspense } from 'react';
@@ -20,15 +20,15 @@ import Grid from '@material-ui/core/Grid';
20
20
  import { isNil, get as get$1 } from 'lodash';
21
21
  import { DndProvider } from 'react-dnd';
22
22
  import { HTML5Backend } from 'react-dnd-html5-backend';
23
+ import moment from 'moment';
23
24
  import axios from 'axios';
24
25
  import { _adapters, Chart, CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip as Tooltip$1, Legend, TimeScale } from 'chart.js';
25
- import moment from 'moment';
26
26
  import zoomPlugin from 'chartjs-plugin-zoom';
27
27
  import Popover from '@material-ui/core/Popover';
28
28
  import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown';
29
29
  import FolderIcon from '@material-ui/icons/Folder';
30
30
  import InsertDriveFileIcon from '@material-ui/icons/InsertDriveFile';
31
- import { Alert as Alert$3, TreeView as TreeView$1, TreeItem as TreeItem$1 } from '@material-ui/lab';
31
+ import { Alert as Alert$3, TreeView as TreeView$1, TreeItem as TreeItem$1, Autocomplete } from '@material-ui/lab';
32
32
  import { ArrowRight, ChevronLeft, ChevronRight } from '@material-ui/icons';
33
33
  import { Line } from 'react-chartjs-2';
34
34
  import PersonPinCircleIcon from '@material-ui/icons/PersonPinCircle';
@@ -1298,7 +1298,7 @@ var DialogTitle = withStyles(styles)(function (props) {
1298
1298
  var DialogContent = withStyles(function (theme) { return ({
1299
1299
  root: {
1300
1300
  padding: theme.spacing(2),
1301
- minWidth: 300
1301
+ minWidth: 600
1302
1302
  }
1303
1303
  }); })(DialogContent$1);
1304
1304
  var DialogActions = withStyles(function (theme) { return ({
@@ -8283,6 +8283,210 @@ var Home = function () { return (React__default.createElement("div", { style: {
8283
8283
  position: "absolute"
8284
8284
  } })); };
8285
8285
 
8286
+ var TrendingsInitialState = {
8287
+ timeScopeStart: moment(new Date()).subtract(1, "days").toDate(),
8288
+ timeScopeEnd: new Date(),
8289
+ scope: "1 day",
8290
+ graphPan: false,
8291
+ graphShouldUpdate: 0,
8292
+ views: [
8293
+ {
8294
+ ViewId: 0,
8295
+ ViewName: '',
8296
+ UserName: null,
8297
+ IsPublic: false,
8298
+ LastModified: null,
8299
+ LastModifiedBy: null
8300
+ }
8301
+ ],
8302
+ viewSelected: null,
8303
+ viewTags: [
8304
+ {
8305
+ ViewId: 0,
8306
+ TagId: 0,
8307
+ TagName: '',
8308
+ Color: '',
8309
+ IsVisible: true,
8310
+ MinScale: 0,
8311
+ MaxScale: 0,
8312
+ IsAutoScale: true,
8313
+ Alias: '',
8314
+ TagType: '',
8315
+ Unit: ''
8316
+ }
8317
+ ]
8318
+ };
8319
+ var TrendingsReducer = createSlice({
8320
+ name: "__",
8321
+ initialState: TrendingsInitialState,
8322
+ reducers: {
8323
+ setTotalScope: function (state, _a) {
8324
+ var payload = _a.payload; _a.type;
8325
+ state.graphShouldUpdate += 1;
8326
+ if (!isNil$1(payload.start) && !isNil$1(payload.end) && !isNil$1(payload.scope)) {
8327
+ //from arrow navigators
8328
+ state.timeScopeStart = payload.start;
8329
+ state.timeScopeEnd = payload.end;
8330
+ state.scope = payload.scope;
8331
+ return;
8332
+ }
8333
+ if (!isNil$1(payload.scope)) {
8334
+ if (payload.scope !== "custom") {
8335
+ switch (payload.scope) {
8336
+ case "10 min":
8337
+ state.timeScopeStart = moment(state.timeScopeEnd)
8338
+ .subtract(10, "minutes")
8339
+ .toDate();
8340
+ break;
8341
+ case "1 hour":
8342
+ state.timeScopeStart = moment(state.timeScopeEnd)
8343
+ .subtract(1, "hours")
8344
+ .toDate();
8345
+ break;
8346
+ case "4 hours":
8347
+ state.timeScopeStart = moment(state.timeScopeEnd)
8348
+ .subtract(4, "hours")
8349
+ .toDate();
8350
+ break;
8351
+ case "12 hours":
8352
+ state.timeScopeStart = moment(state.timeScopeEnd)
8353
+ .subtract(12, "hours")
8354
+ .toDate();
8355
+ break;
8356
+ case "1 day":
8357
+ state.timeScopeStart = moment(state.timeScopeEnd)
8358
+ .subtract(1, "days")
8359
+ .toDate();
8360
+ break;
8361
+ case "10 days":
8362
+ state.timeScopeStart = moment(state.timeScopeEnd)
8363
+ .subtract(10, "days")
8364
+ .toDate();
8365
+ break;
8366
+ }
8367
+ }
8368
+ state.scope = payload.scope;
8369
+ return;
8370
+ }
8371
+ if (!isNil$1(payload.start) && !isNil$1(payload.end) && isNil$1(payload.graphPan)) {
8372
+ // from zoom
8373
+ state.timeScopeStart = payload.start;
8374
+ state.timeScopeEnd = payload.end;
8375
+ state.scope = "custom";
8376
+ return;
8377
+ }
8378
+ if (!isNil$1(payload.start) && !isNil$1(payload.end) && !isNil$1(payload.graphPan)) {
8379
+ // from pan
8380
+ state.timeScopeStart = payload.start;
8381
+ state.timeScopeEnd = payload.end;
8382
+ return;
8383
+ }
8384
+ if (!isNil$1(payload.start)) {
8385
+ state.timeScopeStart = payload.start;
8386
+ if (state.scope !== "custom") {
8387
+ switch (state.scope) {
8388
+ case "10 min":
8389
+ state.timeScopeEnd = moment(payload.start)
8390
+ .add(10, "minutes")
8391
+ .toDate();
8392
+ break;
8393
+ case "1 hour":
8394
+ state.timeScopeEnd = moment(payload.start)
8395
+ .add(1, "hours")
8396
+ .toDate();
8397
+ break;
8398
+ case "4 hours":
8399
+ state.timeScopeEnd = moment(payload.start)
8400
+ .add(4, "hours")
8401
+ .toDate();
8402
+ break;
8403
+ case "12 hours":
8404
+ state.timeScopeEnd = moment(payload.start)
8405
+ .add(12, "hours")
8406
+ .toDate();
8407
+ break;
8408
+ case "1 day":
8409
+ state.timeScopeEnd = moment(payload.start)
8410
+ .add(1, "days")
8411
+ .toDate();
8412
+ break;
8413
+ case "10 days":
8414
+ state.timeScopeEnd = moment(payload.start)
8415
+ .add(10, "days")
8416
+ .toDate();
8417
+ break;
8418
+ }
8419
+ }
8420
+ return;
8421
+ }
8422
+ if (!isNil$1(payload.end)) {
8423
+ state.timeScopeEnd = payload.end;
8424
+ if (state.scope !== "custom") {
8425
+ switch (state.scope) {
8426
+ case "10 min":
8427
+ state.timeScopeStart = moment(payload.end)
8428
+ .subtract(10, "minutes")
8429
+ .toDate();
8430
+ break;
8431
+ case "1 hour":
8432
+ state.timeScopeStart = moment(payload.end)
8433
+ .subtract(1, "hours")
8434
+ .toDate();
8435
+ break;
8436
+ case "4 hours":
8437
+ state.timeScopeStart = moment(payload.end)
8438
+ .subtract(4, "hours")
8439
+ .toDate();
8440
+ break;
8441
+ case "12 hours":
8442
+ state.timeScopeStart = moment(payload.end)
8443
+ .subtract(12, "hours")
8444
+ .toDate();
8445
+ break;
8446
+ case "1 day":
8447
+ state.timeScopeStart = moment(payload.end)
8448
+ .subtract(1, "days")
8449
+ .toDate();
8450
+ break;
8451
+ case "10 days":
8452
+ state.timeScopeStart = moment(payload.end)
8453
+ .subtract(10, "days")
8454
+ .toDate();
8455
+ break;
8456
+ }
8457
+ }
8458
+ return;
8459
+ }
8460
+ },
8461
+ setViews: function (state, _a) {
8462
+ var payload = _a.payload;
8463
+ state.views = payload;
8464
+ },
8465
+ setViewSelected: function (state, _a) {
8466
+ var payload = _a.payload;
8467
+ state.viewSelected = payload;
8468
+ },
8469
+ setViewTags: function (state, _a) {
8470
+ var payload = _a.payload;
8471
+ state.viewTags = payload;
8472
+ }
8473
+ }
8474
+ });
8475
+
8476
+ var TrendingContext = createContext({
8477
+ state: TrendingsReducer.getInitialState(),
8478
+ actions: TrendingsReducer.actions
8479
+ });
8480
+ var useTrendingContext = function () { return useContext(TrendingContext); };
8481
+ var TrendingProvider = function (_a) {
8482
+ var children = _a.children;
8483
+ var _b = useComplexState({
8484
+ initialState: TrendingsReducer.getInitialState(),
8485
+ reducers: TrendingsReducer.caseReducers
8486
+ }), state = _b[0], actions = _b[1];
8487
+ return (React__default.createElement(TrendingContext.Provider, { value: { state: state, actions: actions } }, children));
8488
+ };
8489
+
8286
8490
  /*!
8287
8491
  * chartjs-adapter-moment v1.0.1
8288
8492
  * https://www.chartjs.org
@@ -8422,8 +8626,9 @@ var ColorPicker = function (_a) {
8422
8626
  var TagSelectionModal = function (_a) {
8423
8627
  var isOpen = _a.isOpen; _a.onClose; var onTagSelect = _a.onTagSelect;
8424
8628
  var _b = useState(true), isLoading = _b[0], setIsLoading = _b[1];
8425
- var _c = useState([]), treeData = _c[0], setTreeData = _c[1];
8426
- var _d = useState([]), expanded = _d[0], setExpanded = _d[1];
8629
+ var _c = useState(''), error = _c[0], setError = _c[1];
8630
+ var _d = useState([]), treeData = _d[0], setTreeData = _d[1];
8631
+ var _e = useState([]), expanded = _e[0], setExpanded = _e[1];
8427
8632
  var currentColorIndex = useRef(0);
8428
8633
  useEffect(function () {
8429
8634
  var loadData = function () { return __awaiter(void 0, void 0, void 0, function () {
@@ -8438,8 +8643,8 @@ var TagSelectionModal = function (_a) {
8438
8643
  children = _a.sent();
8439
8644
  setTreeData([
8440
8645
  {
8441
- tagId: null,
8442
- tagName: "root",
8646
+ TagId: null,
8647
+ TagName: "root",
8443
8648
  children: children,
8444
8649
  isLoaded: true,
8445
8650
  shortName: "Tags",
@@ -8488,20 +8693,19 @@ var TagSelectionModal = function (_a) {
8488
8693
  case 1:
8489
8694
  children = _a.sent();
8490
8695
  return [2 /*return*/, {
8491
- tagId: dbTag.tagId,
8492
- tagName: childTagName,
8696
+ TagId: dbTag.tagId,
8697
+ TagName: childTagName,
8493
8698
  shortName: dbTag.tagName,
8494
8699
  children: children,
8495
8700
  isLoaded: true,
8496
8701
  tag: {
8497
- tagId: dbTag.tagId,
8498
- tagName: dbTag.tagName,
8499
- tagType: dbTag.tagType,
8500
- color: getColor(),
8501
- autoScale: true,
8502
- minScale: null,
8503
- maxScale: null,
8504
- visible: true
8702
+ TagId: dbTag.tagId,
8703
+ TagName: dbTag.tagName,
8704
+ Color: getColor(),
8705
+ IsAutoScale: true,
8706
+ MinScale: dbTag.minScale,
8707
+ MaxScale: dbTag.maxScale,
8708
+ IsVisible: true
8505
8709
  }
8506
8710
  }];
8507
8711
  }
@@ -8514,7 +8718,7 @@ var TagSelectionModal = function (_a) {
8514
8718
  return [2 /*return*/, childrenData];
8515
8719
  case 4:
8516
8720
  error_1 = _a.sent();
8517
- console.error("Error fetching children:", error_1);
8721
+ setError(error_1.message);
8518
8722
  return [2 /*return*/, []];
8519
8723
  case 5: return [2 /*return*/];
8520
8724
  }
@@ -8533,7 +8737,7 @@ var TagSelectionModal = function (_a) {
8533
8737
  var node;
8534
8738
  return __generator(this, function (_a) {
8535
8739
  node = findNode(treeData, nodeId);
8536
- if (node === null || node === void 0 ? void 0 : node.tagId) {
8740
+ if (node === null || node === void 0 ? void 0 : node.TagId) {
8537
8741
  onTagSelect(node.tag);
8538
8742
  }
8539
8743
  return [2 /*return*/];
@@ -8542,7 +8746,7 @@ var TagSelectionModal = function (_a) {
8542
8746
  var findNode = function (nodes, tagName) {
8543
8747
  for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
8544
8748
  var node = nodes_1[_i];
8545
- if (node.tagName === tagName) {
8749
+ if (node.TagName === tagName) {
8546
8750
  return node;
8547
8751
  }
8548
8752
  else if (node.children) {
@@ -8553,553 +8757,720 @@ var TagSelectionModal = function (_a) {
8553
8757
  }
8554
8758
  return null;
8555
8759
  };
8556
- var renderTree = function (node) { return (React__default.createElement(TreeItem$1, { key: node.tagName, nodeId: node.tagName, label: node.shortName, endIcon: React__default.createElement(ArrowDropDownIcon, null), icon: node.children && node.children.length > 0 ? (React__default.createElement(FolderIcon, null)) : (React__default.createElement(InsertDriveFileIcon, null)) }, node.children && node.children.map(function (child) { return renderTree(child); }))); };
8557
- return (React__default.createElement("div", { style: {
8558
- display: isOpen ? "block" : "none",
8559
- minHeight: "400px",
8560
- minWidth: "600px"
8561
- } },
8562
- React__default.createElement("div", null, isLoading ? (React__default.createElement(Grid$1, { container: true, justifyContent: "center", alignItems: "center", style: { minHeight: "100px" } },
8563
- React__default.createElement(CircularProgress$1, { size: "2rem" }))) : (React__default.createElement(TreeView$1, { expanded: expanded, onNodeSelect: handleNodeSelect, onNodeToggle: handleNodeToggle }, treeData.map(function (tree) { return renderTree(tree); }))))));
8760
+ var renderTree = function (node) { return (React__default.createElement(TreeItem$1, { key: node.TagName, nodeId: node.TagName, label: node.shortName, endIcon: React__default.createElement(ArrowDropDownIcon, null), icon: node.children && node.children.length > 0 ? (React__default.createElement(FolderIcon, null)) : (React__default.createElement(InsertDriveFileIcon, null)) }, node.children && node.children.map(function (child) { return renderTree(child); }))); };
8761
+ return (React__default.createElement(React__default.Fragment, null,
8762
+ React__default.createElement("div", { style: {
8763
+ display: isOpen ? "block" : "none",
8764
+ minHeight: "400px",
8765
+ minWidth: "600px"
8766
+ } },
8767
+ React__default.createElement("div", null, isLoading ? (React__default.createElement(Grid$1, { container: true, justifyContent: "center", alignItems: "center", style: { minHeight: "100px" } },
8768
+ React__default.createElement(CircularProgress$1, { size: "2rem" }))) : (React__default.createElement(TreeView$1, { expanded: expanded, onNodeSelect: handleNodeSelect, onNodeToggle: handleNodeToggle }, treeData.map(function (tree) { return renderTree(tree); }))))),
8769
+ React__default.createElement(ErrorModal, { error: error, onHide: function () { return setError(''); } })));
8564
8770
  };
8565
8771
 
8566
8772
  var AddTagModal = function (_a) {
8567
8773
  var open = _a.open, handleClose = _a.handleClose, onTagSelect = _a.onTagSelect;
8568
- return (React__default.createElement(MesfModal, { open: open, handleClose: handleClose, maxWidth: "lg", "aria-labelledby": "modal-modal-title", "aria-describedby": "modal-modal-description", title: 'Tags' },
8569
- React__default.createElement(MesfModal.Content, null,
8570
- React__default.createElement(Box, null,
8571
- React__default.createElement(Typography, { id: "modal-modal-description" },
8572
- React__default.createElement(TagSelectionModal, { isOpen: open, onClose: function () { return handleClose; }, onTagSelect: onTagSelect }))))));
8774
+ return (React__default.createElement(React__default.Fragment, null,
8775
+ React__default.createElement(MesfModal, { open: open, handleClose: handleClose, maxWidth: "lg", "aria-labelledby": "modal-modal-title", "aria-describedby": "modal-modal-description", title: 'Tags' },
8776
+ React__default.createElement(MesfModal.Content, null,
8777
+ React__default.createElement(Box, null,
8778
+ React__default.createElement(Typography, { id: "modal-modal-description" },
8779
+ React__default.createElement(TagSelectionModal, { isOpen: open, onClose: function () { return handleClose; }, onTagSelect: onTagSelect })))))));
8573
8780
  };
8574
8781
 
8575
- var useTagsDataTable = function (_a) {
8576
- var cursorData = _a.cursorData, tagList = _a.tagList, chartData = _a.chartData;
8577
- return useMemo(function () {
8578
- // calculo y1,y2,y2y1,ymin,ymax por cada tag
8579
- var _a;
8580
- var dataTable = {};
8581
- if (cursorData) {
8582
- var _loop_1 = function (idx) {
8583
- var tag = tagList[idx];
8584
- var datasetForTag = ((_a = chartData.datasets.find(function (ds) { return ds.tagId === tag.tagId; })) === null || _a === void 0 ? void 0 : _a.data) || [];
8585
- var p1 = { x: new Date('1900-01-01'), y: 0 };
8586
- var p2 = { x: new Date('1900-01-01'), y: 0 };
8587
- var p1Found = false;
8588
- var pmin = { x: 0, y: Number.POSITIVE_INFINITY };
8589
- var pmax = { x: 0, y: Number.NEGATIVE_INFINITY };
8590
- for (var idx_1 = 0; idx_1 < datasetForTag.length; idx_1++) {
8591
- var curr = datasetForTag[idx_1];
8592
- var currentVal = curr.x;
8593
- if (!p1Found) {
8594
- if (currentVal < cursorData.x1) {
8595
- p1 = curr;
8596
- p2 = JSON.parse(JSON.stringify(p1));
8597
- pmin = JSON.parse(JSON.stringify(p1));
8598
- pmax = JSON.parse(JSON.stringify(p1));
8599
- continue;
8600
- }
8601
- else {
8602
- p1Found = true;
8603
- }
8604
- }
8605
- else {
8606
- if (currentVal < cursorData.x2) {
8607
- p2 = curr;
8608
- if (pmin['y'] > curr['y']) {
8609
- pmin = JSON.parse(JSON.stringify(curr));
8610
- }
8611
- if (pmax['y'] < curr['y']) {
8612
- pmax = JSON.parse(JSON.stringify(curr));
8613
- }
8614
- }
8615
- else {
8616
- break;
8617
- }
8618
- }
8619
- }
8620
- dataTable[tag.tagName] = {
8621
- y1: p1.y,
8622
- y2: p2.y,
8623
- y2y1: Number(p2.y) - Number(p1.y),
8624
- pmin: pmin,
8625
- pmax: pmax
8626
- };
8627
- };
8628
- for (var idx = 0; idx < tagList.length; idx++) {
8629
- _loop_1(idx);
8630
- }
8631
- }
8632
- return dataTable;
8633
- }, [tagList, chartData, cursorData]);
8782
+ var ButtonWithLoading = function (_a) {
8783
+ var children = _a.children, isLoading = _a.isLoading, props = __rest(_a, ["children", "isLoading"]);
8784
+ return (React__default.createElement(Button$1, __assign({}, props, { disabled: isLoading }),
8785
+ isLoading && React__default.createElement(CircularProgress$1, { size: "1rem" }),
8786
+ children));
8634
8787
  };
8635
8788
 
8636
- var useTagsTableStyles = makeStyles$1(function (theme) { return ({
8637
- checkbox: {
8638
- '& input[type="checkbox"]': {
8639
- zoom: 1.5
8640
- },
8641
- textAlign: 'center'
8642
- },
8643
- rowHover: {
8644
- '&:hover': {
8645
- backgroundColor: "#f2f2f2"
8789
+ var saveTagDefaults = function (TagId, Alias, Color, MinScale, MaxScale, Unit) { return __awaiter(void 0, void 0, void 0, function () {
8790
+ var apiService, parameters, resp;
8791
+ return __generator(this, function (_a) {
8792
+ switch (_a.label) {
8793
+ case 0:
8794
+ apiService = new MESApiService();
8795
+ parameters = [];
8796
+ parameters.push({ name: "TagId", value: TagId });
8797
+ parameters.push({ name: "Alias", value: Alias });
8798
+ parameters.push({ name: "Color", value: Color });
8799
+ parameters.push({ name: "MinScale", value: MinScale });
8800
+ parameters.push({ name: "MaxScale", value: MaxScale });
8801
+ parameters.push({ name: "Unit", value: Unit });
8802
+ return [4 /*yield*/, apiService.callV2("[mssql2022].[IH_100020].[ih].[SaveTagDefaults]", parameters)];
8803
+ case 1:
8804
+ resp = _a.sent();
8805
+ return [2 /*return*/, resp];
8646
8806
  }
8647
- },
8648
- topTitles: {
8649
- border: "0.0625rem black solid",
8650
- borderBottom: "none",
8651
- backgroundColor: "#e9ecef"
8652
- },
8653
- bottomTitlesRow: {
8654
- '& th': {
8655
- border: "1px black solid"
8807
+ });
8808
+ }); };
8809
+ //views
8810
+ var getViews = function (Search) { return __awaiter(void 0, void 0, void 0, function () {
8811
+ var apiService, parameters, resp;
8812
+ return __generator(this, function (_a) {
8813
+ switch (_a.label) {
8814
+ case 0:
8815
+ apiService = new MESApiService();
8816
+ parameters = [];
8817
+ parameters.push({ name: "Search", value: Search });
8818
+ return [4 /*yield*/, apiService.callV2("[mssql2022].[IH_100020].[ih].[GetViews]", parameters)];
8819
+ case 1:
8820
+ resp = _a.sent();
8821
+ return [2 /*return*/, resp];
8822
+ }
8823
+ });
8824
+ }); };
8825
+ var getViewTags = function (ViewId) { return __awaiter(void 0, void 0, void 0, function () {
8826
+ var apiService, parameters, resp;
8827
+ return __generator(this, function (_a) {
8828
+ switch (_a.label) {
8829
+ case 0:
8830
+ apiService = new MESApiService();
8831
+ parameters = [];
8832
+ parameters.push({ name: "ViewId", value: ViewId });
8833
+ return [4 /*yield*/, apiService.callV2("[mssql2022].[IH_100020].[ih].[GetViewTags]", parameters)];
8834
+ case 1:
8835
+ resp = _a.sent();
8836
+ return [2 /*return*/, resp];
8837
+ }
8838
+ });
8839
+ }); };
8840
+ var upsertView = function (ViewId, ViewName, isPublic) { return __awaiter(void 0, void 0, void 0, function () {
8841
+ var apiService, parameters, resp;
8842
+ return __generator(this, function (_a) {
8843
+ switch (_a.label) {
8844
+ case 0:
8845
+ apiService = new MESApiService();
8846
+ parameters = [];
8847
+ parameters.push({ name: "ViewId", value: ViewId });
8848
+ parameters.push({ name: "ViewName", value: ViewName });
8849
+ parameters.push({ name: "isPublic", value: isPublic });
8850
+ return [4 /*yield*/, apiService.callV2("[mssql2022].[IH_100020].[ih].[UpsertView]", parameters)];
8851
+ case 1:
8852
+ resp = _a.sent();
8853
+ return [2 /*return*/, resp];
8854
+ }
8855
+ });
8856
+ }); };
8857
+ var upsertViewTag = function (ViewId, TagId, Color, MinScale, MaxScale, IsVisible, IsAutoScale) { return __awaiter(void 0, void 0, void 0, function () {
8858
+ var apiService, parameters, resp;
8859
+ return __generator(this, function (_a) {
8860
+ switch (_a.label) {
8861
+ case 0:
8862
+ apiService = new MESApiService();
8863
+ parameters = [];
8864
+ parameters.push({ name: "ViewId", value: ViewId });
8865
+ parameters.push({ name: "TagId", value: TagId });
8866
+ parameters.push({ name: "Color", value: Color });
8867
+ parameters.push({ name: "MinScale", value: MinScale });
8868
+ parameters.push({ name: "MaxScale", value: MaxScale });
8869
+ parameters.push({ name: "IsVisible", value: IsVisible });
8870
+ parameters.push({ name: "IsAutoScale", value: IsAutoScale });
8871
+ return [4 /*yield*/, apiService.callV2("[mssql2022].[IH_100020].[ih].[UpsertViewTag]", parameters)];
8872
+ case 1:
8873
+ resp = _a.sent();
8874
+ return [2 /*return*/, resp];
8875
+ }
8876
+ });
8877
+ }); };
8878
+
8879
+ var LoadViewModal = function (_a) {
8880
+ var open = _a.open, handleClose = _a.handleClose;
8881
+ var _b = useTrendingContext(), _c = _b.state; _c.viewTags; var views = _c.views, viewSelected = _c.viewSelected, _d = _b.actions; _d.setViews; var setViewTags = _d.setViewTags, setViewSelected = _d.setViewSelected;
8882
+ var _e = useState(false), isLoading = _e[0], setIsLoading = _e[1];
8883
+ var _f = useState(''), error = _f[0], setError = _f[1];
8884
+ var handleSelect = function () { return __awaiter(void 0, void 0, void 0, function () {
8885
+ var viewTagsResp;
8886
+ return __generator(this, function (_a) {
8887
+ switch (_a.label) {
8888
+ case 0:
8889
+ if (!viewSelected) return [3 /*break*/, 2];
8890
+ setIsLoading(true);
8891
+ return [4 /*yield*/, getViewTags(viewSelected.ViewId)];
8892
+ case 1:
8893
+ viewTagsResp = _a.sent();
8894
+ if (viewTagsResp.ok) {
8895
+ setViewTags(viewTagsResp.data.tables[0].rows);
8896
+ }
8897
+ else {
8898
+ setError(viewTagsResp.message);
8899
+ }
8900
+ setIsLoading(false);
8901
+ handleClose();
8902
+ _a.label = 2;
8903
+ case 2: return [2 /*return*/];
8904
+ }
8905
+ });
8906
+ }); };
8907
+ return (React__default.createElement("div", null,
8908
+ React__default.createElement(MesfModal, { open: open, handleClose: handleClose, maxWidth: "xl", "aria-labelledby": "modal-modal-title", "aria-describedby": "modal-modal-description", title: 'Tags' },
8909
+ React__default.createElement(MesfModal.Content, null,
8910
+ React__default.createElement(Grid$1, { container: true },
8911
+ React__default.createElement(Grid$1, { item: true, md: 12 }, views.length ? (React__default.createElement(Autocomplete, { size: 'small', id: "list-of-views", options: views, getOptionLabel: function (option) { return option.ViewName; }, onChange: function (ev, val) { return setViewSelected(val); }, style: { width: "100%" }, renderInput: function (params) { return React__default.createElement(TextField, __assign({}, params, { label: "Views", variant: "outlined" })); } })) :
8912
+ (React__default.createElement("div", null, "No tag views detected, please add one"))))),
8913
+ React__default.createElement(MesfModal.Actions, null,
8914
+ React__default.createElement("div", { style: { paddingTop: "1rem" } },
8915
+ React__default.createElement(Button$1, { variant: 'outlined', style: { marginRight: "1rem" }, color: 'secondary', onClick: handleClose }, "Cancel"),
8916
+ React__default.createElement(ButtonWithLoading, { onClick: handleSelect, variant: 'contained', color: 'primary', isLoading: isLoading, style: { marginRight: "1rem" } }, "Apply")))),
8917
+ React__default.createElement(ErrorModal, { error: error, onHide: function () { return setError(''); } })));
8918
+ };
8919
+
8920
+ var useTrendingStyles = makeStyles$1(function (theme) { return ({
8921
+ datetimePicker: {
8922
+ alignItems: "center",
8923
+ "& .MuiInputBase-root": {
8924
+ color: "black",
8925
+ backgroundColor: "white",
8926
+ borderRadius: theme.shape.borderRadius,
8927
+ width: "90%",
8928
+ minWidth: "90%",
8929
+ maxWidth: "90%"
8656
8930
  },
8657
- backgroundColor: "#e9ecef"
8658
- },
8659
- doubleInput: {
8660
- padding: "0",
8661
- '& input[type="text"] ': {
8662
- width: "100%",
8663
- height: "17px",
8664
- display: "block",
8665
- margin: "0",
8666
- padding: "0"
8931
+ "& .MuiInputBase-input": {
8932
+ fontSize: "13px !important",
8933
+ height: "15px !important",
8934
+ paddingRight: "3px",
8935
+ paddingLeft: "5px"
8936
+ },
8937
+ "& .MuiInput-underline:before": {
8938
+ borderBottomColor: "rgba(0, 0, 0, 0.42)"
8667
8939
  }
8668
8940
  },
8669
- inputCol: {
8670
- width: "11.25rem",
8671
- overflow: 'hidden',
8672
- textOverflow: 'ellipsis',
8673
- whiteSpace: 'nowrap'
8674
- },
8675
- autoScale: {
8676
- width: '7.5rem'
8677
- },
8678
- scale: {
8679
- width: '37.5rem',
8680
- padding: "0"
8681
- },
8682
- visible: {
8683
- width: '3.75rem'
8941
+ select: {
8942
+ "& .MuiInput-root": {
8943
+ width: "100%"
8944
+ },
8945
+ "& .MuiInputBase-root": {
8946
+ color: "black",
8947
+ backgroundColor: "white",
8948
+ borderRadius: theme.shape.borderRadius,
8949
+ minWidth: "100%"
8950
+ },
8951
+ "& .MuiInputBase-input": {
8952
+ fontSize: "14px !important",
8953
+ height: "15px !important"
8954
+ },
8955
+ "& .MuiInput-underline:before": {
8956
+ borderBottomColor: "rgba(0, 0, 0, 0.42)"
8957
+ }
8684
8958
  },
8685
- color: {
8686
- width: '4.375rem'
8959
+ labelOptions: {
8960
+ paddingLeft: "2rem",
8961
+ userSelect: "none",
8962
+ "& > label": {
8963
+ display: "flex",
8964
+ alignItems: "center",
8965
+ gap: "5px"
8966
+ },
8967
+ '& input[type="checkbox"]': {
8968
+ zoom: 1.5
8969
+ }
8687
8970
  },
8688
- unit: {
8689
- width: '7.5rem'
8971
+ isPublicCheckbox: {
8972
+ userSelect: "none",
8973
+ paddingLeft: '1rem',
8974
+ "& > label": {
8975
+ display: "flex",
8976
+ alignItems: "center",
8977
+ gap: "15px"
8978
+ },
8979
+ '& input[type="checkbox"]': {
8980
+ zoom: 1.5
8981
+ }
8690
8982
  },
8691
- xStats: {
8692
- // ...
8983
+ navigatorButton: {
8984
+ "& .MuiSvgIcon-root": {
8985
+ cursor: "pointer !important"
8986
+ }
8693
8987
  }
8694
8988
  }); });
8695
8989
 
8696
- var timeDifference = function (start, end) {
8697
- var differenceMilliseconds = start - end;
8698
- var seconds = Math.floor(differenceMilliseconds / 1000);
8699
- var minutes = Math.floor(seconds / 60);
8700
- var hours = Math.floor(minutes / 60);
8701
- var remainingMinutes = minutes % 60;
8702
- var remainingSeconds = seconds % 60;
8703
- return "".concat(hours, "h ").concat(remainingMinutes, "m ").concat(remainingSeconds, "s");
8704
- };
8705
-
8706
- var TableComponent = function (_a) {
8707
- var tagList = _a.tagList, setTagList = _a.setTagList, chartData = _a.chartData, cursorData = _a.cursorData;
8708
- var classes = useTagsTableStyles();
8709
- var _b = useState(""); _b[0]; _b[1];
8710
- var dataTable = useTagsDataTable({ tagList: tagList, chartData: chartData, cursorData: cursorData });
8711
- var _c = useState({}), editableTagNames = _c[0], setEditableTagNames = _c[1];
8712
- var handleChange = function (index, value, property) {
8713
- setTagList(function (prev) { return prev.map(function (tag, currentIndex) {
8714
- var _a;
8715
- return currentIndex === index ? __assign(__assign({}, tag), (_a = {}, _a[property] = value, _a.autoScale = false, _a)) : tag;
8716
- }); });
8717
- };
8718
- var handleChangeAlias = function (tagId, newName) {
8719
- setTagList(function (prevTagList) {
8720
- return prevTagList.map(function (tag) { return (tag.tagId === tagId ? __assign(__assign({}, tag), { tagName: newName }) : tag); });
8721
- });
8722
- };
8723
- var handleVisibilityChange = function (index, value) {
8724
- setTagList(function (prev) { return prev.map(function (tag, currentIndex) { return currentIndex === index ? __assign(__assign({}, tag), { visible: value }) : tag; }); });
8725
- };
8726
- var handleAutoScaleChange = function (index, value) {
8727
- setTagList(function (prev) { return prev.map(function (tag, currentIndex) { return currentIndex === index ? __assign(__assign({}, tag), { autoScale: value }) : tag; }); });
8728
- };
8729
- var handleColorChange = function (tagId, value) {
8730
- setTagList(function (prev) { return prev.map(function (tag) { return tag.tagId === tagId ? __assign(__assign({}, tag), { color: value }) : tag; }); });
8731
- };
8732
- var handleDeleteTag = function (tagId) {
8733
- setTagList(function (prevTagList) {
8734
- return prevTagList.filter(function (tag) { return tag.tagId !== tagId; });
8735
- });
8736
- };
8737
- var handleAddTag = function (newTag) {
8738
- if (newTag) {
8739
- setTagList(function (prevTagList) {
8740
- // Check if the tag is already in the list to avoid duplicates
8741
- if (prevTagList.some(function (tag) { return tag.tagId === newTag.tagId; })) {
8742
- return prevTagList; // Return the existing list if the tag is already there
8743
- }
8744
- return __spreadArray(__spreadArray([], prevTagList, true), [newTag], false); // Add the new tag to the list
8745
- });
8746
- }
8747
- };
8748
- var _d = useState(null), selectedRowIndex = _d[0], setSelectedRowIndex = _d[1];
8749
- var _e = useState(false), addTagModalOpen = _e[0], setAddTagModalOpen = _e[1];
8750
- var handleClose = function () { return setAddTagModalOpen(false); };
8751
- var ContextMenu = function (_a) {
8752
- var x = _a.x, y = _a.y, options = _a.options;
8753
- var handleContextMenuClick = function (e) {
8754
- e.stopPropagation(); // Prevent click inside the menu from closing it
8755
- };
8756
- return (React__default.createElement("div", { className: "context-menu", style: { top: y, left: x }, onClick: handleContextMenuClick },
8757
- React__default.createElement("ul", null, options.map(function (option) { return (React__default.createElement("li", { key: option.id, onClick: option.onClick }, option.label)); }))));
8758
- };
8759
- // Position state for the context menu
8760
- var _f = useState({ x: 0, y: 0 }), contextMenuPosition = _f[0], setContextMenuPosition = _f[1];
8761
- var contextMenuOptions = [
8762
- { id: 'delete', label: 'Remove Tag', onClick: function () { return handleDelete(); } },
8763
- { id: 'add', label: 'Add Tag', onClick: function () { return setAddTagModalOpen(true); } },
8764
- { id: 'saveDefault', label: 'Save Default To Tag', onClick: function () { } },
8765
- { id: 'saveAsView', label: 'Save as View', onClick: function () { } },
8766
- { id: 'loadView', label: 'Load View', onClick: function () { } },
8767
- ];
8768
- var handleTagSelect = function (selectedTag) {
8769
- handleAddTag(selectedTag);
8770
- handleClose();
8771
- };
8772
- var handleDelete = function (index) {
8773
- if (selectedRowIndex !== null) {
8774
- var tagToDelete = tagList[selectedRowIndex];
8775
- handleDeleteTag(tagToDelete.tagId);
8776
- setSelectedRowIndex(null); // Reset the selected row index
8777
- }
8778
- };
8779
- useEffect(function () {
8780
- setEditableTagNames(tagList.reduce(function (acc, tag) {
8781
- acc[tag.tagId] = tag.tagName;
8782
- return acc;
8783
- }, {}));
8784
- }, [tagList]);
8785
- useEffect(function () {
8786
- var handleGlobalClick = function (e) {
8787
- if (selectedRowIndex !== null) {
8788
- setSelectedRowIndex(null);
8789
- }
8790
- };
8791
- var handleKeyDown = function (e) {
8792
- if (e.key === "Escape" && selectedRowIndex !== null) {
8793
- setSelectedRowIndex(null);
8990
+ var SaveAsViewModal = function (_a) {
8991
+ var open = _a.open, handleClose = _a.handleClose;
8992
+ var classes = useTrendingStyles();
8993
+ var _b = useState(false), isLoading = _b[0], setIsLoading = _b[1];
8994
+ var _c = useState(''), error = _c[0], setError = _c[1];
8995
+ var viewTags = useTrendingContext().state.viewTags;
8996
+ var _d = useState(true), isPublic = _d[0], setIsPublic = _d[1];
8997
+ var _e = useState(''), viewName = _e[0], setViewName = _e[1];
8998
+ var handleCheck = function () { return setIsPublic(!isPublic); };
8999
+ var handleInputChange = function (e) { return setViewName(e.target.value); };
9000
+ var handleSubmit = function () { return __awaiter(void 0, void 0, void 0, function () {
9001
+ var resp, ViewId_1, results;
9002
+ return __generator(this, function (_a) {
9003
+ switch (_a.label) {
9004
+ case 0:
9005
+ setIsLoading(true);
9006
+ return [4 /*yield*/, upsertView(null, viewName, isPublic)];
9007
+ case 1:
9008
+ resp = _a.sent();
9009
+ if (!resp.ok) return [3 /*break*/, 3];
9010
+ ViewId_1 = resp.data.returnValue;
9011
+ return [4 /*yield*/, Promise.allSettled(viewTags.map(function (_a) {
9012
+ var TagId = _a.TagId, Color = _a.Color, MinScale = _a.MinScale, MaxScale = _a.MaxScale, IsAutoScale = _a.IsAutoScale, IsVisible = _a.IsVisible;
9013
+ upsertViewTag(ViewId_1, TagId, Color, MinScale, MaxScale, IsVisible, IsAutoScale)
9014
+ .then(function (r) {
9015
+ if (!r.ok) {
9016
+ setError(r.message);
9017
+ }
9018
+ });
9019
+ }))];
9020
+ case 2:
9021
+ results = _a.sent();
9022
+ results.forEach(function (result, index) {
9023
+ if (result.status === "rejected") {
9024
+ setError("Tag ".concat(index, " failed with reason: ").concat(result.reason));
9025
+ }
9026
+ else {
9027
+ handleClose();
9028
+ }
9029
+ });
9030
+ return [3 /*break*/, 4];
9031
+ case 3:
9032
+ setError(resp.message);
9033
+ _a.label = 4;
9034
+ case 4:
9035
+ setIsLoading(false);
9036
+ return [2 /*return*/];
8794
9037
  }
8795
- };
8796
- // Attach event listeners
8797
- document.addEventListener("click", handleGlobalClick);
8798
- document.addEventListener("keydown", handleKeyDown);
8799
- // Cleanup function
8800
- return function () {
8801
- document.removeEventListener("click", handleGlobalClick);
8802
- document.removeEventListener("keydown", handleKeyDown);
8803
- };
8804
- }, [selectedRowIndex]);
8805
- var handleRowClick = function (index) {
8806
- setSelectedRowIndex(index);
8807
- };
8808
- var handleRightClick = function (event, index) {
8809
- event.preventDefault();
8810
- event.stopPropagation(); // Prevent the click event from propagating to the document
8811
- setSelectedRowIndex(index);
8812
- setContextMenuPosition({ x: event.clientX, y: event.clientY });
8813
- };
8814
- return (React__default.createElement(Grid$1, { container: true, spacing: 1 },
8815
- React__default.createElement(Grid$1, { item: true, xs: 12 },
8816
- React__default.createElement("div", { style: { overflowX: 'auto', width: '100%' } },
8817
- React__default.createElement("table", { style: { width: '100%', tableLayout: 'fixed', textAlign: "center" } },
8818
- React__default.createElement("thead", null,
8819
- React__default.createElement("tr", null,
8820
- React__default.createElement("th", { className: classes.visible }),
8821
- React__default.createElement("th", { className: classes.inputCol }),
8822
- React__default.createElement("th", { className: classes.color }),
8823
- React__default.createElement("th", { colSpan: 4, className: "".concat(classes.topTitles, " ").concat(classes.scale) }, "Scale"),
8824
- React__default.createElement("th", { className: "".concat(classes.topTitles, " ").concat(classes.xStats) }, cursorData ? (function () {
8825
- var date = new Date(cursorData.x1);
8826
- var formattedDate = date.toLocaleString('en-US', {
8827
- hour12: false,
8828
- month: 'short',
8829
- day: 'numeric',
8830
- hour: '2-digit',
8831
- minute: '2-digit',
8832
- second: '2-digit'
8833
- });
8834
- var milliseconds = date.getMilliseconds().toString().padStart(3, '0');
8835
- var dateText = "".concat(formattedDate, ".").concat(milliseconds);
8836
- return (React__default.createElement(React__default.Fragment, null,
8837
- React__default.createElement("span", { style: {
8838
- height: '10px',
8839
- width: '10px',
8840
- backgroundColor: "red",
8841
- borderRadius: '50%',
8842
- display: 'inline-block',
8843
- marginRight: '5px'
8844
- } }),
8845
- dateText));
8846
- })() : null),
8847
- React__default.createElement("th", { className: "".concat(classes.topTitles, " ").concat(classes.xStats) }, cursorData ? (function () {
8848
- var date = new Date(cursorData.x2);
8849
- var formattedDate = date.toLocaleString('en-US', {
8850
- hour12: false,
8851
- month: 'short',
8852
- day: 'numeric',
8853
- hour: '2-digit',
8854
- minute: '2-digit',
8855
- second: '2-digit'
8856
- });
8857
- var milliseconds = date.getMilliseconds().toString().padStart(3, '0');
8858
- var dateText = "".concat(formattedDate, ".").concat(milliseconds);
8859
- return (React__default.createElement(React__default.Fragment, null,
8860
- React__default.createElement("span", { style: {
8861
- height: '10px',
8862
- width: '10px',
8863
- backgroundColor: "blue",
8864
- borderRadius: '50%',
8865
- display: 'inline-block',
8866
- marginRight: '5px'
8867
- } }),
8868
- dateText));
8869
- })() : null),
8870
- React__default.createElement("th", { colSpan: 3, className: "".concat(classes.topTitles, " ").concat(classes.xStats) }, cursorData ? timeDifference(cursorData.x2, cursorData.x1) : null)))),
8871
- React__default.createElement("table", { style: { width: '100%', tableLayout: 'fixed', textAlign: "center" } },
8872
- React__default.createElement("thead", null,
8873
- React__default.createElement("tr", { className: classes.bottomTitlesRow },
8874
- React__default.createElement("th", { className: classes.visible }, "Visible"),
8875
- React__default.createElement("th", { className: classes.inputCol }, "Alias / Tagname"),
8876
- React__default.createElement("th", { className: classes.color }, "Color"),
8877
- React__default.createElement("th", { className: classes.inputCol }, "Min Scale"),
8878
- React__default.createElement("th", { className: classes.inputCol }, "Max Scale"),
8879
- React__default.createElement("th", { className: classes.unit }, "Unit"),
8880
- React__default.createElement("th", { className: classes.autoScale }, "AutoScale"),
8881
- React__default.createElement("th", null, " "),
8882
- React__default.createElement("th", null),
8883
- React__default.createElement("th", null, "Y2-Y1"),
8884
- React__default.createElement("th", null, "Min"),
8885
- React__default.createElement("th", null, "Max")))))),
8886
- React__default.createElement(Grid$1, { item: true, xs: 12 },
8887
- React__default.createElement("div", { style: { width: '100%', overflowY: 'auto', maxHeight: ' 20svh' } },
8888
- React__default.createElement("table", { cellPadding: '4px', style: { width: '100%', tableLayout: 'fixed', textAlign: "center" } },
8889
- React__default.createElement("tbody", null, tagList.map(function (tag, index) {
8890
- var _a, _b, _c, _d, _e, _f, _g;
8891
- return (React__default.createElement("tr", { key: tag.tagName, onClick: function () { return handleRowClick(index); }, onContextMenu: function (e) { return handleRightClick(e, index); }, className: classes.rowHover },
8892
- React__default.createElement("td", { className: "".concat(classes.visible, " ").concat(classes.checkbox) },
8893
- React__default.createElement("input", { type: "checkbox", checked: tag.visible, onChange: function (e) { return handleVisibilityChange(index, e.target.checked); } })),
8894
- React__default.createElement("td", { className: classes.inputCol },
8895
- React__default.createElement(Tooltip, { title: tag.tagName, placement: "top", arrow: true, interactive: true, enterDelay: 500 },
8896
- React__default.createElement("div", null,
8897
- React__default.createElement("input", { type: "text", style: { width: '100%' }, value: editableTagNames[tag.tagId] || '', onFocus: function (e) { return e.target.select(); }, onChange: function (e) {
8898
- var _a;
8899
- setEditableTagNames(__assign(__assign({}, editableTagNames), (_a = {}, _a[tag.tagId] = e.target.value, _a)));
8900
- }, onKeyDown: function (e) {
8901
- if (e.key === 'Enter') {
8902
- handleChangeAlias(tag.tagId, editableTagNames[tag.tagId]);
8903
- }
8904
- } })))),
8905
- React__default.createElement("td", { className: classes.color },
8906
- React__default.createElement(ColorPicker, { onChange: handleColorChange, color: tag.color, elementId: tag.tagId })),
8907
- React__default.createElement("td", { className: classes.inputCol },
8908
- React__default.createElement("input", { type: "text", style: { width: '100%' }, disabled: tag.autoScale, value: tag.minScale, onFocus: function (e) { return e.target.select(); }, onChange: function (e) {
8909
- var value = e.target.value;
8910
- var numericValue = Number(value);
8911
- // Check if the value is a number and not empty
8912
- handleChange(index, numericValue, 'minScale');
8913
- } })),
8914
- React__default.createElement("td", { className: classes.inputCol },
8915
- React__default.createElement("input", { type: "text", style: { width: '100%' }, disabled: tag.autoScale, value: tag.maxScale, onFocus: function (e) { return e.target.select(); }, onChange: function (e) {
8916
- var value = e.target.value;
8917
- var numericValue = Number(value);
8918
- // Check if the value is a number and not empty
8919
- if (!isNaN(numericValue) && value.trim() !== '') {
8920
- handleChange(index, numericValue, 'maxScale');
8921
- }
8922
- } })),
8923
- React__default.createElement("td", { className: "".concat(classes.autoScale, " ").concat(classes.checkbox) },
8924
- React__default.createElement("input", { type: "text", style: { width: '100%' }, disabled: true, value: /* tag.unit */ "Unit ", onFocus: function (e) { return e.target.select(); } })),
8925
- React__default.createElement("td", { className: "".concat(classes.autoScale, " ").concat(classes.checkbox) },
8926
- React__default.createElement("input", { type: "checkbox", checked: tag.autoScale, onChange: function (e) { return handleAutoScaleChange(index, e.target.checked); } })),
8927
- React__default.createElement("td", null, (_a = dataTable[tag.tagName]) === null || _a === void 0 ? void 0 : _a.y1),
8928
- React__default.createElement("td", { className: classes.doubleInput }, (_b = dataTable[tag.tagName]) === null || _b === void 0 ? void 0 : _b.y2),
8929
- React__default.createElement("td", null, (_c = dataTable[tag.tagName]) === null || _c === void 0 ? void 0 : _c.y2y1),
8930
- React__default.createElement("td", null,
8931
- !isNaN(((_d = dataTable[tag.tagName]) === null || _d === void 0 ? void 0 : _d.pmin.y) * 0) ? (_e = dataTable[tag.tagName]) === null || _e === void 0 ? void 0 : _e.pmin.y : 0,
8932
- " "),
8933
- React__default.createElement("td", null,
8934
- !isNaN(((_f = dataTable[tag.tagName]) === null || _f === void 0 ? void 0 : _f.pmax.y) * 0) ? (_g = dataTable[tag.tagName]) === null || _g === void 0 ? void 0 : _g.pmax.y : 0,
8935
- " ")));
8936
- }))))),
8937
- selectedRowIndex !== null && (React__default.createElement(ContextMenu, { x: contextMenuPosition.x, y: contextMenuPosition.y, options: contextMenuOptions })),
8938
- React__default.createElement(AddTagModal, { open: addTagModalOpen, handleClose: handleClose, onTagSelect: handleTagSelect })));
9038
+ });
9039
+ }); };
9040
+ return (React__default.createElement(React__default.Fragment, null,
9041
+ React__default.createElement(MesfModal, { open: open, handleClose: handleClose, maxWidth: "xl", "aria-labelledby": "modal-modal-title", "aria-describedby": "modal-modal-description", title: 'Tags' },
9042
+ React__default.createElement(Divider, null),
9043
+ React__default.createElement(MesfModal.Content, null,
9044
+ React__default.createElement(Grid$1, { container: true, spacing: 5, style: { padding: "1rem" } },
9045
+ React__default.createElement(Grid$1, { item: true, md: 12, xs: 12, style: { padding: "10px", width: "100%" } },
9046
+ React__default.createElement(TextField, { size: 'small', id: "outlined-basic", label: "View Name", variant: "outlined", value: viewName, onChange: handleInputChange, style: { width: "100%" } }))),
9047
+ React__default.createElement(Grid$1, { item: true, md: 12, xs: 12, style: { paddingTop: "2rem" }, className: classes.isPublicCheckbox },
9048
+ React__default.createElement("label", null,
9049
+ "Public",
9050
+ React__default.createElement("input", { type: "checkbox", checked: isPublic, onChange: handleCheck })))),
9051
+ React__default.createElement(Divider, null),
9052
+ React__default.createElement(MesfModal.Actions, null,
9053
+ React__default.createElement(Grid$1, { container: true, spacing: 1, style: { display: 'flex', alignItems: 'flex-end', justifyContent: 'flex-end' } },
9054
+ React__default.createElement(Grid$1, { item: true },
9055
+ React__default.createElement(Button$1, { variant: 'outlined', color: 'secondary', onClick: handleClose }, "Cancel")),
9056
+ React__default.createElement(Grid$1, { item: true },
9057
+ React__default.createElement(ButtonWithLoading, { variant: 'contained', color: 'primary', onClick: handleSubmit, isLoading: isLoading }, "Save"))))),
9058
+ React__default.createElement(ErrorModal, { error: error, onHide: function () { return setError(''); } })));
8939
9059
  };
8940
9060
 
8941
- var TrendingsInitialState = {
8942
- timeScopeStart: moment(new Date()).subtract(1, "days").toDate(),
8943
- timeScopeEnd: new Date(),
8944
- scope: "1 day",
8945
- graphPan: false
8946
- };
8947
- var TrendingsReducer = createSlice({
8948
- name: "__",
8949
- initialState: TrendingsInitialState,
8950
- reducers: {
8951
- setTotalScope: function (state, _a) {
8952
- var payload = _a.payload; _a.type;
8953
- if (!isNil$1(payload.start) && !isNil$1(payload.end) && !isNil$1(payload.scope)) {
8954
- //from arrow navigators
8955
- state.timeScopeStart = payload.start;
8956
- state.timeScopeEnd = payload.end;
8957
- state.scope = payload.scope;
8958
- return;
8959
- }
8960
- if (!isNil$1(payload.scope)) {
8961
- if (payload.scope !== "custom") {
8962
- switch (payload.scope) {
8963
- case "10 min":
8964
- state.timeScopeStart = moment(state.timeScopeEnd)
8965
- .subtract(10, "minutes")
8966
- .toDate();
8967
- break;
8968
- case "1 hour":
8969
- state.timeScopeStart = moment(state.timeScopeEnd)
8970
- .subtract(1, "hours")
8971
- .toDate();
8972
- break;
8973
- case "4 hours":
8974
- state.timeScopeStart = moment(state.timeScopeEnd)
8975
- .subtract(4, "hours")
8976
- .toDate();
8977
- break;
8978
- case "12 hours":
8979
- state.timeScopeStart = moment(state.timeScopeEnd)
8980
- .subtract(12, "hours")
8981
- .toDate();
8982
- break;
8983
- case "1 day":
8984
- state.timeScopeStart = moment(state.timeScopeEnd)
8985
- .subtract(1, "days")
8986
- .toDate();
8987
- break;
8988
- case "10 days":
8989
- state.timeScopeStart = moment(state.timeScopeEnd)
8990
- .subtract(10, "days")
8991
- .toDate();
8992
- break;
8993
- }
8994
- }
8995
- state.scope = payload.scope;
8996
- return;
8997
- }
8998
- if (!isNil$1(payload.start) && !isNil$1(payload.end) && isNil$1(payload.graphPan)) {
8999
- // from zoom
9000
- state.timeScopeStart = payload.start;
9001
- state.timeScopeEnd = payload.end;
9002
- state.scope = "custom";
9003
- return;
9004
- }
9005
- if (!isNil$1(payload.start) && !isNil$1(payload.end) && !isNil$1(payload.graphPan)) {
9006
- // from pan
9007
- state.timeScopeStart = payload.start;
9008
- state.timeScopeEnd = payload.end;
9009
- return;
9010
- }
9011
- if (!isNil$1(payload.start)) {
9012
- state.timeScopeStart = payload.start;
9013
- if (state.scope !== "custom") {
9014
- switch (state.scope) {
9015
- case "10 min":
9016
- state.timeScopeEnd = moment(payload.start)
9017
- .add(10, "minutes")
9018
- .toDate();
9019
- break;
9020
- case "1 hour":
9021
- state.timeScopeEnd = moment(payload.start)
9022
- .add(1, "hours")
9023
- .toDate();
9024
- break;
9025
- case "4 hours":
9026
- state.timeScopeEnd = moment(payload.start)
9027
- .add(4, "hours")
9028
- .toDate();
9029
- break;
9030
- case "12 hours":
9031
- state.timeScopeEnd = moment(payload.start)
9032
- .add(12, "hours")
9033
- .toDate();
9034
- break;
9035
- case "1 day":
9036
- state.timeScopeEnd = moment(payload.start)
9037
- .add(1, "days")
9038
- .toDate();
9039
- break;
9040
- case "10 days":
9041
- state.timeScopeEnd = moment(payload.start)
9042
- .add(10, "days")
9043
- .toDate();
9044
- break;
9061
+ var useTagsDataTable = function (_a) {
9062
+ var cursorData = _a.cursorData, viewTags = _a.viewTags, chartData = _a.chartData;
9063
+ return useMemo(function () {
9064
+ var _a;
9065
+ var dataTable = {};
9066
+ if (cursorData) {
9067
+ var _loop_1 = function (idx) {
9068
+ var tag = viewTags[idx];
9069
+ var datasetForTag = ((_a = chartData.datasets.find(function (ds) {
9070
+ return ds.tagId === (tag === null || tag === void 0 ? void 0 : tag.TagId);
9071
+ })) === null || _a === void 0 ? void 0 : _a.data) || [];
9072
+ var p1 = { x: new Date('1900-01-01'), y: 0 };
9073
+ var p2 = { x: new Date('1900-01-01'), y: 0 };
9074
+ var p1Found = false;
9075
+ var pmin = { x: 0, y: Number.POSITIVE_INFINITY };
9076
+ var pmax = { x: 0, y: Number.NEGATIVE_INFINITY };
9077
+ for (var idx_1 = 0; idx_1 < datasetForTag.length; idx_1++) {
9078
+ var curr = datasetForTag[idx_1];
9079
+ var currentVal = curr.x;
9080
+ if (!p1Found) {
9081
+ if (currentVal < cursorData.x1) {
9082
+ p1 = curr;
9083
+ p2 = JSON.parse(JSON.stringify(p1));
9084
+ pmin = JSON.parse(JSON.stringify(p1));
9085
+ pmax = JSON.parse(JSON.stringify(p1));
9086
+ continue;
9087
+ }
9088
+ else {
9089
+ p1Found = true;
9090
+ }
9045
9091
  }
9046
- }
9047
- return;
9048
- }
9049
- if (!isNil$1(payload.end)) {
9050
- state.timeScopeEnd = payload.end;
9051
- if (state.scope !== "custom") {
9052
- switch (state.scope) {
9053
- case "10 min":
9054
- state.timeScopeStart = moment(payload.end)
9055
- .subtract(10, "minutes")
9056
- .toDate();
9057
- break;
9058
- case "1 hour":
9059
- state.timeScopeStart = moment(payload.end)
9060
- .subtract(1, "hours")
9061
- .toDate();
9062
- break;
9063
- case "4 hours":
9064
- state.timeScopeStart = moment(payload.end)
9065
- .subtract(4, "hours")
9066
- .toDate();
9067
- break;
9068
- case "12 hours":
9069
- state.timeScopeStart = moment(payload.end)
9070
- .subtract(12, "hours")
9071
- .toDate();
9072
- break;
9073
- case "1 day":
9074
- state.timeScopeStart = moment(payload.end)
9075
- .subtract(1, "days")
9076
- .toDate();
9077
- break;
9078
- case "10 days":
9079
- state.timeScopeStart = moment(payload.end)
9080
- .subtract(10, "days")
9081
- .toDate();
9092
+ else {
9093
+ if (currentVal < cursorData.x2) {
9094
+ p2 = curr;
9095
+ if (pmin['y'] > curr['y']) {
9096
+ pmin = JSON.parse(JSON.stringify(curr));
9097
+ }
9098
+ if (pmax['y'] < curr['y']) {
9099
+ pmax = JSON.parse(JSON.stringify(curr));
9100
+ }
9101
+ }
9102
+ else {
9082
9103
  break;
9104
+ }
9083
9105
  }
9084
9106
  }
9085
- return;
9107
+ dataTable[tag === null || tag === void 0 ? void 0 : tag.TagName] = {
9108
+ y1: p1.y,
9109
+ y2: p2.y,
9110
+ y2y1: Number(p2.y) - Number(p1.y),
9111
+ pmin: pmin,
9112
+ pmax: pmax
9113
+ };
9114
+ };
9115
+ for (var idx = 0; idx < viewTags.length; idx++) {
9116
+ _loop_1(idx);
9086
9117
  }
9087
9118
  }
9119
+ return dataTable;
9120
+ }, [viewTags, chartData, cursorData]);
9121
+ };
9122
+
9123
+ var useTagsTableStyles = makeStyles$1(function (theme) { return ({
9124
+ checkbox: {
9125
+ '& input[type="checkbox"]': {
9126
+ zoom: 1.5
9127
+ },
9128
+ textAlign: 'center'
9129
+ },
9130
+ rowHover: {
9131
+ '&:hover': {
9132
+ backgroundColor: "#f2f2f2"
9133
+ }
9134
+ },
9135
+ topTitles: {
9136
+ border: "0.0625rem black solid",
9137
+ borderBottom: "none",
9138
+ backgroundColor: "#e9ecef"
9139
+ },
9140
+ bottomTitlesRow: {
9141
+ '& th': {
9142
+ border: "1px black solid"
9143
+ },
9144
+ backgroundColor: "#e9ecef"
9145
+ },
9146
+ doubleInput: {
9147
+ padding: "0",
9148
+ '& input[type="text"] ': {
9149
+ width: "100%",
9150
+ height: "17px",
9151
+ display: "block",
9152
+ margin: "0",
9153
+ padding: "0"
9154
+ }
9155
+ },
9156
+ inputCol: {
9157
+ width: "11.25rem",
9158
+ overflow: 'hidden',
9159
+ textOverflow: 'ellipsis',
9160
+ whiteSpace: 'nowrap'
9161
+ },
9162
+ autoScale: {
9163
+ width: '7.5rem'
9164
+ },
9165
+ scale: {
9166
+ width: '37.5rem',
9167
+ padding: "0"
9168
+ },
9169
+ visible: {
9170
+ width: '3.75rem'
9171
+ },
9172
+ color: {
9173
+ width: '4.375rem'
9174
+ },
9175
+ unit: {
9176
+ width: '7.5rem'
9177
+ },
9178
+ xStats: {
9179
+ // ...
9088
9180
  }
9089
- });
9181
+ }); });
9090
9182
 
9091
- var TrendingContext = createContext({
9092
- state: TrendingsReducer.getInitialState(),
9093
- actions: TrendingsReducer.actions
9094
- });
9095
- var useTrendingContext = function () { return useContext(TrendingContext); };
9096
- var TrendingProvider = function (_a) {
9097
- var children = _a.children;
9098
- var _b = useComplexState({
9099
- initialState: TrendingsReducer.getInitialState(),
9100
- reducers: TrendingsReducer.caseReducers
9101
- }), state = _b[0], actions = _b[1];
9102
- return (React__default.createElement(TrendingContext.Provider, { value: { state: state, actions: actions } }, children));
9183
+ var timeDifference = function (start, end) {
9184
+ var differenceMilliseconds = start - end;
9185
+ var seconds = Math.floor(differenceMilliseconds / 1000);
9186
+ var minutes = Math.floor(seconds / 60);
9187
+ var hours = Math.floor(minutes / 60);
9188
+ var remainingMinutes = minutes % 60;
9189
+ var remainingSeconds = seconds % 60;
9190
+ return "".concat(hours, "h ").concat(remainingMinutes, "m ").concat(remainingSeconds, "s");
9191
+ };
9192
+
9193
+ var TableComponent = function (_a) {
9194
+ var chartData = _a.chartData, cursorData = _a.cursorData;
9195
+ var classes = useTagsTableStyles();
9196
+ var _b = useTrendingContext(), _c = _b.state, viewTags = _c.viewTags, viewSelected = _c.viewSelected, setViewTags = _b.actions.setViewTags;
9197
+ var _d = useState(''), error = _d[0], setError = _d[1];
9198
+ var _e = useState(""); _e[0]; _e[1];
9199
+ var dataTable = useTagsDataTable({ viewTags: viewTags, chartData: chartData, cursorData: cursorData });
9200
+ var _f = useState({}), editableTagNames = _f[0], setEditableTagNames = _f[1];
9201
+ var handleChange = function (tagId, value, property) {
9202
+ var newTags = viewTags.map(function (tag) {
9203
+ var _a;
9204
+ return tag.TagId === tagId ? __assign(__assign({}, tag), (_a = {}, _a[property] = value, _a.IsAutoScale = false, _a)) : tag;
9205
+ });
9206
+ setViewTags(newTags);
9207
+ };
9208
+ var handleChangeAlias = function (tagId, newName) {
9209
+ var newTags = viewTags.map(function (tag) { return (tag.TagId === tagId ? __assign(__assign({}, tag), { Alias: newName }) : tag); });
9210
+ setViewTags(newTags);
9211
+ };
9212
+ var handleVisibilityChange = function (tagId, value) {
9213
+ var newTags = viewTags.map(function (tag) { return tag.TagId === tagId ? __assign(__assign({}, tag), { IsVisible: value }) : tag; });
9214
+ setViewTags(newTags);
9215
+ };
9216
+ var handleAutoScaleChange = function (tagId, checked) {
9217
+ var newTags = viewTags.map(function (t) { return t.TagId == tagId ? __assign(__assign({}, t), { IsAutoScale: !checked }) : t; });
9218
+ setViewTags(newTags);
9219
+ };
9220
+ var handleColorChange = function (tagId, value) {
9221
+ var newTags = viewTags.map(function (tag) { return tag.TagId === tagId ? __assign(__assign({}, tag), { Color: value }) : tag; });
9222
+ setViewTags(newTags);
9223
+ };
9224
+ var handleDeleteTag = function (tagId) {
9225
+ var newTags = viewTags.filter(function (tag) { return tag.TagId !== tagId; });
9226
+ setViewTags(newTags);
9227
+ };
9228
+ var handleAddTag = function (newTag) {
9229
+ var newArr = __spreadArray([], viewTags, true);
9230
+ if (newTag) {
9231
+ newArr.push(newTag);
9232
+ setViewTags(newArr);
9233
+ }
9234
+ };
9235
+ var _g = useState(null), selectedRowIndex = _g[0], setSelectedRowIndex = _g[1];
9236
+ var _h = useState(false), addTagModalOpen = _h[0], setAddTagModalOpen = _h[1];
9237
+ var _j = useState(false), saveAsViewModalOpen = _j[0], setSaveAsViewModalOpen = _j[1];
9238
+ var _k = useState(false), loadViewOpen = _k[0], setLoadViewOpen = _k[1];
9239
+ var handleClose = function () { return setAddTagModalOpen(false); };
9240
+ var ContextMenu = function (_a) {
9241
+ var x = _a.x, y = _a.y, options = _a.options;
9242
+ var handleContextMenuClick = function (e) {
9243
+ e.stopPropagation(); // Prevent click inside the menu from closing it
9244
+ };
9245
+ return (React__default.createElement("div", { className: "context-menu", style: { top: y, left: x }, onClick: handleContextMenuClick },
9246
+ React__default.createElement("ul", null, options.map(function (option) { return (React__default.createElement("li", { key: option.id, onClick: option.onClick }, option.label)); }))));
9247
+ };
9248
+ // Position state for the context menu
9249
+ var _l = useState({ x: 0, y: 0 }), contextMenuPosition = _l[0], setContextMenuPosition = _l[1];
9250
+ var contextMenuOptions = [
9251
+ { id: 'delete', label: 'Remove Tag', onClick: function () { return handleDelete(); } },
9252
+ { id: 'add', label: 'Add Tag', onClick: function () { return setAddTagModalOpen(true); } },
9253
+ { id: 'saveDefault', label: 'Save Default To Tag', onClick: function () { return handleSaveDefaultToTag(); } },
9254
+ { id: 'saveAsView', label: 'Save as View', onClick: function () { return setSaveAsViewModalOpen(true); } },
9255
+ { id: 'loadView', label: 'Load View', onClick: function () { return setLoadViewOpen(true); } },
9256
+ ];
9257
+ var handleTagSelect = function (selectedTag) {
9258
+ handleAddTag(selectedTag);
9259
+ handleClose();
9260
+ };
9261
+ var handleDelete = function (index) {
9262
+ if (selectedRowIndex !== null) {
9263
+ var tagToDelete = viewTags[selectedRowIndex];
9264
+ handleDeleteTag(tagToDelete.TagId);
9265
+ setSelectedRowIndex(null); // Reset the selected row index
9266
+ }
9267
+ };
9268
+ useEffect(function () {
9269
+ if (Array.isArray(viewTags)) {
9270
+ setEditableTagNames(viewTags.reduce(function (acc, tag) {
9271
+ acc[tag.TagId] = tag.Alias || tag.TagName;
9272
+ return acc;
9273
+ }, {}));
9274
+ }
9275
+ }, [viewTags]);
9276
+ useEffect(function () {
9277
+ var handleGlobalClick = function (e) {
9278
+ if (selectedRowIndex !== null) {
9279
+ setSelectedRowIndex(null);
9280
+ }
9281
+ };
9282
+ var handleKeyDown = function (e) {
9283
+ if (e.key === "Escape" && selectedRowIndex !== null) {
9284
+ setSelectedRowIndex(null);
9285
+ }
9286
+ };
9287
+ // Attach event listeners
9288
+ document.addEventListener("click", handleGlobalClick);
9289
+ document.addEventListener("keydown", handleKeyDown);
9290
+ // Cleanup function
9291
+ return function () {
9292
+ document.removeEventListener("click", handleGlobalClick);
9293
+ document.removeEventListener("keydown", handleKeyDown);
9294
+ };
9295
+ }, [selectedRowIndex]);
9296
+ var handleRightClick = function (event, index) {
9297
+ event.preventDefault();
9298
+ event.stopPropagation(); // Prevent the click event from propagating to the document
9299
+ setSelectedRowIndex(index);
9300
+ setContextMenuPosition({ x: event.clientX, y: event.clientY });
9301
+ };
9302
+ var handleSaveDefaultToTag = function () { return __awaiter(void 0, void 0, void 0, function () {
9303
+ var promises, allResponses, error_1;
9304
+ return __generator(this, function (_a) {
9305
+ switch (_a.label) {
9306
+ case 0:
9307
+ _a.trys.push([0, 2, 3, 4]);
9308
+ promises = viewTags.map(function (vt) { return __awaiter(void 0, void 0, void 0, function () {
9309
+ var response;
9310
+ return __generator(this, function (_a) {
9311
+ switch (_a.label) {
9312
+ case 0: return [4 /*yield*/, saveTagDefaults(vt.TagId, vt.Alias, vt.Color, vt.MinScale, vt.MaxScale, vt.Unit)];
9313
+ case 1:
9314
+ response = _a.sent();
9315
+ return [2 /*return*/, response];
9316
+ }
9317
+ });
9318
+ }); });
9319
+ return [4 /*yield*/, Promise.all(promises)];
9320
+ case 1:
9321
+ allResponses = _a.sent();
9322
+ allResponses.forEach(function (r) {
9323
+ if (!r.ok) {
9324
+ setError(r.message);
9325
+ }
9326
+ });
9327
+ return [3 /*break*/, 4];
9328
+ case 2:
9329
+ error_1 = _a.sent();
9330
+ setError(error_1.message);
9331
+ return [3 /*break*/, 4];
9332
+ case 3:
9333
+ setSelectedRowIndex(null);
9334
+ return [7 /*endfinally*/];
9335
+ case 4: return [2 /*return*/];
9336
+ }
9337
+ });
9338
+ }); };
9339
+ return (React__default.createElement(React__default.Fragment, null,
9340
+ React__default.createElement(Grid$1, { container: true, spacing: 1 },
9341
+ React__default.createElement(Grid$1, { item: true, xs: 12 },
9342
+ React__default.createElement("div", { style: { overflowX: 'auto', width: '100%' } },
9343
+ React__default.createElement("table", { style: { width: '100%', tableLayout: 'fixed', textAlign: "center" } },
9344
+ React__default.createElement("thead", null,
9345
+ React__default.createElement("tr", null,
9346
+ React__default.createElement("th", { className: classes.visible }, "View:"),
9347
+ React__default.createElement("th", { className: classes.inputCol }, viewSelected === null || viewSelected === void 0 ? void 0 : viewSelected.ViewName),
9348
+ React__default.createElement("th", { className: classes.color }),
9349
+ React__default.createElement("th", { colSpan: 4, className: "".concat(classes.topTitles, " ").concat(classes.scale) }, "Scale"),
9350
+ React__default.createElement("th", { className: "".concat(classes.topTitles, " ").concat(classes.xStats) }, cursorData ? (function () {
9351
+ var date = new Date(cursorData.x1);
9352
+ var formattedDate = date.toLocaleString('en-US', {
9353
+ hour12: false,
9354
+ month: 'short',
9355
+ day: 'numeric',
9356
+ hour: '2-digit',
9357
+ minute: '2-digit',
9358
+ second: '2-digit'
9359
+ });
9360
+ var milliseconds = date.getMilliseconds().toString().padStart(3, '0');
9361
+ var dateText = "".concat(formattedDate, ".").concat(milliseconds);
9362
+ return (React__default.createElement(React__default.Fragment, null,
9363
+ React__default.createElement("span", { style: {
9364
+ height: '10px',
9365
+ width: '10px',
9366
+ backgroundColor: "red",
9367
+ borderRadius: '50%',
9368
+ display: 'inline-block',
9369
+ marginRight: '5px'
9370
+ } }),
9371
+ dateText));
9372
+ })() : null),
9373
+ React__default.createElement("th", { className: "".concat(classes.topTitles, " ").concat(classes.xStats) }, cursorData ? (function () {
9374
+ var date = new Date(cursorData.x2);
9375
+ var formattedDate = date.toLocaleString('en-US', {
9376
+ hour12: false,
9377
+ month: 'short',
9378
+ day: 'numeric',
9379
+ hour: '2-digit',
9380
+ minute: '2-digit',
9381
+ second: '2-digit'
9382
+ });
9383
+ var milliseconds = date.getMilliseconds().toString().padStart(3, '0');
9384
+ var dateText = "".concat(formattedDate, ".").concat(milliseconds);
9385
+ return (React__default.createElement(React__default.Fragment, null,
9386
+ React__default.createElement("span", { style: {
9387
+ height: '10px',
9388
+ width: '10px',
9389
+ backgroundColor: "blue",
9390
+ borderRadius: '50%',
9391
+ display: 'inline-block',
9392
+ marginRight: '5px'
9393
+ } }),
9394
+ dateText));
9395
+ })() : null),
9396
+ React__default.createElement("th", { colSpan: 3, className: "".concat(classes.topTitles, " ").concat(classes.xStats) }, cursorData ? timeDifference(cursorData.x2, cursorData.x1) : null)))),
9397
+ React__default.createElement("table", { style: { width: '100%', tableLayout: 'fixed', textAlign: "center" } },
9398
+ React__default.createElement("thead", null,
9399
+ React__default.createElement("tr", { className: classes.bottomTitlesRow },
9400
+ React__default.createElement("th", { className: classes.visible }, "Visible"),
9401
+ React__default.createElement("th", { className: classes.inputCol }, "Alias / Tagname"),
9402
+ React__default.createElement("th", { className: classes.color }, "Color"),
9403
+ React__default.createElement("th", { className: classes.inputCol }, "Min Scale"),
9404
+ React__default.createElement("th", { className: classes.inputCol }, "Max Scale"),
9405
+ React__default.createElement("th", { className: classes.unit }, "Unit"),
9406
+ React__default.createElement("th", { className: classes.autoScale }, "AutoScale"),
9407
+ React__default.createElement("th", null, " "),
9408
+ React__default.createElement("th", null),
9409
+ React__default.createElement("th", null, "Y2-Y1"),
9410
+ React__default.createElement("th", null, "Min"),
9411
+ React__default.createElement("th", null, "Max")))))),
9412
+ React__default.createElement(Grid$1, { item: true, xs: 12 },
9413
+ React__default.createElement("div", { style: { width: '100%', overflowY: 'auto', maxHeight: ' 20svh' } },
9414
+ React__default.createElement("table", { cellPadding: '4px', style: { width: '100%', tableLayout: 'fixed', textAlign: "center" } },
9415
+ React__default.createElement("tbody", null, viewTags && viewTags.length && Array.isArray(viewTags) ? viewTags.map(function (tag, index) {
9416
+ var _a, _b, _c, _d, _e, _f, _g;
9417
+ return (React__default.createElement("tr", { key: tag.TagName,
9418
+ // onClick={() => handleRowClick(index)}
9419
+ onContextMenu: function (e) { return handleRightClick(e, index); }, className: classes.rowHover },
9420
+ React__default.createElement("td", { className: "".concat(classes.visible, " ").concat(classes.checkbox) },
9421
+ React__default.createElement("input", { type: "checkbox", checked: tag.IsVisible, onChange: function (e) { return handleVisibilityChange(tag.TagId, e.target.checked); } })),
9422
+ React__default.createElement("td", { className: classes.inputCol },
9423
+ React__default.createElement(Tooltip, { title: tag.TagName, placement: "top", arrow: true, interactive: true, enterDelay: 500 },
9424
+ React__default.createElement("div", null,
9425
+ React__default.createElement("input", { type: "text", style: { width: '100%' }, value: editableTagNames[tag.TagId], onFocus: function (e) { return e.target.select(); }, onChange: function (e) {
9426
+ var _a;
9427
+ setEditableTagNames(__assign(__assign({}, editableTagNames), (_a = {}, _a[tag.TagId] = e.target.value, _a)));
9428
+ }, onKeyDown: function (e) {
9429
+ if (e.key === 'Enter') {
9430
+ handleChangeAlias(tag.TagId, editableTagNames[tag.TagId]);
9431
+ }
9432
+ } })))),
9433
+ React__default.createElement("td", { className: classes.color },
9434
+ React__default.createElement(ColorPicker, { onChange: handleColorChange, color: tag.Color, elementId: tag.TagId })),
9435
+ React__default.createElement("td", { className: classes.inputCol },
9436
+ React__default.createElement("input", { type: "text", style: { width: '100%' }, disabled: tag.IsAutoScale, value: tag.MinScale, onFocus: function (e) { return e.target.select(); }, onChange: function (e) {
9437
+ var value = e.target.value;
9438
+ var numericValue = Number(value);
9439
+ handleChange(tag.TagId, numericValue, 'MinScale');
9440
+ } })),
9441
+ React__default.createElement("td", { className: classes.inputCol },
9442
+ React__default.createElement("input", { type: "text", style: { width: '100%' }, disabled: tag.IsAutoScale, value: tag.MaxScale, onFocus: function (e) { return e.target.select(); }, onChange: function (e) {
9443
+ var value = e.target.value;
9444
+ var numericValue = Number(value);
9445
+ // Check if the value is a number and not empty
9446
+ if (!isNaN(numericValue) && value.trim() !== '') {
9447
+ handleChange(tag.TagId, numericValue, 'MaxScale');
9448
+ }
9449
+ } })),
9450
+ React__default.createElement("td", { className: "".concat(classes.autoScale, " ").concat(classes.checkbox) },
9451
+ React__default.createElement("input", { type: "text", style: { width: '100%' }, disabled: true, value: tag.Unit, onFocus: function (e) { return e.target.select(); } })),
9452
+ React__default.createElement("td", { className: "".concat(classes.autoScale, " ").concat(classes.checkbox) },
9453
+ React__default.createElement("input", { type: "checkbox", checked: tag.IsAutoScale, onChange: function (e) { return handleAutoScaleChange(tag.TagId, tag.IsAutoScale); } })),
9454
+ React__default.createElement("td", null, (_a = dataTable[tag.TagName]) === null || _a === void 0 ? void 0 : _a.y1),
9455
+ React__default.createElement("td", { className: classes.doubleInput }, (_b = dataTable[tag.TagName]) === null || _b === void 0 ? void 0 : _b.y2),
9456
+ React__default.createElement("td", null, (_c = dataTable[tag.TagName]) === null || _c === void 0 ? void 0 : _c.y2y1),
9457
+ React__default.createElement("td", null,
9458
+ !isNaN(((_d = dataTable[tag.TagName]) === null || _d === void 0 ? void 0 : _d.pmin.y) * 0) ? (_e = dataTable[tag.TagName]) === null || _e === void 0 ? void 0 : _e.pmin.y : 0,
9459
+ " "),
9460
+ React__default.createElement("td", null,
9461
+ !isNaN(((_f = dataTable[tag.TagName]) === null || _f === void 0 ? void 0 : _f.pmax.y) * 0) ? (_g = dataTable[tag.TagName]) === null || _g === void 0 ? void 0 : _g.pmax.y : 0,
9462
+ " ")));
9463
+ }) : React__default.createElement("div", { style: { padding: '2rem' } },
9464
+ React__default.createElement("div", { style: { padding: "1rem" } }, "No tag view detected. "),
9465
+ React__default.createElement("div", { style: { padding: "1rem" } },
9466
+ React__default.createElement(Button$1, { onClick: function () { return setAddTagModalOpen(true); }, variant: 'contained', color: 'primary' }, " Add tag")),
9467
+ React__default.createElement("div", null,
9468
+ React__default.createElement(Button$1, { onClick: function () { return setLoadViewOpen(true); }, variant: 'outlined', color: 'primary' }, " Load view"))))))),
9469
+ selectedRowIndex !== null && (React__default.createElement(ContextMenu, { x: contextMenuPosition.x, y: contextMenuPosition.y, options: contextMenuOptions })),
9470
+ React__default.createElement(AddTagModal, { open: addTagModalOpen, handleClose: handleClose, onTagSelect: handleTagSelect }),
9471
+ React__default.createElement(SaveAsViewModal, { open: saveAsViewModalOpen, handleClose: function () { return setSaveAsViewModalOpen(false); } }),
9472
+ React__default.createElement(LoadViewModal, { open: loadViewOpen, handleClose: function () { return setLoadViewOpen(false); } })),
9473
+ React__default.createElement(ErrorModal, { error: error, onHide: function () { return setError(''); } })));
9103
9474
  };
9104
9475
 
9105
9476
  var formatDateTimeToString = function (date) {
@@ -9199,9 +9570,6 @@ var useChartOptions = function () {
9199
9570
  }
9200
9571
  }
9201
9572
  }
9202
- else {
9203
- console.log('sin y', keys);
9204
- }
9205
9573
  }
9206
9574
  }
9207
9575
  },
@@ -9225,64 +9593,6 @@ var useChartOptions = function () {
9225
9593
  });
9226
9594
  };
9227
9595
 
9228
- var useTrendingStyles = makeStyles$1(function (theme) { return ({
9229
- datetimePicker: {
9230
- alignItems: "center",
9231
- "& .MuiInputBase-root": {
9232
- color: "black",
9233
- backgroundColor: "white",
9234
- borderRadius: theme.shape.borderRadius,
9235
- width: "90%",
9236
- minWidth: "90%",
9237
- maxWidth: "90%"
9238
- },
9239
- "& .MuiInputBase-input": {
9240
- fontSize: "13px !important",
9241
- height: "15px !important",
9242
- paddingRight: "3px",
9243
- paddingLeft: "5px"
9244
- },
9245
- "& .MuiInput-underline:before": {
9246
- borderBottomColor: "rgba(0, 0, 0, 0.42)"
9247
- }
9248
- },
9249
- select: {
9250
- "& .MuiInput-root": {
9251
- width: "100%"
9252
- },
9253
- "& .MuiInputBase-root": {
9254
- color: "black",
9255
- backgroundColor: "white",
9256
- borderRadius: theme.shape.borderRadius,
9257
- minWidth: "100%"
9258
- },
9259
- "& .MuiInputBase-input": {
9260
- fontSize: "14px !important",
9261
- height: "15px !important"
9262
- },
9263
- "& .MuiInput-underline:before": {
9264
- borderBottomColor: "rgba(0, 0, 0, 0.42)"
9265
- }
9266
- },
9267
- labelOptions: {
9268
- paddingLeft: "2rem",
9269
- userSelect: "none",
9270
- "& > label": {
9271
- display: "flex",
9272
- alignItems: "center",
9273
- gap: "5px"
9274
- },
9275
- '& input[type="checkbox"]': {
9276
- zoom: 1.5
9277
- }
9278
- },
9279
- navigatorButton: {
9280
- "& .MuiSvgIcon-root": {
9281
- cursor: "pointer !important"
9282
- }
9283
- }
9284
- }); });
9285
-
9286
9596
  var CustomOptionsComponent = function (_a) {
9287
9597
  var customOptions = _a.customOptions, setCustomOptions = _a.setCustomOptions;
9288
9598
  var classes = useTrendingStyles();
@@ -9528,11 +9838,13 @@ var useYAxisPlugin = function () {
9528
9838
  };
9529
9839
 
9530
9840
  var areRangesSimilar = function (tag1, tag2) {
9531
- var range1 = tag1.maxScale - tag1.minScale; // Rango de la primera etiqueta
9532
- var range2 = tag2.maxScale - tag2.minScale; // Rango de la segunda etiqueta
9841
+ if (isNil$1(tag1.MaxScale) || isNil$1(tag1.MinScale) || isNil$1(tag2.MaxScale) || isNil$1(tag2.MinScale))
9842
+ return;
9843
+ var range1 = tag1.MaxScale - tag1.MinScale; // Rango de la primera etiqueta
9844
+ var range2 = tag2.MaxScale - tag2.MinScale; // Rango de la segunda etiqueta
9533
9845
  // Determina los límites para la comparación
9534
- var lowerBound = Math.max(tag1.minScale, tag2.minScale);
9535
- var upperBound = Math.min(tag1.maxScale, tag2.maxScale);
9846
+ var lowerBound = Math.max(tag1.MinScale, tag2.MinScale);
9847
+ var upperBound = Math.min(tag1.MaxScale, tag2.MaxScale);
9536
9848
  // Calcula el solapamiento entre los dos rangos
9537
9849
  var overlap = Math.max(0, upperBound - lowerBound);
9538
9850
  // Determina si el solapamiento es significativo comparado con los rangos individuales
@@ -9540,28 +9852,9 @@ var areRangesSimilar = function (tag1, tag2) {
9540
9852
  return isSignificantOverlap;
9541
9853
  };
9542
9854
 
9543
- var calculateScales = function (min, max, sigDigits) {
9544
- var roundToSignificantDigits = function (num) {
9545
- if (num === 0)
9546
- return 0;
9547
- var multiplier = Math.pow(10, sigDigits - Math.floor(Math.log10(Math.abs(num))) - 1);
9548
- return Math.round(num * multiplier) / multiplier;
9549
- };
9550
- var minScale = roundToSignificantDigits(min);
9551
- var maxScale = roundToSignificantDigits(max);
9552
- // Adjust minScale and maxScale if necessary
9553
- if (minScale > min) {
9554
- minScale *= 0.9;
9555
- }
9556
- if (maxScale < max) {
9557
- maxScale *= 1.1;
9558
- }
9559
- return { minScale: minScale, maxScale: maxScale };
9560
- };
9561
-
9562
9855
  var TrendingChart = function (_a) {
9563
- var tagList = _a.tagList, series = _a.series, chartOptions = _a.chartOptions, setChartOptions = _a.setChartOptions, chartData = _a.chartData, setCursorData = _a.setCursorData, setChartData = _a.setChartData;
9564
- var _b = useTrendingContext(), state = _b.state; _b.actions;
9856
+ var series = _a.series, chartOptions = _a.chartOptions, setChartOptions = _a.setChartOptions, chartData = _a.chartData, setCursorData = _a.setCursorData, setChartData = _a.setChartData;
9857
+ var _b = useTrendingContext(), state = _b.state, viewTags = _b.state.viewTags; _b.actions;
9565
9858
  var _c = useState(null), lineTabCoords = _c[0], setLineTabCoords = _c[1];
9566
9859
  var _d = useState(null), chartArea = _d[0], setChartArea = _d[1];
9567
9860
  var chartRef = useRef(null);
@@ -9580,14 +9873,9 @@ var TrendingChart = function (_a) {
9580
9873
  if (!series.length) {
9581
9874
  return;
9582
9875
  }
9583
- tagList.forEach(function (tag, index) {
9584
- if (series[index].length) {
9585
- if (tag.autoScale && series[index]) {
9586
- var serieSamples = series[index].map(function (sample) { return sample.value; });
9587
- var _a = calculateScales(Math.min.apply(Math, serieSamples), Math.max.apply(Math, serieSamples), 3), minScale = _a.minScale, maxScale = _a.maxScale;
9588
- tag.minScale = minScale;
9589
- tag.maxScale = maxScale;
9590
- }
9876
+ viewTags.forEach(function (tag, index) {
9877
+ var _a;
9878
+ if ((_a = series[index]) === null || _a === void 0 ? void 0 : _a.length) {
9591
9879
  var existingAxis = axes.find(function (existingTag) {
9592
9880
  return areRangesSimilar(existingTag, tag);
9593
9881
  });
@@ -9640,7 +9928,7 @@ var TrendingChart = function (_a) {
9640
9928
  return newResp;
9641
9929
  });
9642
9930
  var updatedSeries = series.map(function (serie, index) {
9643
- var tag = tagList[index];
9931
+ var tag = viewTags[index];
9644
9932
  var axisIndex = axes.findIndex(function (existingTag) {
9645
9933
  return areRangesSimilar(existingTag, tag);
9646
9934
  });
@@ -9650,9 +9938,9 @@ var TrendingChart = function (_a) {
9650
9938
  x: new Date(sample.timestamp),
9651
9939
  y: sample.value
9652
9940
  }); }),
9653
- tagId: tag.tagId,
9654
- borderColor: tag.color,
9655
- hidden: !tag.visible,
9941
+ tagId: tag === null || tag === void 0 ? void 0 : tag.TagId,
9942
+ borderColor: tag === null || tag === void 0 ? void 0 : tag.Color,
9943
+ hidden: !(tag === null || tag === void 0 ? void 0 : tag.IsVisible),
9656
9944
  pointRadius: serie.length <= 50 ? 3 : 0
9657
9945
  };
9658
9946
  });
@@ -9661,7 +9949,7 @@ var TrendingChart = function (_a) {
9661
9949
  labels: [],
9662
9950
  datasets: updatedSeries
9663
9951
  });
9664
- }, [JSON.stringify(state), tagList, series]);
9952
+ }, [state.graphShouldUpdate, series]);
9665
9953
  useEffect(function () {
9666
9954
  if (chartShouldInitCursors) {
9667
9955
  if (chartRef.current) {
@@ -9669,7 +9957,7 @@ var TrendingChart = function (_a) {
9669
9957
  chartRef.current.update();
9670
9958
  }
9671
9959
  }
9672
- }, [chartShouldInitCursors, state]);
9960
+ }, [chartShouldInitCursors, state.graphShouldUpdate]);
9673
9961
  return (React__default.createElement(Paper$1, { style: { height: '100%', position: 'relative' } },
9674
9962
  lineTabCoords && chartArea ? (React__default.createElement(DraggableLineControl, { color: 'red', chartArea: chartArea, initialLeft: lineTabCoords === null || lineTabCoords === void 0 ? void 0 : lineTabCoords.x1, onUpdate: function (newLeft) {
9675
9963
  setLineTabCoords(function (prevCoords) {
@@ -9694,18 +9982,17 @@ var TrendingChart = function (_a) {
9694
9982
 
9695
9983
  Chart.register(CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip$1, Legend, TimeScale, zoomPlugin);
9696
9984
  var Trending = function (_a) {
9697
- _a.title; var tags = _a.tags;
9698
- var _b = useTrendingContext(), state = _b.state; _b.actions;
9699
- var _c = useState(true), loading = _c[0], setLoading = _c[1];
9700
- var _d = useState(""), error = _d[0], setError = _d[1];
9701
- var _e = useState(tags), tagList = _e[0], setTagList = _e[1];
9702
- var _f = useState([]), series = _f[0], setSeries = _f[1];
9703
- var _g = useChartOptions(), chartOptions = _g[0], setChartOptions = _g[1];
9704
- var _h = useState({
9985
+ _a.title;
9986
+ var _b = useTrendingContext(), state = _b.state, viewTags = _b.state.viewTags;
9987
+ var _c = useState(''), error = _c[0], setError = _c[1];
9988
+ var _d = useState(true), loading = _d[0], setLoading = _d[1];
9989
+ var _e = useState([]), series = _e[0], setSeries = _e[1];
9990
+ var _f = useChartOptions(), chartOptions = _f[0], setChartOptions = _f[1];
9991
+ var _g = useState({
9705
9992
  labels: [],
9706
9993
  datasets: []
9707
- }), chartData = _h[0], setChartData = _h[1];
9708
- var _j = useState(null), cursorData = _j[0], setCursorData = _j[1];
9994
+ }), chartData = _g[0], setChartData = _g[1];
9995
+ var _h = useState(null), cursorData = _h[0], setCursorData = _h[1];
9709
9996
  var debounceForFetchingData = useRef(null);
9710
9997
  useEffect(function () {
9711
9998
  if (debounceForFetchingData.current) {
@@ -9717,10 +10004,10 @@ var Trending = function (_a) {
9717
10004
  return __generator(this, function (_a) {
9718
10005
  switch (_a.label) {
9719
10006
  case 0:
9720
- _a.trys.push([0, 2, , 3]);
9721
- console.log("fetching data");
10007
+ _a.trys.push([0, 3, , 4]);
9722
10008
  setLoading(true);
9723
- tagIds = tagList.map(function (tag) { return tag.tagId; });
10009
+ if (!(Array.isArray(viewTags) && viewTags.length)) return [3 /*break*/, 2];
10010
+ tagIds = viewTags.map(function (tag) { return tag.TagId; });
9724
10011
  return [4 /*yield*/, axios.post("/series?nodeName=null", {
9725
10012
  start: state.timeScopeStart.getTime(),
9726
10013
  end: state.timeScopeEnd.getTime(),
@@ -9730,84 +10017,81 @@ var Trending = function (_a) {
9730
10017
  case 1:
9731
10018
  response = _a.sent();
9732
10019
  setSeries(response.data || []);
9733
- setLoading(false);
9734
- return [3 /*break*/, 3];
10020
+ _a.label = 2;
9735
10021
  case 2:
10022
+ setLoading(false);
10023
+ return [3 /*break*/, 4];
10024
+ case 3:
9736
10025
  error_1 = _a.sent();
9737
- console.error("Error fetching data:", error_1);
9738
- setError("Failed to fetch data");
10026
+ setError(error_1.message);
9739
10027
  setLoading(false);
9740
- return [3 /*break*/, 3];
9741
- case 3: return [2 /*return*/];
10028
+ return [3 /*break*/, 4];
10029
+ case 4: return [2 /*return*/];
9742
10030
  }
9743
10031
  });
9744
10032
  }); };
9745
10033
  fetchData();
9746
10034
  }, 800);
9747
- }, [JSON.stringify(state), tagList]);
9748
- if (error)
9749
- return React__default.createElement("p", null,
9750
- "Error: ",
9751
- error);
9752
- return (React__default.createElement(Grid$1, { container: true, style: { width: "95svw", height: "81svh", margin: 0 } },
9753
- React__default.createElement(Header, { setChartOptions: setChartOptions }),
9754
- React__default.createElement(Grid$1, { item: true, xs: 12, style: { height: '45%' } },
9755
- React__default.createElement(TrendingChart, { setChartData: setChartData, series: series, tagList: tagList, chartOptions: chartOptions, setChartOptions: setChartOptions, chartData: chartData, setCursorData: setCursorData })),
9756
- React__default.createElement(Grid$1, { item: true, xs: 12, style: { height: '40%', minWidth: "100%", paddingTop: "3rem" } },
9757
- React__default.createElement(TableComponent, { tagList: tagList, chartData: chartData, setTagList: setTagList, cursorData: cursorData })),
9758
- loading && (React__default.createElement(Grid$1, { item: true, xs: 12, style: { textAlign: 'center' } },
9759
- React__default.createElement("p", null, "Loading...")))));
10035
+ }, [state.graphShouldUpdate, viewTags]);
10036
+ return (React__default.createElement(React__default.Fragment, null,
10037
+ React__default.createElement(Grid$1, { container: true, style: { width: "95svw", height: "81svh", margin: 0 } },
10038
+ React__default.createElement(Header, { setChartOptions: setChartOptions }),
10039
+ React__default.createElement(Grid$1, { item: true, xs: 12, style: { height: '45%' } },
10040
+ React__default.createElement(TrendingChart, { series: series, chartData: chartData, setChartData: setChartData, chartOptions: chartOptions, setChartOptions: setChartOptions, setCursorData: setCursorData })),
10041
+ React__default.createElement(Grid$1, { item: true, xs: 12, style: { height: '40%', minWidth: "100%", paddingTop: "3rem" } },
10042
+ React__default.createElement(TableComponent, { chartData: chartData, cursorData: cursorData })),
10043
+ loading && (React__default.createElement(Grid$1, { item: true, xs: 12, style: { textAlign: 'center' } },
10044
+ React__default.createElement("p", null, "Loading...")))),
10045
+ React__default.createElement(ErrorModal, { error: error, onHide: function () { return setError(''); }, title: "ERROR" })));
9760
10046
  };
9761
10047
 
9762
- // @flow
9763
- var TrendingsIndex = function (props) {
9764
- return (React.createElement(TrendingProvider, null,
9765
- React.createElement(Box, { p: 3, style: { maxWidth: "100%" } },
9766
- React.createElement(Paper, null,
9767
- React.createElement(Grid$1, { container: true, spacing: 3, style: { padding: "20px" } },
9768
- React.createElement(Grid$1, { item: true, xs: 12 },
9769
- React.createElement(Trending, { title: "Trending Chart", tags: [
9770
- {
9771
- tagId: 29,
9772
- tagName: "t1",
9773
- tagType: "number",
9774
- color: "red",
9775
- autoScale: true,
9776
- minScale: 0,
9777
- maxScale: 100,
9778
- visible: true
9779
- },
9780
- {
9781
- tagId: 44,
9782
- tagName: "t2",
9783
- tagType: "number",
9784
- color: "blue",
9785
- autoScale: true,
9786
- minScale: 0,
9787
- maxScale: 100,
9788
- visible: true
9789
- },
9790
- {
9791
- tagId: 50,
9792
- tagName: "t3",
9793
- tagType: "number",
9794
- color: "green",
9795
- autoScale: true,
9796
- minScale: 0,
9797
- maxScale: 100,
9798
- visible: true
9799
- },
9800
- {
9801
- tagId: 46,
9802
- tagName: "t4",
9803
- tagType: "number",
9804
- color: "black",
9805
- autoScale: true,
9806
- minScale: 0,
9807
- maxScale: 100,
9808
- visible: true
9809
- },
9810
- ] })))))));
10048
+ var TrendingsPage = function (props) {
10049
+ var _a = useState(''), error = _a[0], setError = _a[1];
10050
+ var _b = useTrendingContext().actions, setViews = _b.setViews, setViewTags = _b.setViewTags, setViewSelected = _b.setViewSelected;
10051
+ useEffect(function () {
10052
+ var getTags = function () { return __awaiter(void 0, void 0, void 0, function () {
10053
+ var viewsResp, lastCreated, viewTagsResp;
10054
+ return __generator(this, function (_a) {
10055
+ switch (_a.label) {
10056
+ case 0: return [4 /*yield*/, getViews(null)];
10057
+ case 1:
10058
+ viewsResp = _a.sent();
10059
+ if (!viewsResp.ok) return [3 /*break*/, 3];
10060
+ setViews(viewsResp.data.tables[0].rows);
10061
+ lastCreated = viewsResp.data.tables[0].rows.reduce(function (prev, current) { return (prev.ViewId > current.ViewId) ? prev : current; });
10062
+ //viewSelected
10063
+ setViewSelected(lastCreated);
10064
+ return [4 /*yield*/, getViewTags(lastCreated.ViewId)];
10065
+ case 2:
10066
+ viewTagsResp = _a.sent();
10067
+ if (viewTagsResp.ok) {
10068
+ setViewTags(viewTagsResp.data.tables[0].rows);
10069
+ }
10070
+ else {
10071
+ setError(viewTagsResp.message);
10072
+ }
10073
+ return [3 /*break*/, 4];
10074
+ case 3:
10075
+ setError(viewsResp.message);
10076
+ _a.label = 4;
10077
+ case 4: return [2 /*return*/];
10078
+ }
10079
+ });
10080
+ }); };
10081
+ getTags();
10082
+ }, []);
10083
+ return (React__default.createElement(React__default.Fragment, null,
10084
+ React__default.createElement(Box, { p: 3, style: { maxWidth: "100%" } },
10085
+ React__default.createElement(Paper, null,
10086
+ React__default.createElement(Grid$1, { container: true, spacing: 3, style: { padding: "20px" } },
10087
+ React__default.createElement(Grid$1, { item: true, xs: 12 },
10088
+ React__default.createElement(Trending, { title: "Trending Chart" }))))),
10089
+ React__default.createElement(ErrorModal, { error: error, onHide: function () { return setError(''); }, size: "xl", title: "ERROR" })));
10090
+ };
10091
+
10092
+ var index = function () {
10093
+ return (React__default.createElement(TrendingProvider, null,
10094
+ React__default.createElement(TrendingsPage, null)));
9811
10095
  };
9812
10096
 
9813
10097
  var MESFMainRouter = function () {
@@ -9817,7 +10101,7 @@ var MESFMainRouter = function () {
9817
10101
  React__default.createElement(Route, { path: "/", element: React__default.createElement(Navigate, { replace: true, to: "/home" }) }),
9818
10102
  React__default.createElement(Route, { path: "/configuration/*", element: React__default.createElement(Configuration, null) }),
9819
10103
  React__default.createElement(Route, { path: "/account", element: React__default.createElement(Account, null) }),
9820
- React__default.createElement(Route, { path: "/trendings", element: React__default.createElement(TrendingsIndex, null) }),
10104
+ React__default.createElement(Route, { path: "/trendings", element: React__default.createElement(index, null) }),
9821
10105
  React__default.createElement(Route, { path: "/home", element: React__default.createElement(Home, null) })),
9822
10106
  React__default.createElement(CustomRoutes, null)));
9823
10107
  };
@@ -10004,5 +10288,5 @@ var areaSelector = /*#__PURE__*/Object.freeze({
10004
10288
  AreaSelector: AreaSelector
10005
10289
  });
10006
10290
 
10007
- export { Account, AssetProvider, AuthContext, AuthProvider, BarChartControl, ChangePassword, CheckBoxControl, Configuration$1 as Configuration, CurrencyFormatter, DataGridControl, DateFormatter, DateTimeFormatter, ErrorModal, FetchError, FilterPanel, GenericPanel, GenericTable, GetCrewColor, GetShiftColor, HorizontalTextControl, IntegerFormatter, Login, Logout, LongFilterPanel, MESApiService, MESFMain, MESSAGE_API, MESSAGE_ERRORS, MasterDetailPanel, MesfModal, ModalTreeFilterControl, MultipleSelectorControl, NumberFormatter, NumericTextControl, SimplePasswordControl, SimpleSelectorControl, SimpleTextAreaControl, SimpleTextControl, TimeFormatter, TreePickerControl, TrendingsIndex, USER_LABELS, UTLSettingsProvider, UploadFileControl, UserProvider, axiosInstance, formatNumber, getCrewStyle, getError, getShiftStyle, getTokenFromLS, renewToken, useAssetContext, useToken, useUTLSettingsContext, useUserContext };
10291
+ export { Account, AssetProvider, AuthContext, AuthProvider, BarChartControl, ButtonWithLoading, ChangePassword, CheckBoxControl, Configuration$1 as Configuration, CurrencyFormatter, DataGridControl, DateFormatter, DateTimeFormatter, ErrorModal, FetchError, FilterPanel, GenericPanel, GenericTable, GetCrewColor, GetShiftColor, HorizontalTextControl, IntegerFormatter, Login, Logout, LongFilterPanel, MESApiService, MESFMain, MESSAGE_API, MESSAGE_ERRORS, MasterDetailPanel, MesfModal, ModalTreeFilterControl, MultipleSelectorControl, NumberFormatter, NumericTextControl, SimplePasswordControl, SimpleSelectorControl, SimpleTextAreaControl, SimpleTextControl, TimeFormatter, TreePickerControl, TrendingsPage, USER_LABELS, UTLSettingsProvider, UploadFileControl, UserProvider, axiosInstance, formatNumber, getCrewStyle, getError, getShiftStyle, getTokenFromLS, renewToken, useAssetContext, useToken, useUTLSettingsContext, useUserContext };
10008
10292
  //# sourceMappingURL=index.esm.js.map