Skip to content

Commit

Permalink
Merge pull request #202 from NYPL/feature/DR-3194/general-cleanup
Browse files Browse the repository at this point in the history
DR-3194 general cleanup
  • Loading branch information
avertrees authored Oct 4, 2024
2 parents bf4c849 + 4aa083f commit bb849a5
Show file tree
Hide file tree
Showing 14 changed files with 715 additions and 155 deletions.
32 changes: 32 additions & 0 deletions ENVIRONMENTVARS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# DC Facelift Environment Variables

## Table of Contents

- [General Information](#general-information)
- [Application Variables](#application-variables)

## General Information

Environment variables are used in this code repository to control how the application builds, how and where data is fetched for separate sections in the application, for rendering certain features, and for controlling data flow.

General environment variables are declared in the `.env.example` file. A copy of this file should be made and saved as `.env.local` where real values should be added.

Generally, environment variables are meant to be read through the `process.env` object _on the server_. Variables intended for use on the client side should be prefaced with NEXT*PUBLIC* per Next's [docs](https://nextjs.org/docs/app/building-your-application/configuring/environment-variables).

If an environment variable is updated, make sure to restart the server for the application to pick up the new value.

## Application Variables

These environment variables control how certain elements on the page render and where to fetch data.

| Variable | Type | Value Example | Description |
| ---------------------------- | ------ | ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
| `APP_ENV` | string | "development" | App environment key used to determine various environment-specific app settings. |
| `DC_URL` | string | "" or "https://qa-digitalcollections.nypl.org" or https://digitalcollections.nypl.org | The base URL of the DC url, either points locally or externally to legacy DC. |
| `API_URL` | string | "https://api.repo.nypl.org" or "https://qa.api.repo.nypl.org" | base url for Repo API calls. |
| `AUTH_TOKEN` | string | "" | Auth token for Repo API. |
| `ADOBE_EMBED_URL` | string | "" | Url endpoint used for Adobe Analytics event tracking. |
| `GOOGLE_SHEETS_CLIENT_EMAIL` | string | "" | |
| `GOOGLE_SHEETS_PRIVATE_KEY` | string | "" | |
| `SPREADSHEET_ID` | string | "" | |
| `NEW_RELIC_LICENSE_KEY` | string | "true" | |
455 changes: 455 additions & 0 deletions __tests__/__mocks__/data/mockPaginatedCollections.tsx

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion app/collections/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from "react";
import { Metadata } from "next";
import PageLayout from "../../src/components/pageLayout/pageLayout";
import SearchResults from "@/src/components/search/results";
import { mockItems } from "__tests__/__mocks__/data/mockItems";

type CollectionProps = {
params: { slug: string };
Expand Down Expand Up @@ -29,6 +31,8 @@ export default function Collections({ params }: CollectionProps) {
},
]}
adobeAnalyticsPageName={pageName}
></PageLayout>
>
<SearchResults showFilter={false} isSearchPage={false} data={mockItems} />
</PageLayout>
);
}
5 changes: 3 additions & 2 deletions app/collections/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from "react";
import { Metadata } from "next";
import { CollectionsPage } from "../src/components/pages/collectionsPage/collectionsPage";
import { mockCollectionCards } from "__tests__/__mocks__/data/mockCollectionCards";

export const metadata: Metadata = {
title: "Collections - NYPL Digital Collections",
};

