-
Notifications
You must be signed in to change notification settings - Fork 74
/
index.tsx
301 lines (289 loc) · 9.7 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
import { Box, Separator } from "@artsy/palette"
import { Collection_collection } from "__generated__/Collection_collection.graphql"
import { SeoProductsForArtworks } from "Apps/Collect2/Components/SeoProductsForArtworks"
import { CollectionFilterFragmentContainer as CollectionHeader } from "Apps/Collect2/Routes/Collection/Components/Header"
import { AppContainer } from "Apps/Components/AppContainer"
import { track } from "Artsy/Analytics"
import * as Schema from "Artsy/Analytics/Schema"
import { SystemContextProps, withSystemContext } from "Artsy/SystemContext"
import { FrameWithRecentlyViewed } from "Components/FrameWithRecentlyViewed"
import { RelatedCollectionsRailFragmentContainer as RelatedCollectionsRail } from "Components/RelatedCollectionsRail/RelatedCollectionsRail"
import { BreadCrumbList } from "Components/v2/Seo"
import { Match } from "found"
import { HttpError } from "found"
import React, { Component } from "react"
import { Link, Meta, Title } from "react-head"
import { createRefetchContainer, graphql, RelayRefetchProp } from "react-relay"
import { data as sd } from "sharify"
import truncate from "trunc-html"
import { CollectionsHubRailsContainer as CollectionsHubRails } from "./Components/CollectionsHubRails"
import { trackPageViewWrapper } from "Artsy"
import { BaseArtworkFilter } from "Components/v2/ArtworkFilter"
import {
ArtworkFilterContextProvider,
SharedArtworkFilterContextProps,
} from "Components/v2/ArtworkFilter/ArtworkFilterContext"
import { updateUrl } from "Components/v2/ArtworkFilter/Utils/urlBuilder"
import { TrackingProp } from "react-tracking"
interface CollectionAppProps extends SystemContextProps {
collection: Collection_collection
match: Match
relay: RelayRefetchProp
tracking: TrackingProp
}
@track<CollectionAppProps>(props => ({
context_module: Schema.ContextModule.CollectionDescription,
context_page_owner_slug: props.collection && props.collection.slug,
context_page_owner_id: props.collection && props.collection.slug,
}))
export class CollectionApp extends Component<CollectionAppProps> {
collectionNotFound = collection => {
if (!collection) {
throw new HttpError(404)
}
}
UNSAFE_componentWillMount() {
this.collectionNotFound(this.props.collection)
}
// TODO: Remove after AB test ends.
componentDidMount() {
const { tracking } = this.props
const { CLIENT_NAVIGATION } = sd
const experiment = "client_navigation"
const variation = CLIENT_NAVIGATION
tracking.trackEvent({
action_type: Schema.ActionType.ExperimentViewed,
experiment_id: experiment,
experiment_name: experiment,
variation_id: variation,
variation_name: variation,
nonInteraction: 1,
})
}
render() {
const {
collection,
match: { location },
relay,
} = this.props
const {
title,
slug,
headerImage,
description,
artworksConnection,
} = collection
const collectionHref = `${sd.APP_URL}/collection/${slug}`
const metadataDescription = description
? `Buy, bid, and inquire on ${title} on Artsy. ` +
truncate(description, 158).text
: `Buy, bid, and inquire on ${title} on Artsy.`
const showCollectionHubs = collection.linkedCollections.length > 0
return (
<AppContainer>
<FrameWithRecentlyViewed>
<Title>{`${title} - For Sale on Artsy`}</Title>
<Meta name="description" content={metadataDescription} />
<Meta property="og:url" content={collectionHref} />
<Meta property="og:image" content={headerImage} />
<Meta property="og:description" content={metadataDescription} />
<Meta property="twitter:description" content={metadataDescription} />
<Link rel="canonical" href={collectionHref} />
<BreadCrumbList
items={[
{ path: "/collections", name: "Collections" },
{ path: `/collection/${slug}`, name: title },
]}
/>
{artworksConnection && (
<SeoProductsForArtworks artworks={artworksConnection} />
)}
<CollectionHeader
collection={collection}
artworks={artworksConnection}
/>
{showCollectionHubs && (
<CollectionsHubRails
linkedCollections={collection.linkedCollections}
/>
)}
<Box>
<ArtworkFilterContextProvider
filters={location.query}
sortOptions={[
{ value: "-decayed_merch", text: "Default" },
{ value: "sold,-has_price,-prices", text: "Price (desc.)" },
{ value: "sold,-has_price,prices", text: "Price (asc.)" },
{ value: "-partner_updated_at", text: "Recently updated" },
{ value: "-published_at", text: "Recently added" },
{ value: "-year", text: "Artwork year (desc.)" },
{ value: "year", text: "Artwork year (asc.)" },
]}
aggregations={
artworksConnection.aggregations as SharedArtworkFilterContextProps["aggregations"]
}
onChange={updateUrl}
onFilterClick={(key, value, filterState) => {
this.props.tracking.trackEvent({
action_type: Schema.ActionType.CommercialFilterParamsChanged,
changed: { [key]: value },
current: filterState,
})
}}
>
<BaseArtworkFilter
relay={relay}
viewer={collection}
relayVariables={{
slug: collection.slug,
first: 30,
}}
/>
</ArtworkFilterContextProvider>
</Box>
{collection.linkedCollections.length === 0 && (
<>
<Separator mt={6} mb={3} />
<Box mt="3">
<RelatedCollectionsRail
collections={collection.relatedCollections}
title={collection.title}
lazyLoadImages
/>
</Box>
</>
)}
</FrameWithRecentlyViewed>
</AppContainer>
)
}
}
// TODO: Add `@principalField` to below query
// when KAWS returns a 404 in `errors` for non-existent collections.
// Currently it doesn't send any errors so there isn't anything
// for Metaphysics to propagate.
export const CollectionAppQuery = graphql`
query CollectionRefetch2Query(
$acquireable: Boolean
$aggregations: [ArtworkAggregation] = [
MERCHANDISABLE_ARTISTS
MEDIUM
MAJOR_PERIOD
TOTAL
]
$atAuction: Boolean
$color: String
$forSale: Boolean
$height: String
$inquireableOnly: Boolean
$majorPeriods: [String]
$medium: String
$offerable: Boolean
$page: Int
$priceRange: String
$sort: String
$slug: String!
$width: String
) {
collection: marketingCollection(slug: $slug) {
...Collection_collection
@arguments(
acquireable: $acquireable
aggregations: $aggregations
atAuction: $atAuction
color: $color
forSale: $forSale
height: $height
inquireableOnly: $inquireableOnly
majorPeriods: $majorPeriods
medium: $medium
offerable: $offerable
page: $page
priceRange: $priceRange
sort: $sort
width: $width
first: 30
)
}
}
`
export const CollectionRefetchContainer = createRefetchContainer(
withSystemContext(trackPageViewWrapper(CollectionApp)),
{
collection: graphql`
fragment Collection_collection on MarketingCollection
@argumentDefinitions(
acquireable: { type: "Boolean" }
aggregations: { type: "[ArtworkAggregation]" }
atAuction: { type: "Boolean" }
color: { type: "String" }
forSale: { type: "Boolean" }
height: { type: "String" }
inquireableOnly: { type: "Boolean" }
majorPeriods: { type: "[String]" }
medium: { type: "String", defaultValue: "*" }
offerable: { type: "Boolean" }
page: { type: "Int" }
priceRange: { type: "String" }
sort: { type: "String", defaultValue: "-partner_updated_at" }
width: { type: "String" }
first: { type: "Int" }
) {
...Header_collection
description
headerImage
slug
title
query {
artist_id: artistID
gene_id: geneID
}
relatedCollections {
...RelatedCollectionsRail_collections
}
linkedCollections {
...CollectionsHubRails_linkedCollections
}
artworksConnection(
aggregations: $aggregations
includeMediumFilterInAggregation: true
size: 20
first: 20
sort: "-decayed_merch"
) {
...Header_artworks
...SeoProductsForArtworks_artworks
aggregations {
slice
counts {
value
name
count
}
}
}
filtered_artworks: artworksConnection(
acquireable: $acquireable
aggregations: $aggregations
atAuction: $atAuction
color: $color
forSale: $forSale
height: $height
inquireableOnly: $inquireableOnly
majorPeriods: $majorPeriods
medium: $medium
offerable: $offerable
page: $page
priceRange: $priceRange
first: $first
sort: $sort
width: $width
) {
id
...ArtworkFilterArtworkGrid2_filtered_artworks
}
}
`,
},
CollectionAppQuery
)