-
Notifications
You must be signed in to change notification settings - Fork 2
[CA-4747] Profile editor should update consents with key in snakecase #280
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 |
---|---|---|
|
@@ -135,7 +135,23 @@ export default createWidget<ProfileEditorWidgetProps, ProfileEditorProps>({ | |
accessToken, | ||
fields: resolvedFields.map(({ path }) => path).join(',') | ||
}) | ||
.then(profile => camelCaseProperties(profile) as Profile) /** @todo check api response key format in sdk core */ | ||
/** | ||
* @todo this can be removed when https://github.com/ReachFive/identity-web-core-sdk/pull/260 will be merged | ||
* L'idéal serait que la clé d'un consentement soit en valeur d'une propriété "key" et non une clé de la structure Map utilisée. | ||
* le mieux serait même que `consents` soit un array et non un map. | ||
* Mais bon, difficile de changer ça maintenant sans créer un breaking change pour les utilisateurs de l'api ou du sdk core... | ||
*/ | ||
.then(({ consents, ...profile }) => ({ | ||
...profile, | ||
consents: consents | ||
? Object.fromEntries( | ||
Object.entries(consents).map(([key, value]) => [ | ||
key, | ||
camelCaseProperties(value) as UserConsent | ||
]) | ||
) | ||
: undefined | ||
}) as Profile) /** @todo check api response key format in sdk core */ | ||
Comment on lines
+138
to
+154
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. Cette partie sert juste à palier au fait que le SDK Core format la réponse api en camelcase mais en faisant exception des concents et de toute la structure enfant. |
||
.then((profile: Profile) => { | ||
const filteredProfileConsents = (profile.consents && Object.keys(profile.consents).length > 0) ? filterProfileConsents(fields, config.consentsVersions, profile.consents) : undefined; | ||
const filteredOutConsentsProfile = { ...profile, consents: filteredProfileConsents }; | ||
|
@@ -156,7 +172,11 @@ export default createWidget<ProfileEditorWidgetProps, ProfileEditorProps>({ | |
}); | ||
|
||
// Filter out the profile consents with different version than the one the given consent field own | ||
const filterProfileConsents = (fields: (string | Field)[], consentsVersions: Record<string, ConsentVersions>, profileConsents: Record<string, UserConsent>) => { | ||
const filterProfileConsents = ( | ||
fields: (string | Field)[], | ||
consentsVersions: Record<string, ConsentVersions>, | ||
profileConsents: Record<string, UserConsent> | ||
) => { | ||
return Object.keys(profileConsents) | ||
.filter(profileConsentKey => { | ||
const consentField = fields.map(f => typeof f === 'string' ? f : f.key).find(field => field.startsWith(`consents.${profileConsentKey}`)); | ||
|
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.
Le coeur du problème. PathMapping sert à faire la mapping entre le modèles et les champs d'un formulaire. Par défaut ça fait une conversion camelcase du le nom des propriétés...
(les joies de l'usine à gaz que sont les formulaire sur le SDK UI...)