Skip to content
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

EntityLink cleanup #630

Merged
merged 11 commits into from
Mar 28, 2018
Merged

EntityLink cleanup #630

merged 11 commits into from
Mar 28, 2018

Conversation

mwiencek
Copy link
Member

@mwiencek mwiencek commented Mar 17, 2018

The EntityLink component is used by a ton of pages and components, so it'd be very beneficial to have types for it to ensure it's being used correctly (and is implemented correctly).

I added types and performed some misc. fixes/cleanups.

@mwiencek mwiencek requested review from sambhav and yvanzo March 17, 2018 19:06
hover = entity.sort_name + bracketed(comment);
}

if (entityType === 'artist' || entityType === 'instrument') {
content = content || entity.l_name;
if (entity.entityType === 'area') {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See 75252bf. I only discovered this bug because of the added types (Flow complained about l_name not existing, which caused me to dig deeper and see that the condition was also wrong). So they're already helping. :)

title?: string,
+target?: '_blank',
};
/* eslint-enable sort-keys, flowtype/sort-keys */
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted the keys that are only supposed to exist in the anchorProps spread to be grouped together, so I disabled those eslint rules for this block.


if (showDisambiguation === undefined) {
showDisambiguation = !hasCustomContent;
}

if (entityType === 'artist' && !nonEmpty(hover)) {
if (entity.entityType === 'artist' && !nonEmpty(hover)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since CoreEntityT is now a disjoint union, the entityType check allows Flow to determine that the entity must be an ArtistT inside this block, allowing the entity.sort_name access.

But for some reason this feature only works if you access entity.entityType directly in the conditional, rather than caching it in a variable as we were doing before.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that limitation documented or reported?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found facebook/flow#3932 and facebook/flow#4828 (though they're related to destructuring the values more specifically, I guess the same logic would apply).

It might also be related to refinement invalidation in that Flow can't know if entity.entityType has changed value since it was stored in the constant...so it may be a way to enforce soundness.

@@ -35,7 +37,11 @@ const DeletedLink = ({name, allowNew}) => {
const Comment = ({className, comment}) => (
<Frag>
{' '}
<span className={className}>({isolateText(comment)})</span>
<span className={className}>
{'('}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not bracketed ?


const NoInfoURL = ({url, allowNew}) => (
<Frag>
<a href={url}>{url}</a>
{' '}
<DeletedLink name={'[' + l('info') + ']'} allowNew={allowNew} />
<DeletedLink allowNew={allowNew} name={'[' + l('info') + ']'} />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can modify bracketed to do all 3 kinds of brackets depending on flags passed and default to round?

@@ -209,7 +224,7 @@ const EntityLink = ({
}

if (infoLink) {
parts.push(' [', <a href={infoLink} key="info">{l('info')}</a>, ']')
parts.push(' [', <a href={infoLink} key="info">{l('info')}</a>, ']');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can also be replaced by the refactored bracketed util?

@mwiencek mwiencek force-pushed the entitylink-cleanup branch from c33b18f to ab7c48a Compare March 19, 2018 07:23
@mwiencek
Copy link
Member Author

mwiencek commented Mar 19, 2018

@sambhav Agreed about using bracketed, though the result isn't 100% pretty: ab7c48a

About removing the space from the strings as mentioned in the commit: I'm not sure if it's necessary for some languages to control the presence of the space, and if that's the reason it was included, or just because it was convenient to have because most callers want the space.

Should we change the translated string from e.g. ' ({text})' to '({text})'?

@yvanzo
Copy link
Contributor

yvanzo commented Mar 19, 2018

Yes, this space has to be moved out of this function eventually.

It happens that bracketed text always comes after another text, thus there always is a space before. IMHO, it is overfactorization. I don’t think it is necessary to any language, at least it is not useful to any of currently supported language, not to mention it does not support RTL languages.

@mwiencek mwiencek force-pushed the entitylink-cleanup branch from ab7c48a to bf2518a Compare March 19, 2018 17:00
mwiencek added a commit to mwiencek/musicbrainz-server that referenced this pull request Mar 19, 2018
@mwiencek mwiencek force-pushed the entitylink-cleanup branch from bf2518a to b5fc65b Compare March 19, 2018 17:07
mwiencek added a commit to mwiencek/musicbrainz-server that referenced this pull request Mar 19, 2018
@mwiencek
Copy link
Member Author

@yvanzo Agreed, I removed the leading space from the JS version of bracketed in 484ae62

mwiencek added 10 commits March 19, 2018 23:03
Fixes a couple issues in the previous code:

 * It should've been checking for areas, not artists. Artists don't have
   translated names (not counting aliases), but areas which are
   countries do. You can see this is the behavior of the original TT
   macros, too: areas and instruments default to l_name for their
   content.

 * We don't serialize any l_name property. We have to get the translated
   name from the appropriate gettext domain.
This is what this actually intends to test.
Allow passing a "type" option to bracketed specifying which type of
brackets to use. Defaults to "()".

Use this in EntityLink.
@mwiencek mwiencek force-pushed the entitylink-cleanup branch from b5fc65b to 230cc07 Compare March 20, 2018 04:19
to distinguish from JS function `bracketed` for further conversion.
Copy link
Contributor

@yvanzo yvanzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed TT macro bracketed since it mismatches JS function bracketed in 5cb19e7.

@mwiencek
Copy link
Member Author

Yes, good call. Thanks!

@mwiencek mwiencek merged commit 362aa4d into metabrainz:master Mar 28, 2018
@mwiencek mwiencek deleted the entitylink-cleanup branch March 28, 2018 05:56
reosarevok pushed a commit to reosarevok/musicbrainz-server that referenced this pull request Apr 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants