fix dropdown selection problem

This commit is contained in:
prisar
2023-07-22 14:33:57 +05:30
parent a12dd7fd9c
commit 701d68f26b
3 changed files with 22 additions and 85 deletions

View File

@@ -22,20 +22,16 @@ const Devices = () => {
const changeDevice = ({ value }) => {
console.log(value);
// console.log(event);
setDevice(value);
setDays([...new Set(allTests
.filter((x) => {
if (x.deviceSerialNumber === device) return x;
if (x.deviceSerialNumber === value) return x;
})
.map(x => moment(x.testTime).format("YYYY-MM-DD")))]
.sort()
.reverse());
// setTests(allTests
// .filter((x) => {
// if (x.deviceSerialNumber === device && x.testTime === ) return x;
// })
// .map(x => x.testTime));
}
const changeTestDate = ({ value }) => {
@@ -45,7 +41,7 @@ const Devices = () => {
setShowGraph(false);
setTests(allTests
.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(value).startOf('day'), moment(value).endOf('day'))) return x;
})
.map(x => x._id)
.sort());
@@ -60,26 +56,28 @@ const Devices = () => {
}
useEffect(() => {
const q = query(collection(db, "testData"));
if (!allTests) {
const q = query(collection(db, "testData"));
const unsub = onSnapshot(q, (querySnapshot) => {
const testDevices = new Set();
const hposTests = [];
querySnapshot.forEach((document) => {
const hposTestData = document.data();
hposTests.push(hposTestData);
const { deviceSerialNumber } = hposTestData;
testDevices.add(deviceSerialNumber);
// console.log(document.data());
const unsub = onSnapshot(q, (querySnapshot) => {
const testDevices = new Set();
const hposTests = [];
querySnapshot.forEach((document) => {
const hposTestData = document.data();
hposTests.push(hposTestData);
const { deviceSerialNumber } = hposTestData;
testDevices.add(deviceSerialNumber);
// console.log(document.data());
});
const groups = [...testDevices];
// console.log(groups);
setDevices(groups);
setAllTests(hposTests);
});
const groups = [...testDevices];
// console.log(groups);
setDevices(groups);
setAllTests(hposTests);
});
return () => unsub;
}, [curTestData, curTest]);
return () => unsub;
}
}, [curTestData, curTest, device, testDate]);
return (
<div>