Skip to content

Commit

Permalink
Updated view options
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Jul 18, 2024
1 parent 202a0e5 commit ad61d5d
Show file tree
Hide file tree
Showing 8 changed files with 466 additions and 718 deletions.
2 changes: 1 addition & 1 deletion codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const config: CodegenConfig = {
schema: [{
[drupalUrl]: {
headers: {
"Authorization": "Basic " + Buffer.from(process.env.DRUPAL_BASIC_AUTH_ADMIN as string).toString("base64")
"Authorization": "Basic " + Buffer.from(process.env.DRUPAL_BASIC_AUTH_ADMIN || process.env.DRUPAL_BASIC_AUTH as string).toString("base64")
}
}
}],
Expand Down
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@mui/base": "5.0.0-dev.20240529-082515-213b5e33ab",
"@next/third-parties": "^14.2.5",
"@tailwindcss/container-queries": "^0.1.1",
"@types/node": "^20.14.10",
"@types/node": "^20.14.11",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"algoliasearch": "^4.24.0",
Expand All @@ -32,20 +32,20 @@
"graphql-request": "^7.1.0",
"graphql-tag": "^2.12.6",
"html-entities": "^2.5.2",
"html-react-parser": "^5.1.10",
"html-react-parser": "^5.1.12",
"next": "^14.2.5",
"postcss": "^8.4.39",
"qs": "^6.12.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-focus-lock": "^2.12.1",
"react-instantsearch": "^7.12.1",
"react-instantsearch-nextjs": "^0.3.6",
"react-instantsearch": "^7.12.2",
"react-instantsearch-nextjs": "^0.3.7",
"react-slick": "^0.30.2",
"react-tiny-oembed": "^1.1.0",
"sharp": "^0.33.4",
"tailwind-merge": "^2.4.0",
"tailwindcss": "^3.4.5",
"tailwindcss": "^3.4.6",
"typescript": "^5.5.3",
"usehooks-ts": "^3.1.0"
},
Expand All @@ -56,13 +56,13 @@
"@graphql-codegen/typescript-graphql-request": "^6.2.0",
"@graphql-codegen/typescript-operations": "^4.2.3",
"@next/bundle-analyzer": "^14.2.5",
"@storybook/addon-essentials": "^8.2.3",
"@storybook/addon-interactions": "^8.2.3",
"@storybook/addon-links": "^8.2.3",
"@storybook/addon-essentials": "^8.2.4",
"@storybook/addon-interactions": "^8.2.4",
"@storybook/addon-links": "^8.2.4",
"@storybook/addon-styling": "^1.3.7",
"@storybook/blocks": "^8.2.3",
"@storybook/nextjs": "^8.2.3",
"@storybook/react": "^8.2.3",
"@storybook/blocks": "^8.2.4",
"@storybook/nextjs": "^8.2.4",
"@storybook/react": "^8.2.4",
"@storybook/testing-library": "^0.2.2",
"@types/react-slick": "^0.23.13",
"concurrently": "^8.2.2",
Expand All @@ -71,13 +71,13 @@
"eslint-config-next": "^14.2.5",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-deprecation": "^3.0.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-storybook": "^0.8.0",
"eslint-plugin-unused-imports": "^4.0.0",
"prettier": "^3.3.3",
"prettier-plugin-tailwindcss": "^0.6.5",
"react-docgen": "^7.0.3",
"storybook": "^8.2.3",
"storybook": "^8.2.4",
"storybook-addon-module-mock": "^1.3.0",
"tsconfig-paths-webpack-plugin": "^4.1.0"
},
Expand Down
52 changes: 29 additions & 23 deletions src/components/paragraphs/stanford-lists/list-paragraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
NodeStanfordPublication,
NodeUnion,
ParagraphStanfordList,
StanfordBasicPagesQueryVariables,
StanfordBasicPagesSortKeys,
} from "@lib/gql/__generated__/drupal.d"
import {getParagraphBehaviors} from "@components/paragraphs/get-paragraph-behaviors"
import {graphqlClient} from "@lib/gql/gql-client"
Expand Down Expand Up @@ -139,7 +141,7 @@ const getViewPagedItems = cache(
let totalItems = 0
// View filters allow multiples of 3 for page sizes. If the user wants 4, we"ll fetch 6 and then slice it at the end.
const itemsPerPage = pageSize ? Math.min(Math.ceil(pageSize / 3) * 3, 99) : undefined
const queryVariables = {pageSize: itemsPerPage, page, offset}
const queryVariables: StanfordBasicPagesQueryVariables = {pageSize: itemsPerPage, page, offset}

const tags = ["views"]
switch (`${viewId}--${displayId}`) {
Expand All @@ -149,6 +151,7 @@ const getViewPagedItems = cache(

case "stanford_basic_pages--basic_page_type_list":
case "stanford_basic_pages--viewfield_block_1":
case "stanford_basic_pages--card_grid_alpha":
tags.push("views:stanford_page")
break

Expand Down Expand Up @@ -179,16 +182,19 @@ const getViewPagedItems = cache(
}

const client = graphqlClient({next: {tags}})
let filters = getViewFilters(["term_node_taxonomy_name_depth"], contextualFilter)
let contextualFilters = getContextualFilters(["term_node_taxonomy_name_depth"], contextualFilter)
let graphqlResponse

try {
switch (`${viewId}--${displayId}`) {
case "stanford_basic_pages--card_grid_alpha":
queryVariables.sortKey = StanfordBasicPagesSortKeys["Title"]

case "stanford_basic_pages--basic_page_type_list":
case "stanford_basic_pages--viewfield_block_1":
filters = getViewFilters(["term_node_taxonomy_name_depth"], contextualFilter)
contextualFilters = getContextualFilters(["term_node_taxonomy_name_depth"], contextualFilter)
graphqlResponse = await client.stanfordBasicPages({
filters,
contextualFilters,
...queryVariables,
})
items = graphqlResponse.stanfordBasicPages?.results as unknown as NodeStanfordPage[]
Expand All @@ -198,7 +204,7 @@ const getViewPagedItems = cache(
case "stanford_courses--default_list_viewfield_block":
case "stanford_courses--vertical_teaser_viewfield_block":
graphqlResponse = await client.stanfordCourses({
filters,
contextualFilters,
...queryVariables,
})
items = graphqlResponse.stanfordCourses?.results as unknown as NodeStanfordCourse[]
Expand All @@ -207,7 +213,7 @@ const getViewPagedItems = cache(

case "stanford_events--cards":
case "stanford_events--list_page":
filters = getViewFilters(
contextualFilters = getContextualFilters(
[
"term_node_taxonomy_name_depth",
"term_node_taxonomy_name_depth_1",
Expand All @@ -216,17 +222,17 @@ const getViewPagedItems = cache(
],
contextualFilter
)
graphqlResponse = await client.stanfordEventsCardGrid({
filters,
graphqlResponse = await client.stanfordEvents({
contextualFilters,
...queryVariables,
})
items = graphqlResponse.stanfordEventsCardGrid?.results as unknown as NodeStanfordEvent[]
totalItems = graphqlResponse.stanfordEventsCardGrid?.pageInfo.total || 0
items = graphqlResponse.stanfordEvents?.results as unknown as NodeStanfordEvent[]
totalItems = graphqlResponse.stanfordEvents?.pageInfo.total || 0
break

case "stanford_events--past_events_list_block":
graphqlResponse = await client.stanfordEventsPastEvents({
filters,
contextualFilters,
...queryVariables,
})
items = graphqlResponse.stanfordEventsPastEvents?.results as unknown as NodeStanfordEvent[]
Expand All @@ -235,17 +241,17 @@ const getViewPagedItems = cache(

case "stanford_news--block_1":
case "stanford_news--vertical_cards":
graphqlResponse = await client.stanfordNewsDefaultList({
filters,
graphqlResponse = await client.stanfordNews({
contextualFilters,
...queryVariables,
})
items = graphqlResponse.stanfordNewsDefaultList?.results as unknown as NodeStanfordNews[]
totalItems = graphqlResponse.stanfordNewsDefaultList?.pageInfo.total || 0
items = graphqlResponse.stanfordNews?.results as unknown as NodeStanfordNews[]
totalItems = graphqlResponse.stanfordNews?.pageInfo.total || 0
break

case "stanford_person--grid_list_all":
graphqlResponse = await client.stanfordPerson({
filters,
contextualFilters,
...queryVariables,
})
items = graphqlResponse.stanfordPerson?.results as unknown as NodeStanfordPerson[]
Expand All @@ -254,18 +260,18 @@ const getViewPagedItems = cache(

case "stanford_publications--apa_list":
case "stanford_publications--chicago_list":
graphqlResponse = await client.stanfordPublicationsApa({
filters,
graphqlResponse = await client.stanfordPublications({
contextualFilters,
...queryVariables,
})
items = graphqlResponse.stanfordPublicationsApa?.results as unknown as NodeStanfordPublication[]
totalItems = graphqlResponse.stanfordPublicationsApa?.pageInfo.total || 0
items = graphqlResponse.stanfordPublications?.results as unknown as NodeStanfordPublication[]
totalItems = graphqlResponse.stanfordPublications?.pageInfo.total || 0
break

case "stanford_shared_tags--card_grid":
filters = getViewFilters(["term_node_taxonomy_name_depth", "type"], contextualFilter)
contextualFilters = getContextualFilters(["term_node_taxonomy_name_depth", "type"], contextualFilter)
graphqlResponse = await client.stanfordSharedTags({
filters,
contextualFilters,
...queryVariables,
})
items = graphqlResponse.stanfordSharedTags?.results as unknown as NodeUnion[]
Expand All @@ -284,7 +290,7 @@ const getViewPagedItems = cache(
}
)

const getViewFilters = (
const getContextualFilters = (
keys: string[],
values?: Maybe<string[]>,
defaults: Record<string, string | undefined> = {}
Expand Down
1 change: 1 addition & 0 deletions src/components/views/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const View = async ({viewId, displayId, items, totalItems, loadPage, headingLeve
return <EventsListView items={items as NodeStanfordEvent[]} headingLevel={headingLevel} />

case "stanford_basic_pages--viewfield_block_1":
case "stanford_basic_pages--card_grid_alpha":
return <PageCardView items={items as NodeStanfordPage[]} headingLevel={headingLevel} />

case "stanford_shared_tags--card_grid":
Expand Down
Loading

0 comments on commit ad61d5d

Please sign in to comment.