Skip to content

Commit 457f7e8

Browse files
feat: support bug reporting user consents (#1383)
* feat: support bug reporting user consents * fix: ios tests * fix: add change log * fix: userConsentTypo * fix: action type ios nullability * fix: ios nullability
1 parent 256e72a commit 457f7e8

File tree

15 files changed

+162
-4
lines changed

15 files changed

+162
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [Unreleased]
4+
5+
### Added
6+
7+
- Add support for BugReporting user consents. ([#1383](https://github.com/Instabug/Instabug-React-Native/pull/1383))
8+
39
## [14.3.0](https://github.com/Instabug/Instabug-React-Native/compare/v14.1.0...14.3.0)
410

511
### Added

android/src/main/java/com/instabug/reactlibrary/ArgsRegistry.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ static Map<String, Object> getAll() {
6060
putAll(locales);
6161
putAll(placeholders);
6262
putAll(launchType);
63+
putAll(userConsentActionType);
6364
}};
6465
}
6566

@@ -142,6 +143,12 @@ static Map<String, Object> getAll() {
142143
put("reproStepsDisabled", ReproMode.Disable);
143144
}};
144145

146+
static final ArgsMap<String> userConsentActionType = new ArgsMap<String>() {{
147+
put("dropAutoCapturedMedia", com.instabug.bug.userConsent.ActionType.DROP_AUTO_CAPTURED_MEDIA);
148+
put("dropLogs", com.instabug.bug.userConsent.ActionType.DROP_LOGS);
149+
put("noChat", com.instabug.bug.userConsent.ActionType.NO_CHAT);
150+
}};
151+
145152
static final ArgsMap<Integer> sdkLogLevels = new ArgsMap<Integer>() {{
146153
put("sdkDebugLogsLevelNone", com.instabug.library.LogLevel.NONE);
147154
put("sdkDebugLogsLevelError", com.instabug.library.LogLevel.ERROR);

android/src/main/java/com/instabug/reactlibrary/RNInstabugBugReportingModule.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.annotation.SuppressLint;
44
import android.annotation.TargetApi;
5+
import androidx.annotation.Nullable;
56

67
import com.facebook.react.bridge.Arguments;
78
import com.facebook.react.bridge.Callback;
@@ -21,6 +22,7 @@
2122
import com.instabug.reactlibrary.utils.ArrayUtil;
2223
import com.instabug.reactlibrary.utils.EventEmitterModule;
2324
import com.instabug.reactlibrary.utils.MainThreadHandler;
25+
import com.instabug.bug.userConsent.ActionType;
2426

2527
import java.util.ArrayList;
2628

@@ -415,4 +417,30 @@ public void run() {
415417
}
416418
});
417419
}
420+
421+
/**
422+
* Adds a user consent item to the bug reporting
423+
* @param key A unique identifier string for the consent item.
424+
* @param description The text shown to the user describing the consent item.
425+
* @param mandatory Whether the user must agree to this item before submitting a report.
426+
* @param checked Whether the consent checkbox is pre-selected.
427+
* @param actionType A string representing the action type to map to SDK behavior.
428+
*/
429+
@ReactMethod
430+
public void addUserConsent(String key, String description, boolean mandatory, boolean checked, @Nullable String actionType) {
431+
MainThreadHandler.runOnMainThread(new Runnable() {
432+
@Override
433+
public void run() {
434+
try {
435+
String mappedActionType = ArgsRegistry.userConsentActionType.get(actionType);
436+
BugReporting.addUserConsent(key, description, mandatory, checked, mappedActionType);
437+
} catch (Exception e) {
438+
e.printStackTrace();
439+
}
440+
}
441+
});
442+
443+
}
444+
445+
418446
}

android/src/test/java/com/instabug/reactlibrary/RNInstabugBugReportingModuleTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,22 @@ public Object answer(InvocationOnMock invocation) {
362362

363363
BugReporting.setCommentMinimumCharacterCount(count, type1);
364364
}
365+
@Test
366+
public void TestAddUserConsent() {
367+
final Map<String, String> args = ArgsRegistry.userConsentActionType;
368+
final String[] keysArray = args.keySet().toArray(new String[0]);
369+
370+
final String key = "testKey";
371+
final String description = "Consent description";
372+
final boolean mandatory = true;
373+
final boolean checked = true;
374+
final String inputAction = keysArray[0];
375+
376+
final String expectedMappedAction = args.get(inputAction);
377+
378+
bugReportingModule.addUserConsent(key, description, mandatory, checked, inputAction);
379+
380+
verify(BugReporting.class, VerificationModeFactory.times(1));
381+
BugReporting.addUserConsent(key, description, mandatory, checked, expectedMappedAction);
382+
}
365383
}

examples/default/ios/InstabugTests/InstabugBugReportingTests.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,27 @@ - (void) testSetCommentMinimumCharacterCount {
187187
[self.instabugBridge setCommentMinimumCharacterCount:limit reportTypes:reportTypesArr];
188188
OCMVerify([mock setCommentMinimumCharacterCountForReportTypes:reportTypes withLimit:limit.intValue]);
189189
}
190+
- (void)testAddUserConsentWithKey {
191+
id mock = OCMClassMock([IBGBugReporting class]);
190192

193+
NSString *key = @"testKey";
194+
NSString *description = @"Consent description";
195+
BOOL mandatory = YES;
196+
BOOL checked = NO;
197+
NSNumber *actionType = @2;
198+
IBGActionType mappedActionType = (IBGActionType)[actionType integerValue];
199+
200+
[self.instabugBridge addUserConsent:key
201+
description:description
202+
mandatory:mandatory
203+
checked:checked
204+
actionType:actionType];
205+
206+
OCMVerify([mock addUserConsentWithKey:key
207+
description:description
208+
mandatory:mandatory
209+
checked:checked
210+
actionType:mappedActionType]);
211+
}
191212
@end
192213

ios/RNInstabug/ArgsRegistry.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ typedef NSDictionary<NSString*, NSNumber*> ArgsDictionary;
2323
+ (ArgsDictionary *) locales;
2424
+ (ArgsDictionary *)nonFatalExceptionLevel;
2525
+ (ArgsDictionary *) launchType;
26+
+ (ArgsDictionary *) userConsentActionTypes;
2627

2728
+ (NSDictionary<NSString *, NSString *> *) placeholders;
2829

ios/RNInstabug/ArgsRegistry.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ + (NSMutableDictionary *) getAll {
2121
[all addEntriesFromDictionary:ArgsRegistry.nonFatalExceptionLevel];
2222
[all addEntriesFromDictionary:ArgsRegistry.placeholders];
2323
[all addEntriesFromDictionary:ArgsRegistry.launchType];
24-
24+
[all addEntriesFromDictionary:ArgsRegistry.userConsentActionTypes];
25+
2526
return all;
2627
}
2728

@@ -110,7 +111,13 @@ + (ArgsDictionary *) actionTypes {
110111
@"addCommentToFeature": @(IBGActionAddCommentToFeature),
111112
};
112113
}
113-
114+
+ (ArgsDictionary *) userConsentActionTypes {
115+
return @{
116+
@"dropAutoCapturedMedia": @(IBGActionTypeDropAutoCapturedMedia),
117+
@"dropLogs": @(IBGActionTypeDropLogs),
118+
@"noChat": @(IBGActionTypeNoChat)
119+
};
120+
}
114121
+ (ArgsDictionary *) extendedBugReportStates {
115122
return @{
116123
@"enabledWithRequiredFields": @(IBGExtendedBugReportModeEnabledWithRequiredFields),

ios/RNInstabug/InstabugBugReportingBridge.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,10 @@
5151

5252
- (void)setCommentMinimumCharacterCount:(NSNumber *)limit reportTypes:(NSArray *)reportTypes;
5353

54+
- (void)addUserConsent:(NSString *)key
55+
description:(NSString *)description
56+
mandatory:(BOOL)mandatory
57+
checked:(BOOL)checked
58+
actionType:(id)actionType;
59+
5460
@end

ios/RNInstabug/InstabugBugReportingBridge.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,21 @@ - (void) showBugReportingWithReportTypeAndOptionsHelper:(NSArray*)args {
219219
[IBGBugReporting setCommentMinimumCharacterCountForReportTypes:parsedReportTypes withLimit:limit.intValue];
220220
}
221221

222+
RCT_EXPORT_METHOD(addUserConsent:(NSString *)key
223+
description:(NSString *)description
224+
mandatory:(BOOL)mandatory
225+
checked:(BOOL)checked
226+
actionType:(id)actionType) {
227+
IBGActionType mappedActionType = (IBGActionType)[actionType integerValue];
228+
229+
[IBGBugReporting addUserConsentWithKey:key
230+
description:description
231+
mandatory:mandatory
232+
checked:checked
233+
actionType:mappedActionType];
234+
}
235+
236+
222237
@synthesize description;
223238

224239
@synthesize hash;

ios/RNInstabug/RCTConvert+InstabugEnums.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,11 @@ @implementation RCTConvert (InstabugEnums)
109109
integerValue
110110
);
111111

112+
RCT_ENUM_CONVERTER(
113+
IBGActionType,
114+
ArgsRegistry.userConsentActionTypes,
115+
IBGActionTypeNoChat,
116+
integerValue
117+
);
118+
112119
@end

src/modules/BugReporting.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
InvocationOption,
1111
RecordingButtonPosition,
1212
ReportType,
13+
userConsentActionType,
1314
} from '../utils/Enums';
1415

1516
/**
@@ -169,6 +170,23 @@ export const setViewHierarchyEnabled = (isEnabled: boolean) => {
169170
NativeBugReporting.setViewHierarchyEnabled(isEnabled);
170171
};
171172

173+
/**
174+
* Adds a user consent item to the bug reporting form.
175+
* @param key A unique identifier string for the consent item.
176+
* @param description The text shown to the user describing the consent item.
177+
* @param mandatory Whether the user must agree to this item before submitting a report.
178+
* @param checked Whether the consent checkbox is pre-selected.
179+
* @param actionType A string representing the action type to map to SDK behavior.
180+
*/
181+
export const addUserConsent = (
182+
key: string,
183+
description: string,
184+
mandatory: boolean,
185+
checked: boolean,
186+
actionType?: userConsentActionType,
187+
) => {
188+
NativeBugReporting.addUserConsent(key, description, mandatory, checked, actionType);
189+
};
172190
/**
173191
* Sets a block of code to be executed when a prompt option is selected.
174192
* @param handler - A callback that gets executed when a prompt option is selected.

src/native/NativeBugReporting.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
InvocationOption,
99
RecordingButtonPosition,
1010
ReportType,
11+
userConsentActionType,
1112
} from '../utils/Enums';
1213
import { NativeModules } from './NativePackage';
1314

@@ -48,6 +49,14 @@ export interface BugReportingNativeModule extends NativeModule {
4849
setOnSDKDismissedHandler(
4950
handler: (dismissType: DismissType, reportType: ReportType) => void,
5051
): void;
52+
53+
addUserConsent(
54+
key: string,
55+
description: string,
56+
mandatory: boolean,
57+
checked: boolean,
58+
actionType?: userConsentActionType,
59+
): void;
5160
}
5261

5362
export const NativeBugReporting = NativeModules.IBGBugReporting;

src/native/NativeConstants.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@ export type NativeConstants = NativeSdkDebugLogsLevel &
1313
NativeLocale &
1414
NativeNonFatalErrorLevel &
1515
NativeStringKey &
16-
NativeLaunchType;
16+
NativeLaunchType &
17+
NativeUserConsentActionType;
1718

1819
interface NativeSdkDebugLogsLevel {
1920
sdkDebugLogsLevelVerbose: any;
2021
sdkDebugLogsLevelDebug: any;
2122
sdkDebugLogsLevelError: any;
2223
sdkDebugLogsLevelNone: any;
2324
}
24-
25+
interface NativeUserConsentActionType {
26+
dropAutoCapturedMedia: any;
27+
dropLogs: any;
28+
noChat: any;
29+
}
2530
interface NativeInvocationEvent {
2631
invocationEventNone: any;
2732
invocationEventShake: any;

src/utils/Enums.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ export enum LogLevel {
1212
error = constants.sdkDebugLogsLevelError,
1313
none = constants.sdkDebugLogsLevelNone,
1414
}
15+
/**
16+
* Enum representing the available user consent action types.
17+
*
18+
*/
19+
export enum userConsentActionType {
20+
dropAutoCapturedMedia = constants.dropAutoCapturedMedia,
21+
dropLogs = constants.dropLogs,
22+
noChat = constants.noChat,
23+
}
1524

1625
/**
1726
* The event used to invoke the feedback form.

test/mocks/mockBugReporting.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const mockBugReporting: BugReportingNativeModule = {
2323
setVideoRecordingFloatingButtonPosition: jest.fn(),
2424
setDisclaimerText: jest.fn(),
2525
setCommentMinimumCharacterCount: jest.fn(),
26+
addUserConsent: jest.fn(),
2627
};
2728

2829
export default mockBugReporting;

0 commit comments

Comments
 (0)