Skip to content

Commit bae66a7

Browse files
committedMar 17, 2025
add proactive bug reporting
1 parent 9c2910d commit bae66a7

File tree

6 files changed

+55
-87
lines changed

6 files changed

+55
-87
lines changed
 

‎examples/default/src/App.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ import { StyleSheet } from 'react-native';
33

44
import { GestureHandlerRootView } from 'react-native-gesture-handler';
55
import { NavigationContainer, useNavigationContainerRef } from '@react-navigation/native';
6-
import {
7-
BugReporting,
8-
ProactiveReportingConfigs,
9-
type SessionMetadata,
10-
} from 'instabug-reactnative';
6+
import { BugReporting, type SessionMetadata } from 'instabug-reactnative';
117
import Instabug, {
128
CrashReporting,
139
InvocationEvent,
@@ -23,6 +19,7 @@ import { nativeBaseTheme } from './theme/nativeBaseTheme';
2319
import { navigationTheme } from './theme/navigationTheme';
2420

2521
import { QueryClient, QueryClientProvider } from 'react-query';
22+
import { createProactiveReportingConfig } from 'instabug-reactnative';
2623

2724
const queryClient = new QueryClient();
2825

@@ -52,15 +49,15 @@ export const App: React.FC = () => {
5249
});
5350
CrashReporting.setNDKCrashesEnabled(true);
5451

52+
Instabug.setCodePushVersion('33');
53+
54+
Instabug.setCodePushVersion('33');
55+
5556
Instabug.setReproStepsConfig({
5657
all: ReproStepsMode.enabled,
5758
});
5859

59-
const config = new ProactiveReportingConfigs.Builder()
60-
.setGapBetweenModals(5)
61-
.setModalDelayAfterDetection(5)
62-
.isEnabled(true)
63-
.build();
60+
const config = createProactiveReportingConfig();
6461

6562
BugReporting.setProactiveReportingConfigurations(config);
6663
}, []);

‎src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
import type { InstabugConfig } from './models/InstabugConfig';
33
import Report from './models/Report';
44
import Trace from './models/Trace';
5-
import ProactiveReportingConfigs from './models/ProactiveReportingConfigs';
5+
import {
6+
createProactiveReportingConfig,
7+
type ProactiveReportingConfigOptions,
8+
} from './models/ProactiveReportingConfigs';
69

