Skip to content

Commit

Permalink
communities-ui: verified icon display logic change and deterministic …
Browse files Browse the repository at this point in the history
…sorting
  • Loading branch information
ptamarit committed Oct 18, 2024
1 parent 36ccbaa commit 98e0479
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
href="{{ url_for('invenio_app_rdm_communities.communities_detail', pid_value=community.slug) }}" class="ui small header">
{{ community.metadata.title }}
</a>
{% if community.parent and community.parent.is_verified %}
<!-- Show the icon for subcommunities -->
{% if community.parent %}
<p class="ml-2 mb-0 display-inline-block"><i class="green check circle outline icon"></i></p>
{% endif %}
{% if community.parent %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,31 @@ export const DisplayPartOfCommunities = ({ communities }) => {
const PartOfCommunities = () => {
// FIXME: Uncomment to enable themed banner
// const communitiesEntries = communities.entries?.filter((community) => !(community.id === communities?.default && community?.theme));
const communitiesEntries = communities.entries;
let communitiesEntries = communities.entries;

if (communitiesEntries?.length > 0) {
communitiesEntries = communitiesEntries.sort((a, b) => {
// Put parent communities before other communities.
if (
a.children !== undefined &&
b.children !== undefined &&
a.children.allow !== b.children.allow
) {
return a.children.allow ? -1 : 1;
}
// Put subcommunities before regular communities.
if ((a.parent !== undefined) !== (b.parent !== undefined)) {
return a.parent !== undefined ? -1 : 1;
}
// Then sort communities by their title.
const titleCompare = a.metadata?.title.localeCompare(b.metadata?.title);
if (titleCompare !== undefined && titleCompare !== 0) {
return titleCompare;
}
// Finally if all else is equal, sort by slug (which is unique).
return a.slug.localeCompare(b.slug);
});

return (
<>
{i18next.t("Part of ")}
Expand All @@ -26,7 +48,8 @@ export const DisplayPartOfCommunities = ({ communities }) => {
{community.metadata?.title}
</a>
<span>&nbsp;</span>
{community.parent?.is_verified && (
{/* Show the icon for communities allowing children, and for subcommunities */}
{(community.children?.allow || community.parent !== undefined) && (
<Popup
trigger={<Icon name="check outline circle" color="green mr-0" />}
content="Verified community"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ export class RecordCommunitiesList extends Component {
<Item.Header className="ui">
<Header as="a" href={community.links.self_html} size="small">
{community.metadata.title}
{community.parent?.is_verified && (
{/* Show the icon for communities allowing children, and for subcommunities */}
{(community.children?.allow ||
community.parent !== undefined) && (
<p className="ml-5 display-inline-block">
<Popup
content="Verified community"
Expand Down

0 comments on commit 98e0479

Please sign in to comment.