UNPKG

@atlaskit/editor-plugin-feedback-dialog

Version:

Feedback dialog plugin for @atlaskit/editor-core

134 lines (132 loc) 6.93 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.openFeedbackDialog = exports.feedbackDialogPlugin = void 0; var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); var _react = _interopRequireDefault(require("react")); var _analytics = require("@atlaskit/editor-common/analytics"); var _messages = require("@atlaskit/editor-common/messages"); var _quickInsert = require("@atlaskit/editor-common/quick-insert"); var _loadJiraCollectorDialogScript = _interopRequireDefault(require("./ui/loadJiraCollectorDialogScript")); function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var showJiraCollectorDialog; var feedbackInfoHash; var defaultFeedbackInfo; var hashFeedbackInfo = function hashFeedbackInfo(feedbackInfo) { var product = feedbackInfo.product, packageName = feedbackInfo.packageName, packageVersion = feedbackInfo.packageVersion, labels = feedbackInfo.labels; return [product, packageName, packageVersion].concat((0, _toConsumableArray2.default)(labels || [])).join('|'); }; // Ignored via go/ees005 // eslint-disable-next-line require-await var openFeedbackDialog = exports.openFeedbackDialog = /*#__PURE__*/function () { var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(feedbackInfo) { return _regenerator.default.wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: return _context2.abrupt("return", // eslint-disable-next-line no-async-promise-executor new Promise( /*#__PURE__*/function () { var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(resolve, reject) { var combinedFeedbackInfo, newFeedbackInfoHash, timeoutId; return _regenerator.default.wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: combinedFeedbackInfo = _objectSpread(_objectSpread(_objectSpread({}, { product: 'n/a', labels: [], packageName: '', packageVersion: '', coreVersion: '', sessionId: '', contentId: '', tabId: '' }), defaultFeedbackInfo), feedbackInfo); newFeedbackInfoHash = hashFeedbackInfo(combinedFeedbackInfo); if (!(!showJiraCollectorDialog || feedbackInfoHash !== newFeedbackInfoHash)) { _context.next = 13; break; } _context.prev = 3; _context.next = 6; return (0, _loadJiraCollectorDialogScript.default)([combinedFeedbackInfo.product].concat((0, _toConsumableArray2.default)(combinedFeedbackInfo.labels)), combinedFeedbackInfo.packageName, combinedFeedbackInfo.coreVersion, combinedFeedbackInfo.packageVersion, combinedFeedbackInfo.sessionId, combinedFeedbackInfo.contentId, combinedFeedbackInfo.tabId); case 6: showJiraCollectorDialog = _context.sent; feedbackInfoHash = newFeedbackInfoHash; _context.next = 13; break; case 10: _context.prev = 10; _context.t0 = _context["catch"](3); reject(_context.t0); case 13: timeoutId = window.setTimeout(showJiraCollectorDialog, 0); // Return the timoutId for consumers to call clearTimeout if they need to. resolve(timeoutId); case 15: case "end": return _context.stop(); } }, _callee, null, [[3, 10]]); })); return function (_x2, _x3) { return _ref2.apply(this, arguments); }; }())); case 1: case "end": return _context2.stop(); } }, _callee2); })); return function openFeedbackDialog(_x) { return _ref.apply(this, arguments); }; }(); var feedbackDialogPlugin = exports.feedbackDialogPlugin = function feedbackDialogPlugin(_ref3) { var feedbackInfo = _ref3.config, api = _ref3.api; defaultFeedbackInfo = feedbackInfo !== null && feedbackInfo !== void 0 ? feedbackInfo : {}; return { name: 'feedbackDialog', actions: { openFeedbackDialog: openFeedbackDialog }, pluginsOptions: { quickInsert: function quickInsert(_ref4) { var formatMessage = _ref4.formatMessage; return [{ id: 'feedbackdialog', title: formatMessage(_messages.toolbarInsertBlockMessages.feedbackDialog), description: formatMessage(_messages.toolbarInsertBlockMessages.feedbackDialogDescription), priority: 400, keywords: ['bug'], icon: function icon() { return /*#__PURE__*/_react.default.createElement(_quickInsert.IconFeedback, null); }, action: function action(insert, state) { var _api$analytics; var tr = insert(''); openFeedbackDialog(feedbackInfo); api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({ action: _analytics.ACTION.OPENED, actionSubject: _analytics.ACTION_SUBJECT.FEEDBACK_DIALOG, attributes: { inputMethod: _analytics.INPUT_METHOD.QUICK_INSERT }, eventType: _analytics.EVENT_TYPE.UI })(tr); return tr; } }]; } } }; };