Skip to content

Commit

Permalink
naming and use airgap purpose title and description over default
Browse files Browse the repository at this point in the history
  • Loading branch information
kate-kazantseva committed Oct 22, 2024
1 parent 0612beb commit 1dffe31
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 82 deletions.
22 changes: 11 additions & 11 deletions src/components/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ import {

// Mapping of purposes to the message translation key
export const DEFAULT_PURPOSE_TO_MESSAGE_KEY: Record<string, DefinedMessage> = {
Essential: completeOptionsMessages.essentialLabel,
Functional: completeOptionsMessages.functionalLabel,
Analytics: completeOptionsMessages.analyticsLabel,
Advertising: completeOptionsMessages.advertisingLabel,
SaleOfInfo: completeOptionsMessages.saleOfInfoLabel,
Essential: completeOptionsMessages['essential.title'],

Check failure on line 9 in src/components/constants.ts

View workflow job for this annotation

GitHub Actions / build-and-upload-artifacts

Element implicitly has an 'any' type because expression of type '"essential.title"' can't be used to index type 'DefinedMessages<"description" | "saveButtonPrimary" | "essentialAriaLabel" | "toggleDisable" | "toggleEnable" | "globalPrivacySignal">'.
Functional: completeOptionsMessages['functional.title'],

Check failure on line 10 in src/components/constants.ts

View workflow job for this annotation

GitHub Actions / build-and-upload-artifacts

Element implicitly has an 'any' type because expression of type '"functional.title"' can't be used to index type 'DefinedMessages<"description" | "saveButtonPrimary" | "essentialAriaLabel" | "toggleDisable" | "toggleEnable" | "globalPrivacySignal">'.
Analytics: completeOptionsMessages['analytics.title'],

Check failure on line 11 in src/components/constants.ts

View workflow job for this annotation

GitHub Actions / build-and-upload-artifacts

Element implicitly has an 'any' type because expression of type '"analytics.title"' can't be used to index type 'DefinedMessages<"description" | "saveButtonPrimary" | "essentialAriaLabel" | "toggleDisable" | "toggleEnable" | "globalPrivacySignal">'.
Advertising: completeOptionsMessages['advertising.title'],

Check failure on line 12 in src/components/constants.ts

View workflow job for this annotation

GitHub Actions / build-and-upload-artifacts

Element implicitly has an 'any' type because expression of type '"advertising.title"' can't be used to index type 'DefinedMessages<"description" | "saveButtonPrimary" | "essentialAriaLabel" | "toggleDisable" | "toggleEnable" | "globalPrivacySignal">'.
SaleOfInfo: completeOptionsMessages['saleOfInfo.title'],

Check failure on line 13 in src/components/constants.ts

View workflow job for this annotation

GitHub Actions / build-and-upload-artifacts

Element implicitly has an 'any' type because expression of type '"saleOfInfo.title"' can't be used to index type 'DefinedMessages<"description" | "saveButtonPrimary" | "essentialAriaLabel" | "toggleDisable" | "toggleEnable" | "globalPrivacySignal">'.
};

export const DEFAULT_PURPOSE_TO_DESCRIPTION_KEY: Record<
string,
DefinedMessage
> = {
Essential: completeOptionsMessages.essentialDescription,
Functional: completeOptionsMessages.functionalDescription,
Analytics: completeOptionsMessages.analyticsDescription,
Advertising: completeOptionsMessages.advertisingDescription,
SaleOfInfo: completeOptionsMessages.saleOfInfoDescription,
Essential: completeOptionsMessages['essential.description'],

Check failure on line 20 in src/components/constants.ts

View workflow job for this annotation

GitHub Actions / build-and-upload-artifacts

Element implicitly has an 'any' type because expression of type '"essential.description"' can't be used to index type 'DefinedMessages<"description" | "saveButtonPrimary" | "essentialAriaLabel" | "toggleDisable" | "toggleEnable" | "globalPrivacySignal">'.
Functional: completeOptionsMessages['functional.description'],
Analytics: completeOptionsMessages['analytics.description'],
Advertising: completeOptionsMessages['advertising.description'],
SaleOfInfo: completeOptionsMessages['saleOfInfo.description'],
}

export const DEFAULT_PURPOSE_TO_INVERTED_MESSAGE_KEY: Record<
string,
DefinedMessage
> = {
Essential: completeOptionsMessages.essentialLabel,
Essential: completeOptionsMessages['essential.title'],
Functional: completeOptionsInvertedMessages.functionalLabel,
Analytics: completeOptionsInvertedMessages.analyticsLabel,
Advertising: completeOptionsInvertedMessages.advertisingLabel,
Expand Down
20 changes: 4 additions & 16 deletions src/hooks/useGetPurposeDescriptionKeys.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import camelCase from 'lodash/camelCase';

Check failure on line 1 in src/hooks/useGetPurposeDescriptionKeys.ts

View workflow job for this annotation

GitHub Actions / build-and-upload-artifacts

Cannot find module 'lodash/camelCase' or its corresponding type declarations.

import type {
TrackingPurposeDetails,

Check failure on line 4 in src/hooks/useGetPurposeDescriptionKeys.ts

View workflow job for this annotation

GitHub Actions / build-and-upload-artifacts

'TrackingPurposeDetails' is declared but never used.
TrackingPurposesTypes,
Expand All @@ -10,8 +12,7 @@ import { useMemo } from 'preact/hooks';

import { DefinedMessage } from '@transcend-io/internationalization';

const CUSTOM_PURPOSE_DESCRIPTION_PREFIX = 'cm-ui.purposeDescription';
const DEFAULT_PURPOSE_DESCRIPTION_PREFIX = 'ui.src.CompleteOptions';
const PURPOSE_MESSAGE_PREFIX = 'purpose.trackingType';

export const useGetPurposeDescriptionKeys = ({
consentSelection,
Expand All @@ -29,20 +30,7 @@ export const useGetPurposeDescriptionKeys = ({
() =>
// the purpose type is unique for the bundle
Object.keys(consentSelection ?? {}).reduce((allMessages, purposeType) => {
if (allMessages[purposeType]) {
return allMessages;
}
const purposeMessageDescriptionId = Object.values(
defaultTrackingPurposes,
).find(
(defaultPurpose) =>
(defaultPurpose as TrackingPurposeDetails).trackingType ===
purposeType,
)
? `${DEFAULT_PURPOSE_DESCRIPTION_PREFIX}.${purposeType
.charAt(0)
.toLowerCase()}${purposeType.slice(1)}Description`
: `${CUSTOM_PURPOSE_DESCRIPTION_PREFIX}.${purposeType}`;
const purposeMessageDescriptionId = `${PURPOSE_MESSAGE_PREFIX}.${camelCase(purposeType)}.description`;
return {
...allMessages,
[purposeType]: {
Expand Down
12 changes: 5 additions & 7 deletions src/hooks/useGetPurposeMessageKeys.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import camelCase from 'lodash/camelCase';

Check failure on line 1 in src/hooks/useGetPurposeMessageKeys.ts

View workflow job for this annotation

GitHub Actions / build-and-upload-artifacts

Cannot find module 'lodash/camelCase' or its corresponding type declarations.
import { ConsentSelection } from '../types';

import { useMemo } from 'preact/hooks';

import { DefinedMessage } from '@transcend-io/internationalization';

const CUSTOM_PURPOSE_MESSAGE_PREFIX = 'cm-ui.purpose';
const PURPOSE_MESSAGE_PREFIX = 'purpose.trackingType';

export const useGetPurposeMessageKeys = ({
consentSelection,
Expand All @@ -19,16 +20,13 @@ export const useGetPurposeMessageKeys = ({
() =>
// the purpose type is unique for the bundle
Object.keys(consentSelection ?? {}).reduce((allMessages, purposeType) => {
if (allMessages[purposeType]) {
return allMessages;
}
const customPurposeMessageLabel = `${CUSTOM_PURPOSE_MESSAGE_PREFIX}.${purposeType}`;
const purposeMessageLabel = `${PURPOSE_MESSAGE_PREFIX}.${camelCase(purposeType)}.title`;
return {
...allMessages,
[purposeType]: {
id: customPurposeMessageLabel,
id: purposeMessageLabel,
defaultMessage: purposeType,
description: `Translatable name for custom purpose '${purposeType}'`,
description: `Translatable name for purpose '${purposeType}'`,
} as DefinedMessage,
};
}, defaultPurposeToMessageKey as Record<string, DefinedMessage>),
Expand Down
99 changes: 51 additions & 48 deletions src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,57 +456,60 @@ export const bottomMenuMessages = defineMessages('ui.src.bottomMenu', {
},
});

export const purposeMessages = defineMessages('purpose.trackingType', {
'essential.title': {
defaultMessage: 'Essential purposes',
description: 'Text for essential purposes in CompleteOptions view state.',
},
'essential.description': {
defaultMessage: 'No consent needed.',
description:
'Text for essential purposes description in CompleteOptions view state.',
},
'functional.title': {
defaultMessage: 'Functionality',
description:
'Text for functional purposes in CompleteOptions view state.',
},
'functional.description': {
defaultMessage: 'Personalization, autofilled forms, etc.',
description:
'Text for functional purposes description in CompleteOptions view state.',
},
'analytics.title': {
defaultMessage: 'Analytics',
description: 'Text for analytics purposes in CompleteOptions view state.',
},
'analytics.description': {
defaultMessage: 'Help us learn how our site is used and how it performs.',
description:
'Text for analytics purposes description in CompleteOptions view state.',
},
'advertising.title': {
defaultMessage: 'Advertising',
description:
'Text for advertising purposes in CompleteOptions view state.',
},
'advertising.description': {
defaultMessage: 'Helps us and others serve ads relevant to you.',
description:
'Text for advertising purposes description in CompleteOptions view state.',
},
'saleOfInfo.title': {
defaultMessage: 'Sale of personal information',
description:
'Text for sale of information purposes in CompleteOptions view state.',
},
'saleOfInfo.description': {
defaultMessage: 'Sale of personal information.',
description:
'Text for advertising purposes description in CompleteOptions view state.',
},
});

export const completeOptionsMessages = defineMessages(
'ui.src.completeOptions',
{
essentialLabel: {
defaultMessage: 'Essential purposes',
description: 'Text for essential purposes in CompleteOptions view state.',
},
essentialDescription: {
defaultMessage: 'No consent needed.',
description:
'Text for essential purposes description in CompleteOptions view state.',
},
functionalLabel: {
defaultMessage: 'Functionality',
description:
'Text for functional purposes in CompleteOptions view state.',
},
functionalDescription: {
defaultMessage: 'Personalization, autofilled forms, etc.',
description:
'Text for functional purposes description in CompleteOptions view state.',
},
analyticsLabel: {
defaultMessage: 'Analytics',
description: 'Text for analytics purposes in CompleteOptions view state.',
},
analyticsDescription: {
defaultMessage: 'Help us learn how our site is used and how it performs.',
description:
'Text for analytics purposes description in CompleteOptions view state.',
},
advertisingLabel: {
defaultMessage: 'Advertising',
description:
'Text for advertising purposes in CompleteOptions view state.',
},
advertisingDescription: {
defaultMessage: 'Helps us and others serve ads relevant to you.',
description:
'Text for advertising purposes description in CompleteOptions view state.',
},
saleOfInfoLabel: {
defaultMessage: 'Sale of personal information',
description:
'Text for sale of information purposes in CompleteOptions view state.',
},
saleOfInfoDescription: {
defaultMessage: 'Sale of personal information.',
description:
'Text for advertising purposes description in CompleteOptions view state.',
},
saveButtonPrimary: {
defaultMessage: 'Confirm',
description: 'Confirm button text in CompleteOptions view state.',
Expand Down

0 comments on commit 1dffe31

Please sign in to comment.