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

resultList: add extra information #341

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// This file is part of CDS RDM
// Copyright (C) 2025 CERN.
//
// CDS RDM is free software; you can redistribute it and/or modify it
// under the terms of the MIT License; see LICENSE file for more details.

import _get from "lodash/get";
import PropTypes from "prop-types";
import React from "react";
import { Item } from "semantic-ui-react";

export const CDSRecordsResultsListItemDescription = ({ result, descriptionStripped }) => {
const getMetadataField = (path) => _get(result, path, []);

const cdsReferenceId = getMetadataField("metadata.identifiers")
.find((id) => id.scheme === "cds_ref")?.identifier;

const experiments = getMetadataField("custom_fields.cern:experiments").map((exp) => exp.title.en);
const accelerators = getMetadataField("custom_fields.cern:accelerators").map((acc) => acc.title.en);

const hasMetaData = cdsReferenceId || accelerators.length > 0 || experiments.length > 0;
const referenceOrAccelerators = cdsReferenceId || accelerators.length > 0;
return (
<div>
Copy link
Contributor

@kpsherva kpsherva Jan 31, 2025

Choose a reason for hiding this comment

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

Suggested change
<div>
</>

<div> can be a problem for semantic styles

<Item.Description className="truncate-lines-2">{descriptionStripped}</Item.Description>

{hasMetaData && (
<Item.Meta className="pt-20">
{cdsReferenceId && <span className="mr-5">{cdsReferenceId}</span>}
{accelerators.length > 0 && (
<>
{cdsReferenceId && <span className="ml- mr-5">|</span>}
<span className={cdsReferenceId ? "ml-5 mr-5" : "mr-5"}>Accelerators: {accelerators.join(", ")}</span>
</>
)}
{experiments.length > 0 && (
<>
{referenceOrAccelerators && <span className="ml-5 mr-5">|</span>}
<span className={referenceOrAccelerators ? "ml-5 mr-5" : "mr-5"}>Experiments: {experiments.join(", ")}</span>
</>
)}
</Item.Meta>
)}
</div>
);
};

CDSRecordsResultsListItemDescription.propTypes = {
result: PropTypes.object.isRequired,
descriptionStripped: PropTypes.string.isRequired,
};
3 changes: 2 additions & 1 deletion assets/js/invenio_app_rdm/overridableRegistry/mapping.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BasicCERNInformation } from "../../components/deposit/BasicInformation";
import { CDSCarouselItem } from "../../components/communities_carousel/overrides/CarouselItem";
import { CDSCommunitiesCarousel } from "../../components/communities_carousel/overrides/CommunitiesCarousel";
import { CDSRecordsList } from "../../components/frontpage/overrides/RecordsList";
import { CDSRecordsResultsListItem } from "../../components/frontpage/overrides/RecordsResultsListItem";
import { CDSRecordsResultsListItemDescription } from "../../components/search/overrides/CDSRecordsResultsListItemDescription";
import { CDSAffiliationsSuggestions } from "../../components/deposit/overrides/CDSAffiliationsSuggestions";

export const overriddenComponents = {
Expand All @@ -15,4 +15,5 @@ export const overriddenComponents = {
"InvenioAppRdm.Deposit.CustomFields.container": () => null,
"ReactInvenioForms.AffiliationsSuggestions.content":
CDSAffiliationsSuggestions,
"InvenioAppRdm.Search.RecordsResultsListItem.description": CDSRecordsResultsListItemDescription,
};
Loading