Skip to content

Commit

Permalink
feat(onyx-1229): add Auctions home view section (#5949)
Browse files Browse the repository at this point in the history
* feat(onyx-1229): add Auctions home view section

* add view all behavior
  • Loading branch information
nickskalkin authored Aug 28, 2024
1 parent 9d938af commit 0baa931
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 0 deletions.
19 changes: 19 additions & 0 deletions _schemaV2.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -11104,6 +11104,7 @@ union HomeViewSection =
| FairsRailHomeViewSection
| HeroUnitsHomeViewSection
| MarketingCollectionsRailHomeViewSection
| SalesRailHomeViewSection
| ShowsRailHomeViewSection
| ViewingRoomsRailHomeViewSection

Expand Down Expand Up @@ -18000,6 +18001,24 @@ enum SaleSorts {
_ID_DESC
}

# A sales rail section in the home view
type SalesRailHomeViewSection implements GenericHomeViewSection & Node {
# The component that is prescribed for this section
component: HomeViewComponent

# A globally unique ID.
id: ID!

# A type-specific ID likely used as a database ID.
internalID: ID!
salesConnection(
after: String
before: String
first: Int
last: Int
): SaleConnection
}

input SaveArtworkInput {
artworkID: String
clientMutationId: String
Expand Down
21 changes: 21 additions & 0 deletions src/schema/v2/homeView/HomeViewSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { NotificationsConnection } from "../notifications"
import { InternalIDFields, NodeInterface } from "../object_identification"
import { HomeViewComponent } from "./HomeViewComponent"
import { auctionResultConnection } from "../auction_result"
import { SalesConnectionField } from "../sales"

// section interface

Expand Down Expand Up @@ -217,6 +218,25 @@ export const AuctionResultsRailHomeViewSectionType = new GraphQLObjectType<
},
})

const SalesRailHomeViewSectionType = new GraphQLObjectType<
any,
ResolverContext
>({
name: "SalesRailHomeViewSection",
description: "A sales rail section in the home view",
interfaces: [GenericHomeViewSectionInterface, NodeInterface],
fields: {
...standardSectionFields,

salesConnection: {
type: SalesConnectionField.type,
args: pageable({}),
resolve: (parent, ...rest) =>
parent.resolver ? parent.resolver(parent, ...rest) : [],
},
},
})

// the Section union type of all concrete sections

export const HomeViewSectionType = new GraphQLUnionType({
Expand All @@ -232,6 +252,7 @@ export const HomeViewSectionType = new GraphQLUnionType({
MarketingCollectionsRailHomeViewSectionType,
ShowsRailHomeViewSectionType,
ViewingRoomsRailHomeViewSectionType,
SalesRailHomeViewSectionType,
],
resolveType: (value) => {
return value.type
Expand Down
8 changes: 8 additions & 0 deletions src/schema/v2/homeView/__tests__/HomeView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ describe("homeView", () => {
},
},
},
Object {
"node": Object {
"__typename": "SalesRailHomeViewSection",
"component": Object {
"title": "Auctions",
},
},
},
Object {
"node": Object {
"__typename": "ArtworksRailHomeViewSection",
Expand Down
81 changes: 81 additions & 0 deletions src/schema/v2/homeView/__tests__/HomeViewSection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -813,4 +813,85 @@ describe("HomeViewSection", () => {
`)
})
})

describe("SalesRailHomeViewSection", () => {
it("returns correct data", async () => {
const query = gql`
{
homeView {
section(id: "home-view-section-auctions") {
__typename
... on SalesRailHomeViewSection {
component {
title
behaviors {
viewAll {
href
buttonText
}
}
}
salesConnection(first: 2) {
edges {
node {
name
}
}
}
}
}
}
}
`

const sales = [
{
name: "Auction 1",
},
{
name: "Auction 2",
},
]

const context = {
authenticatedLoaders: {
meLoader: jest.fn().mockReturnValue({ type: "User" }),
},
salesLoader: jest.fn().mockResolvedValue(sales),
}

const { homeView } = await runQuery(query, context)

expect(homeView.section).toMatchInlineSnapshot(`
Object {
"__typename": "SalesRailHomeViewSection",
"component": Object {
"behaviors": Object {
"viewAll": Object {
"buttonText": "Browse All Auctions",
"href": "/auctions",
},
},
"title": "Auctions",
},
"salesConnection": Object {
"edges": Array [
Object {
"node": Object {
"name": "Auction 1",
},
},
Object {
"node": Object {
"name": "Auction 2",
},
},
],
},
}
`)
})
})
})
3 changes: 3 additions & 0 deletions src/schema/v2/homeView/getSectionsForUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
ViewingRooms,
LatestAuctionResults,
News,
Auctions,
} from "./sections"

export async function getSectionsForUser(
Expand All @@ -38,6 +39,7 @@ export async function getSectionsForUser(
sections = [
LatestActivity,
LatestAuctionResults,
Auctions,
LatestArticles,
RecentlyViewedArtworks,
ShowsForYou,
Expand All @@ -58,6 +60,7 @@ export async function getSectionsForUser(
sections = [
News,
LatestActivity,
Auctions,
CuratorsPicksEmerging,
SimilarToRecentlyViewedArtworks,
ShowsForYou,
Expand Down
21 changes: 21 additions & 0 deletions src/schema/v2/homeView/salesResolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { GraphQLFieldResolver } from "graphql"
import { ResolverContext } from "types/graphql"
import { HomePageSalesModuleType } from "../home/home_page_sales_module"
import { connectionFromArray } from "graphql-relay"

export const SalesResolver: GraphQLFieldResolver<any, ResolverContext> = async (
parent,
args,
context,
info
) => {
const { results: resolver } = HomePageSalesModuleType.getFields()

if (!resolver?.resolve) {
return []
}

const result = await resolver.resolve(parent, args, context, info)

return connectionFromArray(result, args)
}
17 changes: 17 additions & 0 deletions src/schema/v2/homeView/sections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { MarketingCollectionsResolver } from "./marketingCollectionsResolver"
import { LatestActivityResolver } from "./activityResolvers"
import { LatestAuctionResultsResolver } from "./auctionResultsResolvers"
import { HomeViewComponentBehaviors } from "./HomeViewComponent"
import { SalesResolver } from "./salesResolver"

export type HomeViewSection = {
id: string
Expand Down Expand Up @@ -221,7 +222,23 @@ export const News: HomeViewSection = {
resolver: NewsResolver,
}

export const Auctions: HomeViewSection = {
id: "home-view-section-auctions",
type: "SalesRailHomeViewSection",
component: {
title: "Auctions",
behaviors: {
viewAll: {
href: "/auctions",
buttonText: "Browse All Auctions",
},
},
},
resolver: SalesResolver,
}

const sections: HomeViewSection[] = [
Auctions,
AuctionLotsForYou,
CuratorsPicksEmerging,
FeaturedFairs,
Expand Down

0 comments on commit 0baa931

Please sign in to comment.