Skip to content

Commit 8725127

Browse files
committed
✨ setExtendedBugReportMode API for Android and iOS
1 parent 29ad766 commit 8725127

File tree

3 files changed

+92
-2
lines changed

3 files changed

+92
-2
lines changed

src/android/IBGPlugin.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import com.instabug.library.Feature;
99
import com.instabug.library.Instabug;
10+
import com.instabug.library.extendedbugreport.ExtendedBugReport;
1011
import com.instabug.library.invocation.InstabugInvocationEvent;
1112
import com.instabug.library.invocation.InstabugInvocationMode;
1213
import com.instabug.library.invocation.util.InstabugVideoRecordingButtonCorner;
@@ -169,7 +170,10 @@ public boolean execute(final String action, JSONArray args, final CallbackContex
169170
} else if ("setAutoScreenRecordingMaxDuration".equals(action)) {
170171
setAutoScreenRecordingMaxDuration(callbackContext, args.optInt(0));
171172

172-
} else {
173+
} else if ("setExtendedBugReportMode".equals(action)) {
174+
setExtendedBugReportMode(callbackContext, args.optString(0));
175+
176+
}else {
173177
// Method not found.
174178
return false;
175179
}
@@ -244,7 +248,7 @@ private void showIntroDialog(final CallbackContext callbackContext) {
244248
*
245249
* @param callbackContext
246250
* Used when calling back into JavaScript
247-
* @param colorInt
251+
* @param colorString
248252
* The value of the primary color
249253
*/
250254
private void setPrimaryColor(final CallbackContext callbackContext, String colorString) {
@@ -706,6 +710,30 @@ private void setVideoRecordingFloatingButtonPosition(final CallbackContext callb
706710
}
707711
}
708712

713+
/**
714+
* Sets whether the extended bug report mode should be disabled, enabled with
715+
* required fields or enabled with optional fields.
716+
*
717+
* @param callbackContext
718+
* Used when calling back into JavaScript
719+
* @param mode
720+
* A string to disable the extended bug report mode, enable it with
721+
* required or with optional fields
722+
*/
723+
private void setExtendedBugReportMode(final CallbackContext callbackContext, String mode) {
724+
try {
725+
if(mode.equals("enabledWithRequiredFields")) {
726+
Instabug.setExtendedBugReportState(ExtendedBugReport.State.ENABLED_WITH_REQUIRED_FIELDS);
727+
} else if(mode.equals("enabledWithOptionalFields")) {
728+
Instabug.setExtendedBugReportState(ExtendedBugReport.State.ENABLED_WITH_OPTIONAL_FIELDS);
729+
} else if(mode.equals("disabled")) {
730+
Instabug.setExtendedBugReportState(ExtendedBugReport.State.DISABLED);
731+
}
732+
} catch (IllegalStateException e) {
733+
callbackContext.error(errorMsg);
734+
}
735+
}
736+
709737
/**
710738
* Adds intent extras for all options passed to activate().
711739
*/

src/ios/IBGPlugin.m

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,31 @@ - (void) setReproStepsMode:(CDVInvokedUrlCommand*)command
417417
[self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
418418
}
419419

420+
421+
/**
422+
* Sets whether the extended bug report mode should be disabled, enabled with
423+
* required fields or enabled with optional fields.
424+
*
425+
* @param {CDVInvokedUrlCommand*} command
426+
* The command sent from JavaScript
427+
*/
428+
- (void) setExtendedBugReportMode:(CDVInvokedUrlCommand*)command
429+
{
430+
CDVPluginResult* result;
431+
432+
IBGExtendedBugReportMode extendedBugReportMode = [self parseExtendedBugReportMode:[command argumentAtIndex:0]];
433+
434+
if (extendedBugReportMode != -1) {
435+
[Instabug setExtendedBugReportMode:extendedBugReportMode];
436+
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
437+
} else {
438+
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
439+
messageAsString:@"A valid extended bug report mode must be provided."];
440+
}
441+
442+
[self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
443+
}
444+
420445
/**
421446
* Convenience method for setting whether the email
422447
* field is validated or not.
@@ -737,6 +762,24 @@ - (IBGUserStepsMode) parseReproStepsMode:(NSString*)mode
737762
} else return 0;
738763
}
739764

765+
/**
766+
* Convenience method for converting NSString to
767+
* IBGExtendedBugReportMode.
768+
*
769+
* @param {NSString*} mode
770+
* NSString shortcode for IBGExtendedBugReportMode
771+
*/
772+
- (IBGExtendedBugReportMode) parseExtendedBugReportMode:(NSString*)mode
773+
{
774+
if ([mode isEqualToString:@"enabledWithRequiredFields"]) {
775+
return IBGExtendedBugReportModeEnabledWithRequiredFields;
776+
} else if ([mode isEqualToString:@"enabledWithOptionalFields"]) {
777+
return IBGExtendedBugReportModeEnabledWithOptionalFields;
778+
} else if ([mode isEqualToString:@"disabled"]) {
779+
return IBGExtendedBugReportModeDisabled;
780+
} else return -1;
781+
}
782+
740783
/**
741784
* Convenience method for converting NSString to
742785
* IBGLocale.

www/instabug.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ var getReproStepsMode = function () {
2828
};
2929
};
3030

31+
var getExtendedBugReportMode = function () {
32+
return {
33+
enabledWithRequiredFields: 'enabledWithRequiredFields',
34+
enabledWithOptionalFields: 'enabledWithOptionalFields',
35+
disabled: 'disabled'
36+
};
37+
};
38+
3139
var getLocales = function () {
3240
return {
3341
arabic: 'arabic',
@@ -116,6 +124,17 @@ Instabug.setReproStepsMode = function (reproStepsMode, success, error) {
116124
}
117125
};
118126

127+
Instabug.setExtendedBugReportMode = function (extendedBugReportMode, success, error) {
128+
129+
var validatedExtendedBugReportMode = getExtendedBugReportMode()[extendedBugReportMode];
130+
131+
if (validatedExtendedBugReportMode) {
132+
exec(success, error, 'IBGPlugin', 'setExtendedBugReportMode', [validatedExtendedBugReportMode]);
133+
} else {
134+
console.log('Could not set extended bug report mode - "' + validatedExtendedBugReportMode + '" is not valid.');
135+
}
136+
};
137+
119138
Instabug.setUserData = function (data, success, error) {
120139
exec(success, error, 'IBGPlugin', 'setUserData', [data]);
121140
};

0 commit comments

Comments
 (0)