Skip to content

Commit

Permalink
feat(ONYX-1479): add quick links section (#6354)
Browse files Browse the repository at this point in the history
* feat: add quick links section

Co-authored-by: Mounir Dhahri <[email protected]>

* chore: add tracking

Co-authored-by: Mounir Dhahri <[email protected]>

* chore: add tests

Co-authored-by: Mounir Dhahri <[email protected]>

* feat: add contextScreenOwnerId and ownerType

* Update src/schema/v2/homeView/sectionTypes/QuickLinks.ts

Co-authored-by: Mounir Dhahri <[email protected]>

* Update src/schema/v2/homeView/sectionTypes/QuickLinks.ts

Co-authored-by: Mounir Dhahri <[email protected]>

* chore: rename QiockLinks to NavigationPills

* chore: rename section id

* chore: rename

* chore: remove contextScreenOwnerId

* chore: fix text

* fix: broken test

---------

Co-authored-by: Mounir Dhahri <[email protected]>
  • Loading branch information
dariakoko and MounirDhahri authored Feb 3, 2025
1 parent c4e72f6 commit e50a89b
Show file tree
Hide file tree
Showing 12 changed files with 206 additions and 5 deletions.
30 changes: 30 additions & 0 deletions _schemaV2.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -11529,6 +11529,25 @@ type HomeViewSectionMarketingCollections implements HomeViewSectionGeneric & Nod
ownerType: String
}

# A selection of quick links in the home view
type HomeViewSectionNavigationPills implements HomeViewSectionGeneric & Node {
# Component prescription for this section, for overriding or customizing presentation and behavior
component: HomeViewComponent

# [Analytics] `context module` analytics value for this section, as defined in our schema (artsy/cohesion)
contextModule: String

# A globally unique ID.
id: ID!

# A type-specific ID likely used as a database ID.
internalID: ID!

# [Analytics] `owner type` analytics value for this scetion when displayed in a standalone UI, as defined in our schema (artsy/cohesion)
ownerType: String
quickLinks: [NavigationPill]!
}

