@dynatrace/react-native-plugin
Version:
This plugin gives you the ability to use the Dynatrace Mobile agent in your react native application.
51 lines (50 loc) • 1.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PickerHelper = void 0;
const IDynatraceProperties_1 = require("../IDynatraceProperties");
const PickerHelper = (Dynatrace) => ({
attachOnValueChange: (pickerProps) => {
if ((0, IDynatraceProperties_1.isDynatraceIgnored)(pickerProps)) {
return;
}
const origOnValueChange = pickerProps.onValueChange;
const nameOfAction = _findActionName(pickerProps);
if (origOnValueChange != null) {
pickerProps.onValueChange = (itemValue, itemNumber) => {
const value = _getPickerItemValue(itemNumber, itemValue, pickerProps.children);
if (value !== undefined) {
const finalNameOfAction = nameOfAction == null
? `Picked Value: ${value}`
: `Picker ${nameOfAction} Picked Value: ${value}`;
const action = Dynatrace.enterAutoAction(finalNameOfAction);
try {
origOnValueChange(itemValue, itemNumber);
}
finally {
action.leaveAction();
}
}
};
}
},
});
exports.PickerHelper = PickerHelper;
const isPickerItemProps = (props) => props.label !== undefined;
const _findActionName = (pickerProps) => {
if ((0, IDynatraceProperties_1.isDynatraceNaming)(pickerProps)) {
return pickerProps.dtActionName;
}
else if (pickerProps.accessibilityLabel != null) {
return pickerProps.accessibilityLabel;
}
return null;
};
const _getPickerItemValue = (index, value, children) => {
if (children != null &&
index >= 0 &&
children.length > index &&
isPickerItemProps(children[index].props)) {
return children[index].props.label;
}
return value;
};