From c385ca4b8ef6b6a7ef3d6dd69511780cc3f9fbc0 Mon Sep 17 00:00:00 2001 From: William Moore Date: Thu, 16 Feb 2023 08:02:39 +0000 Subject: [PATCH] Refactor to create CatelogTable.jsx --- src/App.jsx | 59 ++++++-------------------------------------- src/CatelogTable.jsx | 52 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 51 deletions(-) create mode 100644 src/CatelogTable.jsx diff --git a/src/App.jsx b/src/App.jsx index 14e574d..64f300f 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -3,8 +3,7 @@ import React from "react"; import Papa from "papaparse"; -import ImageItem from "./ImageItem"; -import ZarrUrl from "./ZarrUrl"; +import CatelogTable from "./CatelogTable"; const supportedColumns = [ "Version", @@ -26,29 +25,28 @@ export default function App() { const [tableData, setTableData] = React.useState([]); const [tableColumns, setTableColumns] = React.useState([]); - // check for ?csv=url const params = new URLSearchParams(location.search); let csvUrl = params.get("csv"); - // columns=Version,Axes,shape,chunks,Wells,Fields,Keywords,Thumbnail, + // columns=Version,Thumbnail etc from supportedColumns let cols = params.get("columns"); - console.log("cols", cols); - let zarr_columns = []; + let zarrColumns = []; if (cols) { - zarr_columns = cols.split(",").filter(col => supportedColumns.includes(col)); + zarrColumns = cols.split(",").filter(col => supportedColumns.includes(col)); } else { - zarr_columns = defaultColumns; + zarrColumns = defaultColumns; } - console.log("zarr_columsn", zarr_columns) try { new URL(csvUrl); } catch (error) { + // If no valid URL provided, use default csvUrl = "/zarr_samples.csv"; } React.useEffect(() => { + // load csv and use this for the left side of the table... Papa.parse(csvUrl, { header: true, download: true, @@ -59,46 +57,5 @@ export default function App() { }); }, []); - - function renderRow(rowdata) { - return - {tableColumns.map((col_name) => { - if (col_name == "URL") { - return - } else { - return {rowdata[col_name]} - } - })} - - } - - const validRows = tableData.filter(rowdata => rowdata.URL?.length > 0); - - const table_rows = validRows.map((rowdata) => { - // Each row is a combination of custom table data and NGFF Image data - return ( - {renderRow(rowdata)} - - - ); - }); - - return ( - - - - {tableColumns.map((name) => ( - - ))} - {zarr_columns.map((name) => ( - - ))} - - {table_rows} - -
{name}{name}
- ); + return } diff --git a/src/CatelogTable.jsx b/src/CatelogTable.jsx new file mode 100644 index 0000000..142cccb --- /dev/null +++ b/src/CatelogTable.jsx @@ -0,0 +1,52 @@ + +import React from "react"; + +import ImageItem from "./ImageItem"; +import ZarrUrl from "./ZarrUrl"; + + +export default function CatelogTable({tableColumns, tableData, zarrColumns}) { + + function renderRow(rowdata) { + return + {tableColumns.map((col_name) => { + if (col_name == "URL") { + return + } else { + return {rowdata[col_name]} + } + })} + + } + + // ignore any row without a "URL" field + const validRows = tableData.filter(rowdata => rowdata.URL?.length > 0); + + const table_rows = validRows.map((rowdata) => { + // Each row is a combination of custom csv data and NGFF Image data + return ( + {renderRow(rowdata)} + + + ); + }); + + return ( + + + + {tableColumns.map((name) => ( + + ))} + {zarrColumns.map((name) => ( + + ))} + + {table_rows} + +
{name}{name}
+ ); +}