Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DR-3305 fallback for featured item updates post reverse proxy launch #254

Merged
merged 14 commits into from
Dec 5, 2024
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased

### Removed

- removed unneccessary variables post reverse proxy launch
- Removed new relic files from frontend (DR-3311)

Expand All @@ -17,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Updated
avertrees marked this conversation as resolved.
Show resolved Hide resolved

- refactored implementation of default featured item & updated default number of digitized items (DR-3305)
- Update thumbnail logic so thumbnails are never restricted (DR-3293)

## [0.2.4] 2024-11-26
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/featuredItem/campaignHero.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("Campaign Hero", () => {
foregroundImageSrc: "/foobar.jpg",
uuid: "510d47e0-cb17-a3d9-e040-e00a18064a99",
title: "Momoyogusa",
href: "https://digitalcollections.nypl.org/items/510d47e0-cb17-a3d9-e040-e00a18064a99",
href: "/items/510d47e0-cb17-a3d9-e040-e00a18064a99",
},
numberOfDigitizedItems: "876,067",
};
Expand Down
43 changes: 9 additions & 34 deletions app/src/data/defaultFeaturedItemData.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,15 @@
import { FeaturedItemDataType } from "../types/FeaturedItemDataType";
type Environment = "development" | "qa" | "production";

const defaultFeaturedItem: Record<Environment, FeaturedItemDataType> = {
development: {
featuredItem: {
imageID: "482815",
backgroundImageSrc: "/482815.jpg",
foregroundImageSrc: "/482815.jpg",
uuid: "510d47d9-4f93-a3d9-e040-e00a18064a99",
title: "Watuppa, From water front, Brooklyn",
href: "https://qa-digitalcollections.nypl.org/items/510d47d9-4f93-a3d9-e040-e00a18064a99",
},
numberOfDigitizedItems: "875,861",
},
qa: {
featuredItem: {
imageID: "482815",
backgroundImageSrc: "/482815.jpg",
foregroundImageSrc: "/482815.jpg",
uuid: "510d47d9-4f93-a3d9-e040-e00a18064a99",
title: "Watuppa, From water front, Brooklyn",
href: "https://qa-digitalcollections.nypl.org/items/510d47d9-4f93-a3d9-e040-e00a18064a99",
},
numberOfDigitizedItems: "875,861",
},
production: {
featuredItem: {
imageID: "482815",
backgroundImageSrc: "/482815.jpg",
foregroundImageSrc: "/482815.jpg",
uuid: "510d47d9-4f93-a3d9-e040-e00a18064a99",
title: "Watuppa, From water front, Brooklyn",
href: "https://digitalcollections.nypl.org/items/510d47d9-4f93-a3d9-e040-e00a18064a99",
},
numberOfDigitizedItems: "875,861",
const defaultFeaturedItem: FeaturedItemDataType = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test fails because this was updated but the reference in campaignHero.tsx was not. In https://github.com/NYPL/digital-collections/blob/main/app/src/components/featuredItem/campaignHero.tsx#L13 you can remove the [appConfig["environment"] as ENV_KEY] and also delete the unused imports.

Because you're importing the object from another file, you can make a copy by doing const defaultFeaturedItemResponse = { ...defaultFeaturedItem };.

You're not modifying defaultFeaturedItem in campaignHero.tsx so it might be safe to just use it directly in the useState, but I think it's better practice to make a copy to make it immutable.

featuredItem: {
imageID: "482815",
backgroundImageSrc: "/482815.jpg",
foregroundImageSrc: "/482815.jpg",
uuid: "510d47d9-4f93-a3d9-e040-e00a18064a99",
title: "Watuppa, From water front, Brooklyn",
href: "/items/510d47d9-4f93-a3d9-e040-e00a18064a99",
},
numberOfDigitizedItems: "1,059,731",
};

export default defaultFeaturedItem;
14 changes: 5 additions & 9 deletions app/src/utils/apiHelpers.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ describe("getFeaturedItemData", () => {
`${process.env.API_URL}/api/v2/items/total`
);
// Fallback data.
expect(result.numberOfDigitizedItems).toEqual("875,861");
expect(result.numberOfDigitizedItems).toEqual("1,059,731");
expect(result.featuredItem.imageID).toEqual(
defaultFeaturedItem.production.featuredItem.imageID
defaultFeaturedItem.featuredItem.imageID
);
});
});
Expand Down Expand Up @@ -256,9 +256,7 @@ describe("getNumDigitizedItems", () => {
const result = await getNumDigitizedItems();

// Fallback data.
expect(result).toEqual(
defaultFeaturedItem["development"].numberOfDigitizedItems
);
expect(result).toEqual(defaultFeaturedItem.numberOfDigitizedItems);
});
});

