Skip to content

Commit 4a9f5f2

Browse files
committed
Added external links component
1 parent b3b57a1 commit 4a9f5f2

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React, { useEffect, useState } from 'react';
2+
import DocumentListItem from '../lib_components/components/Documents/DocumentListItem';
3+
4+
export default function BiorepoCollectionPageContent() {
5+
const [filteredSpecs, setFilteredSpecs] = useState([]);
6+
7+
useEffect(() => {
8+
// Get the list of product IDs from the global JavaScript variable
9+
const productIds = window.BiorepoCollectionData ? JSON.parse(window.BiorepoCollectionData) : [];
10+
11+
if (productIds.length === 0) return;
12+
13+
// Fetch specs for each product ID
14+
const fetchSpecs = async () => {
15+
try {
16+
const responses = await Promise.all(
17+
productIds.map((productId) => fetch(`https://data.neonscience.org/api/v0/products/${productId}`).then((res) => res.json())),
18+
);
19+
20+
// Extract and filter specs based on "Protocol" in specDescription
21+
const allFilteredSpecs = responses.flatMap((response) => response.data?.specs?.filter((spec) => spec.specDescription.includes('Protocol and Procedure')) || []);
22+
23+
setFilteredSpecs(allFilteredSpecs);
24+
} catch (error) {
25+
console.error('Error fetching product specs:', error);
26+
}
27+
};
28+
29+
fetchSpecs();
30+
}, []);
31+
32+
return (
33+
<div>
34+
{filteredSpecs.length > 0 ? (
35+
filteredSpecs.map((spec, index) => (
36+
<DocumentListItem
37+
key={spec.specId || index}
38+
document={{
39+
name: spec.specNumber, // Document name
40+
type: spec.specType || 'application/pdf', // Default to PDF
41+
size: spec.specSize || 0, // Default size
42+
description: spec.specDescription, // Description
43+
}}
44+
containerComponent="div"
45+
enableDownloadButton
46+
/>
47+
))
48+
) : (
49+
<p></p>
50+
)}
51+
</div>
52+
);
53+
}

src/index.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import BiorepoGuidelinesContent from './biorepo_components/BiorepoGuidelinesCont
2323
import BiorepoAboutSamplesContent from './biorepo_components/BiorepoAboutSamplesContent';
2424
import BiorepoCollectionsContent from './biorepo_components/BiorepoCollectionsContent';
2525
import BiorepoChecklistsContent from './biorepo_components/BiorepoChecklistsContent';
26+
import BiorepoCollectionPageContent from './biorepo_components/BiorepoCollectionPageContent';
2627

2728
ReactDOM.render(<BiorepoPage />, document.getElementById('biorepo-page'));
2829

@@ -50,3 +51,8 @@ const biorepoChecklistsElement = document.getElementById('biorepo-checklists-con
5051
if (biorepoChecklistsElement) {
5152
ReactDOM.render(<BiorepoChecklistsContent />, biorepoChecklistsElement);
5253
}
54+
55+
const biorepoCollectionPageElement = document.getElementById('biorepo-collection-page-content');
56+
if (biorepoCollectionPageElement) {
57+
ReactDOM.render(<BiorepoCollectionPageContent />, biorepoCollectionPageElement);
58+
}

0 commit comments

Comments
 (0)