diff --git a/.env b/.env index b1fcb1d..bd87f0d 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -# VITE_REACT_APP_BACKEND_URL="https://sandbox.exampaper.vidh.ai" -# VTE_REACT_APP_BACKEND_URL="http://localhost:9999"I +#VITE_REACT_APP_BACKEND_URL="https://sandbox.exampaper.vidh.ai" METABASE_BASE_URL="http://metabase.usln.in/public/question/d8774923-09bb-4cd9-903b-559d417e12cf" VITE_REACT_APP_BACKEND_URL="https://api.exampaper.vidh.ai" +# VITE_REACT_APP_BACKEND_URL="http://localhost:9999" diff --git a/src/Components/AnomolyPartC.jsx b/src/Components/AnomolyPartC.jsx index 9ab21e2..4ae9b4b 100644 --- a/src/Components/AnomolyPartC.jsx +++ b/src/Components/AnomolyPartC.jsx @@ -1,332 +1,404 @@ -import React, { useEffect, useState } from 'react'; -import { Box, Button, Card, CardContent, Typography, CircularProgress } from '@mui/material'; -import { Layout, theme, Pagination } from 'antd'; +import React, { useEffect, useState } from "react"; +import { + Box, + Button, + Card, + CardContent, + Typography, + CircularProgress, +} from "@mui/material"; +import { Layout, theme, Pagination } from "antd"; import { useNavigate } from "react-router-dom"; import ArrowBackIcon from "@mui/icons-material/ArrowBack"; import HomeIcon from "@mui/icons-material/Home"; -import QueryExecutorCard from './QueryExecutorCard'; -import { updatePartCErrorList, updatePartCErrorData, updateSelectedError, updateSelectedJson } from '../redux/actions/actions'; -import { useSelector, useDispatch } from 'react-redux'; -import SystemNumberDialog from './SystemNumberDialog'; +import QueryExecutorCard from "./QueryExecutorCard"; +import { + updatePartCErrorList, + updatePartCErrorData, + updateSelectedError, + updateSelectedJson, +} from "../redux/actions/actions"; +import { useSelector, useDispatch } from "react-redux"; +import SystemNumberDialog from "./SystemNumberDialog"; +import InputLabel from "@mui/material/InputLabel"; +import MenuItem from "@mui/material/MenuItem"; +import FormControl from "@mui/material/FormControl"; +import Select from "@mui/material/Select"; const { Content, Header } = Layout; function AnomalyPartC() { - const [isLoading, setIsLoading] = useState(false); - const [isLoading2, setIsLoading2] = useState(false); - const [anomalyData, setAnomalyData] = useState(null); - const [evErrors, setEvErrors] = useState([]); - const [error, setError] = useState(null); - const [errorReason, setErrorReason] = useState(null); - const [currentPage, setCurrentPage] = useState(1); - const [totalPages, setTotalPages] = useState(1); - const [showSystemNoContainer, setShowSystemNoContainer] = useState(false); - const [selectedIndex, setSelectedIndex] = useState(null); + const [isLoading, setIsLoading] = useState(false); + const [isLoading2, setIsLoading2] = useState(false); + const [anomalyData, setAnomalyData] = useState(null); + const [evErrors, setEvErrors] = useState([]); + const [error, setError] = useState(null); + const [errorReason, setErrorReason] = useState(null); + const [currentPage, setCurrentPage] = useState(1); + const [totalPages, setTotalPages] = useState(1); + const [showSystemNoContainer, setShowSystemNoContainer] = useState(false); + const [selectedIndex, setSelectedIndex] = useState(null); + const [selectedDegreeType, setSelectedDegreeType] = useState("0"); + const degreeTypes = [ + { type: "UG", type_code: "0" }, + { type: "PG", type_code: "2" }, + ]; - const { - token: { colorBgContainer, borderRadiusLG }, - } = theme.useToken(); - const navigate = useNavigate(); - const dispatch = useDispatch(); - const evErrorsList = useSelector((state) => state?.partCErrorList); - console.log("evErrorsList = ", evErrorsList) + const handleDegreeTypeChange = (e) => { + console.log("Value ===== ", e.target.value); + setSelectedDegreeType(e.target.value); + }; + const { + token: { colorBgContainer, borderRadiusLG }, + } = theme.useToken(); + const navigate = useNavigate(); + const dispatch = useDispatch(); + const evErrorsList = useSelector((state) => state?.partCErrorList); + console.log("evErrorsList = ", evErrorsList); - const evErrorsData = useSelector((state) => state?.partCErrorData); - console.log("evErrorData: ", evErrorsData) + const evErrorsData = useSelector((state) => state?.partCErrorData); + console.log("evErrorData: ", evErrorsData); - const reduxSystemNo = useSelector((state) => state?.systemNumber); - console.log("systemno: ", reduxSystemNo) + const reduxSystemNo = useSelector((state) => state?.systemNumber); + console.log("systemno: ", reduxSystemNo); - // const selectedError = useSelector((state) => state?.selectedError); - // console.log("selectedError: ", selectedError) + // const selectedError = useSelector((state) => state?.selectedError); + // console.log("selectedError: ", selectedError) - // const selectedErrorData = useSelector((state) => state?.selectedErrorData); - // console.log("selectedErrorData: ", selectedErrorData) + // const selectedErrorData = useSelector((state) => state?.selectedErrorData); + // console.log("selectedErrorData: ", selectedErrorData) - const selectedErrorJson = useSelector((state) => state?.selectedErrorJson); - console.log("selectedErrorJson: ", selectedErrorJson) + const selectedErrorJson = useSelector((state) => state?.selectedErrorJson); + console.log("selectedErrorJson: ", selectedErrorJson); - - - useEffect(() => { - if(!reduxSystemNo){ - setShowSystemNoContainer(true) - }else{ - if(evErrorsList.length > 0){ - setAnomalyData(evErrorsList) - }else{ - fetchAnomalyData(); - } - } - - }, [reduxSystemNo]); - - useEffect(() => { - if(!reduxSystemNo){ - setShowSystemNoContainer(true) - }else{ - if( evErrorsData.length>0){ - setEvErrors(evErrorsData) - } - if (error && errorReason) { - fetchAnomalyRecords(reduxSystemNo); - } - } - - }, [error, errorReason]); - - useEffect(() => { - if (evErrors && evErrors.length > 0) { - console.log("len = ", evErrors.length) - const tp = Math.ceil(evErrors.length / 10); - console.log("tp = ", tp) - setTotalPages(tp); - } - }, [evErrors]); - - const updateSystemReservationStatus = async (systemRecords) => { - const payload = { - systemRecords, - sysNo:reduxSystemNo - }; - try { - fetch( - `${ - import.meta.env.VITE_REACT_APP_BACKEND_URL - }/updateSystemReservationStatusPartC`, - { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(payload), - } - ) - .then((response) => response.json()) - .then((responseData) => { - console.log("response from updation : ", responseData); - }); - } catch (error) { - throw new Error("Error in update system records : ", systemRecords); - } - }; - - const fetchAnomalyData = async () => { - setIsLoading(true); - try { - const response = await fetch( - `${import.meta.env.VITE_REACT_APP_BACKEND_URL}/getpartcEv`, - { - method: "GET", - headers: { - "Content-Type": "application/json", - }, - } - ); - const responseData = await response.json(); - setAnomalyData(responseData.data); - dispatch(updatePartCErrorList(responseData.data)) - - } catch (error) { - console.error("Error fetching data: ", error); - } finally { - setIsLoading(false); - } - }; - - const fetchAnomalyRecords = async (reduxSystemNo) => { - setIsLoading(true); - try { - const response = await fetch( - `${import.meta.env.VITE_REACT_APP_BACKEND_URL}/getpartcEvErrors`, - { - method: "POST", - body: JSON.stringify({ - error, - error_reason: errorReason, - sysno: reduxSystemNo - }), - headers: { - "Content-Type": "application/json", - }, - } - ); - const responseData = await response.json(); - var systemRecords = responseData?.data - console.log("System record ====== ",responseData.systemRecord) - if(!responseData.systemRecord){ - systemRecords = getRecordsBySystemId( - responseData?.data, - reduxSystemNo - ); - } - updateSystemReservationStatus(systemRecords); - console.log("System records : ", systemRecords); - - setEvErrors(systemRecords); - dispatch(updatePartCErrorData(systemRecords)) - } catch (error) { - console.error("Error fetching data: ", error); - } finally { - setIsLoading(false); - } - }; - - function getRecordsBySystemId(records, systemId) { - const new_data = []; - for (var i = 0; i < records.length; i++) { - var count = i % 5; - if (count === systemId - 1) { - new_data.push(records[i]); - } - } - return new_data; + useEffect(() => { + if (!reduxSystemNo) { + setShowSystemNoContainer(true); + } else { + if (evErrorsList.length > 0) { + setAnomalyData(evErrorsList); + } else { + fetchAnomalyData(); } + } + }, [reduxSystemNo]); - const handleClick = (error, errorReason, index) => { - setError(error); - setErrorReason(errorReason); - setCurrentPage(1); - setSelectedIndex(index); - let tmp = {} - tmp["error"] = error - tmp["error_reason"] = errorReason - console.log("tmp = ", tmp) - dispatch(updateSelectedJson(tmp)) + useEffect(() => { + if (!reduxSystemNo) { + setShowSystemNoContainer(true); + } else { + if (evErrorsData.length > 0) { + setEvErrors(evErrorsData); + } + if (error && errorReason) { + fetchAnomalyRecords(reduxSystemNo); + } + } + }, [error, errorReason]); + + useEffect(() => { + if (evErrors && evErrors.length > 0) { + console.log("len = ", evErrors.length); + const tp = Math.ceil(evErrors.length / 10); + console.log("tp = ", tp); + setTotalPages(tp); + } + }, [evErrors]); + + useEffect(() => { + dispatch(updatePartCErrorData([])); + setAnomalyData([]); + setEvErrors([]); + fetchAnomalyData(); + }, [selectedDegreeType]); + + const updateSystemReservationStatus = async (systemRecords) => { + const payload = { + systemRecords, + sysNo: reduxSystemNo, }; - - const handlePageChange = (page) => { - setIsLoading2(true); - setCurrentPage(page); - }; - - useEffect(() => { - if (currentPage > 0) { - setIsLoading2(false); + try { + fetch( + `${ + import.meta.env.VITE_REACT_APP_BACKEND_URL + }/updateSystemReservationStatusPartC`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(payload), } - }, [currentPage, evErrors]); + ) + .then((response) => response.json()) + .then((responseData) => { + console.log("response from updation : ", responseData); + }); + } catch (error) { + throw new Error("Error in update system records : ", systemRecords); + } + }; - const getCurrentPageData = () => { - const startIndex = (currentPage - 1) * 10; - const endIndex = startIndex + 10; - return evErrors.slice(startIndex, endIndex); - }; + const fetchAnomalyData = async () => { + setIsLoading(true); + try { + const response = await fetch( + `${ + import.meta.env.VITE_REACT_APP_BACKEND_URL + }/getpartcEv?degreeType=${selectedDegreeType}`, + { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + } + ); + const responseData = await response.json(); + setAnomalyData(responseData.data); + dispatch(updatePartCErrorList(responseData.data)); + } catch (error) { + console.error("Error fetching data: ", error); + } finally { + setIsLoading(false); + } + }; - const handleSystemNoChange = () => { - console.log("System No Change is called"); - setShowSystemNoContainer(true); - dispatch(updateSelectedJson({})) - // dispatch(updatePartCErrorList([])) - dispatch(updatePartCErrorData([])) + const fetchAnomalyRecords = async (reduxSystemNo) => { + setIsLoading(true); + try { + const response = await fetch( + `${import.meta.env.VITE_REACT_APP_BACKEND_URL}/getpartcEvErrors`, + { + method: "POST", + body: JSON.stringify({ + error, + error_reason: errorReason, + sysno: reduxSystemNo, + degreeType: selectedDegreeType, + }), + headers: { + "Content-Type": "application/json", + }, + } + ); + const responseData = await response.json(); + var systemRecords = responseData?.data; + console.log("System record ====== ", responseData.systemRecord); + if (!responseData.systemRecord) { + systemRecords = getRecordsBySystemId(responseData?.data, reduxSystemNo); + } + console.log("System records : ", systemRecords); - }; + setEvErrors(systemRecords); + setIsLoading(false); + dispatch(updatePartCErrorData(systemRecords)); + + updateSystemReservationStatus(systemRecords); + } catch (error) { + setIsLoading(false); + console.error("Error fetching data: ", error); + } + }; - return ( - - -
- - - - {reduxSystemNo && ( - - System No : {reduxSystemNo} - - )} - - - -
- - {isLoading ? ( - - - - ) : ( - <> - {anomalyData && anomalyData.map((item, index) => ( - handleClick(item.error, item.error_reason, index)} - key={index} - style={{ margin: '16px', borderRadius: borderRadiusLG, - alignItems: 'flex-start', textAlign: 'start', cursor: 'pointer', - color:"white", - backgroundColor: selectedIndex === index ? '#3f51b5' : '#537895', - backgroundImage: selectedIndex === index ? - 'linear-gradient(315deg, #70a1ff 0%, #c2c0c0 74%);' : - 'linear-gradient(315deg, #537895 0%, #09203f 74%)' - }} - > - - {item.error && ( - - Code: {item.error} - - )} - {item['count(*)'] && ( - - Count: {item['count(*)']} - - )} - {item.error_reason && ( - - Reason: {item.error_reason} - - )} - - - ))} - {evErrors && evErrors.length > 0 &&( - <> - - - - {isLoading2 ? ( - - - - ) : ( - getCurrentPageData().map((data, index) => ( - - )) - )} - - )} - - )} - - {showSystemNoContainer && ( - { + setError(error); + setErrorReason(errorReason); + setCurrentPage(1); + setSelectedIndex(index); + let tmp = {}; + tmp["error"] = error; + tmp["error_reason"] = errorReason; + console.log("tmp = ", tmp); + dispatch(updateSelectedJson(tmp)); + }; + + const handlePageChange = (page) => { + setIsLoading2(true); + setCurrentPage(page); + }; + + useEffect(() => { + if (currentPage > 0) { + setIsLoading2(false); + } + }, [currentPage, evErrors]); + + const getCurrentPageData = () => { + const startIndex = (currentPage - 1) * 10; + const endIndex = startIndex + 10; + return evErrors.slice(startIndex, endIndex); + }; + + const handleSystemNoChange = () => { + console.log("System No Change is called"); + setShowSystemNoContainer(true); + dispatch(updateSelectedJson({})); + // dispatch(updatePartCErrorList([])) + dispatch(updatePartCErrorData([])); + }; + + return ( + + +
+ + + + {reduxSystemNo && ( + + System No : {reduxSystemNo} + + )} + + + +
+ + {isLoading ? ( + + + + ) : ( + <> + +
Degree Type
+ + + +
+ {anomalyData && + anomalyData.map((item, index) => ( + + handleClick(item.error, item.error_reason, index) + } + key={index} + style={{ + margin: "16px", + borderRadius: borderRadiusLG, + alignItems: "flex-start", + textAlign: "start", + cursor: "pointer", + color: "white", + backgroundColor: + selectedIndex === index ? "#3f51b5" : "#537895", + backgroundImage: + selectedIndex === index + ? "linear-gradient(315deg, #70a1ff 0%, #c2c0c0 74%);" + : "linear-gradient(315deg, #537895 0%, #09203f 74%)", + }} + > + + {item.error && ( + + Code: {item.error} + + )} + {item["count(*)"] && ( + + Count: {item["count(*)"]} + + )} + {item.error_reason && ( + + Reason: {item.error_reason} + + )} + + + ))} + {evErrors && evErrors.length > 0 && ( + <> + + - )} -
-
- ); + + {isLoading2 ? ( + + + + ) : ( + getCurrentPageData().map((data, index) => ( + + )) + )} + + )} + + )} + + {showSystemNoContainer && ( + + )} +
+
+ ); } export default AnomalyPartC;