-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLabResults.tsx
More file actions
100 lines (88 loc) · 3.78 KB
/
Copy pathLabResults.tsx
File metadata and controls
100 lines (88 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import React, { useMemo, useState } from "react";
import { useQuery } from "@tanstack/react-query";
import { getLabResults } from "@/api/api";
import { syntheticResults } from "@/assets/syntheticResults";
import { Card, Typography } from "@equinor/eds-core-react";
import LabResultsPlot from "@/components/LabResultsPlot";
import LabResultsTable from "@/components/LabResultsTable";
import { ExperimentResult } from "@/dto/ExperimentResult.tsx";
import { useSimulationQueries } from "@/hooks/useSimulationQueriesResult.ts";
import DownloadButton from "@/components/DownloadButton.tsx";
import LabResultSimulationRunsStatus from "@/components/LabResultSimulationRunsStatus.tsx";
import {
convertExperimentResultsToTabulatedData,
convertSimulationQueriesResultToTabulatedData,
convertTabulatedDataToCSVFormat,
} from "@/functions/Formatting";
const LabResults: React.FC = () => {
const [selectedExperiments, setSelectedExperiments] = useState<ExperimentResult[]>([]);
const {
data: labResults = syntheticResults,
error,
isLoading,
} = useQuery({
queryKey: ["results"],
queryFn: () => getLabResults(),
retry: false,
});
const selectedExperimentData = useMemo(
() => labResults.filter((result) => selectedExperiments.some((exp) => exp.name === result.name)),
[labResults, selectedExperiments]
);
const simulationQueryResults = useSimulationQueries(selectedExperiments);
if (isLoading) return <>Fetching results ...</>;
let issueRetrievingDataInfo = null;
if (error) {
issueRetrievingDataInfo = (
<Card variant="warning" style={{ margin: "2rem 0" }}>
<Card.Header>
<Card.HeaderTitle>
<Typography variant="h5">Error fetching data from Oasis</Typography>
</Card.HeaderTitle>
</Card.Header>
<Card.Content>
<Typography variant="body_short_bold">{error.message}</Typography>
<Typography variant="body_short">Using synthetic demo data</Typography>
</Card.Content>
</Card>
);
}
return (
<>
<Typography variant="h1">Lab results</Typography>
{issueRetrievingDataInfo}
<LabResultSimulationRunsStatus simulationStatuses={simulationQueryResults.statuses} />
<LabResultsPlot
selectedExperiments={selectedExperiments}
simulationsPerExperiment={simulationQueryResults.data}
/>
{selectedExperiments.length > 0 && (
<div
style={{
display: "flex",
justifyContent: "flex-end",
marginTop: "1rem",
marginBottom: "2rem",
}}
>
<DownloadButton
csvContent={convertTabulatedDataToCSVFormat([
...convertSimulationQueriesResultToTabulatedData(simulationQueryResults.data),
...convertExperimentResultsToTabulatedData(selectedExperiments),
])}
fileName={`AcidWatch-LabResults-${new Date().toISOString().replace(/[:.]/g, "-")}.csv`}
isLoading={
isLoading || simulationQueryResults.statuses.some((status) => status.status === "pending")
}
/>
</div>
)}
<LabResultsTable
labResults={labResults}
selectedExperiments={selectedExperimentData}
setSelectedExperiments={setSelectedExperiments}
/>
</>
);
};
export default LabResults;