in libs/designer/src/lib/ui/settings/index.tsx [725:810]
function TrackingSettings({
nodeId,
readOnly,
nodeSettings,
isExpanded,
dispatch,
updateSettings,
}: SettingSectionProps): JSX.Element | null {
const { trackedProperties, correlation } = nodeSettings;
const onClientTrackingIdChange = (newValue: string): void => {
updateSettings({
correlation: {
isSupported: !!correlation?.isSupported,
value: {
clientTrackingId: newValue,
},
},
});
};
const onTrackedPropertiesDictionaryValueChanged = (newValue: Record<string, string>): void => {
let trackedPropertiesInput: Record<string, any> | undefined = {}; // tslint:disable-line: no-any
if (isObject(newValue) && Object.keys(newValue).length > 0 && Object.keys(newValue).some((key) => newValue[key] !== undefined)) {
trackedPropertiesInput = {};
for (const key of Object.keys(newValue)) {
let propertyValue: any; // tslint:disable-line: no-any
try {
propertyValue = JSON.parse(newValue[key]);
} catch {
propertyValue = newValue[key];
}
trackedPropertiesInput[key] = propertyValue;
}
}
// if tracked properties is empty, set it to undefined
if (Object.keys(trackedPropertiesInput).length === 0) {
trackedPropertiesInput = undefined;
}
updateSettings({
trackedProperties: {
isSupported: !!trackedProperties?.isSupported,
value: trackedPropertiesInput,
},
});
};
const onTrackedPropertiesStringValueChange = (newValue: string): void => {
let trackedPropertiesInput: any = ''; // tslint:disable-line: no-any
if (newValue) {
try {
trackedPropertiesInput = JSON.parse(newValue);
} catch {
trackedPropertiesInput = newValue;
}
}
if (trackedPropertiesInput === '') {
trackedPropertiesInput = undefined;
}
updateSettings({
trackedProperties: {
isSupported: !!trackedProperties?.isSupported,
value: trackedPropertiesInput,
},
});
};
if (trackedProperties?.isSupported || correlation?.isSupported) {
return (
<Tracking
nodeId={nodeId}
readOnly={readOnly}
expanded={isExpanded}
trackedProperties={trackedProperties}
correlation={correlation}
onHeaderClick={(sectionName) => dispatch(setExpandedSections(sectionName))}
onClientTrackingIdChange={onClientTrackingIdChange}
onTrackedPropertiesDictionaryValueChanged={onTrackedPropertiesDictionaryValueChanged}
onTrackedPropertiesStringValueChange={onTrackedPropertiesStringValueChange}
/>
);
}
return null;
}