-
Notifications
You must be signed in to change notification settings - Fork 581
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: Infer artist series when creating alert form artwork screen #9631
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ import { | |
SavedSearchEntityArtist, | ||
SearchCriteriaAttributes, | ||
} from "app/Components/ArtworkFilter/SavedSearch/types" | ||
import { extractNodes } from "app/utils/extractNodes" | ||
import { useFeatureFlag } from "app/utils/hooks/useFeatureFlag" | ||
import { compact } from "lodash" | ||
import { graphql, useFragment } from "react-relay" | ||
|
||
|
@@ -30,6 +32,13 @@ export const CreateArtworkAlertModal: React.FC<CreateArtworkAlertModalProps> = ( | |
const data = useFragment<CreateArtworkAlertModalProps["artwork"]>( | ||
graphql` | ||
fragment CreateArtworkAlertModal_artwork on Artwork { | ||
artistSeriesConnection(first: 5) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using 5 as the maximum number of artist series used when creating an alert would cover 99.98% of the cases.(context: artsy/force#13244 (comment)) |
||
edges { | ||
node { | ||
slug | ||
} | ||
} | ||
} | ||
title | ||
internalID | ||
slug | ||
|
@@ -52,38 +61,40 @@ export const CreateArtworkAlertModal: React.FC<CreateArtworkAlertModalProps> = ( | |
artwork | ||
) | ||
|
||
const artworkAlert = useComputeArtworkAlertProps(data) | ||
|
||
const { isEligibleToCreateAlert } = data | ||
|
||
if (!isEligibleToCreateAlert) { | ||
return null | ||
} | ||
|
||
const artworkAlert = computeArtworkAlertProps(data) | ||
if (!artworkAlert) { | ||
return null | ||
} | ||
Comment on lines
+72
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactoring this component to be able to remove the forbidden non-null assertions. |
||
|
||
return ( | ||
<CreateSavedSearchModal | ||
visible={visible} | ||
entity={artworkAlert.entity!} | ||
attributes={artworkAlert.attributes!} | ||
aggregations={artworkAlert.aggregations!} | ||
entity={artworkAlert.entity} | ||
attributes={artworkAlert.attributes} | ||
aggregations={artworkAlert.aggregations} | ||
closeModal={onClose} | ||
contextModule={contextModule} | ||
currentArtworkID={data.internalID} | ||
/> | ||
) | ||
} | ||
|
||
export const computeArtworkAlertProps = ( | ||
export const useComputeArtworkAlertProps = ( | ||
artwork: CreateArtworkAlertModal_artwork$data | BrowseSimilarWorks_artwork$data | ||
) => { | ||
const enableArtistSeriesFilter = useFeatureFlag("AREnableArtistSeriesFilter") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still an open discussion whether to use a second feature flag here (Slack Thread) |
||
|
||
const { isEligibleToCreateAlert } = artwork | ||
|
||
if (!isEligibleToCreateAlert) { | ||
return { | ||
entity: null, | ||
attributes: null, | ||
aggregations: null, | ||
} | ||
return null | ||
} | ||
|
||
let aggregations: Aggregations = [] | ||
|
@@ -93,7 +104,7 @@ export const computeArtworkAlertProps = ( | |
const attributionClass = compact([artwork?.attributionClass?.internalID]) | ||
const formattedArtists: SavedSearchEntityArtist[] = artists.map((artist) => ({ | ||
id: artist.internalID, | ||
name: artist.name!, | ||
name: artist.name || "", | ||
})) | ||
|
||
const entity: SavedSearchEntity = { | ||
|
@@ -121,10 +132,15 @@ export const computeArtworkAlertProps = ( | |
] | ||
} | ||
|
||
const artistSeriesIDs = enableArtistSeriesFilter | ||
? extractNodes(artwork?.artistSeriesConnection).map((series) => series.slug) | ||
: [] | ||
|
||
const attributes: SearchCriteriaAttributes = { | ||
artistIDs: formattedArtists.map((artist) => artist.id), | ||
attributionClass, | ||
additionalGeneIDs, | ||
artistSeriesIDs, | ||
} | ||
|
||
return { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { toTitleCase } from "@artsy/to-title-case" | ||
import { | ||
aggregationForFilter, | ||
Aggregations, | ||
|
@@ -156,6 +157,16 @@ export const extractAdditionalGeneIDsPills = (values: string[]): SavedSearchPill | |
}) | ||
} | ||
|
||
export const extractPillFromArtistSeriesIDs = (values: string[]): SavedSearchPill[] => { | ||
return values.map((value) => { | ||
return { | ||
label: toTitleCase(value.replaceAll("-", " ")), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't ideal, but it should be good enough for now. We have already moved the pill/label generation to Metaphysics and will remove this code soon in favor of using the backend-generated labels. Because of this, I have decided not to write any additional code to make the name of the artist series accessible here and use this quick workaround until removing this code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree with this, let's push to work on the migration asap. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also, do you mind if you add a test for this as we do for other existing extractors |
||
value, | ||
paramName: SearchCriteria.artistSeriesIDs, | ||
} | ||
}) | ||
} | ||
|
||
export const extractPriceRangePill = (value: string): SavedSearchPill => { | ||
const { min, max } = parseRange(value) | ||
|
||
|
@@ -239,6 +250,10 @@ export const extractPillsFromCriteria = ( | |
return extractAdditionalGeneIDsPills(paramValue) | ||
} | ||
|
||
if (paramName === SearchCriteria.artistSeriesIDs) { | ||
return extractPillFromArtistSeriesIDs(paramValue) | ||
} | ||
|
||
// Extract label from aggregations | ||
if (shouldExtractValueNamesFromAggregation.includes(paramName)) { | ||
return extractPillFromAggregation(paramName, paramValue, aggregations) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: I would avoid this in favour of using our own
__globalStoreTestUtils__?.injectFeatureFlags
helper.