# A sales (auctions) section in the home view
type HomeViewSectionSales implements HomeViewSectionGeneric & Node {
# Component prescription for this section, for overriding or customizing presentation and behavior
Expand Down Expand Up @@ -14545,6 +14564,17 @@ type MyLocation {
timezone: String
}

type NavigationPill {
# Quick link URL
href: String!

# The context module for analytics
ownerType: String!

# Quick link title
title: String!
}

input Near {
lat: Float!
lng: Float!
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"string-width": "4.2.3"
},
"dependencies": {
"@artsy/cohesion": "^4.219.0",
"@artsy/cohesion": "^4.228.0",
"@artsy/img": "1.0.3",
"@artsy/morgan": "^1.0.2",
"@artsy/multienv": "^1.2.0",
Expand Down
6 changes: 6 additions & 0 deletions src/schema/v2/homeView/__tests__/HomeView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ describe("homeView", () => {
expect(homeView.sectionsConnection).toMatchInlineSnapshot(`
{
"edges": [
{
"node": {
"__typename": "HomeViewSectionNavigationPills",
"component": null,
},
},
{
"node": {
"__typename": "HomeViewSectionTasks",
Expand Down
47 changes: 47 additions & 0 deletions src/schema/v2/homeView/sectionTypes/NavigationPills.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {
GraphQLList,
GraphQLNonNull,
GraphQLObjectType,
GraphQLString,
} from "graphql"
import { ResolverContext } from "types/graphql"
import { NodeInterface } from "../../object_identification"
import { HomeViewGenericSectionInterface } from "./GenericSectionInterface"
import { HomeViewSectionTypeNames } from "./names"
import { standardSectionFields } from "./GenericSectionInterface"
import { QuickLink } from "../sections/QuickLinks"

const NavigationPillType = new GraphQLObjectType<QuickLink, ResolverContext>({
name: "NavigationPill",
fields: () => ({
title: {
type: new GraphQLNonNull(GraphQLString),
description: "Quick link title",
},
href: {
type: new GraphQLNonNull(GraphQLString),
description: "Quick link URL",
},
ownerType: {
type: new GraphQLNonNull(GraphQLString),
description: "The context module for analytics",
},
}),
})

export const HomeViewNavigationPillsSectionType = new GraphQLObjectType<
any,
ResolverContext
>({
name: HomeViewSectionTypeNames.HomeViewSectionNavigationPills,
description: "A selection of quick links in the home view",
interfaces: [HomeViewGenericSectionInterface, NodeInterface],
fields: {
...standardSectionFields,
quickLinks: {
type: new GraphQLNonNull(new GraphQLList(NavigationPillType)),
resolve: (parent, ...rest) =>
parent.resolver ? parent.resolver(parent, ...rest) : [],
},
},
})
2 changes: 2 additions & 0 deletions src/schema/v2/homeView/sectionTypes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { HomeViewSalesSectionType } from "./Sales"
import { HomeViewShowsSectionType } from "./Shows"
import { HomeViewTasksSectionType } from "./Tasks"
import { HomeViewViewingRoomsSectionType } from "./ViewingRooms"
import { HomeViewNavigationPillsSectionType } from "./NavigationPills"

export const homeViewSectionTypes: GraphQLObjectType<any, ResolverContext>[] = [
HomeViewActivitySectionType,
Expand All @@ -26,6 +27,7 @@ export const homeViewSectionTypes: GraphQLObjectType<any, ResolverContext>[] = [
HomeViewFairsSectionType,
HomeViewHeroUnitsSectionType,
HomeViewMarketingCollectionsSectionType,
HomeViewNavigationPillsSectionType,
HomeViewSalesSectionType,
HomeViewShowsSectionType,
HomeViewTasksSectionType,
Expand Down
1 change: 1 addition & 0 deletions src/schema/v2/homeView/sectionTypes/names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const HomeViewSectionTypeNames = {
HomeViewSectionGeneric: "HomeViewSectionGeneric",
HomeViewSectionHeroUnits: "HomeViewSectionHeroUnits",
HomeViewSectionMarketingCollections: "HomeViewSectionMarketingCollections",
HomeViewSectionNavigationPills: "HomeViewSectionNavigationPills",
HomeViewSectionSales: "HomeViewSectionSales",
HomeViewSectionShows: "HomeViewSectionShows",
HomeViewSectionTasks: "HomeViewSectionTasks",
Expand Down
37 changes: 37 additions & 0 deletions src/schema/v2/homeView/sections/QuickLinks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { ContextModule, OwnerType } from "@artsy/cohesion"
import { HomeViewSection } from "."
import { HomeViewSectionTypeNames } from "../sectionTypes/names"

export const QuickLinks: HomeViewSection = {
id: "home-view-section-quick-links",
contextModule: ContextModule.quickLinks,
ownerType: OwnerType.quickLinks,
type: HomeViewSectionTypeNames.HomeViewSectionNavigationPills,
requiresAuthentication: true,
resolver: () => {
return QUICK_LINKS
},
}

export interface QuickLink {
title: string
href: string
ownerType: OwnerType
}

const QUICK_LINKS: Array<QuickLink> = [
{ title: "Follows", href: "/favorites", ownerType: OwnerType.follows },
{ title: "Auctions", href: "/auctions", ownerType: OwnerType.auctions },
{ title: "Saves", href: "/favorites/saves", ownerType: OwnerType.saves },
{
title: "Art under $1000",
href: "/collect?price_range=%2A-1000",
ownerType: OwnerType.collect,
},
{
title: "Price Database",
href: "/price-database",
ownerType: OwnerType.priceDatabase,
},
{ title: "Editorial", href: "/news", ownerType: OwnerType.articles },
]
73 changes: 73 additions & 0 deletions src/schema/v2/homeView/sections/__tests__/QuickLinks.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import gql from "lib/gql"
import { runQuery } from "schema/v2/test/utils"

describe("QuickLinks", () => {
it("returns the section's data", async () => {
const query = gql`
{
homeView {
section(id: "home-view-section-quick-links") {
__typename
internalID
contextModule
ownerType
... on HomeViewSectionNavigationPills {
quickLinks {
title
href
ownerType
}
}
}
}
}
`

const context = {
accessToken: "424242",
}

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

expect(homeView.section).toMatchInlineSnapshot(`
{
"__typename": "HomeViewSectionNavigationPills",
"contextModule": "quickLinks",
"internalID": "home-view-section-quick-links",
"ownerType": "quickLinks",
"quickLinks": [
{
"href": "/favorites",
"ownerType": "follows",
"title": "Follows",
},
{
"href": "/auctions",
"ownerType": "auctions",
"title": "Auctions",
},
{
"href": "/favorites/saves",
"ownerType": "saves",
"title": "Saves",
},
{
"href": "/collect?price_range=%2A-1000",
"ownerType": "collect",
"title": "Art under $1000",
},
{
"href": "/price-database",
"ownerType": "priceDatabase",
"title": "Price Database",
},
{
"href": "/news",
"ownerType": "articles",
"title": "Editorial",
},
],
}
`)
})
})
2 changes: 2 additions & 0 deletions src/schema/v2/homeView/sections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { TrendingArtists } from "./TrendingArtists"
import { ViewingRooms } from "./ViewingRooms"
import { InfiniteDiscovery } from "./InfiniteDiscovery"
import { SemanticVersionNumber } from "lib/semanticVersioning"
import { QuickLinks } from "./QuickLinks"

type MaybeResolved<T> =
| T
Expand Down Expand Up @@ -70,6 +71,7 @@ const sections: HomeViewSection[] = [
News,
NewWorksForYou,
NewWorksFromGalleriesYouFollow,
QuickLinks,
RecentlyViewedArtworks,
RecommendedArtists,
RecommendedArtworks,
Expand Down
1 change: 1 addition & 0 deletions src/schema/v2/homeView/zones/__tests__/default.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe("getSections", () => {

expect(sectionIds).toMatchInlineSnapshot(`
[
"home-view-section-quick-links",
"home-view-section-tasks",
"home-view-section-latest-activity",
"home-view-section-new-works-for-you",
Expand Down
2 changes: 2 additions & 0 deletions src/schema/v2/homeView/zones/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ import { Tasks } from "../sections/Tasks"
import { TrendingArtists } from "../sections/TrendingArtists"
import { ViewingRooms } from "../sections/ViewingRooms"
import { InfiniteDiscovery } from "../sections/InfiniteDiscovery"
import { QuickLinks } from "../sections/QuickLinks"

const SECTIONS: HomeViewSection[] = [
QuickLinks,
Tasks,
LatestActivity,
NewWorksForYou,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"@jridgewell/gen-mapping" "^0.3.5"
"@jridgewell/trace-mapping" "^0.3.24"

"@artsy/cohesion@^4.219.0":
version "4.219.0"
resolved "https://registry.yarnpkg.com/@artsy/cohesion/-/cohesion-4.219.0.tgz#331cdd7ea0b0f76754cac65c17ac8c0a145d1392"
integrity sha512-KzDpewJfnuZ+WoGqlVlFcE307yALyWtzdtw58QjCW1JAZZOGUi4inEf4zpVsqcmeARJCzVHvqySej+ZBkbtkjg==
"@artsy/cohesion@^4.228.0":
version "4.228.0"
resolved "https://registry.yarnpkg.com/@artsy/cohesion/-/cohesion-4.228.0.tgz#7fc5346fcf6f516be4236be06c5758448225ec11"
integrity sha512-2XwygAKbVsZZyM8KQ/Eo/oZVfirS7t/bMuxo16QE9UwbeBbRs6SIxhmnk6I1xjrKWhUiri+B46qAWYcwGXSk0g==
dependencies:
core-js "3"

Expand Down

0 comments on commit e50a89b

Please sign in to comment.