export default function Collections() {
return <CollectionsPage />;
export default async function Collections() {
return <CollectionsPage data={mockCollectionCards} />;
}
11 changes: 6 additions & 5 deletions app/search/index/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from "react";
import { Metadata } from "next";
import PageLayout from "../../src/components/pageLayout/pageLayout";
import SearchResults from "../../src/components/search/results";
import { mockItems } from "../../../__tests__/__mocks__/data/mockItems"; // TODO: render mockItems

export const metadata: Metadata = {
title: "Search - NYPL Digital Collections",
export type SearchProps = {
params: { slug: string };
searchParams: { page: string };
};

export default function Search() {
export default async function Search() {
return (
<PageLayout
activePage="collections"
Expand All @@ -17,7 +18,7 @@ export default function Search() {
]}
adobeAnalyticsPageName="search"
>
<SearchResults />
<SearchResults showFilter={false} isSearchPage data={mockItems} />
</PageLayout>
);
}
89 changes: 15 additions & 74 deletions app/src/components/grids/collectionsGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,88 +1,29 @@
"use client";

import { useSearchParams, usePathname, useRouter } from "next/navigation";
import { Heading, Pagination } from "@nypl/design-system-react-components";
import React from "react";
import { CollectionCardModel } from "../../models/collectionCard";
import useBreakpoints from "../../hooks/useBreakpoints";
import CollectionDataType from "../../types/CollectionDataType";
import React, { useRef, useState } from "react";
import { totalNumPages } from "../../utils/utils";
import { SimpleGrid as DCSimpleGrid } from "../simpleGrid/simpleGrid";
import { Card as DCCard } from "../card/card";
import { useTooltipOffset } from "@/src/hooks/useTooltipOffset";

export const CollectionsGrid = ({ data }: any) => {
const pathname = usePathname();
const queryParams = useSearchParams();
const headingRef = useRef<HTMLHeadingElement>(null);

const [currentPage, setCurrentPage] = useState(
Number(queryParams.get("page")) || 1
);

const { replace } = useRouter();

export const CollectionsGrid = ({ collections }: any) => {
const { isLargerThanLargeTablet } = useBreakpoints();

const totalPages = totalNumPages(data.numFound, data.perPage);

const updatePageURL = async (pageNumber: number) => {
const params = new URLSearchParams();
params.set("page", pageNumber.toString());
setCurrentPage(pageNumber);
const url = `${pathname}?${params.toString()}#${data.slug}`;
replace(url);
headingRef.current?.focus;
};

const cardRef = useRef<HTMLDivElement>(null);
const tooltipOffset = useTooltipOffset(cardRef);

return (
<>
<Heading
ref={headingRef}
tabIndex={-1}
level="h2"
id={data.slug}
size="heading3"
style={{ width: "fit-content" }}
>
{`Collections in the ${data.name}`}
</Heading>
<DCSimpleGrid>
{data?.collections?.map((collection: CollectionDataType, index) => {
const collectionModel = new CollectionCardModel(collection);
return (
<DCCard
key={index}
ref={cardRef}
tooltipOffset={tooltipOffset}
id={index}
slug={collectionModel.title}
record={collectionModel}
isLargerThanLargeTablet={isLargerThanLargeTablet}
/>
);
})}
</DCSimpleGrid>
{totalPages > 1 && (
<>
<Pagination
id="pagination-id"
initialPage={currentPage}
currentPage={currentPage}
pageCount={totalPages}
onPageChange={updatePageURL}
sx={{
display: "flex",
justifyContent: "center",
gap: "s",
marginTop: "xxl",
}}
<DCSimpleGrid>
{collections?.map((collection: CollectionDataType, index) => {
const collectionModel = new CollectionCardModel(collection);
return (
<DCCard
key={index}
id={index}
slug={collectionModel.title}
record={collectionModel}
isLargerThanLargeTablet={isLargerThanLargeTablet}
/>
</>
)}
</>
);
})}
</DCSimpleGrid>
);
};
29 changes: 29 additions & 0 deletions app/src/components/grids/itemsGrid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use client";

import useBreakpoints from "../../hooks/useBreakpoints";
import React from "react";
import { SimpleGrid as DCSimpleGrid } from "../simpleGrid/simpleGrid";
import { Card as DCCard } from "../card/card";
import ItemCardDataType from "@/src/types/ItemCardDataType";
import { ItemCardModel } from "@/src/models/itemCard";

export const ItemsGrid = ({ items }: any) => {
console.log("items are: ", items);
const { isLargerThanLargeTablet } = useBreakpoints();

return (
<DCSimpleGrid>
{items?.map((item: ItemCardDataType, index) => {
const itemModel = new ItemCardModel(item);
return (
<DCCard
key={index}
id={index}
record={itemModel}
isLargerThanLargeTablet={isLargerThanLargeTablet}
/>
);
})}
</DCSimpleGrid>
);
};
32 changes: 11 additions & 21 deletions app/src/components/pages/collectionLanePage/collectionLanePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import {
import { useParams } from "next/navigation";
import { headerBreakpoints } from "../../../utils/breakpoints";
import { slugToString } from "../../../utils/utils";
import { mockCollections } from "../../../../../__tests__/__mocks__/data/mockCollections";
import { mockCollectionCards } from "__tests__/__mocks__/data/mockCollectionCards";
import { CollectionsGrid } from "../../grids/collectionsGrid";
import React, { useEffect, useRef, useState } from "react";
import PageLayout from "../../pageLayout/pageLayout";
import { SimpleGrid as DCSimpleGrid } from "../../simpleGrid/simpleGrid";
import { CollectionCardModel } from "@/src/models/collectionCard";
import CollectionDataType from "@/src/types/CollectionDataType";
import { Card as DCCard } from "../../card/card";
// import CollectionLanesLoading from "../../lanes/collectionLanes/collectionLanesLoading";
// import { SimpleGrid as DCSimpleGrid } from "../../simpleGrid/simpleGrid";
// import { CollectionCardModel } from "@/src/models/collectionCard";
// import CollectionDataType from "@/src/types/CollectionDataType";
// import { Card as DCCard } from "../../card/card";
import useBreakpoints from "@/src/hooks/useBreakpoints";
import { useTooltipOffset } from "@/src/hooks/useTooltipOffset";
import LaneLoading from "../../lane/laneLoading";
Expand All @@ -31,6 +33,7 @@ export default function CollectionLanePage() {
useEffect(() => {
setIsLoaded(true);
}, []);

return (
<PageLayout
activePage="swimlane"
Expand All @@ -55,22 +58,9 @@ export default function CollectionLanePage() {
</Box>
<HorizontalRule sx={{ marginTop: "xxl", marginBottom: "xxl" }} />
{isLoaded ? (
<DCSimpleGrid>
{mockCollections?.map((collection: CollectionDataType, index) => {
const collectionModel = new CollectionCardModel(collection);
return (
<DCCard
key={index}
ref={cardRef}
tooltipOffset={tooltipOffset}
id={`${index}`}
slug={collectionModel.title}
record={collectionModel}
isLargerThanLargeTablet={isLargerThanLargeTablet}
/>
);
})}
</DCSimpleGrid>
<>
<CollectionsGrid collections={mockCollectionCards} />
</>
) : (
<>
<LaneLoading withTitle={false} />,
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/pages/collectionsPage/collectionsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from "@nypl/design-system-react-components";
import { headerBreakpoints } from "../../../utils/breakpoints";

export const CollectionsPage = () => {
export const CollectionsPage = ({ data }) => {
return (
<PageLayout
activePage="collections"
Expand Down Expand Up @@ -49,7 +49,7 @@ export const CollectionsPage = () => {
/>
</Box>
<HorizontalRule sx={{ marginTop: "xxl", marginBottom: "xxl" }} />
<SearchResults />
<SearchResults showFilter isSearchPage={false} data={data} />
</PageLayout>
);
};
Loading

0 comments on commit bb849a5

Please sign in to comment.