Skip to content

Commit

Permalink
Merge pull request #674 from SynBioHub/detailsbug
Browse files Browse the repository at this point in the history
fixed bug with details having html tags, fixed nesting issue and fixe…
  • Loading branch information
danielfang97 authored Jun 6, 2024
2 parents 530ea78 + a62c56a commit 6238315
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 24 deletions.
27 changes: 12 additions & 15 deletions frontend/components/Viewing/MetadataInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { isUriOwner, formatMultipleTitles } from './Shell';

const { publicRuntimeConfig } = getConfig();

export default function MetadataInfo({ title, link, label, icon, specific, uri, editable }) {
export default function MetadataInfo({ title, link, label, icon, specific, uri }) {
const theme = JSON.parse(localStorage.getItem('theme')) || {};
const [isHovered, setIsHovered] = useState(false);

Expand Down Expand Up @@ -263,8 +263,6 @@ export default function MetadataInfo({ title, link, label, icon, specific, uri,





// Rendered label with plus icon
const renderedLabel = (
<div className={styles.infolabel}>
Expand Down Expand Up @@ -311,13 +309,13 @@ export default function MetadataInfo({ title, link, label, icon, specific, uri,
}
const renderedTitle = (
<div className={styles.infotitle}>
<table>
<tbody>
<div>
<div>
{metadata.map((data, index) => {
let isEditingThisItem = false;
let currentValue = "";
let correspondingLink = (label === 'Source' || label === 'Type' || label === 'Role')
? (link && link.length > 0 && typeof link === 'object' ? link[index] : null)
? (link && link.length > 0 && typeof link === 'object' ? link[index] : (link ? link : null))
: link;
let processedSource = data;
if (typeof (data) === 'string' && data.match(urlRegex)) {
Expand All @@ -339,10 +337,9 @@ export default function MetadataInfo({ title, link, label, icon, specific, uri,
default:
break;
}

return (
<tr key={index}>
<td>
<div key={index}>
<div>
{isEditingThisItem ? (
<div>
<input
Expand All @@ -369,14 +366,14 @@ export default function MetadataInfo({ title, link, label, icon, specific, uri,
</div>
) : (
<a
href={correspondingLink ? correspondingLink : `http://localhost:3333/${processedSource}`}
href={correspondingLink ? correspondingLink : `/${processedSource}`}
target="_blank"
rel="noopener noreferrer"
>
{processedSource}
</a>
)}
</td><td>
</div><div>
{(label === "Source" || label === "Type" || label === "Role") && data && (
isEditingThisItem ? null : (
<div>
Expand All @@ -393,12 +390,12 @@ export default function MetadataInfo({ title, link, label, icon, specific, uri,
</div>
)
)}
</td>
</tr>
</div>
</div>
);
})}
</tbody>
</table>
</div>
</div>
</div>
);

Expand Down
16 changes: 10 additions & 6 deletions frontend/components/Viewing/PageJSON/Rendering/MetadataRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ export default function MetadataRenderer({ title, content, editable, uri }) {
const [sectionIcon, setSectionIcon] = useState(null);
const contentConsolidated = content.map((row, index) => {
return (
<RowWrapper
sections={row}
metadata={true}
setSectionIcon={setSectionIcon}
key={index}
/>
<table key={index}>
<tbody>
<RowWrapper
sections={row}
metadata={true}
setSectionIcon={setSectionIcon}
key={index}
/>
</tbody>
</table>
);
});
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ export default function RowWrapper({ sections, metadata, setSectionIcon }) {
<MiniLoading height={10} width={50} />
</td>
</tr>

);
}
return <tr>{content}</tr>;
Expand Down
15 changes: 13 additions & 2 deletions frontend/components/Viewing/Sections/Details/Section.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import styles from "../../../../styles/view.module.css";
import { faPencilAlt } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import React from "react";
import parse from "html-react-parser";

/**
* The section for each field in details.
Expand All @@ -11,6 +10,8 @@ import parse from "html-react-parser";
* @returns The name of the section and the content in it.
*/
export default function Section(properties) {
const sanitizedText = removeHtmlTags(properties.text);

return (
<React.Fragment>
{properties.owner && (
Expand All @@ -26,7 +27,17 @@ export default function Section(properties) {
/>
)}
<h4 className={styles.detailsheader}>{properties.title}</h4>
<p className={styles.detailstext}>{parse(properties.text)}</p>
<p className={styles.detailstext}>{sanitizedText}</p>
</React.Fragment>
);
}

/**
* Function to remove HTML tags from a string.
*
* @param {string} text The input text with potential HTML tags.
* @returns {string} The text with HTML tags removed.
*/
function removeHtmlTags(text) {
return text.replace(/<\/?[^>]+(>|$)/g, "");
}
2 changes: 1 addition & 1 deletion frontend/public/commitHash.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
438f4afa7b08703b5a5cddd52db3eecd50330620
530ea786424d2c7c88e0302a2930132f29c79883

0 comments on commit 6238315

Please sign in to comment.