Expand Down Expand Up @@ -332,7 +330,7 @@ describe("getRandomFeaturedItem", () => {
describe("getFeaturedImage", () => {
it("returns expected image", async () => {
(fetchApi as jest.Mock).mockResolvedValueOnce(
Promise.resolve(defaultFeaturedItem["production"].featuredItem)
Promise.resolve(defaultFeaturedItem.featuredItem)
);
const imageData = await getFeaturedImage();
expect(fetchApi as jest.Mock).toHaveBeenCalledWith(
Expand All @@ -353,9 +351,7 @@ describe("getFeaturedImage", () => {
const imageData = await getFeaturedImage();

// Fallback data.
expect(imageData.uuid).toEqual(
defaultFeaturedItem["development"].featuredItem.uuid
);
expect(imageData.uuid).toEqual(defaultFeaturedItem.featuredItem.uuid);
});
});

Expand Down
10 changes: 2 additions & 8 deletions app/src/utils/apiHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import data from "../data/lanes";
import type { LaneDataType } from "../types/Lane";
import { ENV_KEY } from "../types/EnvironmentType";
import { imageURL, addCommas } from "./utils";
import appConfig from "../../../appConfig";
import defaultFeaturedItems from "../data/defaultFeaturedItemData";
import { CARDS_PER_PAGE } from "../config/constants";
import { fetchApi } from "./fetchApi";
Expand All @@ -29,7 +27,6 @@ export const getHomePageData = async () => {
});

const newResponse = { randomNumber, lanesWithNumItems: updatedLanes };
console.log("new response is: ", newResponse);
return newResponse;
};

Expand Down Expand Up @@ -63,8 +60,7 @@ export const getFeaturedItemData = async () => {
};

export const getFeaturedImage = async () => {
const defaultResponse =
defaultFeaturedItems[appConfig.environment as ENV_KEY].featuredItem;
const defaultResponse = defaultFeaturedItems.featuredItem;
const apiResponse = await getRandomFeaturedItem();

return {
Expand Down Expand Up @@ -92,9 +88,7 @@ export const getNumDigitizedItems = async () => {
const apiUrl = `${process.env.API_URL}/api/v2/items/total`;
const res = await fetchApi(apiUrl);

const fallbackCount =
defaultFeaturedItems[appConfig.environment as ENV_KEY]
.numberOfDigitizedItems;
const fallbackCount = defaultFeaturedItems.numberOfDigitizedItems;
const totalItems = res?.count?.$ ? addCommas(res.count.$) : fallbackCount; // only add commas to repo api response data
return totalItems;
};
Expand Down
2 changes: 2 additions & 0 deletions public/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased

### Removed

- removed unneccessary variables post reverse proxy launch
- Removed new relic files from frontend (DR-3311)

Expand All @@ -17,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Updated

- refactored implementation of default featured item & updated default number of digitized items (DR-3305)
- Update thumbnail logic so thumbnails are never restricted (DR-3293)

## [0.2.4] 2024-11-26
Expand Down
Loading