Skip to content

Commit

Permalink
Updated views with page size params
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Feb 24, 2024
1 parent 8d2292a commit 115d677
Show file tree
Hide file tree
Showing 9 changed files with 2,408 additions and 2,276 deletions.
672 changes: 336 additions & 336 deletions .yarn/releases/yarn-4.0.2.cjs → .yarn/releases/yarn-4.1.0.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.0.2.cjs
yarnPath: .yarn/releases/yarn-4.1.0.cjs
5 changes: 5 additions & 0 deletions app/(public)/admin/paragraph/[id]/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {NextResponse} from "next/server";

export const GET = () => {
return NextResponse.json("Preview is no longer supported.");
}
32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"@mui/base": "^5.0.0-beta.33",
"@tailwindcss/container-queries": "^0.1.1",
"@tailwindcss/typography": "^0.5.10",
"@tanstack/react-query": "^5.18.0",
"@types/node": "^20.11.13",
"@types/react": "^18.2.48",
"@tanstack/react-query": "^5.22.2",
"@types/node": "^20.11.20",
"@types/react": "^18.2.58",
"@uidotdev/usehooks": "^2.4.1",
"autoprefixer": "^10.4.17",
"axios": "^1.6.7",
Expand All @@ -30,40 +30,40 @@
"graphql": "^16.8.1",
"graphql-request": "^6.1.0",
"graphql-tag": "^2.12.6",
"html-react-parser": "^5.1.1",
"html-react-parser": "^5.1.7",
"jsona": "^1.12.1",
"next": "^14.1.0",
"next-drupal": "^1.6.0",
"nextjs-google-analytics": "^2.3.3",
"postcss": "^8.4.33",
"postcss": "^8.4.35",
"react": "^18.2.0",
"react-aria": "^3.31.1",
"react-aria": "^3.32.1",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.12",
"react-focus-lock": "^2.9.7",
"react-intersection-observer": "^9.5.3",
"react-focus-lock": "^2.11.1",
"react-intersection-observer": "^9.8.1",
"react-obfuscate": "^3.6.9",
"react-obfuscate-email": "^1.1.2",
"react-resize-detector": "^10.0.1",
"react-stately": "^3.29.1",
"react-stately": "^3.30.1",
"react-tiny-oembed": "^1.1.0",
"server-only": "^0.0.1",
"sharp": "^0.33.2",
"tailwind-merge": "^2.2.1",
"tailwindcss": "^3.4.1",
"typescript": "^5.3.3",
"usehooks-ts": "^2.10.0",
"usehooks-ts": "^2.15.1",
"xml2js": "^0.6.2"
},
"devDependencies": {
"@graphql-codegen/cli": "5.0.1",
"@graphql-codegen/typescript-graphql-request": "^6.1.0",
"@graphql-codegen/typescript-operations": "4.1.0",
"@graphql-codegen/cli": "5.0.2",
"@graphql-codegen/typescript-graphql-request": "^6.2.0",
"@graphql-codegen/typescript-operations": "4.2.0",
"@types/debug": "^4.1.12",
"@types/qs": "^6.9.11",
"eslint": "^8.56.0",
"eslint": "^8.57.0",
"eslint-config-next": "^14.1.0",
"eslint-plugin-unused-imports": "^3.0.0"
"eslint-plugin-unused-imports": "^3.1.0"
},
"packageManager": "yarn@4.0.2"
"packageManager": "yarn@4.1.0"
}
24 changes: 13 additions & 11 deletions src/components/paragraph/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SulCollection from "@/components/paragraph/sul-collection";
import SulFeaturedCollection from "@/components/paragraph/sul-featured-collection";
import SulContactCard from "@/components/paragraph/sul-contact-card";
import SulButton from "@/components/paragraph/sul-button";
import {HTMLAttributes, useId} from "react";
import {HTMLAttributes, Suspense, useId} from "react";
import SulLibguides from "@/components/paragraph/sul-libguides";
import {ParagraphUnion} from "@/lib/gql/__generated__/drupal";
import {ParagraphBehaviors} from "@/lib/drupal/drupal";
Expand Down Expand Up @@ -74,16 +74,18 @@ const Paragraph = ({paragraph, singleRow = false, fullWidth = false, ...props}:
<StanfordWysiwyg text={paragraph.suWysiwygText?.processed} {...props}/>}

{paragraph.__typename === 'ParagraphStanfordList' &&
<StanfordLists
headline={paragraph.suListHeadline}
description={paragraph.suListDescription?.processed}
link={paragraph.suListButton}
view={paragraph.suListView}
behaviors={paragraphBehaviors}
headerId={headerId}
uuid={paragraph.id}
{...props}
/>
<Suspense>
<StanfordLists
headline={paragraph.suListHeadline}
description={paragraph.suListDescription?.processed}
link={paragraph.suListButton}
view={paragraph.suListView}
behaviors={paragraphBehaviors}
headerId={headerId}
uuid={paragraph.id}
{...props}
/>
</Suspense>
}

