@zohodesk/dot 1.8.1 → 1.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  In this Library, we Provide Some Basic Components to Build Your Application
4
4
 
5
+ # 1.8.2
6
+
7
+ - **GlobalNotification**
8
+ - `onStatusChange` prop added.
9
+
5
10
  # 1.8.1
6
11
 
7
12
  - Font Family Migrated to Font-weight across all css (Impacted)
@@ -7,6 +7,8 @@ import AlertClose from "../AlertClose/AlertClose";
7
7
  import style from "./GlobalNotification.module.css";
8
8
  import { Container, Box } from '@zohodesk/components/es/Layout';
9
9
  import { cancelBubblingEffect } from '@zohodesk/components/es/utils/Common';
10
+ import getCurrentTime from '@zohodesk/utils/es/getCurrentTime';
11
+ import { STATUS } from "./utils/constants";
10
12
  export default class GlobalNotification extends React.Component {
11
13
  constructor(props) {
12
14
  super(props);
@@ -15,6 +17,8 @@ export default class GlobalNotification extends React.Component {
15
17
  shadowClose: true
16
18
  };
17
19
  this.onClose = this.onClose.bind(this);
20
+ this.getNotificationData = this.getNotificationData.bind(this);
21
+ this.handleStatusChange = this.handleStatusChange.bind(this);
18
22
  }
19
23
 
20
24
  componentDidMount() {
@@ -24,18 +28,44 @@ export default class GlobalNotification extends React.Component {
24
28
  id,
25
29
  needAutoClose
26
30
  } = this.props;
31
+ this.handleStatusChange(STATUS.MOUNTED);
27
32
 
28
33
  if (needAutoClose) {
29
34
  this.hideMessageTimer = setTimeout(() => {
30
35
  hideMessage(id);
36
+ this.handleStatusChange(STATUS.DISMISSING);
31
37
  }, hideTime);
32
38
  }
33
39
  }
34
40
 
41
+ componentDidUpdate(prevProps) {
42
+ if (prevProps.id === this.props.id && (prevProps.message !== this.props.message || prevProps.type !== this.props.type)) {
43
+ this.handleStatusChange(STATUS.UPDATED);
44
+ }
45
+ }
46
+
35
47
  componentWillUnmount() {
36
48
  if (this.hideMessageTimer) {
37
49
  clearTimeout(this.hideMessageTimer);
38
50
  }
51
+
52
+ this.handleStatusChange(STATUS.UNMOUNTED);
53
+ }
54
+
55
+ handleStatusChange(status) {
56
+ const {
57
+ onStatusChange
58
+ } = this.props;
59
+
60
+ if (typeof onStatusChange == 'function') {
61
+ const notificationData = this.getNotificationData();
62
+ const currentTime = getCurrentTime();
63
+ onStatusChange({
64
+ status,
65
+ ...notificationData,
66
+ time: currentTime
67
+ });
68
+ }
39
69
  }
40
70
 
41
71
  onClose(e) {
@@ -47,20 +77,31 @@ export default class GlobalNotification extends React.Component {
47
77
  this.setState({
48
78
  shadowClose: false
49
79
  });
80
+ this.handleStatusChange(STATUS.DISMISSING);
50
81
  hideMessage && hideMessage(id);
51
82
  onClose && onClose(e);
52
83
  }
53
84
 
85
+ getNotificationData() {
86
+ const {
87
+ id,
88
+ type,
89
+ message
90
+ } = this.props;
91
+ return {
92
+ id,
93
+ type,
94
+ message
95
+ };
96
+ }
97
+
54
98
  render() {
55
99
  let {
56
- type,
57
- message,
58
100
  hideMessage,
59
101
  onClick,
60
102
  i18nKeys = {},
61
103
  customProps,
62
104
  dataSelectorId,
63
- id,
64
105
  needShadow,
65
106
  shadowCount,
66
107
  eleRef
@@ -71,15 +112,13 @@ export default class GlobalNotification extends React.Component {
71
112
  let {
72
113
  closeTitle = 'Close'
73
114
  } = i18nKeys;
74
- return /*#__PURE__*/React.createElement(GlobalNotificationUI, {
75
- type: type,
76
- message: message,
115
+ const notificationData = this.getNotificationData();
116
+ return /*#__PURE__*/React.createElement(GlobalNotificationUI, { ...notificationData,
77
117
  hideMessage: hideMessage,
78
118
  onClick: onClick,
79
119
  closeTitle: closeTitle,
80
120
  customProps: customProps,
81
121
  dataSelectorId: dataSelectorId,
82
- id: id,
83
122
  shadowCount: shadowCount,
84
123
  onClose: this.onClose,
85
124
  needShadow: shadowClose && needShadow,
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { render } from '@testing-library/react';
3
3
  import GlobalNotification from "../GlobalNotification";
4
+ import { STATUS } from "../utils/constants";
4
5
  describe('GlobalNotification', () => {
5
6
  test('rendering the defult props', () => {
6
7
  const {
@@ -8,4 +9,12 @@ describe('GlobalNotification', () => {
8
9
  } = render( /*#__PURE__*/React.createElement(GlobalNotification, null));
9
10
  expect(asFragment()).toMatchSnapshot();
10
11
  });
12
+ });
13
+ describe('GlobalNotification Constants', () => {
14
+ test('should have correct constant values', () => {
15
+ expect(STATUS.MOUNTED).toBe('mounted');
16
+ expect(STATUS.UPDATED).toBe('updated');
17
+ expect(STATUS.DISMISSING).toBe('dismissing');
18
+ expect(STATUS.UNMOUNTED).toBe('unmounted');
19
+ });
11
20
  });
@@ -10,12 +10,13 @@ export const propTypes = {
10
10
  customProps: PropTypes.shape({
11
11
  ExtraProps: PropTypes.object
12
12
  }),
13
- id: PropTypes.number,
13
+ id: PropTypes.string,
14
14
  hideTime: PropTypes.number,
15
15
  needAutoClose: PropTypes.bool,
16
16
  isCollapseView: PropTypes.bool,
17
17
  shadowCount: PropTypes.number,
18
- needShadow: PropTypes.bool
18
+ needShadow: PropTypes.bool,
19
+ onStatusChange: PropTypes.func
19
20
  };
20
21
  export const UI_propTypes = {
21
22
  dataSelectorId: PropTypes.string,
@@ -28,7 +29,7 @@ export const UI_propTypes = {
28
29
  }),
29
30
  needShadow: PropTypes.bool,
30
31
  shadowCount: PropTypes.number,
31
- id: PropTypes.number,
32
+ id: PropTypes.string,
32
33
  onClose: PropTypes.func
33
34
  };
34
35
  export const new_propTypes = {
@@ -0,0 +1,6 @@
1
+ export const STATUS = {
2
+ MOUNTED: 'mounted',
3
+ UNMOUNTED: 'unmounted',
4
+ UPDATED: 'updated',
5
+ DISMISSING: 'dismissing'
6
+ };
@@ -27,10 +27,20 @@ var _Layout = require("@zohodesk/components/es/Layout");
27
27
 
28
28
  var _Common = require("@zohodesk/components/es/utils/Common");
29
29
 
30
+ var _getCurrentTime = _interopRequireDefault(require("@zohodesk/utils/es/getCurrentTime"));
31
+
32
+ var _constants = require("./utils/constants");
33
+
30
34
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
31
35
 
32
36
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
33
37
 
38
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
39
+
40
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
41
+
42
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
43
+
34
44
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
35
45
 
36
46
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
@@ -67,30 +77,61 @@ var GlobalNotification = /*#__PURE__*/function (_React$Component) {
67
77
  shadowClose: true
68
78
  };
69
79
  _this.onClose = _this.onClose.bind(_assertThisInitialized(_this));
80
+ _this.getNotificationData = _this.getNotificationData.bind(_assertThisInitialized(_this));
81
+ _this.handleStatusChange = _this.handleStatusChange.bind(_assertThisInitialized(_this));
70
82
  return _this;
71
83
  }
72
84
 
73
85
  _createClass(GlobalNotification, [{
74
86
  key: "componentDidMount",
75
87
  value: function componentDidMount() {
88
+ var _this2 = this;
89
+
76
90
  var _this$props = this.props,
77
91
  hideMessage = _this$props.hideMessage,
78
92
  hideTime = _this$props.hideTime,
79
93
  id = _this$props.id,
80
94
  needAutoClose = _this$props.needAutoClose;
95
+ this.handleStatusChange(_constants.STATUS.MOUNTED);
81
96
 
82
97
  if (needAutoClose) {
83
98
  this.hideMessageTimer = setTimeout(function () {
84
99
  hideMessage(id);
100
+
101
+ _this2.handleStatusChange(_constants.STATUS.DISMISSING);
85
102
  }, hideTime);
86
103
  }
87
104
  }
105
+ }, {
106
+ key: "componentDidUpdate",
107
+ value: function componentDidUpdate(prevProps) {
108
+ if (prevProps.id === this.props.id && (prevProps.message !== this.props.message || prevProps.type !== this.props.type)) {
109
+ this.handleStatusChange(_constants.STATUS.UPDATED);
110
+ }
111
+ }
88
112
  }, {
89
113
  key: "componentWillUnmount",
90
114
  value: function componentWillUnmount() {
91
115
  if (this.hideMessageTimer) {
92
116
  clearTimeout(this.hideMessageTimer);
93
117
  }
118
+
119
+ this.handleStatusChange(_constants.STATUS.UNMOUNTED);
120
+ }
121
+ }, {
122
+ key: "handleStatusChange",
123
+ value: function handleStatusChange(status) {
124
+ var onStatusChange = this.props.onStatusChange;
125
+
126
+ if (typeof onStatusChange == 'function') {
127
+ var notificationData = this.getNotificationData();
128
+ var currentTime = (0, _getCurrentTime["default"])();
129
+ onStatusChange(_objectSpread(_objectSpread({
130
+ status: status
131
+ }, notificationData), {}, {
132
+ time: currentTime
133
+ }));
134
+ }
94
135
  }
95
136
  }, {
96
137
  key: "onClose",
@@ -102,42 +143,51 @@ var GlobalNotification = /*#__PURE__*/function (_React$Component) {
102
143
  this.setState({
103
144
  shadowClose: false
104
145
  });
146
+ this.handleStatusChange(_constants.STATUS.DISMISSING);
105
147
  hideMessage && hideMessage(id);
106
148
  onClose && onClose(e);
107
149
  }
108
150
  }, {
109
- key: "render",
110
- value: function render() {
151
+ key: "getNotificationData",
152
+ value: function getNotificationData() {
111
153
  var _this$props3 = this.props,
112
- type = _this$props3.type,
113
- message = _this$props3.message,
114
- hideMessage = _this$props3.hideMessage,
115
- onClick = _this$props3.onClick,
116
- _this$props3$i18nKeys = _this$props3.i18nKeys,
117
- i18nKeys = _this$props3$i18nKeys === void 0 ? {} : _this$props3$i18nKeys,
118
- customProps = _this$props3.customProps,
119
- dataSelectorId = _this$props3.dataSelectorId,
120
154
  id = _this$props3.id,
121
- needShadow = _this$props3.needShadow,
122
- shadowCount = _this$props3.shadowCount,
123
- eleRef = _this$props3.eleRef;
155
+ type = _this$props3.type,
156
+ message = _this$props3.message;
157
+ return {
158
+ id: id,
159
+ type: type,
160
+ message: message
161
+ };
162
+ }
163
+ }, {
164
+ key: "render",
165
+ value: function render() {
166
+ var _this$props4 = this.props,
167
+ hideMessage = _this$props4.hideMessage,
168
+ onClick = _this$props4.onClick,
169
+ _this$props4$i18nKeys = _this$props4.i18nKeys,
170
+ i18nKeys = _this$props4$i18nKeys === void 0 ? {} : _this$props4$i18nKeys,
171
+ customProps = _this$props4.customProps,
172
+ dataSelectorId = _this$props4.dataSelectorId,
173
+ needShadow = _this$props4.needShadow,
174
+ shadowCount = _this$props4.shadowCount,
175
+ eleRef = _this$props4.eleRef;
124
176
  var shadowClose = this.state.shadowClose;
125
177
  var _i18nKeys$closeTitle = i18nKeys.closeTitle,
126
178
  closeTitle = _i18nKeys$closeTitle === void 0 ? 'Close' : _i18nKeys$closeTitle;
127
- return /*#__PURE__*/_react["default"].createElement(GlobalNotificationUI, {
128
- type: type,
129
- message: message,
179
+ var notificationData = this.getNotificationData();
180
+ return /*#__PURE__*/_react["default"].createElement(GlobalNotificationUI, _extends({}, notificationData, {
130
181
  hideMessage: hideMessage,
131
182
  onClick: onClick,
132
183
  closeTitle: closeTitle,
133
184
  customProps: customProps,
134
185
  dataSelectorId: dataSelectorId,
135
- id: id,
136
186
  shadowCount: shadowCount,
137
187
  onClose: this.onClose,
138
188
  needShadow: shadowClose && needShadow,
139
189
  eleRef: eleRef
140
- });
190
+ }));
141
191
  }
142
192
  }]);
143
193
 
@@ -6,6 +6,8 @@ var _react2 = require("@testing-library/react");
6
6
 
7
7
  var _GlobalNotification = _interopRequireDefault(require("../GlobalNotification"));
8
8
 
9
+ var _constants = require("../utils/constants");
10
+
9
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
12
 
11
13
  describe('GlobalNotification', function () {
@@ -15,4 +17,12 @@ describe('GlobalNotification', function () {
15
17
 
16
18
  expect(asFragment()).toMatchSnapshot();
17
19
  });
20
+ });
21
+ describe('GlobalNotification Constants', function () {
22
+ test('should have correct constant values', function () {
23
+ expect(_constants.STATUS.MOUNTED).toBe('mounted');
24
+ expect(_constants.STATUS.UPDATED).toBe('updated');
25
+ expect(_constants.STATUS.DISMISSING).toBe('dismissing');
26
+ expect(_constants.STATUS.UNMOUNTED).toBe('unmounted');
27
+ });
18
28
  });
@@ -20,12 +20,13 @@ var propTypes = {
20
20
  customProps: _propTypes["default"].shape({
21
21
  ExtraProps: _propTypes["default"].object
22
22
  }),
23
- id: _propTypes["default"].number,
23
+ id: _propTypes["default"].string,
24
24
  hideTime: _propTypes["default"].number,
25
25
  needAutoClose: _propTypes["default"].bool,
26
26
  isCollapseView: _propTypes["default"].bool,
27
27
  shadowCount: _propTypes["default"].number,
28
- needShadow: _propTypes["default"].bool
28
+ needShadow: _propTypes["default"].bool,
29
+ onStatusChange: _propTypes["default"].func
29
30
  };
30
31
  exports.propTypes = propTypes;
31
32
  var UI_propTypes = {
@@ -39,7 +40,7 @@ var UI_propTypes = {
39
40
  }),
40
41
  needShadow: _propTypes["default"].bool,
41
42
  shadowCount: _propTypes["default"].number,
42
- id: _propTypes["default"].number,
43
+ id: _propTypes["default"].string,
43
44
  onClose: _propTypes["default"].func
44
45
  };
45
46
  exports.UI_propTypes = UI_propTypes;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.STATUS = void 0;
7
+ var STATUS = {
8
+ MOUNTED: 'mounted',
9
+ UNMOUNTED: 'unmounted',
10
+ UPDATED: 'updated',
11
+ DISMISSING: 'dismissing'
12
+ };
13
+ exports.STATUS = STATUS;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/dot",
3
- "version": "1.8.1",
3
+ "version": "1.8.2",
4
4
  "main": "lib/index",
5
5
  "module": "es/index.js",
6
6
  "private": false,
@@ -73,29 +73,29 @@
73
73
  "@zohodesk-private/node-plugins": "1.1.13",
74
74
  "@zohodesk-private/react-prop-validator": "1.2.3",
75
75
  "@zohodesk/a11y": "2.3.8",
76
- "@zohodesk/components": "1.5.1",
76
+ "@zohodesk/components": "1.5.2",
77
77
  "@zohodesk/hooks": "2.0.6",
78
- "@zohodesk/icons": "1.1.3",
78
+ "@zohodesk/icons": "1.1.4",
79
79
  "@zohodesk/layout": "^3.1.0",
80
- "@zohodesk/svg": "1.2.3",
81
- "@zohodesk/utils": "1.3.15",
80
+ "@zohodesk/svg": "1.2.5",
81
+ "@zohodesk/utils": "1.3.16",
82
82
  "@zohodesk/variables": "1.2.0",
83
83
  "@zohodesk/virtualizer": "1.0.13",
84
84
  "react-sortable-hoc": "^0.8.3",
85
85
  "velocity-react": "1.4.3",
86
- "@zohodesk/dotkit": "1.0.3",
86
+ "@zohodesk/dotkit": "1.0.4",
87
87
  "@zohodesk/react-cli": "1.1.27"
88
88
  },
89
89
  "peerDependencies": {
90
90
  "velocity-react": "1.4.3",
91
91
  "@zohodesk/variables": "1.2.0",
92
- "@zohodesk/components": "1.5.1",
93
- "@zohodesk/icons": "1.1.3",
94
- "@zohodesk/svg": "1.2.3",
92
+ "@zohodesk/components": "1.5.2",
93
+ "@zohodesk/icons": "1.1.4",
94
+ "@zohodesk/svg": "1.2.5",
95
95
  "@zohodesk/virtualizer": "1.0.13",
96
96
  "react-sortable-hoc": "^0.8.3",
97
97
  "@zohodesk/hooks": "2.0.6",
98
- "@zohodesk/utils": "1.3.15",
98
+ "@zohodesk/utils": "1.3.16",
99
99
  "@zohodesk/a11y": "2.3.8",
100
100
  "@zohodesk/layout": "3.1.0"
101
101
  }