-
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MBS-8242: Link to specific relationship type docs from rel edits
This adds a link to the doc page(s) for the relationship type(s) involved in a relationship edit (add, edit or remove). It seems very useful to have direct links to the documentation (often including specific guidelines) directly in the place people need to vote on the changes from. We pass an array to allow multiple types in EditRelationship; we pass the rels through a Set to remove duplicates when EditRelationship does not change the rel type.
- Loading branch information
1 parent
d944604
commit 105d125
Showing
5 changed files
with
136 additions
and
49 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* @flow strict | ||
* Copyright (C) 2023 MetaBrainz Foundation | ||
* | ||
* This file is part of MusicBrainz, the open internet music database, | ||
* and is licensed under the GPL version 2, or (at your option) any | ||
* later version: http://www.gnu.org/licenses/gpl-2.0.txt | ||
*/ | ||
|
||
import commaOnlyList | ||
from '../../static/scripts/common/i18n/commaOnlyList.js'; | ||
import HelpIcon from '../../static/scripts/edit/components/HelpIcon.js'; | ||
import getRelationshipLinkType | ||
from '../../static/scripts/edit/utility/getRelationshipLinkType.js'; | ||
|
||
type Props = { | ||
+relationships: $ReadOnlyArray<RelationshipT>, | ||
}; | ||
|
||
const RelationshipDocsTooltip = ({ | ||
relationships, | ||
}: Props): React$Element<'div'> | null => { | ||
const relationshipTypes = [...new Set( | ||
relationships.reduce((types: Array<LinkTypeT>, relationship) => { | ||
const type = getRelationshipLinkType(relationship); | ||
if (type && type.gid && type.name) { | ||
types.push(type); | ||
} | ||
return types; | ||
}, []), | ||
)]; | ||
|
||
if (!relationshipTypes?.length) { | ||
return null; | ||
} | ||
|
||
const docLinks = relationshipTypes.map(relationshipType => exp.l( | ||
'“{doc_link|{name}}”', | ||
{ | ||
doc_link: { | ||
href: '/relationship/' + relationshipType.gid, | ||
target: '_blank', | ||
}, | ||
name: relationshipType.name, | ||
}, | ||
)); | ||
|
||
const helpContent = ( | ||
exp.l( | ||
`See the documentation for the relationship types in this edit: | ||
{doc_links}.`, | ||
{ | ||
doc_links: commaOnlyList(docLinks), | ||
}, | ||
) | ||
); | ||
|
||
return ( | ||
<div className="edit-help"> | ||
<HelpIcon | ||
content={helpContent} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default RelationshipDocsTooltip; |
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
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