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

feat(ONYX-369): navigate to create alerts instead of filers #9350

Merged
merged 6 commits into from
Oct 4, 2023
Merged
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
74 changes: 63 additions & 11 deletions src/app/Components/Artist/ArtistArtworks/ArtistArtworks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
} from "@artsy/palette-mobile"
import { ArtistArtworks_artist$data } from "__generated__/ArtistArtworks_artist.graphql"
import { ArtistArtworksFilterHeader } from "app/Components/Artist/ArtistArtworks/ArtistArtworksFilterHeader"
import { CreateSavedSearchModal } from "app/Components/Artist/ArtistArtworks/CreateSavedSearchModal"
import { useCreateSavedSearchModalFilters } from "app/Components/Artist/ArtistArtworks/hooks/useCreateSavedSearchModalFilters"
import { useShowArtworksFilterModal } from "app/Components/Artist/ArtistArtworks/hooks/useShowArtworksFilterModal"
import { ArtworkFilterNavigator, FilterModalMode } from "app/Components/ArtworkFilter"
import { Aggregations, FilterArray } from "app/Components/ArtworkFilter/ArtworkFilterHelpers"
Expand All @@ -34,7 +36,7 @@ import {
ON_END_REACHED_THRESHOLD_MASONRY,
} from "app/utils/masonryHelpers"
import { Schema } from "app/utils/track"
import React, { useCallback, useEffect, useMemo } from "react"
import React, { useCallback, useEffect, useMemo, useState } from "react"
import { RelayPaginationProp, createPaginationContainer, graphql } from "react-relay"
import { useTracking } from "react-tracking"