{paragraph.__typename === 'ParagraphStanfordEntity' &&
Expand Down
32 changes: 15 additions & 17 deletions src/components/paragraph/stanford-lists.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const ListParagraph = async ({headerId, headline, description, link, view, behav

if (viewId && displayId) {
try {
viewItems = await getViewItems(viewId, displayId, view?.contextualFilter);
viewItems = await getViewItems(viewId, displayId, view?.contextualFilter, view?.pageSize);
} catch (e) {
try {
console.log(`${uuid}: Retrying to fetch view items: View ID: ${viewId}, Display: ${displayId}, Filters: ${view?.contextualFilter?.join('/')}`)
Expand All @@ -45,11 +45,6 @@ const ListParagraph = async ({headerId, headline, description, link, view, behav
}
}

// let viewItems = (viewId && displayId) ? await getViewResults<StanfordNode>(viewId, displayId, paragraph.suListView?.contextualFilter) : [];
if (view?.pageSize) {
viewItems = viewItems.slice(0, view.pageSize)
}

if (behaviors?.list_paragraph?.hide_empty && viewItems.length === 0) return null;

return (
Expand All @@ -76,7 +71,7 @@ const ListParagraph = async ({headerId, headline, description, link, view, behav
)
}

const getViewItems = cache(async (viewId: string, displayId: string, contextualFilter?: ViewReference["contextualFilter"]): Promise<NodeUnion[]> => {
const getViewItems = cache(async (viewId: string, displayId: string, contextualFilter?: ViewReference["contextualFilter"], pageSize?: Maybe<number>): Promise<NodeUnion[]> => {

let items: NodeUnion[] = []

Expand Down Expand Up @@ -116,56 +111,58 @@ const getViewItems = cache(async (viewId: string, displayId: string, contextualF
let filters = getViewFilters(['term_node_taxonomy_name_depth', 'nid'], contextualFilter)
let graphqlResponse;

const itemsPerPage = pageSize ? Math.ceil(pageSize / 3) * 3 : undefined;

switch (`${viewId}--${displayId}`) {
case 'stanford_shared_tags--card_grid':
filters = getViewFilters(['term_node_taxonomy_name_depth', 'type'], contextualFilter)
if (filters && Object.keys(filters).length === 2) filters.nid = '0'
graphqlResponse = await client.stanfordSharedTags({filters});
graphqlResponse = await client.stanfordSharedTags({filters, pageSize: itemsPerPage});
items = graphqlResponse.stanfordSharedTags?.results as unknown as NodeUnion[]
break

case 'stanford_basic_pages--basic_page_type_list':
graphqlResponse = await client.stanfordBasicPages({filters});
graphqlResponse = await client.stanfordBasicPages({filters, pageSize: itemsPerPage});
items = graphqlResponse.stanfordBasicPages?.results as unknown as NodeUnion[]
break

case 'stanford_basic_pages--viewfield_block_1':
graphqlResponse = await client.stanfordBasicPagesCards({filters});
graphqlResponse = await client.stanfordBasicPagesCards({filters, pageSize: itemsPerPage});
items = graphqlResponse.stanfordBasicPagesCards?.results as unknown as NodeUnion[]
break

case 'stanford_events--cards':
filters = getViewFilters(['term_node_taxonomy_name_depth', 'term_node_taxonomy_name_depth_1', 'term_node_taxonomy_name_depth_2', 'term_node_taxonomy_name_depth_3'], contextualFilter)
graphqlResponse = await client.stanfordEventsCardGrid({filters});
graphqlResponse = await client.stanfordEventsCardGrid({filters, pageSize: itemsPerPage});
items = graphqlResponse.stanfordEventsCardGrid?.results as unknown as NodeUnion[]
break

case 'stanford_events--list_page':
filters = getViewFilters(['term_node_taxonomy_name_depth', 'term_node_taxonomy_name_depth_1', 'term_node_taxonomy_name_depth_2', 'term_node_taxonomy_name_depth_3'], contextualFilter);
graphqlResponse = await client.stanfordEvents({filters});
graphqlResponse = await client.stanfordEvents({filters, pageSize: itemsPerPage});
items = graphqlResponse.stanfordEvents?.results as unknown as NodeUnion[]
break

case 'stanford_events--past_events_list_block':
filters = getViewFilters(['term_node_taxonomy_name_depth'], contextualFilter)
graphqlResponse = await client.stanfordEventsPastEvents({filters});
graphqlResponse = await client.stanfordEventsPastEvents({filters, pageSize: itemsPerPage});
items = graphqlResponse.stanfordEventsPastEvents?.results as unknown as NodeUnion[]
break

case 'stanford_news--block_1':
filters = getViewFilters(['term_node_taxonomy_name_depth'], contextualFilter)
graphqlResponse = await client.stanfordNewsDefaultList({filters});
graphqlResponse = await client.stanfordNewsDefaultList({filters, pageSize: itemsPerPage});
items = graphqlResponse.stanfordNewsDefaultList?.results as unknown as NodeUnion[]
break

case 'stanford_news--vertical_cards':
graphqlResponse = await client.stanfordNewsCardGrid({filters});
graphqlResponse = await client.stanfordNewsCardGrid({filters, pageSize: itemsPerPage});
items = graphqlResponse.stanfordNewsCardGrid?.results as unknown as NodeUnion[]
break

case 'stanford_person--grid_list_all':
filters = getViewFilters(['term_node_taxonomy_name_depth'], contextualFilter)
graphqlResponse = await client.stanfordPerson({filters});
graphqlResponse = await client.stanfordPerson({filters, pageSize: itemsPerPage});
items = graphqlResponse.stanfordPerson?.results as unknown as NodeUnion[]
break

Expand All @@ -178,7 +175,8 @@ const getViewItems = cache(async (viewId: string, displayId: string, contextualF
console.error(`Unable to find query for view: ${viewId} display: ${displayId}`)
break;
}
return items;

return pageSize ? items.slice(0, pageSize) : items;
})

const getViewFilters = (keys: string[], values?: Maybe<string[]>) => {
Expand Down
Loading

0 comments on commit 115d677

Please sign in to comment.