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 cd9c0dd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,27 @@ 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) {

Check failure on line 21 in invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/components/DisplayPartOfCommunities.js

View workflow job for this annotation

GitHub Actions / JS / Tests (18.x)

Replace `a.children·!==·undefined·&&·b.children·!==·undefined·&&·a.children.allow·!==·b.children.allow` with `⏎··········a.children·!==·undefined·&&⏎··········b.children·!==·undefined·&&⏎··········a.children.allow·!==·b.children.allow⏎········`

Check failure on line 21 in invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/components/DisplayPartOfCommunities.js

View workflow job for this annotation

GitHub Actions / JS / Tests (20.x)

Replace `a.children·!==·undefined·&&·b.children·!==·undefined·&&·a.children.allow·!==·b.children.allow` with `⏎··········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)) {

Check warning on line 25 in invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/components/DisplayPartOfCommunities.js

View workflow job for this annotation

GitHub Actions / JS / Tests (18.x)

Expected '!==' and instead saw '!='

Check warning on line 25 in invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/components/DisplayPartOfCommunities.js

View workflow job for this annotation

GitHub Actions / JS / Tests (20.x)

Expected '!==' and instead saw '!='
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 +44,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,8 @@ 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) && (

Check failure on line 71 in invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/landing_page/RecordCommunitiesList.js

View workflow job for this annotation

GitHub Actions / JS / Tests (18.x)

Insert `⏎·······················`

Check failure on line 71 in invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/landing_page/RecordCommunitiesList.js

View workflow job for this annotation

GitHub Actions / JS / Tests (20.x)

Insert `⏎·······················`
<p className="ml-5 display-inline-block">
<Popup
content="Verified community"
Expand Down

0 comments on commit cd9c0dd

Please sign in to comment.