710
// Modules
811
import * as APM from './modules/APM';
@@ -22,7 +25,8 @@ export * from './utils/Enums';
2225
export {
2326
Report,
2427
Trace,
25-
ProactiveReportingConfigs,
28+
ProactiveReportingConfigOptions,
29+
createProactiveReportingConfig,
2630
APM,
2731
BugReporting,
2832
CrashReporting,
Lines changed: 31 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,37 @@
1-
export default class ProactiveReportingConfigs {
2-
public readonly gapBetweenModals: number; // Time in seconds
3-
public readonly modalDelayAfterDetection: number; // Time in seconds
4-
public readonly enabled: boolean;
1+
import { Logger } from '../utils/logger';
2+
import InstabugConstants from '../utils/InstabugConstants';
53

6-
// Private constructor to ensure it can only be created through the builder
7-
private constructor(
8-
gapBetweenModals: number,
9-
modalDelayAfterDetection: number,
10-
enabled: boolean,
11-
) {
12-
this.gapBetweenModals = gapBetweenModals;
13-
this.modalDelayAfterDetection = modalDelayAfterDetection;
14-
this.enabled = enabled;
15-
}
16-
17-
// Static method to get the builder instance
18-
static Builder = class {
19-
public gapBetweenModals: number = 30; // Default: 30 seconds
20-
public modalDelayAfterDetection: number = 15; // Default: 15 seconds
21-
public enabled: boolean = true; // Default: enabled
22-
23-
// Logger method to handle logging
24-
public logWarning(message: string): void {
25-
console.warn(`Warning: ${message}`);
26-
}
27-
/**
28-
* controls the time gap between showing 2 proactive reporting dialogs in seconds
29-
*/
30-
setGapBetweenModals(gap: number): this {
31-
if (gap <= 0) {
32-
this.logWarning(
33-
'gapBetweenModals must be a positive number. Using default value of 30 seconds.',
34-
);
35-
return this;
36-
}
37-
this.gapBetweenModals = gap;
38-
return this;
39-
}
4+
export interface ProactiveReportingConfigOptions {
5+
gapBetweenModals: number;
6+
modalDelayAfterDetection: number;
7+
enabled: boolean;
8+
}
409

41-
/**
42-
* controls the time gap between detecting a frustrating experience
43-
*/
44-
setModalDelayAfterDetection(delay: number): this {
45-
if (delay <= 0) {
46-
this.logWarning(
47-
'modalDelayAfterDetection must be a positive number. Using default value of 15 seconds.',
48-
);
49-
return this;
50-
}
51-
this.modalDelayAfterDetection = delay;
52-
return this;
53-
}
10+
export function createProactiveReportingConfig(
11+
{
12+
gapBetweenModals = 24,
13+
modalDelayAfterDetection = 20,
14+
enabled = true,
15+
}: ProactiveReportingConfigOptions = {
16+
gapBetweenModals: 24,
17+
modalDelayAfterDetection: 20,
18+
enabled: true,
19+
},
20+
) {
21+
// Validation and defaults
22+
if (gapBetweenModals <= 0) {
23+
Logger.warn(InstabugConstants.GAP_MODEL_ERROR_MESSAGE);
24+
gapBetweenModals = 24; // Use default value if invalid
25+
}
5426

55-
/**
56-
* controls the state of the feature
57-
*/
58-
isEnabled(enabled: boolean): this {
59-
this.enabled = enabled;
60-
return this;
61-
}
27+
if (modalDelayAfterDetection <= 0) {
28+
Logger.warn(InstabugConstants.MODAL_DETECTION_ERROR_MESSAGE);
29+
modalDelayAfterDetection = 20; // Use default value if invalid
30+
}
6231

63-
build(): ProactiveReportingConfigs {
64-
return new ProactiveReportingConfigs(
65-
this.gapBetweenModals,
66-
this.modalDelayAfterDetection,
67-
this.enabled,
68-
);
69-
}
32+
return {
33+
gapBetweenModals,
34+
modalDelayAfterDetection,
35+
enabled,
7036
};
7137
}

‎src/modules/BugReporting.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
RecordingButtonPosition,
1212
ReportType,
1313
} from '../utils/Enums';
14-
import type ProactiveReportingConfigs from '../models/ProactiveReportingConfigs';
14+
import type { ProactiveReportingConfigOptions } from '../models/ProactiveReportingConfigs';
1515

1616
/**
1717
* Enables and disables manual invocation and prompt options for bug and feedback.
@@ -237,7 +237,7 @@ export const setCommentMinimumCharacterCount = (limit: number, reportTypes?: Rep
237237
** prompts end users to submit their feedback after our SDK automatically detects a frustrating experience.
238238
* @param config configuration of proActive bug report.
239239
*/
240-
export const setProactiveReportingConfigurations = (config: ProactiveReportingConfigs) => {
240+
export const setProactiveReportingConfigurations = (config: ProactiveReportingConfigOptions) => {
241241
NativeBugReporting.setProactiveReportingConfigurations(
242242
config.enabled,
243243
config.gapBetweenModals,

‎src/utils/InstabugConstants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ const InstabugConstants = {
55
MAX_NETWORK_BODY_SIZE_IN_BYTES: 1024 * 10, // 10 KB
66
MAX_RESPONSE_BODY_SIZE_EXCEEDED_MESSAGE:
77
'The response body has not been logged because it exceeds the maximum size of 10 Kb',
8+
GAP_MODEL_ERROR_MESSAGE:
9+
'gapBetweenModals must be a positive number. Using default value of 24 seconds.',
10+
MODAL_DETECTION_ERROR_MESSAGE:
11+
'modalDelayAfterDetection must be a positive number. Using default value of 20 seconds.',
12+
813
MAX_REQUEST_BODY_SIZE_EXCEEDED_MESSAGE:
914
'The request body has not been logged because it exceeds the maximum size of 10 Kb',
1015
SET_USER_ATTRIBUTES_ERROR_TYPE_MESSAGE:

‎test/modules/BugReporting.spec.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99
InvocationOption,
1010
RecordingButtonPosition,
1111
ReportType,
12-
} from '../../src/utils/Enums';
13-
import ProactiveReportingConfigs from '../../src/models/ProactiveReportingConfigs';
12+
} from '../../src';
13+
import { createProactiveReportingConfig } from '../../src';
1414

1515
describe('Testing BugReporting Module', () => {
1616
beforeEach(() => {
@@ -269,15 +269,11 @@ describe('Testing BugReporting Module', () => {
269269
});
270270

271271
it('should call the native method setProactiveReportingConfigurations', () => {
272-
const configs = new ProactiveReportingConfigs.Builder()
273-
.setGapBetweenModals(2)
274-
.setModalDelayAfterDetection(20)
275-
.isEnabled(true)
276-
.build();
272+
const configs = createProactiveReportingConfig();
277273

278274
BugReporting.setProactiveReportingConfigurations(configs);
279275

280276
expect(NativeBugReporting.setProactiveReportingConfigurations).toBeCalledTimes(1);
281-
expect(NativeBugReporting.setProactiveReportingConfigurations).toBeCalledWith(true, 2, 20);
277+
expect(NativeBugReporting.setProactiveReportingConfigurations).toBeCalledWith(true, 24, 20);
282278
});
283279
});

0 commit comments

Comments
 (0)
Please sign in to comment.