Skip to content

Commit

Permalink
Handle no ?csv=file.csv with placeholder message
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed Mar 10, 2023
1 parent 106b166 commit 5f190e1
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ export default function App() {
const [tableData, setTableData] = React.useState([]);
const [tableColumns, setTableColumns] = React.useState([]);

const location = window.location.href;
let showPlaceholder = false;

// check for ?csv=url
const params = new URLSearchParams(location.search);
const params = new URLSearchParams(window.location.search);
let csvUrl = params.get("csv");
// columns=Version,Thumbnail etc from supportedColumns
let cols = params.get("columns");
Expand All @@ -40,24 +43,32 @@ export default function App() {
}
try {
new URL(csvUrl);

} catch (error) {
// If no valid URL provided, use default
csvUrl = zarr_samples_csv;
showPlaceholder = true;
}


React.useEffect(() => {

// load csv and use this for the left side of the table...
Papa.parse(csvUrl, {
header: true,
download: true,
complete: function (results) {
setTableData(results.data);
setTableColumns(results.meta.fields);
},
});
if (csvUrl) {
// load csv and use this for the left side of the table...
Papa.parse(csvUrl, {
header: true,
download: true,
complete: function (results) {
setTableData(results.data);
setTableColumns(results.meta.fields);
},
});
}
}, []);

if (showPlaceholder) {
return <p>
To display a table of Zarr data, load a CSV table with a URL column.
For example <a href={location + "?csv=" + zarr_samples_csv}>{location + "?csv=" + zarr_samples_csv}</a>
</p>
}
return <CatelogTable tableColumns={tableColumns} zarrColumns={zarrColumns} tableData={tableData} />
}

0 comments on commit 5f190e1

Please sign in to comment.