Skip to content

Commit cc44fa6

Browse files
committed
fix(types): Fix optional types for theme
1 parent 3c62ba4 commit cc44fa6

File tree

4 files changed

+43
-24
lines changed

4 files changed

+43
-24
lines changed

packages/feedback/src/integration.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,17 @@ import {
1717
SUCCESS_MESSAGE_TEXT,
1818
} from './constants';
1919
import type {
20-
CreateWidgetOptionOverrides,
21-
FeedbackConfigurationWithDefaults,
20+
OptionalFeedbackConfiguration,
2221
FeedbackInternalOptions,
2322
Widget,
2423
} from './types';
24+
import { mergeOptions } from './util/mergeOptions';
2525
import { createActorStyles } from './widget/Actor.css';
2626
import { createShadowHost } from './widget/createShadowHost';
2727
import { createWidget } from './widget/createWidget';
2828

2929
const doc = WINDOW.document;
3030

31-
type FeedbackConfiguration = Partial<FeedbackConfigurationWithDefaults>;
32-
3331
/**
3432
* Feedback integration. When added as an integration to the SDK, it will
3533
* inject a button in the bottom-right corner of the window that opens a
@@ -110,7 +108,7 @@ export class Feedback implements Integration {
110108
onDialogOpen,
111109
onSubmitError,
112110
onSubmitSuccess,
113-
}: FeedbackConfiguration = {}) {
111+
}: OptionalFeedbackConfiguration = {}) {
114112
// Initializations
115113
this.name = Feedback.id;
116114

@@ -132,8 +130,14 @@ export class Feedback implements Integration {
132130
useSentryUser,
133131

134132
colorScheme,
135-
themeDark: Object.assign({}, DEFAULT_THEME.dark, themeDark),
136-
themeLight: Object.assign({}, DEFAULT_THEME.light, themeLight),
133+
themeDark: {
134+
...DEFAULT_THEME.dark,
135+
...themeDark
136+
},
137+
themeLight: {
138+
...DEFAULT_THEME.light,
139+
...themeLight
140+
},
137141

138142
buttonLabel,
139143
cancelButtonLabel,
@@ -190,12 +194,9 @@ export class Feedback implements Integration {
190194
/**
191195
* Adds click listener to attached element to open a feedback dialog
192196
*/
193-
public attachTo(el: Element | string, optionOverrides: CreateWidgetOptionOverrides): Widget | null {
197+
public attachTo(el: Element | string, optionOverrides: OptionalFeedbackConfiguration): Widget | null {
194198
try {
195-
const options = {
196-
...this.options,
197-
...optionOverrides,
198-
};
199+
const options = mergeOptions(this.options, optionOverrides);
199200

200201
return this._ensureShadowHost<Widget | null>(options, ({ shadow }) => {
201202
const targetEl =
@@ -219,12 +220,9 @@ export class Feedback implements Integration {
219220
/**
220221
* Creates a new widget. Accepts partial options to override any options passed to constructor.
221222
*/
222-
public createWidget(optionOverrides: CreateWidgetOptionOverrides): Widget | null {
223+
public createWidget(optionOverrides: OptionalFeedbackConfiguration): Widget | null {
223224
try {
224-
return this._createWidget({
225-
...this.options,
226-
...optionOverrides,
227-
});
225+
return this._createWidget(mergeOptions(this.options, optionOverrides));
228226
} catch (err) {
229227
logger.error(err);
230228
return null;

packages/feedback/src/types/index.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,22 @@ export interface FeedbackCallbacks {
196196
onSubmitError?: () => void;
197197
}
198198

199-
export interface FeedbackConfigurationWithDefaults
199+
/**
200+
* The integration's internal `options` member where every value should be set
201+
*/
202+
export interface FeedbackInternalOptions
200203
extends FeedbackGeneralConfiguration,
201204
FeedbackThemeConfiguration,
202205
FeedbackTextConfiguration,
203206
FeedbackCallbacks {}
204207

205208
/**
206-
* The integration's internal `options` member
209+
* Partial configuration that overrides default configuration values
207210
*/
208-
export type FeedbackInternalOptions = FeedbackConfigurationWithDefaults;
211+
export interface OptionalFeedbackConfiguration extends Omit<Partial<FeedbackInternalOptions>, 'themeLight'|'themeDark'> {
212+
themeLight?: Partial<FeedbackTheme>;
213+
themeDark?: Partial<FeedbackTheme>;
214+
}
209215

210216
export interface FeedbackTheme {
211217
/**
@@ -246,8 +252,6 @@ export interface FeedbackTheme {
246252
error: string;
247253
}
248254

249-
export type CreateWidgetOptionOverrides = Partial<FeedbackConfigurationWithDefaults>;
250-
251255
export interface FeedbackThemes {
252256
dark: FeedbackTheme;
253257
light: FeedbackTheme;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { FeedbackInternalOptions, OptionalFeedbackConfiguration } from "../types";
2+
3+
export function mergeOptions(defaultOptions: FeedbackInternalOptions, optionOverrides: OptionalFeedbackConfiguration) {
4+
return {
5+
...defaultOptions,
6+
...optionOverrides,
7+
themeDark: {
8+
...defaultOptions.themeDark,
9+
...optionOverrides.themeDark,
10+
},
11+
themeLight: {
12+
...defaultOptions.themeLight,
13+
...optionOverrides.themeLight,
14+
}
15+
};
16+
17+
}

packages/feedback/src/widget/Actor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { FeedbackComponent, FeedbackConfigurationWithDefaults } from '../types';
1+
import type { FeedbackComponent, FeedbackInternalOptions } from '../types';
22
import { Icon } from './Icon';
33
import { createElement } from './util/createElement';
44

5-
export interface ActorProps extends Pick<FeedbackConfigurationWithDefaults, 'buttonLabel'> {
5+
export interface ActorProps extends Pick<FeedbackInternalOptions, 'buttonLabel'> {
66
onClick?: (e: MouseEvent) => void;
77
}
88

0 commit comments

Comments
 (0)