Skip to content

Commit

Permalink
Dashboard stats via RTK Query.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdilauro committed Jul 28, 2024
1 parent 4945ff6 commit 3dfe156
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 145 deletions.
5 changes: 0 additions & 5 deletions src/components/Stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ export const Stats = (props: StatsProps) => {
const { data: statisticsData, error, isLoading } = useGetStatsQuery();
// TODO: This is to overcome a type inference problem with a RTKQ hook.
const fetchError = error as FetchErrorData;
console.log("useGetStatsQuery response:", {
statisticsData,
fetchError,
isLoading,
});

const summaryStatistics = statisticsData?.summaryStatistics;
const targetLibraryData = statisticsData?.libraries?.find(
Expand Down
16 changes: 2 additions & 14 deletions src/components/__tests__/LibraryStats-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { expect } from "chai";
import * as React from "react";
import { mount } from "enzyme";

import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import ContextProvider from "../ContextProvider";
import { componentWithProviders } from "../../../tests/jest/testUtils/withProviders";

import LibraryStats from "../LibraryStats";
import { BarChart } from "recharts";
Expand All @@ -18,18 +17,7 @@ import {

import { normalizeStatistics } from "../../features/stats/normalizeStatistics";

const AllProviders = ({ children }) => {
const queryClient = new QueryClient();
return (
<ContextProvider
csrfToken={""}
featureFlags={{}}
email={"[email protected]"}
>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</ContextProvider>
);
};
const AllProviders = componentWithProviders();

describe("LibraryStats", () => {
// Convert from the API format to our in-app format.
Expand Down
119 changes: 0 additions & 119 deletions src/components/__tests__/Stats-test.tsx

This file was deleted.

3 changes: 1 addition & 2 deletions src/features/stats/statsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { StatisticsData } from "../../interfaces";
import { normalizeStatistics } from "./normalizeStatistics";
import { FetchErrorData } from "@thepalaceproject/web-opds-client/lib/interfaces";

const STATS_API_ENDPOINT = "/version.json";
export const STATS_API_ENDPOINT = "/admin/stats";

export const statsApi = api.injectEndpoints({
endpoints: (builder) => ({
Expand All @@ -15,7 +15,6 @@ export const statsApi = api.injectEndpoints({
responseBody,
{ request, response }
): FetchErrorData => {
console.log("Error transform:", responseBody, { request, response });
return {
url: request.url,
status: response.status,
Expand Down
5 changes: 5 additions & 0 deletions src/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { TypedUseSelectorHook, useDispatch, useSelector } from "react-redux";
import { AppDispatch, RootState } from "./store";

export const useAppDispatch = () => useDispatch<AppDispatch>();
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
1 change: 1 addition & 0 deletions tests/__data__/statisticsApiResponseData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { StatisticsData } from "../../src/interfaces";

export const testLibraryKey = "lyrasis-reads";
export const testLibraryName = "LYRASIS Reads";
export const noCollectionsLibraryKey = "unfunded-library";
export const noInventoryLibraryKey = "unfunded-library";
export const noPatronsLibraryKey = "unused-library";
Expand Down
Loading

0 comments on commit 3dfe156

Please sign in to comment.