@atlaskit/feedback-collector 8.0.2 → 9.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @atlaskit/feedback-collector
2
2
 
3
+ ## 9.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 9.0.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [`90a4afb3339`](https://bitbucket.org/atlassian/atlassian-frontend/commits/90a4afb3339) - Updating only a comment
14
+
15
+ ## 9.0.0
16
+
17
+ ### Major Changes
18
+
19
+ - [`de5ad5f78ba`](https://bitbucket.org/atlassian/atlassian-frontend/commits/de5ad5f78ba) - Use Stargate proxy instead of Cookie
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies
24
+
3
25
  ## 8.0.2
4
26
 
5
27
  ### Patch Changes
@@ -31,7 +31,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
31
31
 
32
32
  var _react = _interopRequireWildcard(require("react"));
33
33
 
34
- var _truncate = _interopRequireDefault(require("lodash/truncate"));
34
+ var _Truncate = _interopRequireDefault(require("../utils/Truncate"));
35
35
 
36
36
  var _FeedbackForm = _interopRequireDefault(require("./FeedbackForm"));
37
37
 
@@ -52,9 +52,7 @@ var MAX_SUMMARY_LENGTH_CHARS = 100;
52
52
  var singleLineTruncatedText = function singleLineTruncatedText(text) {
53
53
  var length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : MAX_SUMMARY_LENGTH_CHARS;
54
54
  var singleLineText = text.replace(/\n/g, ' ');
55
- return (0, _truncate.default)(singleLineText, {
56
- length: length
57
- });
55
+ return (0, _Truncate.default)(singleLineText, length);
58
56
  };
59
57
 
60
58
  var FeedbackCollector = /*#__PURE__*/function (_Component) {
@@ -74,23 +72,24 @@ var FeedbackCollector = /*#__PURE__*/function (_Component) {
74
72
  _this = _super.call.apply(_super, [this].concat(args));
75
73
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "postFeedback", /*#__PURE__*/function () {
76
74
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(formValues) {
77
- var requestType, embedKey, formData, body, postData;
75
+ var requestType, embedKey, url, formData, body, postData;
78
76
  return _regenerator.default.wrap(function _callee$(_context) {
79
77
  while (1) {
80
78
  switch (_context.prev = _context.next) {
81
79
  case 0:
82
80
  requestType = _this.props.requestTypeId;
83
- embedKey = _this.props.embeddableKey; // Don't dispatch unless we have suitable props (allows tests to pass through empty strings and avoid redundant network calls)
81
+ embedKey = _this.props.embeddableKey;
82
+ url = _this.props.url; // Don't dispatch unless we have suitable props (allows tests to pass through empty strings and avoid redundant network calls)
84
83
 
85
84
  if (!(embedKey && requestType)) {
86
- _context.next = 9;
85
+ _context.next = 11;
87
86
  break;
88
87
  }
89
88
 
90
- _context.next = 5;
89
+ _context.next = 6;
91
90
  return _this.mapFormToJSD(formValues);
92
91
 
93
- case 5:
92
+ case 6:
94
93
  formData = _context.sent;
95
94
  body = {
96
95
  feedback: _objectSpread({
@@ -98,20 +97,27 @@ var FeedbackCollector = /*#__PURE__*/function (_Component) {
98
97
  embedKey: _this.props.embeddableKey
99
98
  }, formData)
100
99
  };
100
+
101
+ if (_this.props.url === "/gateway/api") {
102
+ url += '/feedback-collector-api';
103
+ } else {
104
+ url = 'https://feedback-collector-api.services.atlassian.com';
105
+ }
106
+
101
107
  postData = Buffer.from(JSON.stringify(body)).toString('base64');
102
- fetch('https://feedback-collector-api.services.atlassian.com/feedback', {
108
+ fetch("".concat(url, "/feedback"), _objectSpread({
103
109
  method: 'POST',
104
- headers: _objectSpread({
110
+ headers: {
105
111
  'Content-Type': 'application/json'
106
- }, _this.props.cookie ? {
107
- Cookie: _this.props.cookie
108
- } : {}),
112
+ },
109
113
  body: JSON.stringify({
110
114
  data: postData
111
115
  })
112
- });
116
+ }, _this.props.url === "/gateway/api" ? {
117
+ credentials: 'include'
118
+ } : {}));
113
119
 
114
- case 9:
120
+ case 11:
115
121
  _this.props.onClose(); // slightly delay confirming submit since we don't wait for the REST call to succeed
116
122
  //
117
123
  // Because `onClose` is invoked prior to this timeout triggering, the `componentWillUnmount`
@@ -124,7 +130,7 @@ var FeedbackCollector = /*#__PURE__*/function (_Component) {
124
130
  return _this.props.onSubmit(formValues);
125
131
  }, _this.props.timeoutOnSubmit);
126
132
 
127
- case 11:
133
+ case 13:
128
134
  case "end":
129
135
  return _context.stop();
130
136
  }
@@ -142,22 +148,19 @@ var FeedbackCollector = /*#__PURE__*/function (_Component) {
142
148
  (0, _createClass2.default)(FeedbackCollector, [{
143
149
  key: "getEntitlementInformation",
144
150
  value: function () {
145
- var _getEntitlementInformation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(cookie) {
146
- var _productName, url, productName, productEntitlement, entitlementDetails, productKey, _document$querySelect, hasPremium, entitlement, entitlementInformation;
151
+ var _getEntitlementInformation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
152
+ var _productName;
153
+
154
+ var url, productName, productEntitlement, entitlementDetails, productKey, _document$querySelect, hasPremium, entitlement, entitlementInformation;
147
155
 
148
156
  return _regenerator.default.wrap(function _callee2$(_context2) {
149
157
  while (1) {
150
158
  switch (_context2.prev = _context2.next) {
151
159
  case 0:
152
- if (!(cookie && cookie.length)) {
153
- _context2.next = 24;
154
- break;
155
- }
156
-
157
- url = cookie.includes('cloud.session.token.stg') ? 'https://api-private.stg.atlassian.com' : 'https://api-private.atlassian.com'; // jira / connie / bb
160
+ url = this.props.url; // jira / confluence / bitbucket
158
161
 
159
162
  if (!window.location.host.includes('bitbucket.org')) {
160
- _context2.next = 10;
163
+ _context2.next = 9;
161
164
  break;
162
165
  }
163
166
 
@@ -166,10 +169,10 @@ var FeedbackCollector = /*#__PURE__*/function (_Component) {
166
169
  entitlementDetails = JSON.parse(JSON.stringify((_document$querySelect = document.querySelector('meta[name="bb-bootstrap"]')) === null || _document$querySelect === void 0 ? void 0 : _document$querySelect.getAttribute('data-current-user')));
167
170
  hasPremium = entitlementDetails['hasPremium'];
168
171
  productEntitlement = hasPremium ? 'PREMIUM' : 'STANDARD';
169
- _context2.next = 20;
172
+ _context2.next = 19;
170
173
  break;
171
174
 
172
- case 10:
175
+ case 9:
173
176
  if (document.querySelector('meta[id="confluence-context-path"]')) {
174
177
  productName = 'Confluence';
175
178
  productKey = 'pricingplan.confluence.ondemand';
@@ -178,35 +181,36 @@ var FeedbackCollector = /*#__PURE__*/function (_Component) {
178
181
  productKey = 'jira-software.ondemand';
179
182
  }
180
183
 
181
- _context2.prev = 11;
182
- _context2.next = 14;
183
- return fetch("".concat(url, "/customer-context/entitlements/").concat(window.location.host), {
184
+ _context2.prev = 10;
185
+ _context2.next = 13;
186
+ return fetch("".concat(url, "/customer-context/entitlements/").concat(window.location.host), _objectSpread({
184
187
  method: 'GET',
185
188
  headers: {
186
- 'Content-Type': 'application/json',
187
- Cookie: cookie
188
- },
189
+ 'Content-Type': 'application/json'
190
+ }
191
+ }, this.props.url === "/gateway/api" ? {
189
192
  credentials: 'include'
190
- });
193
+ } : {}));
191
194
 
192
- case 14:
195
+ case 13:
193
196
  entitlementDetails = _context2.sent;
194
- _context2.next = 20;
197
+ _context2.next = 19;
195
198
  break;
196
199
 
197
- case 17:
198
- _context2.prev = 17;
199
- _context2.t0 = _context2["catch"](11);
200
+ case 16:
201
+ _context2.prev = 16;
202
+ _context2.t0 = _context2["catch"](10);
200
203
  entitlementDetails = undefined;
201
204
 
202
- case 20:
205
+ case 19:
206
+ entitlementInformation = [];
207
+
203
208
  if (entitlementDetails && entitlementDetails.children) {
204
209
  entitlement = entitlementDetails.children.find(function (entitlement) {
205
210
  return entitlement.key === productKey;
206
211
  });
207
212
  }
208
213
 
209
- entitlementInformation = [];
210
214
  entitlementInformation.push({
211
215
  id: 'product',
212
216
  value: productName ? (_productName = productName) === null || _productName === void 0 ? void 0 : _productName.toLowerCase() : ''
@@ -219,18 +223,15 @@ var FeedbackCollector = /*#__PURE__*/function (_Component) {
219
223
  });
220
224
  return _context2.abrupt("return", entitlementInformation);
221
225
 
222
- case 24:
223
- return _context2.abrupt("return", []);
224
-
225
- case 25:
226
+ case 23:
226
227
  case "end":
227
228
  return _context2.stop();
228
229
  }
229
230
  }
230
- }, _callee2, null, [[11, 17]]);
231
+ }, _callee2, this, [[10, 16]]);
231
232
  }));
232
233
 
233
- function getEntitlementInformation(_x2) {
234
+ function getEntitlementInformation() {
234
235
  return _getEntitlementInformation.apply(this, arguments);
235
236
  }
236
237
 
@@ -286,26 +287,13 @@ var FeedbackCollector = /*#__PURE__*/function (_Component) {
286
287
  while (1) {
287
288
  switch (_context3.prev = _context3.next) {
288
289
  case 0:
289
- if (!this.props.cookie) {
290
- _context3.next = 6;
291
- break;
292
- }
293
-
294
- _context3.next = 3;
295
- return this.getEntitlementInformation(this.props.cookie);
296
-
297
- case 3:
298
- _context3.t0 = _context3.sent;
299
- _context3.next = 7;
300
- break;
301
-
302
- case 6:
303
- _context3.t0 = [];
290
+ _context3.next = 2;
291
+ return this.getEntitlementInformation();
304
292
 
305
- case 7:
306
- entitlementInformation = _context3.t0;
293
+ case 2:
294
+ entitlementInformation = _context3.sent;
307
295
  return _context3.abrupt("return", {
308
- fields: [].concat((0, _toConsumableArray2.default)(entitlementInformation), [this.props.showTypeField ? {
296
+ fields: [].concat((0, _toConsumableArray2.default)(entitlementInformation !== null && entitlementInformation || []), [this.props.showTypeField ? {
309
297
  id: this.props.typeFieldId,
310
298
  value: this.getTypeFieldValue(formValues.type)
311
299
  } : undefined, {
@@ -329,7 +317,7 @@ var FeedbackCollector = /*#__PURE__*/function (_Component) {
329
317
  } : undefined], (0, _toConsumableArray2.default)(this.props.additionalFields)).filter(Boolean)
330
318
  });
331
319
 
332
- case 9:
320
+ case 4:
333
321
  case "end":
334
322
  return _context3.stop();
335
323
  }
@@ -337,7 +325,7 @@ var FeedbackCollector = /*#__PURE__*/function (_Component) {
337
325
  }, _callee3, this);
338
326
  }));
339
327
 
340
- function mapFormToJSD(_x3) {
328
+ function mapFormToJSD(_x2) {
341
329
  return _mapFormToJSD.apply(this, arguments);
342
330
  }
343
331
 
@@ -366,7 +354,7 @@ var FeedbackCollector = /*#__PURE__*/function (_Component) {
366
354
 
367
355
  exports.default = FeedbackCollector;
368
356
  (0, _defineProperty2.default)(FeedbackCollector, "defaultProps", {
369
- cookie: '',
357
+ url: '/gateway/api',
370
358
  canBeContactedFieldId: 'customfield_10043',
371
359
  canBeContactedDefaultValue: [{
372
360
  id: '10109'
@@ -17,10 +17,12 @@ var _checkCircle = _interopRequireDefault(require("@atlaskit/icon/glyph/check-ci
17
17
 
18
18
  var _colors = require("@atlaskit/theme/colors");
19
19
 
20
+ var _tokens = require("@atlaskit/tokens");
21
+
20
22
  var FeedbackFlag = function FeedbackFlag(props) {
21
23
  return /*#__PURE__*/_react.default.createElement(_flag.AutoDismissFlag, (0, _extends2.default)({
22
24
  icon: /*#__PURE__*/_react.default.createElement(_checkCircle.default, {
23
- primaryColor: "var(--ds-icon-success, ".concat(_colors.G300, ")"),
25
+ primaryColor: (0, _tokens.token)('color.icon.success', _colors.G300),
24
26
  label: "Success"
25
27
  }),
26
28
  id: "feedbackSent",
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = truncate;
7
+
8
+ function truncate(text, maxLength) {
9
+ if (!text || !maxLength) {
10
+ return text;
11
+ }
12
+
13
+ if (text.length <= maxLength) {
14
+ return text;
15
+ }
16
+
17
+ return text.substring(0, maxLength) + '...';
18
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/feedback-collector",
3
- "version": "8.0.2",
3
+ "version": "9.0.2",
4
4
  "sideEffects": false
5
5
  }
@@ -1,14 +1,12 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import React, { Component } from 'react';
3
- import truncate from 'lodash/truncate';
3
+ import truncate from '../utils/Truncate';
4
4
  import FeedbackForm from './FeedbackForm';
5
5
  const MAX_SUMMARY_LENGTH_CHARS = 100;
6
6
 
7
7
  const singleLineTruncatedText = (text, length = MAX_SUMMARY_LENGTH_CHARS) => {
8
8
  const singleLineText = text.replace(/\n/g, ' ');
9
- return truncate(singleLineText, {
10
- length
11
- });
9
+ return truncate(singleLineText, length);
12
10
  };
13
11
 
14
12
  export default class FeedbackCollector extends Component {
@@ -17,7 +15,8 @@ export default class FeedbackCollector extends Component {
17
15
 
18
16
  _defineProperty(this, "postFeedback", async formValues => {
19
17
  const requestType = this.props.requestTypeId;
20
- const embedKey = this.props.embeddableKey; // Don't dispatch unless we have suitable props (allows tests to pass through empty strings and avoid redundant network calls)
18
+ const embedKey = this.props.embeddableKey;
19
+ let url = this.props.url; // Don't dispatch unless we have suitable props (allows tests to pass through empty strings and avoid redundant network calls)
21
20
 
22
21
  if (embedKey && requestType) {
23
22
  const formData = await this.mapFormToJSD(formValues);
@@ -28,18 +27,25 @@ export default class FeedbackCollector extends Component {
28
27
  ...formData
29
28
  }
30
29
  };
30
+
31
+ if (this.props.url === `/gateway/api`) {
32
+ url += '/feedback-collector-api';
33
+ } else {
34
+ url = 'https://feedback-collector-api.services.atlassian.com';
35
+ }
36
+
31
37
  const postData = Buffer.from(JSON.stringify(body)).toString('base64');
32
- fetch('https://feedback-collector-api.services.atlassian.com/feedback', {
38
+ fetch(`${url}/feedback`, {
33
39
  method: 'POST',
34
40
  headers: {
35
- 'Content-Type': 'application/json',
36
- ...(this.props.cookie ? {
37
- Cookie: this.props.cookie
38
- } : {})
41
+ 'Content-Type': 'application/json'
39
42
  },
40
43
  body: JSON.stringify({
41
44
  data: postData
42
- })
45
+ }),
46
+ ...(this.props.url === `/gateway/api` ? {
47
+ credentials: 'include'
48
+ } : {})
43
49
  });
44
50
  }
45
51
 
@@ -54,71 +60,68 @@ export default class FeedbackCollector extends Component {
54
60
  });
55
61
  }
56
62
 
57
- async getEntitlementInformation(cookie) {
58
- if (cookie && cookie.length) {
59
- var _productName;
63
+ async getEntitlementInformation() {
64
+ var _productName;
60
65
 
61
- const url = cookie.includes('cloud.session.token.stg') ? 'https://api-private.stg.atlassian.com' : 'https://api-private.atlassian.com'; // jira / connie / bb
66
+ const url = this.props.url; // jira / confluence / bitbucket
62
67
 
63
- let productName;
64
- let productEntitlement;
65
- let entitlementDetails;
66
- let productKey;
68
+ let productName;
69
+ let productEntitlement;
70
+ let entitlementDetails;
71
+ let productKey;
67
72
 
68
- if (window.location.host.includes('bitbucket.org')) {
69
- var _document$querySelect;
73
+ if (window.location.host.includes('bitbucket.org')) {
74
+ var _document$querySelect;
70
75
 
71
- productName = 'Bitbucket';
72
- productKey = 'bitbucket';
73
- entitlementDetails = JSON.parse(JSON.stringify((_document$querySelect = document.querySelector('meta[name="bb-bootstrap"]')) === null || _document$querySelect === void 0 ? void 0 : _document$querySelect.getAttribute('data-current-user')));
74
- const hasPremium = entitlementDetails['hasPremium'];
75
- productEntitlement = hasPremium ? 'PREMIUM' : 'STANDARD';
76
+ productName = 'Bitbucket';
77
+ productKey = 'bitbucket';
78
+ entitlementDetails = JSON.parse(JSON.stringify((_document$querySelect = document.querySelector('meta[name="bb-bootstrap"]')) === null || _document$querySelect === void 0 ? void 0 : _document$querySelect.getAttribute('data-current-user')));
79
+ const hasPremium = entitlementDetails['hasPremium'];
80
+ productEntitlement = hasPremium ? 'PREMIUM' : 'STANDARD';
81
+ } else {
82
+ if (document.querySelector('meta[id="confluence-context-path"]')) {
83
+ productName = 'Confluence';
84
+ productKey = 'pricingplan.confluence.ondemand';
76
85
  } else {
77
- if (document.querySelector('meta[id="confluence-context-path"]')) {
78
- productName = 'Confluence';
79
- productKey = 'pricingplan.confluence.ondemand';
80
- } else {
81
- productName = 'Jira';
82
- productKey = 'jira-software.ondemand';
83
- }
84
-
85
- try {
86
- entitlementDetails = await fetch(`${url}/customer-context/entitlements/${window.location.host}`, {
87
- method: 'GET',
88
- headers: {
89
- 'Content-Type': 'application/json',
90
- Cookie: cookie
91
- },
92
- credentials: 'include'
93
- });
94
- } catch (e) {
95
- entitlementDetails = undefined;
96
- }
86
+ productName = 'Jira';
87
+ productKey = 'jira-software.ondemand';
97
88
  }
98
89
 
99
- let entitlement;
100
-
101
- if (entitlementDetails && entitlementDetails.children) {
102
- entitlement = entitlementDetails.children.find(entitlement => {
103
- return entitlement.key === productKey;
90
+ try {
91
+ entitlementDetails = await fetch(`${url}/customer-context/entitlements/${window.location.host}`, {
92
+ method: 'GET',
93
+ headers: {
94
+ 'Content-Type': 'application/json'
95
+ },
96
+ ...(this.props.url === `/gateway/api` ? {
97
+ credentials: 'include'
98
+ } : {})
104
99
  });
100
+ } catch (e) {
101
+ entitlementDetails = undefined;
105
102
  }
103
+ }
106
104
 
107
- const entitlementInformation = [];
108
- entitlementInformation.push({
109
- id: 'product',
110
- value: productName ? (_productName = productName) === null || _productName === void 0 ? void 0 : _productName.toLowerCase() : ''
111
- }, {
112
- id: 'hostingType',
113
- value: entitlement && entitlement.product ? entitlement.product.hostingType : 'CLOUD'
114
- }, {
115
- id: 'entitlementEdition',
116
- value: productEntitlement || ''
105
+ let entitlement;
106
+ const entitlementInformation = [];
107
+
108
+ if (entitlementDetails && entitlementDetails.children) {
109
+ entitlement = entitlementDetails.children.find(entitlement => {
110
+ return entitlement.key === productKey;
117
111
  });
118
- return entitlementInformation;
119
112
  }
120
113
 
121
- return [];
114
+ entitlementInformation.push({
115
+ id: 'product',
116
+ value: productName ? (_productName = productName) === null || _productName === void 0 ? void 0 : _productName.toLowerCase() : ''
117
+ }, {
118
+ id: 'hostingType',
119
+ value: entitlement && entitlement.product ? entitlement.product.hostingType : 'CLOUD'
120
+ }, {
121
+ id: 'entitlementEdition',
122
+ value: productEntitlement || ''
123
+ });
124
+ return entitlementInformation;
122
125
  }
123
126
 
124
127
  getTypeFieldValue(dtype) {
@@ -158,9 +161,9 @@ export default class FeedbackCollector extends Component {
158
161
  }
159
162
 
160
163
  async mapFormToJSD(formValues) {
161
- const entitlementInformation = this.props.cookie ? await this.getEntitlementInformation(this.props.cookie) : [];
164
+ const entitlementInformation = await this.getEntitlementInformation();
162
165
  return {
163
- fields: [...entitlementInformation, this.props.showTypeField ? {
166
+ fields: [...(entitlementInformation !== null && entitlementInformation || []), this.props.showTypeField ? {
164
167
  id: this.props.typeFieldId,
165
168
  value: this.getTypeFieldValue(formValues.type)
166
169
  } : undefined, {
@@ -204,7 +207,7 @@ export default class FeedbackCollector extends Component {
204
207
  }
205
208
 
206
209
  _defineProperty(FeedbackCollector, "defaultProps", {
207
- cookie: '',
210
+ url: '/gateway/api',
208
211
  canBeContactedFieldId: 'customfield_10043',
209
212
  canBeContactedDefaultValue: [{
210
213
  id: '10109'
@@ -3,10 +3,11 @@ import React from 'react';
3
3
  import { AutoDismissFlag } from '@atlaskit/flag';
4
4
  import SuccessIcon from '@atlaskit/icon/glyph/check-circle';
5
5
  import { G300 } from '@atlaskit/theme/colors';
6
+ import { token } from '@atlaskit/tokens';
6
7
 
7
8
  const FeedbackFlag = props => /*#__PURE__*/React.createElement(AutoDismissFlag, _extends({
8
9
  icon: /*#__PURE__*/React.createElement(SuccessIcon, {
9
- primaryColor: `var(--ds-icon-success, ${G300})`,
10
+ primaryColor: token('color.icon.success', G300),
10
11
  label: "Success"
11
12
  }),
12
13
  id: "feedbackSent",
@@ -0,0 +1,11 @@
1
+ export default function truncate(text, maxLength) {
2
+ if (!text || !maxLength) {
3
+ return text;
4
+ }
5
+
6
+ if (text.length <= maxLength) {
7
+ return text;
8
+ }
9
+
10
+ return text.substring(0, maxLength) + '...';
11
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/feedback-collector",
3
- "version": "8.0.2",
3
+ "version": "9.0.2",
4
4
  "sideEffects": false
5
5
  }
@@ -18,16 +18,14 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
18
18
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
19
19
 
20
20
  import React, { Component } from 'react';
21
- import truncate from 'lodash/truncate';
21
+ import truncate from '../utils/Truncate';
22
22
  import FeedbackForm from './FeedbackForm';
23
23
  var MAX_SUMMARY_LENGTH_CHARS = 100;
24
24
 
25
25
  var singleLineTruncatedText = function singleLineTruncatedText(text) {
26
26
  var length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : MAX_SUMMARY_LENGTH_CHARS;
27
27
  var singleLineText = text.replace(/\n/g, ' ');
28
- return truncate(singleLineText, {
29
- length: length
30
- });
28
+ return truncate(singleLineText, length);
31
29
  };
32
30
 
33
31
  var FeedbackCollector = /*#__PURE__*/function (_Component) {
@@ -48,23 +46,24 @@ var FeedbackCollector = /*#__PURE__*/function (_Component) {
48
46
 
49
47
  _defineProperty(_assertThisInitialized(_this), "postFeedback", /*#__PURE__*/function () {
50
48
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(formValues) {
51
- var requestType, embedKey, formData, body, postData;
49
+ var requestType, embedKey, url, formData, body, postData;
52
50
  return _regeneratorRuntime.wrap(function _callee$(_context) {
53
51
  while (1) {
54
52
  switch (_context.prev = _context.next) {
55
53
  case 0:
56
54
  requestType = _this.props.requestTypeId;
57
- embedKey = _this.props.embeddableKey; // Don't dispatch unless we have suitable props (allows tests to pass through empty strings and avoid redundant network calls)
55
+ embedKey = _this.props.embeddableKey;
56
+ url = _this.props.url; // Don't dispatch unless we have suitable props (allows tests to pass through empty strings and avoid redundant network calls)
58
57
 
59
58
  if (!(embedKey && requestType)) {
60
- _context.next = 9;
59
+ _context.next = 11;
61
60
  break;
62
61
  }
63
62
 
64
- _context.next = 5;
63
+ _context.next = 6;
65
64
  return _this.mapFormToJSD(formValues);
66
65
 
67
- case 5:
66
+ case 6:
68
67
  formData = _context.sent;
69
68
  body = {
70
69
  feedback: _objectSpread({
@@ -72,20 +71,27 @@ var FeedbackCollector = /*#__PURE__*/function (_Component) {
72
71
  embedKey: _this.props.embeddableKey
73
72
  }, formData)
74
73
  };
74
+
75
+ if (_this.props.url === "/gateway/api") {
76
+ url += '/feedback-collector-api';
77
+ } else {
78
+ url = 'https://feedback-collector-api.services.atlassian.com';
79
+ }
80
+
75
81
  postData = Buffer.from(JSON.stringify(body)).toString('base64');
76
- fetch('https://feedback-collector-api.services.atlassian.com/feedback', {
82
+ fetch("".concat(url, "/feedback"), _objectSpread({
77
83
  method: 'POST',
78
- headers: _objectSpread({
84
+ headers: {
79
85
  'Content-Type': 'application/json'
80
- }, _this.props.cookie ? {
81
- Cookie: _this.props.cookie
82
- } : {}),
86
+ },
83
87
  body: JSON.stringify({
84
88
  data: postData
85
89
  })
86
- });
90
+ }, _this.props.url === "/gateway/api" ? {
91
+ credentials: 'include'
92
+ } : {}));
87
93
 
88
- case 9:
94
+ case 11:
89
95
  _this.props.onClose(); // slightly delay confirming submit since we don't wait for the REST call to succeed
90
96
  //
91
97
  // Because `onClose` is invoked prior to this timeout triggering, the `componentWillUnmount`
@@ -98,7 +104,7 @@ var FeedbackCollector = /*#__PURE__*/function (_Component) {
98
104
  return _this.props.onSubmit(formValues);
99
105
  }, _this.props.timeoutOnSubmit);
100
106
 
101
- case 11:
107
+ case 13:
102
108
  case "end":
103
109
  return _context.stop();
104
110
  }
@@ -117,22 +123,19 @@ var FeedbackCollector = /*#__PURE__*/function (_Component) {
117
123
  _createClass(FeedbackCollector, [{
118
124
  key: "getEntitlementInformation",
119
125
  value: function () {
120
- var _getEntitlementInformation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(cookie) {
121
- var _productName, url, productName, productEntitlement, entitlementDetails, productKey, _document$querySelect, hasPremium, entitlement, entitlementInformation;
126
+ var _getEntitlementInformation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
127
+ var _productName;
128
+
129
+ var url, productName, productEntitlement, entitlementDetails, productKey, _document$querySelect, hasPremium, entitlement, entitlementInformation;
122
130
 
123
131
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
124
132
  while (1) {
125
133
  switch (_context2.prev = _context2.next) {
126
134
  case 0:
127
- if (!(cookie && cookie.length)) {
128
- _context2.next = 24;
129
- break;
130
- }
131
-
132
- url = cookie.includes('cloud.session.token.stg') ? 'https://api-private.stg.atlassian.com' : 'https://api-private.atlassian.com'; // jira / connie / bb
135
+ url = this.props.url; // jira / confluence / bitbucket
133
136
 
134
137
  if (!window.location.host.includes('bitbucket.org')) {
135
- _context2.next = 10;
138
+ _context2.next = 9;
136
139
  break;
137
140
  }
138
141
 
@@ -141,10 +144,10 @@ var FeedbackCollector = /*#__PURE__*/function (_Component) {
141
144
  entitlementDetails = JSON.parse(JSON.stringify((_document$querySelect = document.querySelector('meta[name="bb-bootstrap"]')) === null || _document$querySelect === void 0 ? void 0 : _document$querySelect.getAttribute('data-current-user')));
142
145
  hasPremium = entitlementDetails['hasPremium'];
143
146
  productEntitlement = hasPremium ? 'PREMIUM' : 'STANDARD';
144
- _context2.next = 20;
147
+ _context2.next = 19;
145
148
  break;
146
149
 
147
- case 10:
150
+ case 9:
148
151
  if (document.querySelector('meta[id="confluence-context-path"]')) {
149
152
  productName = 'Confluence';
150
153
  productKey = 'pricingplan.confluence.ondemand';
@@ -153,35 +156,36 @@ var FeedbackCollector = /*#__PURE__*/function (_Component) {
153
156
  productKey = 'jira-software.ondemand';
154
157
  }
155
158
 
156
- _context2.prev = 11;
157
- _context2.next = 14;
158
- return fetch("".concat(url, "/customer-context/entitlements/").concat(window.location.host), {
159
+ _context2.prev = 10;
160
+ _context2.next = 13;
161
+ return fetch("".concat(url, "/customer-context/entitlements/").concat(window.location.host), _objectSpread({
159
162
  method: 'GET',
160
163
  headers: {
161
- 'Content-Type': 'application/json',
162
- Cookie: cookie
163
- },
164
+ 'Content-Type': 'application/json'
165
+ }
166
+ }, this.props.url === "/gateway/api" ? {
164
167
  credentials: 'include'
165
- });
168
+ } : {}));
166
169
 
167
- case 14:
170
+ case 13:
168
171
  entitlementDetails = _context2.sent;
169
- _context2.next = 20;
172
+ _context2.next = 19;
170
173
  break;
171
174
 
172
- case 17:
173
- _context2.prev = 17;
174
- _context2.t0 = _context2["catch"](11);
175
+ case 16:
176
+ _context2.prev = 16;
177
+ _context2.t0 = _context2["catch"](10);
175
178
  entitlementDetails = undefined;
176
179
 
177
- case 20:
180
+ case 19:
181
+ entitlementInformation = [];
182
+
178
183
  if (entitlementDetails && entitlementDetails.children) {
179
184
  entitlement = entitlementDetails.children.find(function (entitlement) {
180
185
  return entitlement.key === productKey;
181
186
  });
182
187
  }
183
188
 
184
- entitlementInformation = [];
185
189
  entitlementInformation.push({
186
190
  id: 'product',
187
191
  value: productName ? (_productName = productName) === null || _productName === void 0 ? void 0 : _productName.toLowerCase() : ''
@@ -194,18 +198,15 @@ var FeedbackCollector = /*#__PURE__*/function (_Component) {
194
198
  });
195
199
  return _context2.abrupt("return", entitlementInformation);
196
200
 
197
- case 24:
198
- return _context2.abrupt("return", []);
199
-
200
- case 25:
201
+ case 23:
201
202
  case "end":
202
203
  return _context2.stop();
203
204
  }
204
205
  }
205
- }, _callee2, null, [[11, 17]]);
206
+ }, _callee2, this, [[10, 16]]);
206
207
  }));
207
208
 
208
- function getEntitlementInformation(_x2) {
209
+ function getEntitlementInformation() {
209
210
  return _getEntitlementInformation.apply(this, arguments);
210
211
  }
211
212
 
@@ -261,26 +262,13 @@ var FeedbackCollector = /*#__PURE__*/function (_Component) {
261
262
  while (1) {
262
263
  switch (_context3.prev = _context3.next) {
263
264
  case 0:
264
- if (!this.props.cookie) {
265
- _context3.next = 6;
266
- break;
267
- }
268
-
269
- _context3.next = 3;
270
- return this.getEntitlementInformation(this.props.cookie);
271
-
272
- case 3:
273
- _context3.t0 = _context3.sent;
274
- _context3.next = 7;
275
- break;
276
-
277
- case 6:
278
- _context3.t0 = [];
265
+ _context3.next = 2;
266
+ return this.getEntitlementInformation();
279
267
 
280
- case 7:
281
- entitlementInformation = _context3.t0;
268
+ case 2:
269
+ entitlementInformation = _context3.sent;
282
270
  return _context3.abrupt("return", {
283
- fields: [].concat(_toConsumableArray(entitlementInformation), [this.props.showTypeField ? {
271
+ fields: [].concat(_toConsumableArray(entitlementInformation !== null && entitlementInformation || []), [this.props.showTypeField ? {
284
272
  id: this.props.typeFieldId,
285
273
  value: this.getTypeFieldValue(formValues.type)
286
274
  } : undefined, {
@@ -304,7 +292,7 @@ var FeedbackCollector = /*#__PURE__*/function (_Component) {
304
292
  } : undefined], _toConsumableArray(this.props.additionalFields)).filter(Boolean)
305
293
  });
306
294
 
307
- case 9:
295
+ case 4:
308
296
  case "end":
309
297
  return _context3.stop();
310
298
  }
@@ -312,7 +300,7 @@ var FeedbackCollector = /*#__PURE__*/function (_Component) {
312
300
  }, _callee3, this);
313
301
  }));
314
302
 
315
- function mapFormToJSD(_x3) {
303
+ function mapFormToJSD(_x2) {
316
304
  return _mapFormToJSD.apply(this, arguments);
317
305
  }
318
306
 
@@ -341,7 +329,7 @@ var FeedbackCollector = /*#__PURE__*/function (_Component) {
341
329
  }(Component);
342
330
 
343
331
  _defineProperty(FeedbackCollector, "defaultProps", {
344
- cookie: '',
332
+ url: '/gateway/api',
345
333
  canBeContactedFieldId: 'customfield_10043',
346
334
  canBeContactedDefaultValue: [{
347
335
  id: '10109'
@@ -3,11 +3,12 @@ import React from 'react';
3
3
  import { AutoDismissFlag } from '@atlaskit/flag';
4
4
  import SuccessIcon from '@atlaskit/icon/glyph/check-circle';
5
5
  import { G300 } from '@atlaskit/theme/colors';
6
+ import { token } from '@atlaskit/tokens';
6
7
 
7
8
  var FeedbackFlag = function FeedbackFlag(props) {
8
9
  return /*#__PURE__*/React.createElement(AutoDismissFlag, _extends({
9
10
  icon: /*#__PURE__*/React.createElement(SuccessIcon, {
10
- primaryColor: "var(--ds-icon-success, ".concat(G300, ")"),
11
+ primaryColor: token('color.icon.success', G300),
11
12
  label: "Success"
12
13
  }),
13
14
  id: "feedbackSent",
@@ -0,0 +1,11 @@
1
+ export default function truncate(text, maxLength) {
2
+ if (!text || !maxLength) {
3
+ return text;
4
+ }
5
+
6
+ if (text.length <= maxLength) {
7
+ return text;
8
+ }
9
+
10
+ return text.substring(0, maxLength) + '...';
11
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/feedback-collector",
3
- "version": "8.0.2",
3
+ "version": "9.0.2",
4
4
  "sideEffects": false
5
5
  }
@@ -9,8 +9,8 @@ declare type FeedbackType = {
9
9
  fields: FieldType[];
10
10
  };
11
11
  export interface Props {
12
- /** Required. The customer session token. Usage: `cookie={"cloud.session.token=<session-token>"}` */
13
- cookie: string;
12
+ /** Override the URL for HTTPS calls, only needed if service is not behind stargate (like the Atlaskit frontend itself) */
13
+ url: string;
14
14
  /** The customer email */
15
15
  email?: string;
16
16
  /** The customer name */
@@ -23,61 +23,61 @@ export interface Props {
23
23
  additionalFields: FieldType[];
24
24
  /** Override the default id for the "can be contacted" custom field in your widget service **/
25
25
  canBeContactedFieldId: string;
26
- /** Override the default value for the "can be contacted" custom field in your widget service **/
26
+ /** Override the default value for the "can be contacted" custom field in your widget service */
27
27
  canBeContactedDefaultValue: FieldValueType;
28
- /** Override the default id for the "customer name" custom field in your widget service **/
28
+ /** Override the default id for the "customer name" custom field in your widget service */
29
29
  customerNameFieldId: string;
30
- /** Override the default value for the "customer name" custom field in your widget service **/
30
+ /** Override the default value for the "customer name" custom field in your widget service */
31
31
  customerNameDefaultValue: FieldValueType;
32
- /** Override the default id for the "description" custom field in your widget service **/
32
+ /** Override the default id for the "description" custom field in your widget service */
33
33
  descriptionFieldId: string;
34
- /** Override the default value for the "description" custom field in your widget service **/
34
+ /** Override the default value for the "description" custom field in your widget service */
35
35
  descriptionDefaultValue: FieldValueType;
36
- /** Override the default id for the "enroll in research" custom field in your widget service **/
36
+ /** Override the default id for the "enroll in research" custom field in your widget service */
37
37
  enrollInResearchFieldId: string;
38
- /** Override the default value for the "enroll in research" custom field in your widget service **/
38
+ /** Override the default value for the "enroll in research" custom field in your widget service */
39
39
  enrollInResearchDefaultValue: FieldValueType;
40
- /** Override the default id for the "email" custom field in your widget service **/
40
+ /** Override the default id for the "email" custom field in your widget service */
41
41
  emailFieldId: string;
42
- /** Override the default value for the "email" custom field in your widget service **/
42
+ /** Override the default value for the "email" custom field in your widget service */
43
43
  emailDefaultValue: FieldValueType;
44
- /** Override the default id for the "summary" custom field in your widget service **/
44
+ /** Override the default id for the "summary" custom field in your widget service */
45
45
  summaryFieldId: string;
46
- /** Override the default value for the "summary" custom field in your widget service **/
46
+ /** Override the default value for the "summary" custom field in your widget service */
47
47
  summaryDefaultValue: FieldValueType;
48
- /** Number of characters that the "summary" field accepts, the rest will be truncated **/
48
+ /** Number of characters that the "summary" field accepts, the rest will be truncated */
49
49
  summaryTruncateLength: number;
50
- /** After this delay the onSubmit callback will be triggered optimistically **/
50
+ /** After this delay the onSubmit callback will be triggered optimistically */
51
51
  timeoutOnSubmit: number;
52
- /** Override the default id for the "type" custom field in your widget service **/
52
+ /** Override the default id for the "type" custom field in your widget service */
53
53
  typeFieldId: string;
54
- /** Override the default value for the "Bug" type of response in your widget service **/
54
+ /** Override the default value for the "Bug" type of response in your widget service */
55
55
  typeBugDefaultValue: FieldValueType;
56
- /** Override the default value for the "Comment" type of response in your widget service **/
56
+ /** Override the default value for the "Comment" type of response in your widget service */
57
57
  typeCommentDefaultValue: FieldValueType;
58
- /** Override the default value for the "Suggestion" type of response in your widget service **/
58
+ /** Override the default value for the "Suggestion" type of response in your widget service */
59
59
  typeSuggestionDefaultValue: FieldValueType;
60
- /** Override the default value for the "Question" type of response in your widget service **/
60
+ /** Override the default value for the "Question" type of response in your widget service */
61
61
  typeQuestionDefaultValue: FieldValueType;
62
- /** Override the default value for the "Empty" type of response in your widget service **/
62
+ /** Override the default value for the "Empty" type of response in your widget service */
63
63
  typeEmptyDefaultValue: FieldValueType;
64
- /** Override to hide the feedback type select drop down for the feedback **/
64
+ /** Override to hide the feedback type select drop down for the feedback */
65
65
  showTypeField: boolean;
66
- /** Message which will be shown as the title of the feedback dialog **/
66
+ /** Message which will be shown as the title of the feedback dialog */
67
67
  feedbackTitle?: React.ReactText;
68
- /** Message which will be shown below the title of the feedback dialog **/
68
+ /** Message which will be shown below the title of the feedback dialog */
69
69
  feedbackTitleDetails?: React.ReactChild;
70
- /** Message which will be shown next to the enrol in research checkbox **/
70
+ /** Message which will be shown next to the enrol in research checkbox */
71
71
  enrolInResearchLabel?: React.ReactChild;
72
- /** Message which will be shown next to the can be contacted checkbox **/
72
+ /** Message which will be shown next to the can be contacted checkbox */
73
73
  canBeContactedLabel?: React.ReactChild;
74
- /** Message which will be shown inside the summary text field **/
74
+ /** Message which will be shown inside the summary text field */
75
75
  summaryPlaceholder?: string;
76
- /** Message for submit button label **/
76
+ /** Message for submit button label */
77
77
  submitButtonLabel?: string;
78
- /** Message for cancel button label **/
78
+ /** Message for cancel button label */
79
79
  cancelButtonLabel?: string;
80
- /** Message for select option labels and field labels **/
80
+ /** Message for select option labels and field labels */
81
81
  feedbackGroupLabels?: Record<SelectValue, SelectOptionDetails>;
82
82
  /** Function that will be called to initiate the exit transition. */
83
83
  onClose: () => void;
@@ -86,7 +86,7 @@ export interface Props {
86
86
  }
87
87
  export default class FeedbackCollector extends Component<Props> {
88
88
  static defaultProps: {
89
- cookie: string;
89
+ url: string;
90
90
  canBeContactedFieldId: string;
91
91
  canBeContactedDefaultValue: {
92
92
  id: string;
@@ -126,7 +126,7 @@ export default class FeedbackCollector extends Component<Props> {
126
126
  onClose: () => void;
127
127
  onSubmit: () => void;
128
128
  };
129
- getEntitlementInformation(cookie: string | undefined): Promise<FieldType[] | []>;
129
+ getEntitlementInformation(): Promise<FieldType[] | []>;
130
130
  getTypeFieldValue(dtype: SelectValue): FieldValueType;
131
131
  getEmail(formValues: FormFields): Object;
132
132
  getDescription(formValues: FormFields): Object;
@@ -0,0 +1 @@
1
+ export default function truncate(text: string, maxLength: number): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/feedback-collector",
3
- "version": "8.0.2",
3
+ "version": "9.0.2",
4
4
  "description": "A component that collects feedback across Atlassian products.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -15,9 +15,9 @@
15
15
  "sideEffects": false,
16
16
  "atlaskit:src": "src/index.ts",
17
17
  "atlassian": {
18
- "team": "Design System Team",
18
+ "team": "Self-Help Experience",
19
19
  "deprecatedAutoEntryPoints": true,
20
- "releaseModel": "scheduled",
20
+ "releaseModel": "continuous",
21
21
  "website": {
22
22
  "name": "Feedback Collector"
23
23
  }
@@ -26,18 +26,17 @@
26
26
  "access": "public"
27
27
  },
28
28
  "dependencies": {
29
- "@atlaskit/button": "^16.1.0",
29
+ "@atlaskit/button": "^16.2.0",
30
30
  "@atlaskit/checkbox": "^12.3.0",
31
31
  "@atlaskit/flag": "^14.5.0",
32
- "@atlaskit/form": "^8.4.0",
32
+ "@atlaskit/form": "^8.5.0",
33
33
  "@atlaskit/icon": "^21.10.0",
34
34
  "@atlaskit/modal-dialog": "^12.2.0",
35
35
  "@atlaskit/select": "^15.2.0",
36
- "@atlaskit/textarea": "^4.2.0",
36
+ "@atlaskit/textarea": "^4.3.0",
37
37
  "@atlaskit/theme": "^12.1.0",
38
- "@atlaskit/tokens": "^0.6.0",
39
- "@babel/runtime": "^7.0.0",
40
- "lodash": "^4.17.21"
38
+ "@atlaskit/tokens": "^0.7.0",
39
+ "@babel/runtime": "^7.0.0"
41
40
  },
42
41
  "peerDependencies": {
43
42
  "react": "^16.8.0"
@@ -70,4 +69,4 @@
70
69
  }
71
70
  },
72
71
  "prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.1"
73
- }
72
+ }