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 @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### 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)

## [0.2.4] 2024-11-26

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: "https://qa-digitalcollections.nypl.org/items/510d47d9-4f93-a3d9-e040-e00a18064a99",
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this risk linking to QA if this was in production?

Copy link
Member

Choose a reason for hiding this comment

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

Link to /items/510d47d9-4f93-a3d9-e040-e00a18064a99 to be relative to the environment its in.

},
numberOfDigitizedItems: "1,059,731",
};

export default defaultFeaturedItem;
9 changes: 2 additions & 7 deletions app/src/utils/api.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import data from "../../src/data/lanes";
import type { LaneDataType } from "../../src/types/Lane";
import { ENV_KEY } from "../../src/types/EnvironmentType";
import { imageURL, addCommas } from "../utils/utils";
import appConfig from "../../../appConfig";
import defaultFeaturedItems from "../data/defaultFeaturedItemData";
import { CARDS_PER_PAGE } from "../config/constants";
import { DC_URL } from "../config/constants";
Expand Down Expand Up @@ -63,8 +61,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 getItemByIdentifier("featured", "", {
random: "true",
});
Expand Down Expand Up @@ -94,9 +91,7 @@ export const getNumDigitizedItems = async () => {
const apiUrl = `${process.env.API_URL}/api/v2/items/total`;
const res = await apiResponse(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 @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Updated
- refactored implementation of default featured item & updated default number of digitized items (DR-3305)

## [0.2.4] 2024-11-26

Expand Down
Loading