Skip to content

Commit 1e94f74

Browse files
committed
WIP: Add attachTo configuration
1 parent c8557ff commit 1e94f74

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

packages/feedback/src/index.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getCurrentHub } from '@sentry/core';
22
import type { Integration } from '@sentry/types';
3-
import { isNodeEnv } from '@sentry/utils';
3+
import { isNodeEnv, logger } from '@sentry/utils';
44

55
import { sendFeedback } from './sendFeedback';
66
import type { FeedbackConfigurationWithDefaults, FeedbackFormData } from './types';
@@ -88,6 +88,7 @@ export class Feedback implements Integration {
8888
private _hasDialogOpened: boolean;
8989

9090
public constructor({
91+
attachTo = null,
9192
showEmail = true,
9293
showName = true,
9394
useSentryUser = {
@@ -109,6 +110,8 @@ export class Feedback implements Integration {
109110
namePlaceholder = 'Your Name',
110111
nameLabel = 'Name',
111112
successMessageText = 'Thank you for your report!',
113+
114+
onOpenDialog,
112115
}: Partial<FeedbackConfigurationWithDefaults> = {}) {
113116
// Initializations
114117
this.name = Feedback.id;
@@ -120,6 +123,7 @@ export class Feedback implements Integration {
120123
this._hasDialogOpened = false;
121124

122125
this.options = {
126+
attachTo,
123127
isAnonymous,
124128
isEmailRequired,
125129
isNameRequired,
@@ -138,6 +142,8 @@ export class Feedback implements Integration {
138142
nameLabel,
139143
namePlaceholder,
140144
successMessageText,
145+
146+
onOpenDialog,
141147
};
142148

143149
// TOOD: temp for testing;
@@ -253,7 +259,20 @@ export class Feedback implements Integration {
253259
// TODO: End hotloading
254260

255261
this._shadow = this._createShadowHost();
256-
this._createWidgetActor();
262+
263+
// Only create widget actor if `attachTo` was not defined
264+
if (this.options.attachTo === null) {
265+
this._createWidgetActor();
266+
} else {
267+
const actorTarget = document.querySelector(this.options.attachTo);
268+
269+
if (!actorTarget) {
270+
logger.warn(`[Feedback] Unable to find element with selector ${actorTarget}`);
271+
return;
272+
}
273+
274+
actorTarget.addEventListener('click', this._handleActorClick);
275+
}
257276

258277
if (!this._host) {
259278
return;
@@ -338,6 +357,10 @@ export class Feedback implements Integration {
338357
if (this._actor) {
339358
this._actor.hide();
340359
}
360+
361+
if (this.options.onOpenDialog) {
362+
this.options.onOpenDialog();
363+
}
341364
};
342365

343366
/**

packages/feedback/src/types/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ export interface FeedbackFormData {
3535
}
3636

3737
export interface FeedbackConfigurationWithDefaults {
38+
/**
39+
* DOM Selector to attach click listener to, for opening Feedback dialog.
40+
*/
41+
attachTo: string | null;
42+
3843
/**
3944
* If true, will not collect user data (email/name).
4045
*/
@@ -114,6 +119,10 @@ export interface FeedbackConfigurationWithDefaults {
114119
*/
115120
successMessageText: string;
116121
// * End of text customization * //
122+
123+
// * Start of Callbacks * //
124+
onOpenDialog?: () => void;
125+
// * End of Callbacks * //
117126
}
118127

119128
interface BaseTheme {

packages/feedback/src/widget/Icon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { setAttributesNS } from "../util/setAttributesNS";
1+
import { setAttributesNS } from '../util/setAttributesNS';
22

33
const SIZE = 20;
44
const XMLNS = 'http://www.w3.org/2000/svg';

packages/feedback/src/widget/SuccessIcon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { setAttributesNS } from "../util/setAttributesNS";
1+
import { setAttributesNS } from '../util/setAttributesNS';
22

33
const WIDTH = 16;
44
const HEIGHT = 17;

0 commit comments

Comments
 (0)