This repository has been archived by the owner on Apr 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 142
Custom Categories #60
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3493161
Initial commit for adding custom categories
notfelineit 9dacd6a
Modify logic so all categories are checked, and false always takes pr…
notfelineit 044f65d
Refactor to support custom purpose on custom categories
notfelineit 2ed2b05
Rename properties to be more explicit about custom category vs. Segme…
notfelineit 71e0c13
Undo changes to styled components
notfelineit 561267a
Fix substory name
notfelineit 797f550
Undoing package-lock changes
notfelineit fce6dd4
Breakdown interface further
notfelineit 6b71f3f
Override default categories with custom categories
notfelineit e3b331e
Update initialPreferences to reflect custom categories
notfelineit 4a96bca
Change to use integration name
notfelineit a20a2e5
Update property description for customCategories
notfelineit 8750b30
Make sure users can't submit null forms when using customCategories (…
notfelineit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ export default class ConsentManager extends PureComponent<ConsentManagerProps, { | |
implyConsentOnInteraction: false, | ||
onError: undefined, | ||
cookieDomain: undefined, | ||
customCategories: undefined, | ||
bannerTextColor: '#fff', | ||
bannerSubContent: 'You can change your preferences at any time.', | ||
bannerBackgroundColor: '#1f4160', | ||
|
@@ -41,7 +42,7 @@ export default class ConsentManager extends PureComponent<ConsentManagerProps, { | |
preferencesDialogContent, | ||
cancelDialogTitle, | ||
cancelDialogContent, | ||
initialPreferences, | ||
customCategories, | ||
onError | ||
} = this.props | ||
|
||
|
@@ -52,11 +53,13 @@ export default class ConsentManager extends PureComponent<ConsentManagerProps, { | |
otherWriteKeys={otherWriteKeys} | ||
shouldRequireConsent={shouldRequireConsent} | ||
cookieDomain={cookieDomain} | ||
initialPreferences={initialPreferences || zeroValuePreferences} | ||
initialPreferences={this.getInitialPreferences()} | ||
mapCustomPreferences={this.handleMapCustomPreferences} | ||
customCategories={customCategories} | ||
> | ||
{({ | ||
destinations, | ||
customCategories, | ||
newDestinations, | ||
preferences, | ||
isConsentRequired, | ||
|
@@ -65,6 +68,7 @@ export default class ConsentManager extends PureComponent<ConsentManagerProps, { | |
saveConsent | ||
}) => { | ||
return <Container | ||
customCategories={customCategories} | ||
destinations={destinations} | ||
newDestinations={newDestinations} | ||
preferences={preferences} | ||
|
@@ -90,10 +94,53 @@ export default class ConsentManager extends PureComponent<ConsentManagerProps, { | |
) | ||
} | ||
|
||
getInitialPreferences = () => { | ||
const { initialPreferences, customCategories } = this.props | ||
if (initialPreferences) { | ||
return initialPreferences | ||
} | ||
|
||
if (!customCategories) { | ||
return zeroValuePreferences | ||
} | ||
|
||
const initialCustomPreferences = {} | ||
Object.keys(customCategories).forEach(category => { | ||
initialCustomPreferences[category] = null | ||
}) | ||
|
||
return initialCustomPreferences | ||
} | ||
|
||
handleMapCustomPreferences = (destinations: Destination[], preferences: CategoryPreferences) => { | ||
const { customCategories } = this.props | ||
const destinationPreferences = {} | ||
const customPreferences = {} | ||
|
||
if (customCategories) { | ||
for (const preferenceName of Object.keys(customCategories)) { | ||
const value = preferences[preferenceName] | ||
if (typeof value === 'boolean') { | ||
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. You could just do this here I think:
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 think this is saying "if explicitly set as true or false, set as true or false, if not set (i.e. value is null), set to true" |
||
customPreferences[preferenceName] = value | ||
} else { | ||
customPreferences[preferenceName] = true | ||
} | ||
} | ||
|
||
destinations.forEach(destination => { | ||
// Mark custom categories | ||
Object.entries(customCategories).forEach(([categoryName, { integrations }]) => { | ||
const consentAlreadySetToFalse = destinationPreferences[destination.id] === false | ||
const shouldSetConsent = integrations.includes(destination.name) | ||
if (shouldSetConsent && !consentAlreadySetToFalse) { | ||
destinationPreferences[destination.id] = customPreferences[categoryName] | ||
} | ||
}) | ||
}) | ||
|
||
return { destinationPreferences, customPreferences } | ||
} | ||
|
||
// Default unset preferences to true (for implicit consent) | ||
for (const preferenceName of Object.keys(preferences)) { | ||
const value = preferences[preferenceName] | ||
|
@@ -107,12 +154,18 @@ export default class ConsentManager extends PureComponent<ConsentManagerProps, { | |
const customPrefs = customPreferences as CategoryPreferences | ||
|
||
for (const destination of destinations) { | ||
if (ADVERTISING_CATEGORIES.find(c => c === destination.category)) { | ||
// Mark advertising destinations | ||
if (ADVERTISING_CATEGORIES.find(c => c === destination.category) && destinationPreferences[destination.id] !== false) { | ||
destinationPreferences[destination.id] = customPrefs.advertising | ||
} else if (FUNCTIONAL_CATEGORIES.find(c => c === destination.category)) { | ||
} | ||
|
||
// Mark function destinations | ||
if (FUNCTIONAL_CATEGORIES.find(c => c === destination.category) && destinationPreferences[destination.id] !== false) { | ||
destinationPreferences[destination.id] = customPrefs.functional | ||
} else { | ||
// Fallback to marketing | ||
} | ||
|
||
// Fallback to marketing | ||
if (!(destination.id in destinationPreferences)) { | ||
destinationPreferences[destination.id] = customPrefs.marketingAndAnalytics | ||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't the
?
take care of the undefined case here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I originally had it as just
customCategories?: CustomCategories
but it was failing validation - because sometimes we do pass in customCategories but the value is undefined.