UNPKG

@atlaskit/editor-plugin-feedback-dialog

Version:

Feedback dialog plugin for @atlaskit/editor-core

89 lines (88 loc) 3.17 kB
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'; let showJiraCollectorDialog; let feedbackInfoHash; let defaultFeedbackInfo; const hashFeedbackInfo = feedbackInfo => { const { product, packageName, packageVersion, labels } = feedbackInfo; return [product, packageName, packageVersion, ...(labels || [])].join('|'); }; // Ignored via go/ees005 // eslint-disable-next-line require-await export const openFeedbackDialog = async feedbackInfo => // eslint-disable-next-line no-async-promise-executor new Promise(async (resolve, reject) => { const combinedFeedbackInfo = { // default value assignment ...{ product: 'n/a', labels: [], packageName: '', packageVersion: '', coreVersion: '', sessionId: '', contentId: '', tabId: '' }, ...defaultFeedbackInfo, ...feedbackInfo }; const newFeedbackInfoHash = hashFeedbackInfo(combinedFeedbackInfo); if (!showJiraCollectorDialog || feedbackInfoHash !== newFeedbackInfoHash) { try { showJiraCollectorDialog = await loadJiraCollectorDialogScript([combinedFeedbackInfo.product, ...combinedFeedbackInfo.labels], combinedFeedbackInfo.packageName, combinedFeedbackInfo.coreVersion, combinedFeedbackInfo.packageVersion, combinedFeedbackInfo.sessionId, combinedFeedbackInfo.contentId, combinedFeedbackInfo.tabId); feedbackInfoHash = newFeedbackInfoHash; } catch (err) { reject(err); } } const timeoutId = window.setTimeout(showJiraCollectorDialog, 0); // Return the timoutId for consumers to call clearTimeout if they need to. resolve(timeoutId); }); export const feedbackDialogPlugin = ({ config: feedbackInfo, api }) => { defaultFeedbackInfo = feedbackInfo !== null && feedbackInfo !== void 0 ? feedbackInfo : {}; return { name: 'feedbackDialog', actions: { openFeedbackDialog }, pluginsOptions: { quickInsert: ({ formatMessage }) => [{ id: 'feedbackdialog', title: formatMessage(messages.feedbackDialog), description: formatMessage(messages.feedbackDialogDescription), priority: 400, keywords: ['bug'], icon: () => /*#__PURE__*/React.createElement(IconFeedback, null), action(insert, state) { var _api$analytics; const tr = insert(''); openFeedbackDialog(feedbackInfo); api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? 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; } }] } }; };