add sorting in date and test dropdowns

This commit is contained in:
prisar
2023-07-22 13:51:20 +05:30
parent 93208b00c8
commit a12dd7fd9c
5 changed files with 22 additions and 16 deletions

View File

@@ -8,7 +8,7 @@ import './DeviceGraph.css';
class AbsorbanceGraph extends Component { class AbsorbanceGraph extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { url: this.props.url }; this.state = { url: this.props.url, show: this.props.show };
} }
componentDidMount() { componentDidMount() {
this.drawChart(this.props.url); this.drawChart(this.props.url);

View File

@@ -7,7 +7,7 @@ import './DeviceGraph.css';
import AbsorbanceGraph from './AbsorbanceGraph'; import AbsorbanceGraph from './AbsorbanceGraph';
import db from '../firebase'; import db from '../firebase';
function DeviceGraph({url}) { function DeviceGraph({url, show}) {
const [devices, setDevices] = useState([]); const [devices, setDevices] = useState([]);
const [hposTests, setHposTests] = useState(null); const [hposTests, setHposTests] = useState(null);
@@ -63,7 +63,7 @@ function DeviceGraph({url}) {
return ( return (
<div> <div>
<AbsorbanceGraph url={url} /> <AbsorbanceGraph url={url} show={show} />
</div> </div>
); );
} }

View File

@@ -36,8 +36,8 @@
/* display: flex; */ /* display: flex; */
padding: 15px; padding: 15px;
margin: 15px 0 10px 0; margin: 15px 0 10px 0;
font-weight: 600; /* font-weight: 600; */
font-size: larger; font-size: small;
background-color: white; background-color: white;
} }
@@ -55,7 +55,7 @@
.clear-button { .clear-button {
background-color: aquamarine; background-color: aquamarine;
width: 5vw; width: 3vw;
height: 5vh; height: 5vh;
margin: 5px; margin: 5px;
border-radius: 50%; border-radius: 50%;

View File

@@ -18,6 +18,7 @@ const Devices = () => {
const [days, setDays] = useState([]); const [days, setDays] = useState([]);
const [tests, setTests] = useState([]); const [tests, setTests] = useState([]);
const [allTests, setAllTests] = useState(null); const [allTests, setAllTests] = useState(null);
const [showGraph, setShowGraph] = useState(false);
const changeDevice = ({ value }) => { const changeDevice = ({ value }) => {
console.log(value); console.log(value);
@@ -27,7 +28,9 @@ const Devices = () => {
.filter((x) => { .filter((x) => {
if (x.deviceSerialNumber === device) return x; if (x.deviceSerialNumber === device) return x;
}) })
.map(x => moment(x.testTime).format("YYYY-MM-DD")))]); .map(x => moment(x.testTime).format("YYYY-MM-DD")))]
.sort()
.reverse());
// setTests(allTests // setTests(allTests
// .filter((x) => { // .filter((x) => {
// if (x.deviceSerialNumber === device && x.testTime === ) return x; // if (x.deviceSerialNumber === device && x.testTime === ) return x;
@@ -39,18 +42,21 @@ const Devices = () => {
setTestDate(value); setTestDate(value);
setCurTest(null); setCurTest(null);
setCurTestData(null); setCurTestData(null);
setShowGraph(false);
setTests(allTests setTests(allTests
.filter((x) => { .filter((x) => {
if (x.deviceSerialNumber === device && moment(x.testTime).isBetween(moment(testDate).startOf('day'), moment(testDate).endOf('day'))) return x; if (x.deviceSerialNumber === device && moment(x.testTime).isBetween(moment(testDate).startOf('day'), moment(testDate).endOf('day'))) return x;
}) })
.map(x => x._id)); .map(x => x._id)
.sort());
} }
const changeTest = ({ value }) => { const changeTest = ({ value }) => {
setCurTest(null); setCurTestData(null); setCurTest(null); setCurTestData(null); setShowGraph(false);
if (curTest) alert('Click clear button first'); if (curTest) alert('Click clear button first');
setCurTest(value); setCurTest(value);
setCurTestData(allTests.find(x => x._id === value)); setCurTestData(allTests.find(x => x._id === value));
setShowGraph(true);
} }
useEffect(() => { useEffect(() => {
@@ -79,15 +85,15 @@ const Devices = () => {
<div> <div>
<div className='title'>Insights</div> <div className='title'>Insights</div>
<div className='dropdown-group'> <div className='dropdown-group'>
<Dropdown className='device-dropdown' options={devices} onChange={changeDevice} value={device} placeholder="Select an option" /> <Dropdown className='device-dropdown' options={devices} onChange={changeDevice} value={device} placeholder="Select an device" />
<Dropdown className='day-dropdown' options={days} onChange={changeTestDate} value={testDate} placeholder="Select an option" /> <Dropdown className='day-dropdown' options={days} onChange={changeTestDate} value={testDate} placeholder="Select an test date" />
<Dropdown className='test-dropdown' options={tests} onChange={changeTest} value={curTest} placeholder="Select an option" /> <Dropdown className='test-dropdown' options={tests} onChange={changeTest} value={curTest} placeholder="Select an test" />
<button className='clear-button' onClick={() => { setCurTest(null); setCurTestData(null); }}>Clear</button> <button className='clear-button' onClick={() => { setCurTest(null); setCurTestData(null); }}>Clear</button>
</div> </div>
<div className='graph-person-conatiner'> <div className='graph-person-conatiner'>
{!curTestData && <div className='refresh-graph-message'>Select test device, date and person to get the detailed graph. Then, refresh or click clear button to render another entry.</div>} {!curTestData && <div className='refresh-graph-message'>Select test device, date and person to get the detailed graph. Then, refresh or click clear button to render another entry.</div>}
{curTestData?.csvPath && <DeviceGraph url={curTestData?.csvPath} />} {curTestData?.csvPath && <DeviceGraph url={curTestData?.csvPath} show={showGraph} />}
{curTestData && <div className='person-details'> {curTestData && <div className='person-details'>
<table> <table>
@@ -96,10 +102,10 @@ const Devices = () => {
<th>value</th> <th>value</th>
</tr> </tr>
<tr> <tr>
<td>deviceid</td> <td>{curTestData?.deviceId}</td> <td>device</td> <td>{curTestData?.deviceId}</td>
</tr> </tr>
<tr> <tr>
<td>kit serial</td> <td>{curTestData?.kitSerial}</td> <td>kit</td> <td>{curTestData?.kitSerial}</td>
</tr> </tr>
<tr> <tr>
<td>test time</td> <td>{curTestData?.testTime}</td> <td>test time</td> <td>{curTestData?.testTime}</td>

View File

@@ -19,7 +19,7 @@ const router = createBrowserRouter([
element: <Devices />, element: <Devices />,
}, },
{ {
path: "/inshights", path: "/insights",
element: <Devices />, element: <Devices />,
} }
]); ]);