Skip to content

Commit

Permalink
Merge pull request #27 from CLIMB-TRE/development
Browse files Browse the repository at this point in the history
'Export Record to JSON' button on `RecordDetail` modal
  • Loading branch information
tombch authored Jul 31, 2024
2 parents df1ec27 + 634e788 commit ac05253
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/Onyx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { OnyxProps, ProjectField } from "./types";
import "./Onyx.css";
import "./bootstrap.css";

const VERSION = "0.12.0";
const VERSION = "0.12.3";

function flattenFields(fields: Record<string, ProjectField>) {
const flatFields: Record<string, ProjectField> = {};
Expand Down
11 changes: 1 addition & 10 deletions lib/components/LoadingAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,7 @@ function DelayedLoadingAlert() {
return () => clearTimeout(timer);
});

return (
showAlert && (
<Alert variant="light">
<Stack direction="horizontal" gap={2}>
<Spinner />
<span>Loading...</span>
</Stack>
</Alert>
)
);
return showAlert && <LoadingAlert />;
}

export { LoadingAlert, DelayedLoadingAlert };
31 changes: 25 additions & 6 deletions lib/pages/Data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Button from "react-bootstrap/Button";
import Card from "react-bootstrap/Card";
import Pagination from "react-bootstrap/Pagination";
import Modal from "react-bootstrap/Modal";
import { mkConfig, generateCsv, download, asString } from "export-to-csv";
import { mkConfig, generateCsv, asString } from "export-to-csv";
import { useQuery } from "@tanstack/react-query";
import { MultiDropdown } from "../components/Dropdowns";
import Filter from "../components/Filter";
Expand Down Expand Up @@ -278,12 +278,12 @@ function Results(props: ResultsProps) {
});

const handleExportToCSV = () => {
const csv = generateCsv(csvConfig)(props.resultData.data || []);
const csvData = asString(
generateCsv(csvConfig)(props.resultData.data || [])
);

if (props.fileWriter) {
props.fileWriter(fileName + ".csv", asString(csv));
} else {
download(csvConfig)(csv);
props.fileWriter(fileName + ".csv", csvData);
}
};

Expand All @@ -294,6 +294,7 @@ function Results(props: ResultsProps) {
<Button
className="float-end"
size="sm"
disabled={!props.fileWriter}
variant="success"
onClick={handleExportToCSV}
>
Expand Down Expand Up @@ -373,6 +374,14 @@ function RecordDetail(props: RecordDetailProps) {
staleTime: 1 * 60 * 1000,
});

const handleExportToJSON = () => {
const jsonData = JSON.stringify(recordData.data || {});

if (props.fileWriter) {
props.fileWriter(props.recordID + ".json", jsonData);
}
};

return (
<Modal
className="onyx-record-detail"
Expand Down Expand Up @@ -401,13 +410,23 @@ function RecordDetail(props: RecordDetailProps) {
) : (
recordData.data && (
<Container fluid>
<Stack gap={3} direction="vertical">
<Stack gap={2} direction="vertical">
<h5>
Published Date:{" "}
<span className="onyx-text-pink">
{recordData.data["published_date"]}
</span>
<Button
className="float-end"
size="sm"
disabled={!props.fileWriter}
variant="success"
onClick={handleExportToJSON}
>
Export Record to JSON
</Button>
</h5>

<h5>
Site:{" "}
<span className="onyx-text-pink">
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "climb-onyx-gui",
"version": "0.12.0",
"version": "0.12.3",
"type": "module",
"main": "dist/climb-onyx-gui.js",
"types": "dist/main.d.ts",
Expand Down

0 comments on commit ac05253

Please sign in to comment.