Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DONT MERGE] chore(EMI-2213): client side signals tracking #15055

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
OwnerType,
} from "@artsy/cohesion"
import { ShelfArtworkFragmentContainer } from "Components/Artwork/ShelfArtwork"
import { useArtworkGridContext } from "Components/ArtworkGrid/ArtworkGridContext"
import { Rail } from "Components/Rail/Rail"
import { extractNodes } from "Utils/extractNodes"
import { getSignalLabel } from "Utils/getSignalLabel"
Expand All @@ -23,6 +24,7 @@ export const ArtistSeriesArtworkRail: React.FC<
const { trackEvent } = useTracking()
const { artistSeriesConnection } = artwork
const nodes = extractNodes(artistSeriesConnection)
const { signals } = useArtworkGridContext()

if (nodes.length === 0) {
return null
Expand Down Expand Up @@ -73,9 +75,9 @@ export const ArtistSeriesArtworkRail: React.FC<
destination_page_owner_slug: artwork.slug,
horizontal_slide_position: index,
type: "thumbnail",
signal_label: artwork.collectorSignals
? getSignalLabel(artwork.collectorSignals)
: "",
signal_label: getSignalLabel({
signals: signals?.[artwork.internalID] ?? [],
}),
signal_bid_count:
artwork.collectorSignals?.auction?.bidCount ?? undefined,
signal_lot_watcher_count:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { useRouter } from "System/Hooks/useRouter"
import { useMutation } from "Utils/Hooks/useMutation"
import { useTimer } from "Utils/Hooks/useTimer"
import { extractNodes } from "Utils/extractNodes"
import { getSignalLabel } from "Utils/getSignalLabel"
import { getSignalLabel, signalsToArray } from "Utils/getSignalLabel"
import type { ResponsiveValue } from "styled-system"

interface ArtworkSidebarCommercialButtonsProps {
Expand All @@ -65,6 +65,8 @@ export const ArtworkSidebarCommercialButtons: React.FC<
const artwork = useFragment(ARTWORK_FRAGMENT, props.artwork)
const me = useFragment(ME_FRAGMENT, props.me)

const signals = signalsToArray(artwork.collectorSignals)

// Get the first partner offer
const partnerOffer =
(me?.partnerOffersConnection &&
Expand Down Expand Up @@ -120,9 +122,7 @@ export const ArtworkSidebarCommercialButtons: React.FC<
context_owner_type: OwnerType.artwork,
context_owner_slug: artwork.slug,
context_owner_id: artwork.internalID,
signal_label: artwork.collectorSignals
? getSignalLabel(artwork.collectorSignals)
: "",
signal_label: getSignalLabel({ signals }) ?? "",
}
trackEvent(event)

Expand All @@ -136,9 +136,7 @@ export const ArtworkSidebarCommercialButtons: React.FC<
context_owner_id: artwork.internalID,
context_owner_slug: artwork.slug,
flow: "Partner offer",
signal_label: artwork.collectorSignals
? getSignalLabel(artwork.collectorSignals)
: "",
signal_label: getSignalLabel({ signals }) ?? "",
}

trackEvent(event)
Expand Down Expand Up @@ -195,9 +193,7 @@ export const ArtworkSidebarCommercialButtons: React.FC<
context_owner_id: artwork.internalID,
context_owner_slug: artwork.slug,
flow: "Buy now",
signal_label: artwork.collectorSignals
? getSignalLabel(artwork.collectorSignals)
: "",
signal_label: getSignalLabel({ signals }) ?? "",
}

trackEvent(event)
Expand Down Expand Up @@ -334,11 +330,7 @@ export const ArtworkSidebarCommercialButtons: React.FC<
setSelectedEditionSetInContext(
firstAvailableEcommerceEditionSet() as EditionSet,
)
}, [
artwork.editionSets,
firstAvailableEcommerceEditionSet,
setSelectedEditionSetInContext,
])
}, [firstAvailableEcommerceEditionSet, setSelectedEditionSetInContext])