Expand All @@ -52,12 +54,15 @@ const ArtworksGrid: React.FC<ArtworksGridProps> = ({
searchCriteria,
...props
}) => {
const [isCreateAlertModalVisible, setIsCreateAlertModalVisible] = useState(false)

const { showFilterArtworksModal, openFilterArtworksModal, closeFilterArtworksModal } =
useShowArtworksFilterModal({ artist })
const tracking = useTracking()
const space = useSpace()
const { width } = useScreenDimensions()
const showCreateAlertAtEndOfList = useFeatureFlag("ARShowCreateAlertInArtistArtworksListFooter")
const enableAlertsFilters = useFeatureFlag("AREnableAlertsFilters")
const artworks = useMemo(() => extractNodes(artist.artworks), [artist.artworks])
const appliedFilters = ArtworksFiltersStore.useStoreState((state) => state.appliedFilters)

Expand Down Expand Up @@ -95,6 +100,13 @@ const ArtworksGrid: React.FC<ArtworksGridProps> = ({
setInitialFilterStateAction(filters)
}, [])

const { savedSearchEntity, attributes } = useCreateSavedSearchModalFilters({
entityId: artist.internalID!,
entityName: artist.name ?? "",
entitySlug: artist.slug!,
entityOwnerType: OwnerType.artist,
})

const trackClear = (id: string, slug: string) => {
tracking.trackEvent({
action_name: "clearFilters",
Expand All @@ -106,6 +118,10 @@ const ArtworksGrid: React.FC<ArtworksGridProps> = ({
})
}

const handleCompleteSavedSearch = () => {
// TODO: Get the new count of the artist saved alerts
}
Comment on lines +121 to +123
Copy link
Member Author

Choose a reason for hiding this comment

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


const shouldDisplaySpinner = !!artworks.length && !!relay.isLoading() && !!relay.hasMore()

const loadMore = useCallback(() => {
Expand All @@ -122,15 +138,16 @@ const ArtworksGrid: React.FC<ArtworksGridProps> = ({
icon={<BellIcon />}
size="small"
onPress={() => {
openFilterArtworksModal("createAlert")

tracking.trackEvent({
action: ActionType.tappedCreateAlert,
context_screen_owner_type: OwnerType.artist,
context_screen_owner_id: artist.internalID,
context_screen_owner_slug: artist.slug,
context_module: ContextModule.artistArtworksGridEnd,
})
// Could be useful to differenciate between the two at a later point
tracking.trackEvent(
tracks.tappedCreateAlert({ artistId: artist.internalID, artistSlug: artist.slug })
)

if (enableAlertsFilters) {
setIsCreateAlertModalVisible(true)
} else {
openFilterArtworksModal("createAlert")
}
}}
>
Create Alert
Expand All @@ -157,6 +174,7 @@ const ArtworksGrid: React.FC<ArtworksGridProps> = ({
<CreateAlertButton />

<Spacer y={6} />

<ArtworkFilterNavigator
{...props}
id={artist.internalID}
Expand All @@ -168,6 +186,17 @@ const ArtworksGrid: React.FC<ArtworksGridProps> = ({
mode={FilterModalMode.ArtistArtworks}
shouldShowCreateAlertButton
/>

{!!enableAlertsFilters && (
<CreateSavedSearchModal
aggregations={(artist.aggregations?.aggregations as Aggregations) || []}
attributes={attributes}
closeModal={() => setIsCreateAlertModalVisible(false)}
entity={savedSearchEntity}
onComplete={handleCompleteSavedSearch}
visible={isCreateAlertModalVisible}
/>
)}
</Tabs.ScrollView>
)
}
Expand Down Expand Up @@ -245,7 +274,10 @@ const ArtworksGrid: React.FC<ArtworksGridProps> = ({
ListHeaderComponentStyle={{ zIndex: 1 }}
ListHeaderComponent={
<Tabs.SubTabBar>
<ArtistArtworksFilterHeader artist={artist} />
<ArtistArtworksFilterHeader
artist={artist}
showCreateAlertModal={() => setIsCreateAlertModalVisible(true)}
/>
</Tabs.SubTabBar>
}
ListFooterComponent={<ListFooterComponenet />}
Expand All @@ -261,6 +293,16 @@ const ArtworksGrid: React.FC<ArtworksGridProps> = ({
mode={FilterModalMode.ArtistArtworks}
shouldShowCreateAlertButton
/>
{!!enableAlertsFilters && (
<CreateSavedSearchModal
aggregations={(artist.aggregations?.aggregations as Aggregations) || []}
attributes={attributes}
closeModal={() => setIsCreateAlertModalVisible(false)}
entity={savedSearchEntity}
onComplete={handleCompleteSavedSearch}
visible={isCreateAlertModalVisible}
/>
)}
</>
)
}
Expand Down Expand Up @@ -350,3 +392,13 @@ export default createPaginationContainer(
`,
}
)

const tracks = {
tappedCreateAlert: ({ artistId, artistSlug }: { artistId: string; artistSlug: string }) => ({
action: ActionType.tappedCreateAlert,
context_screen_owner_type: OwnerType.artist,
context_screen_owner_id: artistId,
context_screen_owner_slug: artistSlug,
context_module: ContextModule.artistArtworksGridEnd,
}),
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ import { SavedSearchButtonV2 } from "app/Components/Artist/ArtistArtworks/SavedS
import { useShowArtworksFilterModal } from "app/Components/Artist/ArtistArtworks/hooks/useShowArtworksFilterModal"
import { useSelectedFiltersCount } from "app/Components/ArtworkFilter/useArtworkFilters"
import { ArtworksFilterHeader } from "app/Components/ArtworkGrids/ArtworksFilterHeader"
import { useFeatureFlag } from "app/utils/hooks/useFeatureFlag"
import { graphql, useFragment } from "react-relay"

interface ArtistArtworksFilterProps {
artist: ArtistArtworksFilterHeader_artist$key
showCreateAlertModal: () => void
}

export const ArtistArtworksFilterHeader: React.FC<ArtistArtworksFilterProps> = ({ artist }) => {
export const ArtistArtworksFilterHeader: React.FC<ArtistArtworksFilterProps> = ({
artist,
showCreateAlertModal,
}) => {
const enableAlertsFilters = useFeatureFlag("AREnableAlertsFilters")

const data = useFragment(
graphql`
fragment ArtistArtworksFilterHeader_artist on Artist {
Expand All @@ -27,14 +34,22 @@ export const ArtistArtworksFilterHeader: React.FC<ArtistArtworksFilterProps> = (
return (
<Box backgroundColor="white">
<ArtworksFilterHeader
onFilterPress={() => openFilterArtworksModal("sortAndFilter")}
onFilterPress={() => {
openFilterArtworksModal("sortAndFilter")
}}
selectedFiltersCount={appliedFiltersCount}
childrenPosition="left"
>
<SavedSearchButtonV2
artistId={data.internalID}
artistSlug={data.slug}
onPress={() => openFilterArtworksModal("createAlert")}
onPress={() => {
if (enableAlertsFilters) {
showCreateAlertModal()
} else {
openFilterArtworksModal("createAlert")
}
}}
/>
</ArtworksFilterHeader>
</Box>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ScreenOwnerType } from "@artsy/cohesion"
import { getUnitedSelectedAndAppliedFilters } from "app/Components/ArtworkFilter/ArtworkFilterHelpers"
import { ArtworksFiltersStore } from "app/Components/ArtworkFilter/ArtworkFilterStore"
import { getSearchCriteriaFromFilters } from "app/Components/ArtworkFilter/SavedSearch/searchCriteriaHelpers"
import { SavedSearchEntity } from "app/Components/ArtworkFilter/SavedSearch/types"

// A hook that returns the required props to be injected in order to use the CreateSavedSearchModal
export const useCreateSavedSearchModalFilters = ({
entityId,
entitySlug,
entityName,
entityOwnerType,
}: {
entityId: string
entitySlug: string
entityName: string
entityOwnerType: ScreenOwnerType
}) => {
const savedSearchEntity: SavedSearchEntity = {
artists: [{ id: entityId!, name: entityName! }],
owner: {
type: entityOwnerType,
id: entityId!,
slug: entitySlug!,
},
}

const filterState = ArtworksFiltersStore.useStoreState((state) => state)
const unitedFilters = getUnitedSelectedAndAppliedFilters(filterState)
const attributes = getSearchCriteriaFromFilters(savedSearchEntity, unitedFilters)

return {
attributes,
savedSearchEntity,
}
}
21 changes: 13 additions & 8 deletions src/app/Components/ArtworkFilter/ArtworkFilterNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { WaysToBuyOptionsScreen } from "app/Components/ArtworkFilter/Filters/Way
import { YearOptionsScreen } from "app/Components/ArtworkFilter/Filters/YearOptions"
import { FancyModal } from "app/Components/FancyModal/FancyModal"
import { GlobalStore } from "app/store/GlobalStore"
import { useFeatureFlag } from "app/utils/hooks/useFeatureFlag"
import { OwnerEntityTypes, PageNames } from "app/utils/track/schema"
import { useLocalizedUnit } from "app/utils/useLocalizedUnit"
import { useEffect, useState } from "react"
Expand Down Expand Up @@ -122,6 +123,8 @@ export const ArtworkFilterNavigator: React.FC<ArtworkFilterProps> = (props) => {
)
const filterTypeState = ArtworksFiltersStore.useStoreState((state) => state.filterType)

const enableAlertsFilters = useFeatureFlag("AREnableAlertsFilters")

const applyFiltersAction = ArtworksFiltersStore.useStoreActions(
(action) => action.applyFiltersAction
)
Expand Down Expand Up @@ -394,14 +397,16 @@ export const ArtworkFilterNavigator: React.FC<ArtworkFilterProps> = (props) => {
shouldShowCreateAlertButton={shouldShowCreateAlertButton}
/>

<CreateSavedSearchModal
visible={isCreateAlertModalVisible}
entity={savedSearchEntity}
closeModal={() => setIsCreateAlertModalVisible(false)}
onComplete={exitModal}
attributes={attributes}
aggregations={filterState.aggregations}
/>
{!!enableAlertsFilters && (
<CreateSavedSearchModal
visible={isCreateAlertModalVisible}
entity={savedSearchEntity}
closeModal={() => setIsCreateAlertModalVisible(false)}
onComplete={exitModal}
attributes={attributes}
aggregations={filterState.aggregations}
/>
)}
</Flex>
</FancyModal>
</NavigationContainer>
Expand Down