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.
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
[WIP] Provide standardised tools for mapping Data to Link attributes #54791
base: trunk
Are you sure you want to change the base?
[WIP] Provide standardised tools for mapping Data to Link attributes #54791
Changes from all commits
6271874
5a9914d
aa811f8
13071ae
e8526cd
1edac52
b98a8a9
49cf4fa
855c646
13be3c6
63a5b19
2eb7259
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
We'll need to break this into discreet tests asserting on the behaviour. We should do this before things get overly complex 😓
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.
@getdave I think the expected linkRel should be
noopener noreferer nofollow sponsored
because the linkValue isThis test case is passed with incorrect value...
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.
The failed test is found when running unit test against link-value-transforms-with-utils.js
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.
@getdave but I think this is expected with the current
mapping
object in the test file, because the default mapping is 1:1, thereforenofollow
andsponsored
linked withlinkRel
whileopensInNewTab
is not, so the expectedlinkRel
is correct 'nofollow sponsored'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.
What do we think about handling another attribute in this handler? If we don't do it like this we will need some means within
toData
to trigger mutations in other parts of the data tree.Whilst the approach here isn't one I love, it feels less complex to the consumer than any alternative I can conceive of right now.
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.
Also this might cause unexpected conditions because what if
opensInNewTab
were processed afternofollow
? That might mean thatopensInNewTab
value might still represent the old value as it has yet to be processed.We need a test for such a scenario to make it concrete and then we can consider how best to resolve it.
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.
Possibly a "dependencies" idea, whereby properties can declare that they have dependencies on other properties. Then the final value for the property is only calculated once the other property has been processed.
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.
@getdave I have thought about this, can we somehow define
util
methods for the mapping objectWith this approach, we may need to
exclude
the prop name from thelink-value-transforms
methods, since it does not have standardtoLink
andtoData
methods like normal propsThere 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 made a PR for demo this #55143
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've also been thinking about ths concept of utility functions. I think on balance it might be easier to simply allow consumers to provide their own utilities as needed.
For example much of the transforms could be handled with a functional approach using something like
compose
to compose a set of transformations.I think the most common one will be "if this value is a string then concat to an existing string if it exists or otherwise just use the string as the new value". Something like Ramda Concat but that can handle
undefined
would be what we need.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.
Oh I've just realised the concept in your PR 👍
So we could export an additional helper from
link-value-transforms
calledmapGenerator
where we could expose utils for mapping.If I've understood this would accept a mapping object and provide callbacks to the map to allow the consumer to perform typical data operations.
This would also be completely optional.
I think it's clever. I think we should
I really like the idea but I think it may overcomplicate this initial PR. But I would definitely like to explore it.
What do you think?
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.
Yes, it is
The PR #55143 should be a commit to modify the ButtonEdit mapping, but because of the lack of write privilege, I used it as a separate proposal with its own test for better explanation
The same explain as above, the PR was meant for ButtonEdit (as consumer) with it own utils