From b6f152bb7b2991931130713bd8f1822cac384099 Mon Sep 17 00:00:00 2001 From: Mohammad Imran Date: Wed, 26 Jan 2022 17:36:58 +0530 Subject: [PATCH 1/2] fix: prettier errors --- src/components/GraphWrapper/graphWrapper.test.tsx | 7 +++++-- src/components/GraphWrapper/index.tsx | 7 +++++-- src/components/RouteSelector/routeSelector.test.tsx | 7 ++----- src/components/TimeQuerier/index.tsx | 7 +++++-- src/theme/components/DateTime.ts | 7 +++---- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/components/GraphWrapper/graphWrapper.test.tsx b/src/components/GraphWrapper/graphWrapper.test.tsx index ae58cd1..8a39168 100644 --- a/src/components/GraphWrapper/graphWrapper.test.tsx +++ b/src/components/GraphWrapper/graphWrapper.test.tsx @@ -12,8 +12,11 @@ import { queryEntities } from "../../services/queryEntity"; import constants from "../../utils/constants"; import { useGlobalStore } from "../../store/global"; -const { defaultStartTimestamp, defaultStepValue, defaultEndTimestamp } = - constants; +const { + defaultStartTimestamp, + defaultStepValue, + defaultEndTimestamp, +} = constants; const TestComponent = () => { const { changeRoute } = useGlobalStore(); diff --git a/src/components/GraphWrapper/index.tsx b/src/components/GraphWrapper/index.tsx index fea4ba4..9b99864 100644 --- a/src/components/GraphWrapper/index.tsx +++ b/src/components/GraphWrapper/index.tsx @@ -20,8 +20,11 @@ interface PageProps { const GraphWrapper: React.FC = (props: PageProps) => { const { selectedRoutePath } = props; - const { selectedStartTimestamp, selectedEndTimestamp, selectedStepValue } = - useTimeQuerierStore(); + const { + selectedStartTimestamp, + selectedEndTimestamp, + selectedStepValue, + } = useTimeQuerierStore(); const { data, error, status } = useFetch>( queryEntities( diff --git a/src/components/RouteSelector/routeSelector.test.tsx b/src/components/RouteSelector/routeSelector.test.tsx index 9718198..1141faf 100644 --- a/src/components/RouteSelector/routeSelector.test.tsx +++ b/src/components/RouteSelector/routeSelector.test.tsx @@ -8,11 +8,8 @@ import { getRoutes } from "../../services/getRoutes"; import { truncate } from "../../utils/stringManipulation"; jest.mock("axios"); -jest.mock( - "react-virtualized-auto-sizer", - () => - ({ children }: any) => - children({ height: 600, width: 600 }) +jest.mock("react-virtualized-auto-sizer", () => ({ children }: any) => + children({ height: 600, width: 600 }) ); const mockedAxios = axios as jest.Mocked; diff --git a/src/components/TimeQuerier/index.tsx b/src/components/TimeQuerier/index.tsx index 7aa7060..e01d034 100644 --- a/src/components/TimeQuerier/index.tsx +++ b/src/components/TimeQuerier/index.tsx @@ -20,8 +20,11 @@ import { useTimeQuerierStore } from "../../store/timeQuerier"; const TimeQuerier: React.FC = () => { const styles = useStyleConfig("DateTime", {}); - const { selectedStartTimestamp, selectedEndTimestamp, changeTimeQuerier } = - useTimeQuerierStore(); + const { + selectedStartTimestamp, + selectedEndTimestamp, + changeTimeQuerier, + } = useTimeQuerierStore(); const { defaultStepValue, minStepValue, dateFormat, timeFormat } = constants; const [startTime, setStartTime] = useState(moment(selectedStartTimestamp)); const [endTime, setEndTime] = useState(moment(selectedEndTimestamp)); diff --git a/src/theme/components/DateTime.ts b/src/theme/components/DateTime.ts index aa89ac5..6e42c43 100644 --- a/src/theme/components/DateTime.ts +++ b/src/theme/components/DateTime.ts @@ -26,10 +26,9 @@ export const DateTime = { }, ".rdtPicker td.rdtDay:hover,.rdtPicker thead tr:first-of-type th:hover\ ,.rdtPicker .rdtTimeToggle:hover,.rdtCounter .rdtBtn:hover\ - ,td.rdtMonth:hover, td.rdtYear:hover,.rdtSwitch:hover": - { - bg: mode("#eee", "darkPrimary")(props), - }, + ,td.rdtMonth:hover, td.rdtYear:hover,.rdtSwitch:hover": { + bg: mode("#eee", "darkPrimary")(props), + }, ".rdtPicker td.rdtDisabled:hover": { bg: "none", }, From 7f2ad67c7f51f676e01a8cc82b9d1ca4d4720394 Mon Sep 17 00:00:00 2001 From: Mohammad Imran Date: Thu, 27 Jan 2022 09:04:38 +0530 Subject: [PATCH 2/2] feat: migrate useFetch to react-query --- package.json | 1 + src/App.tsx | 31 ++++--- src/components/GraphWrapper/index.tsx | 13 +-- src/components/MachineSelector/index.tsx | 18 ++-- src/components/RouteSelector/index.tsx | 18 ++-- src/utils/customRender.tsx | 9 +- src/utils/useFetch.ts | 100 ++--------------------- yarn.lock | 83 +++++++++++++++++++ 8 files changed, 148 insertions(+), 125 deletions(-) diff --git a/package.json b/package.json index b4b4152..fc4ffab 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "react": "^17.0.2", "react-datetime": "^3.0.4", "react-dom": "^17.0.2", + "react-query": "^3.34.12", "react-router-dom": "^5.2.0", "react-scripts": "4.0.3", "react-virtualized-auto-sizer": "^1.0.5", diff --git a/src/App.tsx b/src/App.tsx index 92d6389..219ecac 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -7,21 +7,28 @@ import { Route, Redirect, } from "react-router-dom"; +import { QueryClient, QueryClientProvider } from "react-query"; +import { ReactQueryDevtools } from "react-query/devtools"; import Home from "./pages/Home"; import theme from "./theme"; +const queryClient = new QueryClient(); + export const App: React.FC = () => ( - - - - - - - - - - - - + + + + + + + + + + + + + + + ); diff --git a/src/components/GraphWrapper/index.tsx b/src/components/GraphWrapper/index.tsx index 9b99864..dc62896 100644 --- a/src/components/GraphWrapper/index.tsx +++ b/src/components/GraphWrapper/index.tsx @@ -26,7 +26,10 @@ const GraphWrapper: React.FC = (props: PageProps) => { selectedStepValue, } = useTimeQuerierStore(); - const { data, error, status } = useFetch>( + const { data, error, isLoading, isFetching, isError } = useFetch< + apiResponse + >( + "graph", queryEntities( selectedRoutePath, selectedStartTimestamp, @@ -35,7 +38,7 @@ const GraphWrapper: React.FC = (props: PageProps) => { ) ); - if (error) { + if (isError) { return ( = (props: PageProps) => { > - {error} + {error?.response?.data} An unexpected error occurred while processing the graph. @@ -60,7 +63,7 @@ const GraphWrapper: React.FC = (props: PageProps) => { ); } - if (status === "fetching" || status === "init") + if (isLoading || isFetching) return ( @@ -93,7 +96,7 @@ const GraphWrapper: React.FC = (props: PageProps) => { return ( - + ); diff --git a/src/components/MachineSelector/index.tsx b/src/components/MachineSelector/index.tsx index 9b1acce..42c61df 100644 --- a/src/components/MachineSelector/index.tsx +++ b/src/components/MachineSelector/index.tsx @@ -13,36 +13,38 @@ import { apiResponse, machineResponse } from "../../utils/types"; const MachineSelector: React.FC = () => { const { selectedMachine, changeSelectedMachine } = useGlobalStore(); - const { data, error, status } = useFetch>( - getActiveMachines() - ); - const machines = data ? data.data.machines : []; + const { data, error, isFetching, isLoading, isError, isFetched } = useFetch< + apiResponse + >("machines", getActiveMachines()); + + const machines = data ? data.data.data.machines : []; useEffect(() => { if (machines.length) changeSelectedMachine(machines[0]); }, [data]); - if (error) { + if (isError) { return ( - {error} + {error?.response?.data} ); } - if (status === "fetching" || status === "init") { + if (isFetching || isLoading) { return ( ); } + return (