@atlaskit/editor-plugin-annotation 2.9.1 → 2.9.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,14 @@
1
1
  # @atlaskit/editor-plugin-annotation
2
2
 
3
+ ## 2.9.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#162493](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/162493)
8
+ [`e2fed6abf826b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e2fed6abf826b) -
9
+ Added some error reporting anayltics for the new annotation manager
10
+ - Updated dependencies
11
+
3
12
  ## 2.9.1
4
13
 
5
14
  ### Patch Changes
@@ -51,13 +51,21 @@ var clearDirtyMark = exports.clearDirtyMark = function clearDirtyMark() {
51
51
  type: _types.ACTIONS.INLINE_COMMENT_CLEAR_DIRTY_MARK
52
52
  });
53
53
  };
54
- var flushPendingSelections = exports.flushPendingSelections = function flushPendingSelections(canSetAsSelectedAnnotations) {
55
- return (0, _pluginFactory.createCommand)({
56
- type: _types.ACTIONS.FLUSH_PENDING_SELECTIONS,
57
- data: {
58
- canSetAsSelectedAnnotations: canSetAsSelectedAnnotations
54
+ var flushPendingSelections = exports.flushPendingSelections = function flushPendingSelections(editorAnalyticsAPI) {
55
+ return function (canSetAsSelectedAnnotations, errorReason) {
56
+ var command = {
57
+ type: _types.ACTIONS.FLUSH_PENDING_SELECTIONS,
58
+ data: {
59
+ canSetAsSelectedAnnotations: canSetAsSelectedAnnotations
60
+ }
61
+ };
62
+ if (!!errorReason) {
63
+ return (0, _pluginFactory.createCommand)(command, function (tr, state) {
64
+ return _transform.default.addPreemptiveGateErrorAnalytics(editorAnalyticsAPI)(errorReason)(tr, state);
65
+ });
59
66
  }
60
- });
67
+ return (0, _pluginFactory.createCommand)(command);
68
+ };
61
69
  };
62
70
  var setPendingSelectedAnnotation = exports.setPendingSelectedAnnotation = function setPendingSelectedAnnotation(id) {
63
71
  return (0, _pluginFactory.createCommand)({
@@ -131,32 +139,34 @@ var removeInlineCommentNearSelection = exports.removeInlineCommentNearSelection
131
139
  return true;
132
140
  };
133
141
  };
134
- var removeInlineCommentFromDoc = exports.removeInlineCommentFromDoc = function removeInlineCommentFromDoc(id) {
135
- var supportedNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
136
- return function (state, dispatch) {
137
- var tr = state.tr;
138
- state.doc.descendants(function (node, pos) {
139
- // Inline comment on mediaInline is not supported as part of comments on media project
140
- // Thus, we skip the decoration for mediaInline node
141
- if (node.type.name === 'mediaInline') {
142
- return false;
143
- }
144
- var isSupportedBlockNode = node.isBlock && (supportedNodes === null || supportedNodes === void 0 ? void 0 : supportedNodes.includes(node.type.name));
145
- node.marks.filter(function (mark) {
146
- return mark.type === state.schema.marks.annotation && mark.attrs.id === id;
147
- }).forEach(function (mark) {
148
- if (isSupportedBlockNode) {
149
- tr.removeNodeMark(pos, mark);
150
- } else {
151
- tr.removeMark(pos, pos + node.nodeSize, mark);
142
+ var removeInlineCommentFromDoc = exports.removeInlineCommentFromDoc = function removeInlineCommentFromDoc(editorAnalyticsAPI) {
143
+ return function (id) {
144
+ var supportedNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
145
+ return function (state, dispatch) {
146
+ var tr = state.tr;
147
+ state.doc.descendants(function (node, pos) {
148
+ // Inline comment on mediaInline is not supported as part of comments on media project
149
+ // Thus, we skip the decoration for mediaInline node
150
+ if (node.type.name === 'mediaInline') {
151
+ return false;
152
152
  }
153
+ var isSupportedBlockNode = node.isBlock && (supportedNodes === null || supportedNodes === void 0 ? void 0 : supportedNodes.includes(node.type.name));
154
+ node.marks.filter(function (mark) {
155
+ return mark.type === state.schema.marks.annotation && mark.attrs.id === id;
156
+ }).forEach(function (mark) {
157
+ if (isSupportedBlockNode) {
158
+ tr.removeNodeMark(pos, mark);
159
+ } else {
160
+ tr.removeMark(pos, pos + node.nodeSize, mark);
161
+ }
162
+ });
153
163
  });
154
- });
155
- if (dispatch) {
156
- dispatch(tr);
157
- return true;
158
- }
159
- return false;
164
+ if (dispatch) {
165
+ dispatch(_transform.default.addDeleteAnalytics(editorAnalyticsAPI)(tr, state));
166
+ return true;
167
+ }
168
+ return false;
169
+ };
160
170
  };
161
171
  };
162
172
  var getDraftCommandAction = function getDraftCommandAction(drafting, targetType, targetNodeId, supportedBlockNodes, isOpeningMediaCommentFromToolbar) {
@@ -136,11 +136,43 @@ var addResolveAnalytics = function addResolveAnalytics(editorAnalyticsAPI) {
136
136
  };
137
137
  };
138
138
  };
139
+ var addPreemptiveGateErrorAnalytics = function addPreemptiveGateErrorAnalytics(editorAnalyticsAPI) {
140
+ return function (errorReason) {
141
+ return function (transaction, state) {
142
+ var analyticsEvent = {
143
+ action: _analytics.ACTION.ERROR,
144
+ actionSubject: _analytics.ACTION_SUBJECT.ANNOTATION,
145
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.INLINE_COMMENT,
146
+ eventType: _analytics.EVENT_TYPE.OPERATIONAL,
147
+ attributes: {
148
+ errorReason: errorReason
149
+ }
150
+ };
151
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(analyticsEvent)(transaction);
152
+ return transaction;
153
+ };
154
+ };
155
+ };
156
+ var addDeleteAnalytics = function addDeleteAnalytics(editorAnalyticsAPI) {
157
+ return function (transaction, state) {
158
+ var analyticsEvent = {
159
+ action: _analytics.ACTION.DELETED,
160
+ actionSubject: _analytics.ACTION_SUBJECT.ANNOTATION,
161
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.INLINE_COMMENT,
162
+ eventType: _analytics.EVENT_TYPE.TRACK,
163
+ attributes: {}
164
+ };
165
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(analyticsEvent)(transaction);
166
+ return transaction;
167
+ };
168
+ };
139
169
  var _default = exports.default = {
140
170
  addAnnotationMark: addAnnotationMark,
141
171
  addInlineComment: addInlineComment,
142
172
  handleDraftState: handleDraftState,
143
173
  addOpenCloseAnalytics: addOpenCloseAnalytics,
144
174
  addInsertAnalytics: addInsertAnalytics,
145
- addResolveAnalytics: addResolveAnalytics
175
+ addResolveAnalytics: addResolveAnalytics,
176
+ addPreemptiveGateErrorAnalytics: addPreemptiveGateErrorAnalytics,
177
+ addDeleteAnalytics: addDeleteAnalytics
146
178
  };
@@ -344,7 +344,7 @@ var clearAnnotation = exports.clearAnnotation = function clearAnnotation(editorV
344
344
  reason: ERROR_REASON_ID_INVALID
345
345
  };
346
346
  }
347
- (0, _editorCommands.removeInlineCommentFromDoc)(id, options.provider.supportedBlockNodes)(editorView.state, editorView.dispatch);
347
+ (0, _editorCommands.removeInlineCommentFromDoc)(options.editorAnalyticsAPI)(id, options.provider.supportedBlockNodes)(editorView.state, editorView.dispatch);
348
348
  return {
349
349
  success: true,
350
350
  actionResult: undefined
@@ -308,7 +308,7 @@ var inlineCommentPlugin = exports.inlineCommentPlugin = function inlineCommentPl
308
308
  }
309
309
 
310
310
  // Flush the pending selections into the selected annotations list.
311
- (0, _editorCommands.flushPendingSelections)(true)(view.state, view.dispatch);
311
+ (0, _editorCommands.flushPendingSelections)(options.editorAnalyticsAPI)(true)(view.state, view.dispatch);
312
312
  latestSelectedAnnotations === null || latestSelectedAnnotations === void 0 || latestSelectedAnnotations.filter(function (annotation) {
313
313
  return (latestPendingSelectedAnnotations === null || latestPendingSelectedAnnotations === void 0 ? void 0 : latestPendingSelectedAnnotations.findIndex(function (pendingAnnotation) {
314
314
  return pendingAnnotation.id === annotation.id;
@@ -342,13 +342,11 @@ var inlineCommentPlugin = exports.inlineCommentPlugin = function inlineCommentPl
342
342
  // Clears the pending selections if the preemptive gate returns false.
343
343
  // We should need to worry about dispatching change events here because the pending selections
344
344
  // are being aborted and the selections will remain unchanged.
345
- (0, _editorCommands.flushPendingSelections)(false)(view.state, view.dispatch);
345
+ (0, _editorCommands.flushPendingSelections)(options.editorAnalyticsAPI)(false)(view.state, view.dispatch);
346
346
  }
347
347
  }).catch(function (error) {
348
- // TODO: EDITOR-595 - Ensure and anlytic is fired to indicate which reports on the error.
349
-
350
348
  // If an error has occured we will clear any pending selections to avoid accidentally setting the wrong thing.
351
- (0, _editorCommands.flushPendingSelections)(false)(view.state, view.dispatch);
349
+ (0, _editorCommands.flushPendingSelections)(options.editorAnalyticsAPI)(false, 'pending-selection-preemptive-gate-error')(view.state, view.dispatch);
352
350
  }).finally(function () {
353
351
  isPreemptiveGateActive = false;
354
352
  });
@@ -123,25 +123,17 @@ var buildToolbar = exports.buildToolbar = function buildToolbar(editorAnalyticsA
123
123
  }
124
124
  },
125
125
  onClick: function onClick(state, dispatch) {
126
- if (editorAnalyticsAPI) {
127
- editorAnalyticsAPI.fireAnalyticsEvent({
128
- action: _analytics.ACTION.CLICKED,
129
- actionSubject: _analytics.ACTION_SUBJECT.BUTTON,
130
- actionSubjectId: _analytics.ACTION_SUBJECT_ID.CREATE_INLINE_COMMENT_FROM_HIGHLIGHT_ACTIONS_MENU,
131
- eventType: _analytics.EVENT_TYPE.UI,
132
- attributes: {
133
- source: 'highlightActionsMenu',
134
- pageMode: 'edit'
135
- }
136
- });
137
- }
138
- if ((0, _platformFeatureFlags.fg)('platform_editor_comments_api_manager')) {
139
- if (!annotationManager) {
140
- // TODO: EDITOR-595 - If we've reached here and the manager is not initialized, we should
141
- // dispatch an analytics event to indicate that the user has clicked the button but
142
- // the action was not completed.
143
- return false;
126
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.fireAnalyticsEvent({
127
+ action: _analytics.ACTION.CLICKED,
128
+ actionSubject: _analytics.ACTION_SUBJECT.BUTTON,
129
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.CREATE_INLINE_COMMENT_FROM_HIGHLIGHT_ACTIONS_MENU,
130
+ eventType: _analytics.EVENT_TYPE.UI,
131
+ attributes: {
132
+ source: 'highlightActionsMenu',
133
+ pageMode: 'edit'
144
134
  }
135
+ });
136
+ if (annotationManager && (0, _platformFeatureFlags.fg)('platform_editor_comments_api_manager')) {
145
137
  annotationManager.checkPreemptiveGate().then(function (canStartDraft) {
146
138
  if (canStartDraft) {
147
139
  createCommentExperience === null || createCommentExperience === void 0 || createCommentExperience.start({
@@ -152,18 +144,30 @@ var buildToolbar = exports.buildToolbar = function buildToolbar(editorAnalyticsA
152
144
  });
153
145
  createCommentExperience === null || createCommentExperience === void 0 || createCommentExperience.initExperience.start();
154
146
  var result = annotationManager.startDraft();
155
- if (result.success) {
156
- // TODO: EDITOR-595 - Ensure and anlytic is fired to indicate that the user has started a draft.
157
- } else {
158
- // TODO: EDITOR-595 - Fire an analytics event to indicate that the user has clicked the button
147
+ if (!result.success) {
148
+ // Fire an analytics event to indicate that the user has clicked the button
159
149
  // but the action was not completed, the result should contain a reason.
150
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.fireAnalyticsEvent({
151
+ action: _analytics.ACTION.ERROR,
152
+ actionSubject: _analytics.ACTION_SUBJECT.ANNOTATION,
153
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.INLINE_COMMENT,
154
+ eventType: _analytics.EVENT_TYPE.OPERATIONAL,
155
+ attributes: {
156
+ errorReason: "toolbar-start-draft-failed/".concat(result.reason)
157
+ }
158
+ });
160
159
  }
161
- } else {
162
- // TODO: EDITOR-595 - Track the toolbar comment button was clicked but the preemptive gate
163
- // check returned false and the draft cannot be started.
164
160
  }
165
161
  }).catch(function () {
166
- // TODO: EDITOR-595 - Handle preemptive gate check error. Something went very wrong in the gate.
162
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.fireAnalyticsEvent({
163
+ action: _analytics.ACTION.ERROR,
164
+ actionSubject: _analytics.ACTION_SUBJECT.ANNOTATION,
165
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.INLINE_COMMENT,
166
+ eventType: _analytics.EVENT_TYPE.OPERATIONAL,
167
+ attributes: {
168
+ errorReason: "toolbar-start-draft-preemptive-gate-error"
169
+ }
170
+ });
167
171
  });
168
172
  return true;
169
173
  } else {
@@ -31,12 +31,18 @@ export const closeComponent = () => createCommand({
31
31
  export const clearDirtyMark = () => createCommand({
32
32
  type: ACTIONS.INLINE_COMMENT_CLEAR_DIRTY_MARK
33
33
  });
34
- export const flushPendingSelections = canSetAsSelectedAnnotations => createCommand({
35
- type: ACTIONS.FLUSH_PENDING_SELECTIONS,
36
- data: {
37
- canSetAsSelectedAnnotations
34
+ export const flushPendingSelections = editorAnalyticsAPI => (canSetAsSelectedAnnotations, errorReason) => {
35
+ const command = {
36
+ type: ACTIONS.FLUSH_PENDING_SELECTIONS,
37
+ data: {
38
+ canSetAsSelectedAnnotations
39
+ }
40
+ };
41
+ if (!!errorReason) {
42
+ return createCommand(command, (tr, state) => transform.addPreemptiveGateErrorAnalytics(editorAnalyticsAPI)(errorReason)(tr, state));
38
43
  }
39
- });
44
+ return createCommand(command);
45
+ };
40
46
  export const setPendingSelectedAnnotation = id => createCommand({
41
47
  type: ACTIONS.SET_PENDING_SELECTIONS,
42
48
  data: {
@@ -109,7 +115,7 @@ export const removeInlineCommentNearSelection = (id, supportedNodes = []) => (st
109
115
  }
110
116
  return true;
111
117
  };
112
- export const removeInlineCommentFromDoc = (id, supportedNodes = []) => (state, dispatch) => {
118
+ export const removeInlineCommentFromDoc = editorAnalyticsAPI => (id, supportedNodes = []) => (state, dispatch) => {
113
119
  const {
114
120
  tr
115
121
  } = state;
@@ -129,7 +135,7 @@ export const removeInlineCommentFromDoc = (id, supportedNodes = []) => (state, d
129
135
  });
130
136
  });
131
137
  if (dispatch) {
132
- dispatch(tr);
138
+ dispatch(transform.addDeleteAnalytics(editorAnalyticsAPI)(tr, state));
133
139
  return true;
134
140
  }
135
141
  return false;
@@ -109,11 +109,37 @@ const addResolveAnalytics = editorAnalyticsAPI => method => (transaction, state)
109
109
  editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent(resolvedPayload)(transaction);
110
110
  return transaction;
111
111
  };
112
+ const addPreemptiveGateErrorAnalytics = editorAnalyticsAPI => errorReason => (transaction, state) => {
113
+ const analyticsEvent = {
114
+ action: ACTION.ERROR,
115
+ actionSubject: ACTION_SUBJECT.ANNOTATION,
116
+ actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
117
+ eventType: EVENT_TYPE.OPERATIONAL,
118
+ attributes: {
119
+ errorReason
120
+ }
121
+ };
122
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent(analyticsEvent)(transaction);
123
+ return transaction;
124
+ };
125
+ const addDeleteAnalytics = editorAnalyticsAPI => (transaction, state) => {
126
+ const analyticsEvent = {
127
+ action: ACTION.DELETED,
128
+ actionSubject: ACTION_SUBJECT.ANNOTATION,
129
+ actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
130
+ eventType: EVENT_TYPE.TRACK,
131
+ attributes: {}
132
+ };
133
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent(analyticsEvent)(transaction);
134
+ return transaction;
135
+ };
112
136
  export default {
113
137
  addAnnotationMark,
114
138
  addInlineComment,
115
139
  handleDraftState,
116
140
  addOpenCloseAnalytics,
117
141
  addInsertAnalytics,
118
- addResolveAnalytics
142
+ addResolveAnalytics,
143
+ addPreemptiveGateErrorAnalytics,
144
+ addDeleteAnalytics
119
145
  };
@@ -328,7 +328,7 @@ export const clearAnnotation = (editorView, options) => id => {
328
328
  reason: ERROR_REASON_ID_INVALID
329
329
  };
330
330
  }
331
- removeInlineCommentFromDoc(id, options.provider.supportedBlockNodes)(editorView.state, editorView.dispatch);
331
+ removeInlineCommentFromDoc(options.editorAnalyticsAPI)(id, options.provider.supportedBlockNodes)(editorView.state, editorView.dispatch);
332
332
  return {
333
333
  success: true,
334
334
  actionResult: undefined
@@ -247,7 +247,7 @@ export const inlineCommentPlugin = options => {
247
247
  }
248
248
 
249
249
  // Flush the pending selections into the selected annotations list.
250
- flushPendingSelections(true)(view.state, view.dispatch);
250
+ flushPendingSelections(options.editorAnalyticsAPI)(true)(view.state, view.dispatch);
251
251
  latestSelectedAnnotations === null || latestSelectedAnnotations === void 0 ? void 0 : latestSelectedAnnotations.filter(annotation => (latestPendingSelectedAnnotations === null || latestPendingSelectedAnnotations === void 0 ? void 0 : latestPendingSelectedAnnotations.findIndex(pendingAnnotation => pendingAnnotation.id === annotation.id)) === -1).forEach(annotation => {
252
252
  var _options$annotationMa, _getAnnotationInlineN;
253
253
  (_options$annotationMa = options.annotationManager) === null || _options$annotationMa === void 0 ? void 0 : _options$annotationMa.emit({
@@ -278,13 +278,11 @@ export const inlineCommentPlugin = options => {
278
278
  // Clears the pending selections if the preemptive gate returns false.
279
279
  // We should need to worry about dispatching change events here because the pending selections
280
280
  // are being aborted and the selections will remain unchanged.
281
- flushPendingSelections(false)(view.state, view.dispatch);
281
+ flushPendingSelections(options.editorAnalyticsAPI)(false)(view.state, view.dispatch);
282
282
  }
283
283
  }).catch(error => {
284
- // TODO: EDITOR-595 - Ensure and anlytic is fired to indicate which reports on the error.
285
-
286
284
  // If an error has occured we will clear any pending selections to avoid accidentally setting the wrong thing.
287
- flushPendingSelections(false)(view.state, view.dispatch);
285
+ flushPendingSelections(options.editorAnalyticsAPI)(false, 'pending-selection-preemptive-gate-error')(view.state, view.dispatch);
288
286
  }).finally(() => {
289
287
  isPreemptiveGateActive = false;
290
288
  });
@@ -121,25 +121,17 @@ export const buildToolbar = editorAnalyticsAPI => ({
121
121
  }
122
122
  },
123
123
  onClick: (state, dispatch) => {
124
- if (editorAnalyticsAPI) {
125
- editorAnalyticsAPI.fireAnalyticsEvent({
126
- action: ACTION.CLICKED,
127
- actionSubject: ACTION_SUBJECT.BUTTON,
128
- actionSubjectId: ACTION_SUBJECT_ID.CREATE_INLINE_COMMENT_FROM_HIGHLIGHT_ACTIONS_MENU,
129
- eventType: EVENT_TYPE.UI,
130
- attributes: {
131
- source: 'highlightActionsMenu',
132
- pageMode: 'edit'
133
- }
134
- });
135
- }
136
- if (fg('platform_editor_comments_api_manager')) {
137
- if (!annotationManager) {
138
- // TODO: EDITOR-595 - If we've reached here and the manager is not initialized, we should
139
- // dispatch an analytics event to indicate that the user has clicked the button but
140
- // the action was not completed.
141
- return false;
124
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.fireAnalyticsEvent({
125
+ action: ACTION.CLICKED,
126
+ actionSubject: ACTION_SUBJECT.BUTTON,
127
+ actionSubjectId: ACTION_SUBJECT_ID.CREATE_INLINE_COMMENT_FROM_HIGHLIGHT_ACTIONS_MENU,
128
+ eventType: EVENT_TYPE.UI,
129
+ attributes: {
130
+ source: 'highlightActionsMenu',
131
+ pageMode: 'edit'
142
132
  }
133
+ });
134
+ if (annotationManager && fg('platform_editor_comments_api_manager')) {
143
135
  annotationManager.checkPreemptiveGate().then(canStartDraft => {
144
136
  if (canStartDraft) {
145
137
  createCommentExperience === null || createCommentExperience === void 0 ? void 0 : createCommentExperience.start({
@@ -150,18 +142,30 @@ export const buildToolbar = editorAnalyticsAPI => ({
150
142
  });
151
143
  createCommentExperience === null || createCommentExperience === void 0 ? void 0 : createCommentExperience.initExperience.start();
152
144
  const result = annotationManager.startDraft();
153
- if (result.success) {
154
- // TODO: EDITOR-595 - Ensure and anlytic is fired to indicate that the user has started a draft.
155
- } else {
156
- // TODO: EDITOR-595 - Fire an analytics event to indicate that the user has clicked the button
145
+ if (!result.success) {
146
+ // Fire an analytics event to indicate that the user has clicked the button
157
147
  // but the action was not completed, the result should contain a reason.
148
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.fireAnalyticsEvent({
149
+ action: ACTION.ERROR,
150
+ actionSubject: ACTION_SUBJECT.ANNOTATION,
151
+ actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
152
+ eventType: EVENT_TYPE.OPERATIONAL,
153
+ attributes: {
154
+ errorReason: `toolbar-start-draft-failed/${result.reason}`
155
+ }
156
+ });
158
157
  }
159
- } else {
160
- // TODO: EDITOR-595 - Track the toolbar comment button was clicked but the preemptive gate
161
- // check returned false and the draft cannot be started.
162
158
  }
163
159
  }).catch(() => {
164
- // TODO: EDITOR-595 - Handle preemptive gate check error. Something went very wrong in the gate.
160
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.fireAnalyticsEvent({
161
+ action: ACTION.ERROR,
162
+ actionSubject: ACTION_SUBJECT.ANNOTATION,
163
+ actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
164
+ eventType: EVENT_TYPE.OPERATIONAL,
165
+ attributes: {
166
+ errorReason: `toolbar-start-draft-preemptive-gate-error`
167
+ }
168
+ });
165
169
  });
166
170
  return true;
167
171
  } else {
@@ -44,13 +44,21 @@ export var clearDirtyMark = function clearDirtyMark() {
44
44
  type: ACTIONS.INLINE_COMMENT_CLEAR_DIRTY_MARK
45
45
  });
46
46
  };
47
- export var flushPendingSelections = function flushPendingSelections(canSetAsSelectedAnnotations) {
48
- return createCommand({
49
- type: ACTIONS.FLUSH_PENDING_SELECTIONS,
50
- data: {
51
- canSetAsSelectedAnnotations: canSetAsSelectedAnnotations
47
+ export var flushPendingSelections = function flushPendingSelections(editorAnalyticsAPI) {
48
+ return function (canSetAsSelectedAnnotations, errorReason) {
49
+ var command = {
50
+ type: ACTIONS.FLUSH_PENDING_SELECTIONS,
51
+ data: {
52
+ canSetAsSelectedAnnotations: canSetAsSelectedAnnotations
53
+ }
54
+ };
55
+ if (!!errorReason) {
56
+ return createCommand(command, function (tr, state) {
57
+ return transform.addPreemptiveGateErrorAnalytics(editorAnalyticsAPI)(errorReason)(tr, state);
58
+ });
52
59
  }
53
- });
60
+ return createCommand(command);
61
+ };
54
62
  };
55
63
  export var setPendingSelectedAnnotation = function setPendingSelectedAnnotation(id) {
56
64
  return createCommand({
@@ -124,32 +132,34 @@ export var removeInlineCommentNearSelection = function removeInlineCommentNearSe
124
132
  return true;
125
133
  };
126
134
  };
127
- export var removeInlineCommentFromDoc = function removeInlineCommentFromDoc(id) {
128
- var supportedNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
129
- return function (state, dispatch) {
130
- var tr = state.tr;
131
- state.doc.descendants(function (node, pos) {
132
- // Inline comment on mediaInline is not supported as part of comments on media project
133
- // Thus, we skip the decoration for mediaInline node
134
- if (node.type.name === 'mediaInline') {
135
- return false;
136
- }
137
- var isSupportedBlockNode = node.isBlock && (supportedNodes === null || supportedNodes === void 0 ? void 0 : supportedNodes.includes(node.type.name));
138
- node.marks.filter(function (mark) {
139
- return mark.type === state.schema.marks.annotation && mark.attrs.id === id;
140
- }).forEach(function (mark) {
141
- if (isSupportedBlockNode) {
142
- tr.removeNodeMark(pos, mark);
143
- } else {
144
- tr.removeMark(pos, pos + node.nodeSize, mark);
135
+ export var removeInlineCommentFromDoc = function removeInlineCommentFromDoc(editorAnalyticsAPI) {
136
+ return function (id) {
137
+ var supportedNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
138
+ return function (state, dispatch) {
139
+ var tr = state.tr;
140
+ state.doc.descendants(function (node, pos) {
141
+ // Inline comment on mediaInline is not supported as part of comments on media project
142
+ // Thus, we skip the decoration for mediaInline node
143
+ if (node.type.name === 'mediaInline') {
144
+ return false;
145
145
  }
146
+ var isSupportedBlockNode = node.isBlock && (supportedNodes === null || supportedNodes === void 0 ? void 0 : supportedNodes.includes(node.type.name));
147
+ node.marks.filter(function (mark) {
148
+ return mark.type === state.schema.marks.annotation && mark.attrs.id === id;
149
+ }).forEach(function (mark) {
150
+ if (isSupportedBlockNode) {
151
+ tr.removeNodeMark(pos, mark);
152
+ } else {
153
+ tr.removeMark(pos, pos + node.nodeSize, mark);
154
+ }
155
+ });
146
156
  });
147
- });
148
- if (dispatch) {
149
- dispatch(tr);
150
- return true;
151
- }
152
- return false;
157
+ if (dispatch) {
158
+ dispatch(transform.addDeleteAnalytics(editorAnalyticsAPI)(tr, state));
159
+ return true;
160
+ }
161
+ return false;
162
+ };
153
163
  };
154
164
  };
155
165
  var getDraftCommandAction = function getDraftCommandAction(drafting, targetType, targetNodeId, supportedBlockNodes, isOpeningMediaCommentFromToolbar) {
@@ -130,11 +130,43 @@ var addResolveAnalytics = function addResolveAnalytics(editorAnalyticsAPI) {
130
130
  };
131
131
  };
132
132
  };
133
+ var addPreemptiveGateErrorAnalytics = function addPreemptiveGateErrorAnalytics(editorAnalyticsAPI) {
134
+ return function (errorReason) {
135
+ return function (transaction, state) {
136
+ var analyticsEvent = {
137
+ action: ACTION.ERROR,
138
+ actionSubject: ACTION_SUBJECT.ANNOTATION,
139
+ actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
140
+ eventType: EVENT_TYPE.OPERATIONAL,
141
+ attributes: {
142
+ errorReason: errorReason
143
+ }
144
+ };
145
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(analyticsEvent)(transaction);
146
+ return transaction;
147
+ };
148
+ };
149
+ };
150
+ var addDeleteAnalytics = function addDeleteAnalytics(editorAnalyticsAPI) {
151
+ return function (transaction, state) {
152
+ var analyticsEvent = {
153
+ action: ACTION.DELETED,
154
+ actionSubject: ACTION_SUBJECT.ANNOTATION,
155
+ actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
156
+ eventType: EVENT_TYPE.TRACK,
157
+ attributes: {}
158
+ };
159
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(analyticsEvent)(transaction);
160
+ return transaction;
161
+ };
162
+ };
133
163
  export default {
134
164
  addAnnotationMark: addAnnotationMark,
135
165
  addInlineComment: addInlineComment,
136
166
  handleDraftState: handleDraftState,
137
167
  addOpenCloseAnalytics: addOpenCloseAnalytics,
138
168
  addInsertAnalytics: addInsertAnalytics,
139
- addResolveAnalytics: addResolveAnalytics
169
+ addResolveAnalytics: addResolveAnalytics,
170
+ addPreemptiveGateErrorAnalytics: addPreemptiveGateErrorAnalytics,
171
+ addDeleteAnalytics: addDeleteAnalytics
140
172
  };
@@ -338,7 +338,7 @@ export var clearAnnotation = function clearAnnotation(editorView, options) {
338
338
  reason: ERROR_REASON_ID_INVALID
339
339
  };
340
340
  }
341
- removeInlineCommentFromDoc(id, options.provider.supportedBlockNodes)(editorView.state, editorView.dispatch);
341
+ removeInlineCommentFromDoc(options.editorAnalyticsAPI)(id, options.provider.supportedBlockNodes)(editorView.state, editorView.dispatch);
342
342
  return {
343
343
  success: true,
344
344
  actionResult: undefined
@@ -301,7 +301,7 @@ export var inlineCommentPlugin = function inlineCommentPlugin(options) {
301
301
  }
302
302
 
303
303
  // Flush the pending selections into the selected annotations list.
304
- flushPendingSelections(true)(view.state, view.dispatch);
304
+ flushPendingSelections(options.editorAnalyticsAPI)(true)(view.state, view.dispatch);
305
305
  latestSelectedAnnotations === null || latestSelectedAnnotations === void 0 || latestSelectedAnnotations.filter(function (annotation) {
306
306
  return (latestPendingSelectedAnnotations === null || latestPendingSelectedAnnotations === void 0 ? void 0 : latestPendingSelectedAnnotations.findIndex(function (pendingAnnotation) {
307
307
  return pendingAnnotation.id === annotation.id;
@@ -335,13 +335,11 @@ export var inlineCommentPlugin = function inlineCommentPlugin(options) {
335
335
  // Clears the pending selections if the preemptive gate returns false.
336
336
  // We should need to worry about dispatching change events here because the pending selections
337
337
  // are being aborted and the selections will remain unchanged.
338
- flushPendingSelections(false)(view.state, view.dispatch);
338
+ flushPendingSelections(options.editorAnalyticsAPI)(false)(view.state, view.dispatch);
339
339
  }
340
340
  }).catch(function (error) {
341
- // TODO: EDITOR-595 - Ensure and anlytic is fired to indicate which reports on the error.
342
-
343
341
  // If an error has occured we will clear any pending selections to avoid accidentally setting the wrong thing.
344
- flushPendingSelections(false)(view.state, view.dispatch);
342
+ flushPendingSelections(options.editorAnalyticsAPI)(false, 'pending-selection-preemptive-gate-error')(view.state, view.dispatch);
345
343
  }).finally(function () {
346
344
  isPreemptiveGateActive = false;
347
345
  });
@@ -116,25 +116,17 @@ export var buildToolbar = function buildToolbar(editorAnalyticsAPI) {
116
116
  }
117
117
  },
118
118
  onClick: function onClick(state, dispatch) {
119
- if (editorAnalyticsAPI) {
120
- editorAnalyticsAPI.fireAnalyticsEvent({
121
- action: ACTION.CLICKED,
122
- actionSubject: ACTION_SUBJECT.BUTTON,
123
- actionSubjectId: ACTION_SUBJECT_ID.CREATE_INLINE_COMMENT_FROM_HIGHLIGHT_ACTIONS_MENU,
124
- eventType: EVENT_TYPE.UI,
125
- attributes: {
126
- source: 'highlightActionsMenu',
127
- pageMode: 'edit'
128
- }
129
- });
130
- }
131
- if (fg('platform_editor_comments_api_manager')) {
132
- if (!annotationManager) {
133
- // TODO: EDITOR-595 - If we've reached here and the manager is not initialized, we should
134
- // dispatch an analytics event to indicate that the user has clicked the button but
135
- // the action was not completed.
136
- return false;
119
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.fireAnalyticsEvent({
120
+ action: ACTION.CLICKED,
121
+ actionSubject: ACTION_SUBJECT.BUTTON,
122
+ actionSubjectId: ACTION_SUBJECT_ID.CREATE_INLINE_COMMENT_FROM_HIGHLIGHT_ACTIONS_MENU,
123
+ eventType: EVENT_TYPE.UI,
124
+ attributes: {
125
+ source: 'highlightActionsMenu',
126
+ pageMode: 'edit'
137
127
  }
128
+ });
129
+ if (annotationManager && fg('platform_editor_comments_api_manager')) {
138
130
  annotationManager.checkPreemptiveGate().then(function (canStartDraft) {
139
131
  if (canStartDraft) {
140
132
  createCommentExperience === null || createCommentExperience === void 0 || createCommentExperience.start({
@@ -145,18 +137,30 @@ export var buildToolbar = function buildToolbar(editorAnalyticsAPI) {
145
137
  });
146
138
  createCommentExperience === null || createCommentExperience === void 0 || createCommentExperience.initExperience.start();
147
139
  var result = annotationManager.startDraft();
148
- if (result.success) {
149
- // TODO: EDITOR-595 - Ensure and anlytic is fired to indicate that the user has started a draft.
150
- } else {
151
- // TODO: EDITOR-595 - Fire an analytics event to indicate that the user has clicked the button
140
+ if (!result.success) {
141
+ // Fire an analytics event to indicate that the user has clicked the button
152
142
  // but the action was not completed, the result should contain a reason.
143
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.fireAnalyticsEvent({
144
+ action: ACTION.ERROR,
145
+ actionSubject: ACTION_SUBJECT.ANNOTATION,
146
+ actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
147
+ eventType: EVENT_TYPE.OPERATIONAL,
148
+ attributes: {
149
+ errorReason: "toolbar-start-draft-failed/".concat(result.reason)
150
+ }
151
+ });
153
152
  }
154
- } else {
155
- // TODO: EDITOR-595 - Track the toolbar comment button was clicked but the preemptive gate
156
- // check returned false and the draft cannot be started.
157
153
  }
158
154
  }).catch(function () {
159
- // TODO: EDITOR-595 - Handle preemptive gate check error. Something went very wrong in the gate.
155
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.fireAnalyticsEvent({
156
+ action: ACTION.ERROR,
157
+ actionSubject: ACTION_SUBJECT.ANNOTATION,
158
+ actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
159
+ eventType: EVENT_TYPE.OPERATIONAL,
160
+ attributes: {
161
+ errorReason: "toolbar-start-draft-preemptive-gate-error"
162
+ }
163
+ });
160
164
  });
161
165
  return true;
162
166
  } else {
@@ -9,10 +9,10 @@ import type { InlineCommentInputMethod, TargetType } from '../types';
9
9
  export declare const updateInlineCommentResolvedState: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (partialNewState: InlineCommentMap, resolveMethod?: RESOLVE_METHOD) => Command;
10
10
  export declare const closeComponent: () => Command;
11
11
  export declare const clearDirtyMark: () => Command;
12
- export declare const flushPendingSelections: (canSetAsSelectedAnnotations: boolean) => Command;
12
+ export declare const flushPendingSelections: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (canSetAsSelectedAnnotations: boolean, errorReason?: string) => Command;
13
13
  export declare const setPendingSelectedAnnotation: (id: string) => Command;
14
14
  export declare const removeInlineCommentNearSelection: (id: string, supportedNodes?: string[]) => Command;
15
- export declare const removeInlineCommentFromDoc: (id: string, supportedNodes?: string[]) => Command;
15
+ export declare const removeInlineCommentFromDoc: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (id: string, supportedNodes?: string[]) => Command;
16
16
  /**
17
17
  * Show active inline comments for a given block node, otherwise,
18
18
  * return false if the node has no comments or no unresolved comments.
@@ -18,5 +18,7 @@ declare const _default: {
18
18
  addOpenCloseAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (drafting: boolean, method?: InlineCommentInputMethod) => (transaction: Transaction, state: EditorState) => Transaction;
19
19
  addInsertAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (transaction: Transaction, state: EditorState) => Transaction;
20
20
  addResolveAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (method?: RESOLVE_METHOD | undefined) => (transaction: Transaction, state: EditorState) => Transaction;
21
+ addPreemptiveGateErrorAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (errorReason?: string | undefined) => (transaction: Transaction, state: EditorState) => Transaction;
22
+ addDeleteAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (transaction: Transaction, state: EditorState) => Transaction;
21
23
  };
22
24
  export default _default;
@@ -9,10 +9,10 @@ import type { InlineCommentInputMethod, TargetType } from '../types';
9
9
  export declare const updateInlineCommentResolvedState: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (partialNewState: InlineCommentMap, resolveMethod?: RESOLVE_METHOD) => Command;
10
10
  export declare const closeComponent: () => Command;
11
11
  export declare const clearDirtyMark: () => Command;
12
- export declare const flushPendingSelections: (canSetAsSelectedAnnotations: boolean) => Command;
12
+ export declare const flushPendingSelections: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (canSetAsSelectedAnnotations: boolean, errorReason?: string) => Command;
13
13
  export declare const setPendingSelectedAnnotation: (id: string) => Command;
14
14
  export declare const removeInlineCommentNearSelection: (id: string, supportedNodes?: string[]) => Command;
15
- export declare const removeInlineCommentFromDoc: (id: string, supportedNodes?: string[]) => Command;
15
+ export declare const removeInlineCommentFromDoc: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (id: string, supportedNodes?: string[]) => Command;
16
16
  /**
17
17
  * Show active inline comments for a given block node, otherwise,
18
18
  * return false if the node has no comments or no unresolved comments.
@@ -18,5 +18,7 @@ declare const _default: {
18
18
  addOpenCloseAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (drafting: boolean, method?: InlineCommentInputMethod) => (transaction: Transaction, state: EditorState) => Transaction;
19
19
  addInsertAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (transaction: Transaction, state: EditorState) => Transaction;
20
20
  addResolveAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (method?: RESOLVE_METHOD | undefined) => (transaction: Transaction, state: EditorState) => Transaction;
21
+ addPreemptiveGateErrorAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (errorReason?: string | undefined) => (transaction: Transaction, state: EditorState) => Transaction;
22
+ addDeleteAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (transaction: Transaction, state: EditorState) => Transaction;
21
23
  };
22
24
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-annotation",
3
- "version": "2.9.1",
3
+ "version": "2.9.2",
4
4
  "description": "Annotation plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -42,7 +42,7 @@
42
42
  "@atlaskit/icon": "^26.4.0",
43
43
  "@atlaskit/onboarding": "^14.2.0",
44
44
  "@atlaskit/platform-feature-flags": "^1.1.0",
45
- "@atlaskit/tmp-editor-statsig": "^5.2.0",
45
+ "@atlaskit/tmp-editor-statsig": "^5.5.0",
46
46
  "@babel/runtime": "^7.0.0"
47
47
  },
48
48
  "peerDependencies": {