versacall-dashboards-library-react 2.0.13 → 2.0.17

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.
@@ -11,8 +11,6 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
 
12
12
  var _styles = require("@material-ui/core/styles");
13
13
 
14
- var _CardActionArea = _interopRequireDefault(require("@material-ui/core/CardActionArea"));
15
-
16
14
  var _Button = _interopRequireDefault(require("@material-ui/core/Button"));
17
15
 
18
16
  var _IconButton = _interopRequireDefault(require("@material-ui/core/IconButton"));
@@ -287,6 +285,23 @@ var reorder = (list, startIndex, endIndex) => {
287
285
  return result;
288
286
  };
289
287
 
288
+ var determineIfAdvanced = condition => {
289
+ // console.log('determinIfAdvanced', condition);
290
+ if (condition) {
291
+ var split = condition.split(/[ ,]+/);
292
+
293
+ if (split.length === 3) {
294
+ var operator = operatorOptions.find(x => x.value === split[1]);
295
+
296
+ if (operator) {
297
+ return false;
298
+ }
299
+ }
300
+ }
301
+
302
+ return true;
303
+ };
304
+
290
305
  class DashboardsCellGlobalConditions extends _react.Component {
291
306
  constructor(props) {
292
307
  super(props);
@@ -296,8 +311,7 @@ class DashboardsCellGlobalConditions extends _react.Component {
296
311
  conditionIndex: null,
297
312
  menuIndex: null,
298
313
  menuAnchorEl: null,
299
- advanced: false,
300
- typeCondition: ''
314
+ advanced: false
301
315
  /* styleColumns: [
302
316
  {
303
317
  id: 'condition', style: { paddingRight: 0 }, label: props.intl.formatMessage({ id: '__condition' }), customCell: custom => conditionCustomCell(custom),
@@ -416,30 +430,39 @@ class DashboardsCellGlobalConditions extends _react.Component {
416
430
  }
417
431
 
418
432
  updateCondition(change) {
419
- var updatedValue = _objectSpread({}, this.props.value);
433
+ var _this$state = this.state,
434
+ conditionIndex = _this$state.conditionIndex,
435
+ tabIndex = _this$state.tabIndex; // console.log(`conditionIndex = ${conditionIndex}`);
436
+
437
+ var updatedValue = _objectSpread({}, this.props.value); // console.log('updatedValue', updatedValue);
438
+ // const conditions = updatedValue[`${typeCondition}Conditions`];
439
+
420
440
 
421
- var conditions = updatedValue["".concat(this.state.typeCondition, "Conditions")]; // const conditions = JSON.parse(JSON.stringify(this.props.value[`${this.state.typeCondition}Conditions`]));
441
+ var conditions = tabIndex === 1 ? updatedValue.contentConditions : updatedValue.styleConditions; // const conditions = JSON.parse(JSON.stringify(this.props.value[`${this.state.typeCondition}Conditions`]));
422
442
 
423
443
  if (this.state.advanced) {
424
- conditions[this.state.conditionIndex].condition = change.value;
444
+ conditions[conditionIndex].condition = change.value;
425
445
  } else {
426
- var split = conditions[this.state.conditionIndex].condition.split(/[ ,]+/);
446
+ var split = conditions[conditionIndex].condition.split(/[ ,]+/);
447
+ var segment1 = split[0];
448
+ var segment2 = split.length > 1 ? split[1] : '===';
449
+ var segment3 = split.length > 2 ? split[2] : '0';
427
450
 
428
451
  switch (change.stringIndex) {
429
452
  case 0:
430
- conditions[this.state.conditionIndex].condition = "".concat(change.value, " ").concat(split[1], " ").concat(split[2]);
453
+ conditions[conditionIndex].condition = "".concat(change.value, " ").concat(segment2, " ").concat(segment3);
431
454
  break;
432
455
 
433
456
  case 1:
434
- conditions[this.state.conditionIndex].condition = "".concat(split[0], " ").concat(change.value, " ").concat(split[2]);
457
+ conditions[conditionIndex].condition = "".concat(segment1, " ").concat(change.value, " ").concat(segment3);
435
458
  break;
436
459
 
437
460
  case 2:
438
- conditions[this.state.conditionIndex].condition = "".concat(split[0], " ").concat(split[1], " ").concat(change.value);
461
+ conditions[conditionIndex].condition = "".concat(segment1, " ").concat(segment2, " ").concat(change.value);
439
462
  break;
440
463
 
441
464
  default:
442
- conditions[this.state.conditionIndex].condition = '1 > 0';
465
+ conditions[conditionIndex].condition = "".concat(segment1, " ").concat(segment2, " ").concat(segment3);
443
466
  break;
444
467
  }
445
468
  } // this.props.updateValue({ [`${this.state.typeCondition}Conditions`]: conditions });
@@ -488,7 +511,6 @@ class DashboardsCellGlobalConditions extends _react.Component {
488
511
 
489
512
  addCondition() {
490
513
  var conditions = JSON.parse(JSON.stringify(this.props.value));
491
- var typeCondition = '';
492
514
  var index = null;
493
515
 
494
516
  if (this.state.tabIndex === 0) {
@@ -498,7 +520,6 @@ class DashboardsCellGlobalConditions extends _react.Component {
498
520
  styleIds: []
499
521
  });
500
522
  index = conditions.styleConditions.length - 1;
501
- typeCondition = 'style';
502
523
  } else {
503
524
  conditions.contentConditions.push({
504
525
  condition: '1 > 0',
@@ -508,7 +529,6 @@ class DashboardsCellGlobalConditions extends _react.Component {
508
529
  }
509
530
  });
510
531
  index = conditions.contentConditions.length - 1;
511
- typeCondition = 'content';
512
532
  }
513
533
 
514
534
  this.props.updateValue({
@@ -517,23 +537,24 @@ class DashboardsCellGlobalConditions extends _react.Component {
517
537
  });
518
538
  this.setState({
519
539
  conditionIndex: index,
520
- advanced: false,
521
- typeCondition: typeCondition
540
+ advanced: false
522
541
  });
523
542
  }
524
543
 
525
544
  copyCondition(condition) {
526
- var conditions = JSON.parse(JSON.stringify(this.props.value));
545
+ var newValue = JSON.parse(JSON.stringify(this.props.value));
527
546
  var newCondition = JSON.parse(JSON.stringify(condition));
528
547
  delete newCondition.index;
529
- conditions[this.state.tabIndex === 0 ? 'styleConditions' : 'contentConditions'].push(newCondition);
548
+ var conditions = newValue[this.state.tabIndex === 0 ? 'styleConditions' : 'contentConditions'];
549
+ conditions.push(newCondition);
550
+ var advanced = determineIfAdvanced(newCondition.condition);
530
551
  this.props.updateValue({
531
- styleConditions: conditions.styleConditions,
532
- contentConditions: conditions.contentConditions
552
+ styleConditions: newValue.styleConditions,
553
+ contentConditions: newValue.contentConditions
533
554
  });
534
555
  this.setState(prevState => ({
535
- conditionIndex: "".concat(conditions[prevState.tabIndex === 0 ? 'styleConditions' : 'contentConditions'].length),
536
- advanced: false
556
+ conditionIndex: conditions.length - 1,
557
+ advanced: advanced
537
558
  }));
538
559
  }
539
560
 
@@ -605,9 +626,14 @@ class DashboardsCellGlobalConditions extends _react.Component {
605
626
  }
606
627
 
607
628
  selectCondition(index) {
608
- // TODO - Determine advanced state
629
+ var value = this.props.value;
630
+ var tabIndex = this.state.tabIndex;
631
+ var conditions = tabIndex === 1 ? value.contentConditions : value.styleConditions;
632
+ var condition = conditions[index];
633
+ var advanced = determineIfAdvanced(condition.condition);
609
634
  this.setState({
610
- conditionIndex: index
635
+ conditionIndex: index,
636
+ advanced: advanced
611
637
  });
612
638
  }
613
639
 
@@ -617,9 +643,9 @@ class DashboardsCellGlobalConditions extends _react.Component {
617
643
  var _this$props = this.props,
618
644
  classes = _this$props.classes,
619
645
  intl = _this$props.intl;
620
- var _this$state = this.state,
621
- tabIndex = _this$state.tabIndex,
622
- conditionIndex = _this$state.conditionIndex;
646
+ var _this$state2 = this.state,
647
+ tabIndex = _this$state2.tabIndex,
648
+ conditionIndex = _this$state2.conditionIndex;
623
649
  var divStyle = {
624
650
  border: '1px solid black',
625
651
  padding: 10,
@@ -682,13 +708,13 @@ class DashboardsCellGlobalConditions extends _react.Component {
682
708
  styles = _this$props2.styles,
683
709
  widgets = _this$props2.widgets,
684
710
  variables = _this$props2.variables;
685
- var _this$state2 = this.state,
686
- open = _this$state2.open,
687
- tabIndex = _this$state2.tabIndex,
688
- conditionIndex = _this$state2.conditionIndex,
689
- menuIndex = _this$state2.menuIndex,
690
- menuAnchorEl = _this$state2.menuAnchorEl,
691
- advanced = _this$state2.advanced;
711
+ var _this$state3 = this.state,
712
+ open = _this$state3.open,
713
+ tabIndex = _this$state3.tabIndex,
714
+ conditionIndex = _this$state3.conditionIndex,
715
+ menuIndex = _this$state3.menuIndex,
716
+ menuAnchorEl = _this$state3.menuAnchorEl,
717
+ advanced = _this$state3.advanced;
692
718
  var currentCondition = null;
693
719
 
694
720
  if (conditionIndex !== null) {
@@ -717,30 +743,23 @@ class DashboardsCellGlobalConditions extends _react.Component {
717
743
  return /*#__PURE__*/_react.default.createElement(_Grid.default, {
718
744
  xs: 6,
719
745
  item: true
720
- }, /*#__PURE__*/_react.default.createElement(_CardActionArea.default, {
721
- onClick: () => this.setState({
722
- open: true
723
- })
724
746
  }, /*#__PURE__*/_react.default.createElement(_Button.default, {
725
747
  variant: "contained",
726
748
  color: "secondary",
727
749
  size: "large",
728
750
  style: {
729
751
  width: '100%'
730
- }
752
+ },
753
+ onClick: () => this.setState({
754
+ open: true
755
+ })
731
756
  }, /*#__PURE__*/_react.default.createElement(_CallSplit.default, {
732
757
  style: {
733
758
  marginRight: 10
734
759
  }
735
760
  }), "".concat(intl.formatMessage({
736
761
  id: '__conditions'
737
- })).concat(totalConditions > 0 ? " (".concat(totalConditions, ")") : '')), totalConditions > 0 && /*#__PURE__*/_react.default.createElement("div", {
738
- style: style.information
739
- }, value.styleConditions.length > 0 && /*#__PURE__*/_react.default.createElement("div", null, "".concat(intl.formatMessage({
740
- id: '__style'
741
- }), ": ").concat(value.styleConditions.length)), value.contentConditions.length > 0 && /*#__PURE__*/_react.default.createElement("div", null, "".concat(intl.formatMessage({
742
- id: '__content'
743
- }), ": ").concat(value.contentConditions.length)))), open && /*#__PURE__*/_react.default.createElement(_Dialog.default, {
762
+ })).concat(totalConditions > 0 ? " (".concat(totalConditions, ")") : '')), open && /*#__PURE__*/_react.default.createElement(_Dialog.default, {
744
763
  maxWidth: "xl",
745
764
  onClose: () => this.setState({
746
765
  open: false,
package/package.json CHANGED
@@ -2,10 +2,10 @@
2
2
  "versacall": {
3
3
  "title": "Versacall Dashboards Library React",
4
4
  "applicationType": "react-library",
5
- "build": 13
5
+ "build": 17
6
6
  },
7
7
  "name": "versacall-dashboards-library-react",
8
- "version": "2.0.13",
8
+ "version": "2.0.17",
9
9
  "description": "Versacall Dashboards Library",
10
10
  "main": "dist/index.js",
11
11
  "module": "dist/index.js",