Skip to content

Commit

Permalink
Merge pull request #6541 from artsy/feat/FX-2193--viewing-room
Browse files Browse the repository at this point in the history
[FX-2193] Viewing room display on show pages
  • Loading branch information
mzikherman committed Oct 26, 2020
2 parents 436255d + 7d13050 commit bc771e1
Show file tree
Hide file tree
Showing 16 changed files with 1,001 additions and 140 deletions.
80 changes: 70 additions & 10 deletions src/v2/Apps/Show/Components/ShowViewingRoom.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,82 @@
import React from "react"
import { Box, BoxProps, ResponsiveBox, Text } from "@artsy/palette"
import { Box, BoxProps, MediumCard, ResponsiveBox, Text } from "@artsy/palette"
import { createFragmentContainer, graphql } from "react-relay"
import { ShowViewingRoom_show } from "v2/__generated__/ShowViewingRoom_show.graphql"
import { RouterLink } from "v2/Artsy/Router/RouterLink"
import { crop } from "v2/Utils/resizer"
import { getTagProps } from "v2/Components/ViewingRoomCard"

interface ShowViewingRoom extends BoxProps {}
interface ShowViewingRoomProps extends BoxProps {
show: ShowViewingRoom_show
}

export const ShowViewingRoom: React.FC<ShowViewingRoomProps> = ({
show,
...rest
}) => {
const [{ node: viewingRoom }] = show.viewingRoomsConnection.edges

const thumbnail = crop(viewingRoom.image.imageURLs.normalized, {
width: 900,
height: 1200,
})

export const ShowViewingRoom = ({ ...rest }) => {
return (
<Box {...rest}>
<Text variant="mediumText" mb={1}>
Viewing Room
</Text>

<ResponsiveBox
bg="black10"
borderRadius={4}
maxWidth="100%"
aspectWidth={3}
aspectHeight={4}
/>
<ResponsiveBox maxWidth="100%" aspectWidth={3} aspectHeight={4}>
<RouterLink to={viewingRoom.href}>
<MediumCard
width="100%"
height="100%"
image={thumbnail}
title={viewingRoom.title}
subtitle={show.partner?.name}
tag={getTagProps(
viewingRoom.status,
viewingRoom.distanceToOpen,
viewingRoom.distanceToClose
)}
/>
</RouterLink>
</ResponsiveBox>
</Box>
)
}

export const ShowViewingRoomFragmentContainer = createFragmentContainer(
ShowViewingRoom,
{
show: graphql`
fragment ShowViewingRoom_show on Show {
partner {
... on Partner {
name
}
... on ExternalPartner {
name
}
}
viewingRoomsConnection {
edges {
node {
status
distanceToOpen(short: true)
distanceToClose(short: true)
title
href
image {
imageURLs {
normalized
}
}
}
}
}
}
`,
}
)
12 changes: 5 additions & 7 deletions src/v2/Apps/Show/ShowApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import { createFragmentContainer, graphql } from "react-relay"
import { AppContainer } from "v2/Apps/Components/AppContainer"
import { HorizontalPadding } from "v2/Apps/Components/HorizontalPadding"
import { Footer } from "v2/Components/Footer"
import { ErrorPage } from "v2/Components/ErrorPage"
import { Box, Column, GridColumns, Separator } from "@artsy/palette"
import { ShowMetaFragmentContainer as ShowMeta } from "v2/Apps/Show/Components/ShowMeta"
import { ShowHeaderFragmentContainer as ShowHeader } from "./Components/ShowHeader"
import { ShowAboutFragmentContainer as ShowAbout } from "./Components/ShowAbout"
import { ShowInstallShotsFragmentContainer as ShowInstallShots } from "./Components/ShowInstallShots"
import { ShowContextualLinkFragmentContainer as ShowContextualLink } from "./Components/ShowContextualLink"
import { ShowViewingRoom } from "./Components/ShowViewingRoom"
import { ShowViewingRoomFragmentContainer as ShowViewingRoom } from "./Components/ShowViewingRoom"
import { ShowApp_show } from "v2/__generated__/ShowApp_show.graphql"
import { ShowArtworksRefetchContainer as ShowArtworks } from "./Components/ShowArtworks"
import { ForwardLink } from "v2/Components/Links/ForwardLink"
Expand All @@ -38,9 +37,7 @@ const FullScreenSeparator = styled(Separator)`
export const ShowApp: React.FC<ShowAppProps> = ({ show }) => {
const { contextPageOwnerSlug, contextPageOwnerType } = useAnalyticsContext()

if (!show) return <ErrorPage code={404} />

const hasViewingRoom = false // TODO
const hasViewingRoom = show.viewingRoomIDs.length > 0
const hasAbout = !!show.about
const hasWideHeader =
(hasAbout && hasViewingRoom) || (!hasAbout && !hasViewingRoom)
Expand Down Expand Up @@ -97,7 +94,7 @@ export const ShowApp: React.FC<ShowAppProps> = ({ show }) => {

{hasViewingRoom && (
<Column span={5} start={8}>
<ShowViewingRoom />
<ShowViewingRoom show={show} />
</Column>
)}
</GridColumns>
Expand Down Expand Up @@ -143,11 +140,13 @@ export default createFragmentContainer(ShowApp, {
internalID
slug
about: description
viewingRoomIDs
...ShowContextualLink_show
...ShowHeader_show
...ShowAbout_show
...ShowMeta_show
...ShowInstallShots_show
...ShowViewingRoom_show
...ShowArtworks_show
@arguments(
acquireable: $acquireable
Expand All @@ -165,7 +164,6 @@ export default createFragmentContainer(ShowApp, {
sizes: $sizes
sort: $sort
)
...ShowContextCard_show
}
`,
Expand Down
3 changes: 0 additions & 3 deletions src/v2/Apps/Show/ShowSubApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Separator } from "@artsy/palette"
import { ShowSubApp_show } from "v2/__generated__/ShowSubApp_show.graphql"
import { HorizontalPadding } from "v2/Apps/Components/HorizontalPadding"
import { Footer } from "v2/Components/Footer"
import { ErrorPage } from "v2/Components/ErrorPage"
import { BackLink } from "v2/Components/Links/BackLink"
import { ShowMetaFragmentContainer as ShowMeta } from "./Components/ShowMeta"
import {
Expand All @@ -20,8 +19,6 @@ interface ShowAppProps {
const ShowApp: React.FC<ShowAppProps> = ({ children, show }) => {
const { contextPageOwnerSlug, contextPageOwnerType } = useAnalyticsContext()

if (!show) return <ErrorPage code={404} />

return (
<>
<ShowMeta show={show} />
Expand Down
38 changes: 23 additions & 15 deletions src/v2/Apps/Show/__tests__/ShowApp.jest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { mount } from "enzyme"
import { MockPayloadGenerator, createMockEnvironment } from "relay-test-utils"
import { QueryRenderer, graphql } from "react-relay"
import ShowApp from "../ShowApp"
import { ShowViewingRoom } from "../Components/ShowViewingRoom"

jest.unmock("react-relay")

Expand All @@ -19,7 +20,7 @@ jest.mock("v2/Apps/Show/Components/ShowInstallShots", () => ({
}))

describe("ShowApp", () => {
const getWrapper = (response = {}) => {
const getWrapper = (mocks = {}) => {
const env = createMockEnvironment()

const TestRenderer = () => (
Expand All @@ -46,33 +47,30 @@ describe("ShowApp", () => {
const wrapper = mount(<TestRenderer />)

env.mock.resolveMostRecentOperation(operation =>
MockPayloadGenerator.generate(operation, {
Show: () => {
return {
name: "Example Show",
...response,
}
},
})
MockPayloadGenerator.generate(operation, mocks)
)
wrapper.update()
return wrapper
}

it("renders the title", () => {
const wrapper = getWrapper()
const wrapper = getWrapper({
Show: () => ({ name: "Example Show" }),
})
expect(wrapper.find("h1")).toHaveLength(1)
expect(wrapper.find("h1").text()).toEqual("Example Show")
})

it("renders the appropriate info", () => {
const wrapper = getWrapper({
href: "/show/example-href",
metaDescription: "Information about the show",
pressRelease: "Press Release",
partner: {
Show: () => ({
href: "/show/example-href",
metaDescription: "Information about the show",
pressRelease: "Press Release",
}),
Partner: () => ({
name: "Example Partner",
},
}),
})

expect(wrapper.text()).toContain("Information about the show")
Expand All @@ -85,4 +83,14 @@ describe("ShowApp", () => {
.first()
expect(moreInfoLink.prop("href")).toEqual("/show2/example-href/info")
})

it("renders a viewing room if there are any", () => {
const wrapper = getWrapper({
Show: () => ({
viewingRoomIDs: ["xxx"],
}),
})

expect(wrapper.find(ShowViewingRoom)).toHaveLength(1)
})
})
63 changes: 63 additions & 0 deletions src/v2/Apps/Show/__tests__/ShowViewingRoom.jest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React from "react"
import { mount } from "enzyme"
import { MockPayloadGenerator, createMockEnvironment } from "relay-test-utils"
import { QueryRenderer, graphql } from "react-relay"
import { ShowViewingRoomFragmentContainer as ShowViewingRoom } from "../Components/ShowViewingRoom"
import { ShowViewingRoom_Test_Query } from "v2/__generated__/ShowViewingRoom_Test_Query.graphql"

jest.unmock("react-relay")

describe("ShowViewingRoom", () => {
const getWrapper = (mocks = {}) => {
const env = createMockEnvironment()

const TestRenderer = () => (
<QueryRenderer<ShowViewingRoom_Test_Query>
environment={env}
variables={{}}
query={graphql`
query ShowViewingRoom_Test_Query {
show(id: "xxx") {
...ShowViewingRoom_show
}
}
`}
render={({ props, error }) => {
if (props?.show) {
return <ShowViewingRoom show={props.show} />
} else if (error) {
console.error(error)
}
}}
/>
)

const wrapper = mount(<TestRenderer />)

env.mock.resolveMostRecentOperation(operation =>
MockPayloadGenerator.generate(operation, {
...mocks,
})
)
wrapper.update()
return wrapper
}

it("renders correctly", () => {
const wrapper = getWrapper({
ViewingRoom: () => ({
title: "Example Viewing Room",
status: "closed",
}),
Partner: () => ({
name: "Example Partner Name",
}),
})

const html = wrapper.html()

expect(html).toContain("Example Viewing Room")
expect(html).toContain("Example Partner Name")
expect(html).toContain("Closed")
})
})
6 changes: 3 additions & 3 deletions src/v2/Apps/Show/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const routes: RouteConfig[] = [
$sizes: [ArtworkSizes]
$sort: String
) {
show(id: $slug) {
show(id: $slug) @principalField {
...ShowApp_show
@arguments(
acquireable: $acquireable
Expand Down Expand Up @@ -65,7 +65,7 @@ export const routes: RouteConfig[] = [
},
query: graphql`
query routes_ShowSubAppQuery($slug: String!) {
show(id: $slug) {
show(id: $slug) @principalField {
...ShowSubApp_show
}
}
Expand All @@ -79,7 +79,7 @@ export const routes: RouteConfig[] = [
},
query: graphql`
query routes_ShowInfoQuery($slug: String!) {
show(id: $slug) {
show(id: $slug) @principalField {
...ShowInfo_show
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Box, Flex, Link, MediumCard, Sans, Spacer } from "@artsy/palette"
import { ViewingRoomsFeaturedRail_featuredViewingRooms } from "v2/__generated__/ViewingRoomsFeaturedRail_featuredViewingRooms.graphql"
import { createFragmentContainer, graphql } from "react-relay"
import { ViewingRoomCarousel } from "./ViewingRoomCarousel"
import { getTagProps } from "../Components/ViewingRoomsLatestGrid"
import { getTagProps } from "v2/Components/ViewingRoomCard"
import { crop } from "v2/Utils/resizer"

interface ViewingRoomsFeaturedRailProps {
Expand Down

0 comments on commit bc771e1

Please sign in to comment.