@atlaskit/editor-plugin-feedback-dialog
Version:
Feedback dialog plugin for @atlaskit/editor-core
127 lines (126 loc) • 6.35 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
import _regeneratorRuntime from "@babel/runtime/regenerator";
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) { _defineProperty(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; }
import React from 'react';
import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
import { IconFeedback } from '@atlaskit/editor-common/quick-insert';
import loadJiraCollectorDialogScript from './ui/loadJiraCollectorDialogScript';
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(_toConsumableArray(labels || [])).join('|');
};
// Ignored via go/ees005
// eslint-disable-next-line require-await
export var openFeedbackDialog = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(feedbackInfo) {
return _regeneratorRuntime.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 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(resolve, reject) {
var combinedFeedbackInfo, newFeedbackInfoHash, timeoutId;
return _regeneratorRuntime.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 loadJiraCollectorDialogScript([combinedFeedbackInfo.product].concat(_toConsumableArray(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);
};
}();
export var 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.feedbackDialog),
description: formatMessage(messages.feedbackDialogDescription),
priority: 400,
keywords: ['bug'],
icon: function icon() {
return /*#__PURE__*/React.createElement(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: ACTION.OPENED,
actionSubject: ACTION_SUBJECT.FEEDBACK_DIALOG,
attributes: {
inputMethod: INPUT_METHOD.QUICK_INSERT
},
eventType: EVENT_TYPE.UI
})(tr);
return tr;
}
}];
}
}
};
};