From 47e881827f8686f254e5dda3b2652161eaf5cb99 Mon Sep 17 00:00:00 2001 From: Maarten Lopes Date: Wed, 26 Jun 2024 16:16:04 -0400 Subject: [PATCH] Populated the preview panel with data about the selected GBIF occurrence --- .../science-info/_components/PreviewPanel.tsx | 71 +++++++++++-------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/strudel_ex/gbif-app/src/pages/science-info/_components/PreviewPanel.tsx b/strudel_ex/gbif-app/src/pages/science-info/_components/PreviewPanel.tsx index cebdc320..3029da6a 100644 --- a/strudel_ex/gbif-app/src/pages/science-info/_components/PreviewPanel.tsx +++ b/strudel_ex/gbif-app/src/pages/science-info/_components/PreviewPanel.tsx @@ -1,9 +1,9 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; import { Box, Button, IconButton, Link, Paper, Stack, Typography } from '@mui/material'; import CloseIcon from '@mui/icons-material/Close'; import { Link as RouterLink } from 'react-router-dom'; import { LabelValueTable } from '../../../components/LabelValueTable'; -import { DataGrid } from '@mui/x-data-grid'; +import { DataGrid, GridColDef } from '@mui/x-data-grid'; import { useExploreData } from '../_context/ContextProvider'; interface PreviewPanelProps { @@ -15,7 +15,21 @@ interface PreviewPanelProps { * next to the ``. */ export const PreviewPanel: React.FC = (props) => { - const {state, dispatch} = useExploreData(); + const { state } = useExploreData(); // Assuming useExploreData provides state + const [relatedRows, setRelatedRows] = useState([]); + + useEffect(() => { + if (state.previewItem) { + const emptyRows = Array(1).fill(0); + const rows = emptyRows.map((_, i) => ({ + id: i, + family: state.previewItem['family'], + species: state.previewItem['species'], + kingdom: state.previewItem['kingdom'], + })); + setRelatedRows(rows); + } + }, [state.previewItem]); // Re-run effect when state.previewItem changes /** * Content to render on the page for this component @@ -38,24 +52,31 @@ export const PreviewPanel: React.FC = (props) => { - Row description, subtitle, or helper text. + + Common Name & Year of Discovery + + - Property Group 1 + Parallels - Property Group 2 + Time and Place @@ -63,11 +84,9 @@ export const PreviewPanel: React.FC = (props) => { Related Data @@ -88,33 +107,27 @@ export const PreviewPanel: React.FC = (props) => { /** * Placeholder columns for related data table */ -const relatedColumns = [ +const relatedColumns: GridColDef[] = [ { field: 'id', headerName: 'ID', width: 50 }, { - field: 'attr1', - headerName: 'Attribute 1', + field: 'family', + headerName: 'Family', width: 100 }, { - field: 'attr2', - headerName: 'Attribute 2', + field: 'species', + headerName: 'Species', width: 100 }, { - field: 'attr3', - headerName: 'Attribute 3', + field: 'kingdom', + headerName: 'Kingdom', width: 100 }, ]; -/** - * Placeholder rows for related data table - */ -const emptyRows = Array(25).fill(0); -const relatedRows = emptyRows.map((d, i) => { - return { id: i, attr1: 'value', attr2: 'value', attr3: 'value'} -}); \ No newline at end of file +export default PreviewPanel;