Skip to content

Commit

Permalink
fix: correct misleading action origin on paste event - rich text (con…
Browse files Browse the repository at this point in the history
…tentful#1385)

* fix: correct misleading action origin on paste event - rich text

* test: update origin in tests

* chore: remove console log

* test: fixed one more occurrence
  • Loading branch information
MayaGillilan authored Apr 3, 2023
1 parent 08a6c49 commit 23e313f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
18 changes: 9 additions & 9 deletions cypress/integration/rich-text/RichTextEditor.Tracking.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('Rich Text Editor - Tracking', { viewportHeight: 2000 }, () => {
richText.editor.click().paste({ 'text/plain': 'Hello World!' });

richText.expectTrackingValue([
action('paste', 'shortcut', {
action('paste', 'shortcut-or-viewport', {
characterCountAfter: 12,
characterCountBefore: 0,
characterCountSelection: 0,
Expand All @@ -60,13 +60,13 @@ describe('Rich Text Editor - Tracking', { viewportHeight: 2000 }, () => {
richText.editor.click().type('{enter}').paste({ 'text/plain': 'Hello World!' });

richText.expectTrackingValue([
action('paste', 'shortcut', {
action('paste', 'shortcut-or-viewport', {
characterCountAfter: 12,
characterCountBefore: 0,
characterCountSelection: 0,
source: 'Unknown',
}),
action('paste', 'shortcut', {
action('paste', 'shortcut-or-viewport', {
characterCountAfter: 25,
characterCountBefore: 13,
characterCountSelection: 0,
Expand All @@ -81,7 +81,7 @@ describe('Rich Text Editor - Tracking', { viewportHeight: 2000 }, () => {
});

richText.expectTrackingValue([
action('paste', 'shortcut', {
action('paste', 'shortcut-or-viewport', {
characterCountAfter: 5,
characterCountBefore: 0,
characterCountSelection: 0,
Expand All @@ -96,7 +96,7 @@ describe('Rich Text Editor - Tracking', { viewportHeight: 2000 }, () => {
});

richText.expectTrackingValue([
action('paste', 'shortcut', {
action('paste', 'shortcut-or-viewport', {
characterCountAfter: 88,
characterCountBefore: 0,
characterCountSelection: 0,
Expand All @@ -111,7 +111,7 @@ describe('Rich Text Editor - Tracking', { viewportHeight: 2000 }, () => {
});

richText.expectTrackingValue([
action('paste', 'shortcut', {
action('paste', 'shortcut-or-viewport', {
characterCountAfter: 12,
characterCountBefore: 0,
characterCountSelection: 0,
Expand All @@ -126,7 +126,7 @@ describe('Rich Text Editor - Tracking', { viewportHeight: 2000 }, () => {
});

richText.expectTrackingValue([
action('paste', 'shortcut', {
action('paste', 'shortcut-or-viewport', {
characterCountAfter: 14,
characterCountBefore: 0,
characterCountSelection: 0,
Expand All @@ -141,7 +141,7 @@ describe('Rich Text Editor - Tracking', { viewportHeight: 2000 }, () => {
});

richText.expectTrackingValue([
action('paste', 'shortcut', {
action('paste', 'shortcut-or-viewport', {
characterCountAfter: 5,
characterCountBefore: 0,
characterCountSelection: 0,
Expand All @@ -156,7 +156,7 @@ describe('Rich Text Editor - Tracking', { viewportHeight: 2000 }, () => {
});

richText.expectTrackingValue([
action('paste', 'shortcut', {
action('paste', 'shortcut-or-viewport', {
characterCountAfter: 5,
characterCountBefore: 0,
characterCountSelection: 0,
Expand Down
11 changes: 10 additions & 1 deletion packages/rich-text/src/plugins/Tracking/createTrackingPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export interface TrackingPluginActions {
data?: Record<string, unknown>
) => ReturnType<RichTextTrackingActionHandler>;

onShortcutOrViewportAction: (
actionName: RichTextTrackingActionName,
data?: Record<string, unknown>
) => ReturnType<RichTextTrackingActionHandler>;

onToolbarAction: (
actionName: RichTextTrackingActionName,
data?: Record<string, unknown>
Expand All @@ -64,6 +69,7 @@ const actionOrigin = {
TOOLBAR: 'toolbar-icon',
SHORTCUT: 'shortcut',
VIEWPORT: 'viewport-interaction',
SHORTCUT_OR_VIEWPORT: 'shortcut-or-viewport',
COMMAND_PALETTE: 'command-palette',
};

Expand Down Expand Up @@ -114,6 +120,9 @@ export const createTrackingPlugin = (onAction: RichTextTrackingActionHandler): P
onShortcutAction: (actionName: RichTextTrackingActionName, data = {}) =>
onAction(actionName, { origin: actionOrigin.SHORTCUT, ...data }),

onShortcutOrViewportAction: (actionName: RichTextTrackingActionName, data = {}) =>
onAction(actionName, { origin: actionOrigin.SHORTCUT_OR_VIEWPORT, ...data }),

onToolbarAction: (actionName: RichTextTrackingActionName, data = {}) =>
onAction(actionName, { origin: actionOrigin.TOOLBAR, ...data }),

Expand All @@ -140,7 +149,7 @@ export const createTrackingPlugin = (onAction: RichTextTrackingActionHandler): P
setTimeout(() => {
const characterCountAfter = getCharacterCount(editor);

trackingActions.onShortcutAction('paste', {
trackingActions.onShortcutOrViewportAction('paste', {
characterCountAfter,
characterCountBefore,
characterCountSelection,
Expand Down

0 comments on commit 23e313f

Please sign in to comment.