Skip to content

Commit

Permalink
Adds ability to request inventory report. (PP-1236) (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdilauro authored May 22, 2024
1 parent 1fccc1c commit e910982
Show file tree
Hide file tree
Showing 12 changed files with 6,194 additions and 21,350 deletions.
26,278 changes: 4,961 additions & 21,317 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
},
"dependencies": {
"@nypl/dgx-svg-icons": "0.3.4",
"@tanstack/react-query": "^4.36.1",
"@thepalaceproject/web-opds-client": "^1.0.1",
"bootstrap": "^3.3.6",
"classnames": "^2.3.1",
Expand Down Expand Up @@ -67,8 +68,10 @@
"url": "^0.11.0"
},
"devDependencies": {
"@tanstack/react-query-devtools": "^4.36.1",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^12.1.5",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/user-event": "^14.4.3",
"@types/jest": "^29.2.6",
"@types/mocha": "^10.0.1",
Expand Down Expand Up @@ -96,6 +99,7 @@
"eslint-plugin-react": "^7.19.0",
"eslint-plugin-react-hooks": "^4.0.0",
"fetch-mock": "^7.3.1",
"fetch-mock-jest": "^1.5.1",
"file-loader": "^6.2.0",
"follow-redirects": "^1.15.6",
"husky": "^4.3.0",
Expand All @@ -110,6 +114,7 @@
"nightwatch": "^3.2.0",
"prettier": "2.1.2",
"react-axe": "^3.3.0",
"react-test-renderer": "^16.14.0",
"redux-mock-store": "^1.5.4",
"sass": "^1.64.2",
"sass-lint": "^1.13.1",
Expand Down
62 changes: 62 additions & 0 deletions src/api/admin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Inventory Report API
export type InventoryReportCollectionInfo = {
id: number;
name: string;
};
export type InventoryReportInfo = {
collections: InventoryReportCollectionInfo[];
};
export type InventoryReportRequestResponse = {
message: string;
};
export type InventoryReportRequestParams = {
library: string;
baseEndpointUrl?: string;
};

export const DEFAULT_BASE_ENDPOINT_URL = "/admin/reports/inventory_report";

/**
* Get information about the inventory report that would be generated for the
* given library, if requested.
*
* @param library -- the library for which the report information is requested.
* @param baseEndpointUrl -- an optional baseURL (for testing). If not provided,
* the `defaultBaseEndpointUrl` will be used.
* @returns an object converted from the information JSON response, if successful.
* @throws an error, if the request is not successful.
*/
export const getInventoryReportInfo = async ({
library,
baseEndpointUrl = DEFAULT_BASE_ENDPOINT_URL,
}: InventoryReportRequestParams): Promise<InventoryReportInfo> => {
const endpointUrl = `${baseEndpointUrl}/${library}`;
const res = await fetch(endpointUrl);
if (!res.ok) {
throw new Error(`Request failed with status ${res.status}: GET ${res.url}`);
}
return res.json();
};

/**
* Request an inventory report for the given library.
*
* @param library -- the library for which the report information is requested.
* @param baseEndpointUrl -- an optional baseURL (for testing). If not provided,
* the `defaultBaseEndpointUrl` will be used.
* @returns an object converted from the message JSON response, if successful.
* @throws an error, if the request is not successful.
*/
export const requestInventoryReport = async ({
library,
baseEndpointUrl = DEFAULT_BASE_ENDPOINT_URL,
}: InventoryReportRequestParams): Promise<InventoryReportRequestResponse> => {
const endpointUrl = `${baseEndpointUrl}/${library}`;
const res = await fetch(endpointUrl, { method: "POST" });
if (!res.ok) {
throw new Error(
`Request failed with status ${res.status}: POST ${res.url}`
);
}
return res.json();
};
6 changes: 5 additions & 1 deletion src/components/AdvancedSearchFilterInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ export default function AdvancedSearchFilterInput({
{selectedFieldOptions.length === 0
? null
: selectedFieldOptions.map((value) => (
<option key={value} value={value}>
<option
key={value}
value={value}
aria-selected={value === filterValue}
>
{value}
</option>
))}
Expand Down
Loading

0 comments on commit e910982

Please sign in to comment.