-
Notifications
You must be signed in to change notification settings - Fork 57
[FIX] Codepush: unset 'useAccessibilityLabel' and 'actionNameAttribute' properties #890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,22 @@ | ||
| /* | ||
| * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
| * This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
| * Copyright 2016-Present Datadog, Inc. | ||
| */ | ||
| import { | ||
| DatadogProvider, | ||
| DatadogProviderConfiguration, | ||
| DdSdkReactNative | ||
| } from '@datadog/mobile-react-native'; | ||
| import type { DdSdkReactNativeConfiguration } from '@datadog/mobile-react-native'; | ||
| import type { | ||
| AutoInstrumentationConfiguration, | ||
| DdSdkReactNativeConfiguration | ||
| } from '@datadog/mobile-react-native'; | ||
| import codePush from 'react-native-code-push'; | ||
|
|
||
| import { DISCARD_PROPERTY, removeDiscardProperties } from './utils'; | ||
| import type { RequiredOrDiscard } from './utils'; | ||
|
|
||
| /** | ||
| * Use this class instead of DdSdkReactNative to initialize the Datadog SDK when using AppCenter CodePush. | ||
| */ | ||
|
|
@@ -31,6 +42,29 @@ const initializeWithCodepushVersion = async ( | |
| DatadogProvider.initialize(configuration); | ||
| }; | ||
|
|
||
| const buildPartialConfiguration = ( | ||
| configuration: DatadogProviderConfiguration | ||
| ): AutoInstrumentationConfiguration => { | ||
| const partialConfiguration: RequiredOrDiscard<AutoInstrumentationConfiguration> = { | ||
| trackErrors: configuration.trackErrors, | ||
| trackResources: configuration.trackResources, | ||
| trackInteractions: configuration.trackInteractions, | ||
| firstPartyHosts: configuration.firstPartyHosts, | ||
| logEventMapper: configuration.logEventMapper, | ||
| errorEventMapper: configuration.errorEventMapper, | ||
| resourceEventMapper: configuration.resourceEventMapper, | ||
| actionEventMapper: configuration.actionEventMapper, | ||
| useAccessibilityLabel: configuration.useAccessibilityLabel, | ||
| resourceTracingSamplingRate: configuration.resourceTracingSamplingRate, | ||
| actionNameAttribute: | ||
| configuration.actionNameAttribute ?? DISCARD_PROPERTY | ||
| }; | ||
|
|
||
| return removeDiscardProperties( | ||
| partialConfiguration | ||
| ) as AutoInstrumentationConfiguration; | ||
|
Comment on lines
+48
to
+65
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm having trouble understanding this, why not just make it partial ?
or if you want some to be partial and others to be required, maybe doing something like this ?
But the way we're doing the types here doesn't feel right.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem with Partial is that you are going to miss certain properties, because TSC won't complain. We can't directly assign each property of If we use If we use I know this does not feel right, but I honestly could not find a good alternative to type it in a way that would force developers to map all properties. |
||
| }; | ||
|
|
||
| export const DatadogCodepushProvider: typeof DatadogProvider = ({ | ||
| configuration, | ||
| ...rest | ||
|
|
@@ -39,16 +73,8 @@ export const DatadogCodepushProvider: typeof DatadogProvider = ({ | |
| // We turn it to partial initialization, while in parallel we get the CodePush version and initialize the SDK. | ||
| if (configuration instanceof DatadogProviderConfiguration) { | ||
| initializeWithCodepushVersion(configuration); | ||
| const partialConfiguration = { | ||
| trackErrors: configuration.trackErrors, | ||
| trackResources: configuration.trackResources, | ||
| trackInteractions: configuration.trackInteractions, | ||
| firstPartyHosts: configuration.firstPartyHosts, | ||
| resourceTracingSamplingRate: | ||
| configuration.resourceTracingSamplingRate | ||
| }; | ||
| return DatadogProvider({ | ||
| configuration: partialConfiguration, | ||
| configuration: buildPartialConfiguration(configuration), | ||
| ...rest | ||
| }); | ||
| } else { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
| * This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
| * Copyright 2016-Present Datadog, Inc. | ||
| */ | ||
|
|
||
| /** | ||
| * A constant used to define a property that should be discarded from a {@link RequiredOrDiscard} object. | ||
| */ | ||
| export const DISCARD_PROPERTY = { _dd_meta_: 'DISCARD' }; | ||
|
|
||
| /** | ||
| * Used to change the type of every property of an object to be either required or {@link DISCARD_PROPERTY}. | ||
| */ | ||
| export type RequiredOrDiscard<T> = { | ||
| [K in keyof T]-?: T[K] | typeof DISCARD_PROPERTY; | ||
| }; | ||
|
|
||
| /** | ||
| * Removes all entries of value {@link DISCARD_PROPERTY} from the given object | ||
| * @param obj The object to remove the {@link DISCARD_PROPERTY} entries from. | ||
| * @returns The object without the {@link DISCARD_PROPERTY} entries. | ||
| */ | ||
| export const removeDiscardProperties = <T extends Record<string, any>>( | ||
|
marco-saia-datadog marked this conversation as resolved.
|
||
| obj: T | ||
| ): { | ||
| [K in keyof T]: T[K] extends null ? undefined : T[K]; | ||
| } => { | ||
| const result = {} as any; | ||
|
marco-saia-datadog marked this conversation as resolved.
|
||
|
|
||
| Object.keys(obj).forEach(key => { | ||
| const value = obj[key]; | ||
| result[key] = value === DISCARD_PROPERTY ? undefined : value; | ||
| }); | ||
|
|
||
| return result; | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.