const isCreateAlertAvailable =
artwork.isEligibleToCreateAlert && artwork.isSold
Expand All @@ -353,7 +345,9 @@ export const ArtworkSidebarCommercialButtons: React.FC<
}
if (artwork.isOfferable && !(activePartnerOffer && artwork.isInquireable)) {
renderButtons.makeOffer =
Object.keys(renderButtons).length == 0 ? "primaryBlack" : "secondaryBlack"
Object.keys(renderButtons).length === 0
? "primaryBlack"
: "secondaryBlack"
}
if (artwork.isInquireable && Object.keys(renderButtons).length < 2) {
renderButtons.contactGallery =
Expand Down Expand Up @@ -697,7 +691,11 @@ const ARTWORK_FRAGMENT = graphql`
}
}
collectorSignals {
primaryLabel(ignore: [PARTNER_OFFER])
partnerOffer {
endAt
}
increasedInterest
curatorsPick
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now on the MP schema side, we separate out the fields requiring auth (e.g. partnerOffer) from fields without requiring auth (e.g. primaryLabel), we'll need to request them both.

}
}
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "@artsy/cohesion"
import { themeGet } from "@styled-system/theme-get"
import { RouterLink } from "System/Components/RouterLink"
import { getSignalLabel } from "Utils/getSignalLabel"
import { getSignalLabel, signalsToArray } from "Utils/getSignalLabel"
import type { ArtworkSidebarPartnerInfo_artwork$data } from "__generated__/ArtworkSidebarPartnerInfo_artwork.graphql"
import { createFragmentContainer, graphql } from "react-relay"
import { useTracking } from "react-tracking"
Expand Down Expand Up @@ -50,6 +50,8 @@ const ArtworkSidebarPartnerInfo: React.FC<
collectorSignals,
} = artwork

const signals = signalsToArray(artwork.collectorSignals)

const { trackEvent } = useTracking()

const { showInquiry, inquiryComponent } = useInquiry({
Expand All @@ -65,7 +67,7 @@ const ArtworkSidebarPartnerInfo: React.FC<
context_owner_type: OwnerType.artwork,
context_owner_slug: slug,
context_owner_id: internalID,
signal_label: collectorSignals ? getSignalLabel(collectorSignals) : "",
signal_label: collectorSignals ? getSignalLabel({ signals }) : "",
}

trackEvent(event)
Expand Down Expand Up @@ -172,7 +174,11 @@ export const ArtworkSidebarPartnerInfoFragmentContainer =
href
}
collectorSignals {
primaryLabel(ignore: [PARTNER_OFFER])
partnerOffer {
endAt
}
increasedInterest
curatorsPick
}
}
`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ describe("ArtworkSidebarPartnerInfo", () => {
isInquireable: true,
},
collectorSignals: {
primaryLabel: null,
partnerOffer: null,
increasedInterest: false,
curatorsPick: false,
},
}),
})
Expand Down
14 changes: 9 additions & 5 deletions src/Apps/Home/Components/HomeEmergingPicksArtworksRail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import {
ShelfArtworkFragmentContainer,
ShelfArtworkPlaceholder,
} from "Components/Artwork/ShelfArtwork"
import { ArtworkGridContextProvider } from "Components/ArtworkGrid/ArtworkGridContext"
import {
ArtworkGridContextProvider,
useArtworkGridContext,
} from "Components/ArtworkGrid/ArtworkGridContext"
import { Rail } from "Components/Rail/Rail"
import { SystemQueryRenderer } from "System/Relay/SystemQueryRenderer"
import { extractNodes } from "Utils/extractNodes"
Expand All @@ -27,7 +30,7 @@ export const HomeEmergingPicksArtworksRail: React.FC<
React.PropsWithChildren<HomeEmergingPicksArtworksRailProps>
> = ({ viewer }) => {
const { trackEvent } = useTracking()

const { signals } = useArtworkGridContext()
const artworks = extractNodes(viewer.artworksConnection)

if (artworks.length === 0) {
Expand Down Expand Up @@ -71,9 +74,10 @@ export const HomeEmergingPicksArtworksRail: React.FC<
destination_page_owner_id: artwork.internalID,
destination_page_owner_slug: artwork.slug,
type: "thumbnail",
signal_label: artwork.collectorSignals
? getSignalLabel(artwork.collectorSignals)
: "",
signal_label: getSignalLabel({
signals: signals?.[artwork.internalID] ?? [],
hideSignals: true,
}),
signal_bid_count:
artwork.collectorSignals?.auction?.bidCount ?? undefined,
signal_lot_watcher_count:
Expand Down
8 changes: 5 additions & 3 deletions src/Apps/Home/Components/HomeNewWorksForYouRail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ShelfArtworkFragmentContainer,
ShelfArtworkPlaceholder,
} from "Components/Artwork/ShelfArtwork"
import { useArtworkGridContext } from "Components/ArtworkGrid/ArtworkGridContext"
import { useSystemContext } from "System/Hooks/useSystemContext"
import { SystemQueryRenderer } from "System/Relay/SystemQueryRenderer"
import { extractNodes } from "Utils/extractNodes"
Expand All @@ -27,6 +28,7 @@ const HomeNewWorksForYouRail: React.FC<
React.PropsWithChildren<HomeNewWorksForYouRailProps>
> = ({ artworksForUser }) => {
const { trackEvent } = useTracking()
const { signals } = useArtworkGridContext()

const artworks = extractNodes(artworksForUser)
if (!artworks || artworks?.length === 0) {
Expand Down Expand Up @@ -55,9 +57,9 @@ const HomeNewWorksForYouRail: React.FC<
destination_page_owner_slug: artwork.slug,
destination_page_owner_type: OwnerType.artwork,
type: "thumbnail",
signal_label: artwork.collectorSignals
? getSignalLabel(artwork.collectorSignals)
: "",
signal_label: getSignalLabel({
signals: signals?.[artwork.internalID] ?? [],
}),
signal_bid_count:
artwork.collectorSignals?.auction?.bidCount ?? undefined,
signal_lot_watcher_count:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ShelfArtworkFragmentContainer,
ShelfArtworkPlaceholder,
} from "Components/Artwork/ShelfArtwork"
import { useArtworkGridContext } from "Components/ArtworkGrid/ArtworkGridContext"
import { Rail } from "Components/Rail/Rail"
import { useAnalyticsContext } from "System/Hooks/useAnalyticsContext"
import { useSystemContext } from "System/Hooks/useSystemContext"
Expand All @@ -32,7 +33,7 @@ const HomeNewWorksFromGalleriesYouFollowRail: React.FC<
const { trackEvent } = useTracking()
const { contextPageOwnerId, contextPageOwnerSlug, contextPageOwnerType } =
useAnalyticsContext()

const { signals } = useArtworkGridContext()
const artworks = extractNodes(newWorksFromGalleriesYouFollowConnection)

if (!artworks || artworks?.length === 0) {
Expand Down Expand Up @@ -72,9 +73,9 @@ const HomeNewWorksFromGalleriesYouFollowRail: React.FC<
destination_page_owner_id: artwork.internalID,
destination_page_owner_slug: artwork.slug,
type: "thumbnail",
signal_label: artwork.collectorSignals
? getSignalLabel(artwork.collectorSignals)
: "",
signal_label: getSignalLabel({
signals: signals?.[artwork.internalID] ?? [],
}),
signal_bid_count:
artwork.collectorSignals?.auction?.bidCount ?? undefined,
signal_lot_watcher_count:
Expand Down
8 changes: 5 additions & 3 deletions src/Apps/Home/Components/HomeRecentlyViewedRail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ShelfArtworkFragmentContainer,
ShelfArtworkPlaceholder,
} from "Components/Artwork/ShelfArtwork"
import { useArtworkGridContext } from "Components/ArtworkGrid/ArtworkGridContext"
import { useSystemContext } from "System/Hooks/useSystemContext"
import { SystemQueryRenderer } from "System/Relay/SystemQueryRenderer"
import { getSignalLabel } from "Utils/getSignalLabel"
Expand All @@ -26,6 +27,7 @@ const HomeRecentlyViewedRail: React.FC<
React.PropsWithChildren<HomeRecentlyViewedRailProps>
> = ({ homePage }) => {
const { trackEvent } = useTracking()
const { signals } = useArtworkGridContext()

const results = homePage.artworkModule?.results
if (!results || results?.length === 0) {
Expand Down Expand Up @@ -54,9 +56,9 @@ const HomeRecentlyViewedRail: React.FC<
destination_page_owner_slug: artwork.slug,
destination_page_owner_type: OwnerType.artwork,
type: "thumbnail",
signal_label: artwork.collectorSignals
? getSignalLabel(artwork.collectorSignals)
: "",
signal_label: getSignalLabel({
signals: signals?.[artwork.internalID] ?? [],
}),
signal_bid_count:
artwork.collectorSignals?.auction?.bidCount ?? undefined,
signal_lot_watcher_count:
Expand Down
8 changes: 5 additions & 3 deletions src/Apps/Home/Components/HomeWorksByArtistsYouFollowRail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ShelfArtworkFragmentContainer,
ShelfArtworkPlaceholder,
} from "Components/Artwork/ShelfArtwork"
import { useArtworkGridContext } from "Components/ArtworkGrid/ArtworkGridContext"
import { useSystemContext } from "System/Hooks/useSystemContext"
import { SystemQueryRenderer } from "System/Relay/SystemQueryRenderer"
import { getSignalLabel } from "Utils/getSignalLabel"
Expand All @@ -26,6 +27,7 @@ const HomeWorksByArtistsYouFollowRail: React.FC<
React.PropsWithChildren<HomeWorksByArtistsYouFollowRailProps>
> = ({ homePage }) => {
const { trackEvent } = useTracking()
const { signals } = useArtworkGridContext()

const results = homePage.artworkModule?.results
if (!results || results?.length === 0) {
Expand Down Expand Up @@ -54,9 +56,9 @@ const HomeWorksByArtistsYouFollowRail: React.FC<
destination_page_owner_slug: artwork.slug,
destination_page_owner_type: OwnerType.artwork,
type: "thumbnail",
signal_label: artwork.collectorSignals
? getSignalLabel(artwork.collectorSignals)
: "",
signal_label: getSignalLabel({
signals: signals?.[artwork.internalID] ?? [],
}),
signal_bid_count:
artwork.collectorSignals?.auction?.bidCount ?? undefined,
signal_lot_watcher_count:
Expand Down
37 changes: 20 additions & 17 deletions src/Apps/Home/HomeApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Join, Spacer } from "@artsy/palette"
import { MyBidsQueryRenderer } from "Apps/Auctions/Components/MyBids/MyBids"
import { HomeAuctionLotsTabBar } from "Apps/Home/Components/HomeAuctionLotsTabBar"
import { HomeNewWorksFromGalleriesYouFollowRailQueryRenderer } from "Apps/Home/Components/HomeNewWorksFromGalleriesYouFollowRail"
import { ArtworkGridContextProvider } from "Components/ArtworkGrid/ArtworkGridContext"
import { FlashBannerQueryRenderer } from "Components/FlashBanner"
import type { HomeApp_featuredEventsOrderedSet$data } from "__generated__/HomeApp_featuredEventsOrderedSet.graphql"
import type { HomeApp_heroUnitsConnection$data } from "__generated__/HomeApp_heroUnitsConnection.graphql"
Expand Down Expand Up @@ -40,33 +41,35 @@ export const HomeApp: React.FC<React.PropsWithChildren<HomeAppProps>> = ({
<Spacer y={[4, 6]} />

<Join separator={<Spacer y={[6, 12]} />}>
{featuredEventsOrderedSet && (
<>
<HomeFeaturedEventsRailFragmentContainer
orderedSet={featuredEventsOrderedSet}
/>
</>
)}
<ArtworkGridContextProvider>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same context and the signals data structure are shared among multiple grids/rails, and I think that means when rendering each grid/rail, the same signals will get updated. I guess it's possible that the desired signals of an artwork could be updated back and forth with server-side and client-side signals, but it would eventually settled with the desired signals, right?

{featuredEventsOrderedSet && (
<>
<HomeFeaturedEventsRailFragmentContainer
orderedSet={featuredEventsOrderedSet}
/>
</>
)}

<MyBidsQueryRenderer />
<MyBidsQueryRenderer />

<HomeWorksForYouTabBar />
<HomeWorksForYouTabBar />

<HomeEmergingPicksArtworksRailQueryRenderer />
<HomeEmergingPicksArtworksRailQueryRenderer />

<HomeFeaturedMarketNewsQueryRenderer />
<HomeFeaturedMarketNewsQueryRenderer />

<HomeAuctionLotsTabBar />
<HomeAuctionLotsTabBar />

<HomeFeaturedShowsRailQueryRenderer />
<HomeFeaturedShowsRailQueryRenderer />

<HomeCurrentFairsQueryRenderer />
<HomeCurrentFairsQueryRenderer />

<HomeFeaturedGalleriesRailQueryRenderer />
<HomeFeaturedGalleriesRailQueryRenderer />

<HomeNewWorksFromGalleriesYouFollowRailQueryRenderer />
<HomeNewWorksFromGalleriesYouFollowRailQueryRenderer />

<HomeTrendingArtistsRailQueryRenderer />
<HomeTrendingArtistsRailQueryRenderer />
</ArtworkGridContextProvider>
</Join>
</>
)
Expand Down
Loading